From: brian z. <bz...@us...> - 2002-01-07 04:59:54
|
Update of /cvsroot/jython/jython/Lib In directory usw-pr-cvs1:/tmp/cvs-serv18975/Lib Modified Files: dbexts.py Log Message: removed dependence on string mod Index: dbexts.py =================================================================== RCS file: /cvsroot/jython/jython/Lib/dbexts.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dbexts.py 2001/12/29 18:00:15 1.4 --- dbexts.py 2002/01/07 04:59:50 1.5 *************** *** 46,50 **** """ ! import os, string, re __author__ = "brian zimmer (bz...@zi...)" --- 46,50 ---- """ ! import os, re __author__ = "brian zimmer (bz...@zi...)" *************** *** 77,81 **** # Check row entry lengths output = [] ! headers = map(string.upper, list(map(lambda x: x or "", headers))) collen = map(len,headers) output.append(headers) --- 77,81 ---- # Check row entry lengths output = [] ! headers = map(lambda header: header.upper(), list(map(lambda x: x or "", headers))) collen = map(len,headers) output.append(headers) *************** *** 101,105 **** for j in range(len(row)): l.append('%-*s' % (collen[j],row[j])) ! output[i] = string.join(l, " | ") # Insert header separator --- 101,105 ---- for j in range(len(row)): l.append('%-*s' % (collen[j],row[j])) ! output[i] = " | ".join(l) # Insert header separator *************** *** 127,131 **** comments = lambda x: re.compile("{.*?}", re.S).sub("", x, 0) ! class ex_proxy: """Wraps mxODBC to provide proxy support for zxJDBC's additional parameters.""" def __init__(self, c): --- 127,131 ---- comments = lambda x: re.compile("{.*?}", re.S).sub("", x, 0) ! class mxODBCProxy: """Wraps mxODBC to provide proxy support for zxJDBC's additional parameters.""" def __init__(self, c): *************** *** 171,175 **** class dbexts: ! def __init__(self, dbname=None, cfg=None, formatter=console, autocommit=1, jndiname=None, out=None): self.verbose = 1 self.results = None --- 171,175 ---- class dbexts: ! def __init__(self, dbname=None, cfg=None, formatter=console, autocommit=0, jndiname=None, out=None): self.verbose = 1 self.results = None *************** *** 203,207 **** if t.has_key("datahandler"): try: ! datahandlerclass = string.split(t['datahandler'], ".")[-1] self.datahandler = __import__(t['datahandler'], globals(), locals(), datahandlerclass) except: --- 203,207 ---- if t.has_key("datahandler"): try: ! datahandlerclass = t['datahandler'].split(".")[-1] self.datahandler = __import__(t['datahandler'], globals(), locals(), datahandlerclass) except: *************** *** 214,218 **** else: self.db = database.lookup(jndiname) ! self.db.autocommit = 0 elif __OS__ == 'nt': --- 214,218 ---- else: self.db = database.lookup(jndiname) ! self.db.autocommit = self.autocommit elif __OS__ == 'nt': *************** *** 231,234 **** --- 231,235 ---- self.db = database.Connect(self.dburl, dbuser, dbpwd, clear_auto_commit=1) + self.dbname = dbname for a in database.sqltype.keys(): setattr(self, database.sqltype[a], a) *************** *** 256,260 **** if self.datahandler: c.datahandler = self.datahandler(c.datahandler) else: ! c = ex_proxy(c) return c --- 257,261 ---- if self.datahandler: c.datahandler = self.datahandler(c.datahandler) else: ! c = mxODBCProxy(c) return c *************** *** 270,276 **** if f: self.results = choose(self.results is None, [], self.results) + f s = cursor.nextset() ! if hasattr(cursor, "lastrowid"): self.lastrowid = cursor.lastrowid ! if hasattr(cursor, "updatecount"): self.updatecount = cursor.updatecount ! if self.autocommit or cursor is None: self.db.commit() if cursor: cursor.close() --- 271,279 ---- if f: self.results = choose(self.results is None, [], self.results) + f s = cursor.nextset() ! if hasattr(cursor, "lastrowid"): ! self.lastrowid = cursor.lastrowid ! if hasattr(cursor, "updatecount"): ! self.updatecount = cursor.updatecount ! if not self.autocommit or cursor is None: self.db.commit() if cursor: cursor.close() *************** *** 313,317 **** results = [] if comments: sql = comments(sql) ! statements = filter(lambda x: len(x) > 0, map(string.strip, string.split(sql, delim))) for a in statements: self.__execute__(a, params, bindings, maxrows=maxrows) --- 316,321 ---- results = [] if comments: sql = comments(sql) ! statements = filter(lambda x: len(x) > 0, ! map(lambda statement: statement.strip(), sql.split(delim))) for a in statements: self.__execute__(a, params, bindings, maxrows=maxrows) *************** *** 431,436 **** self.bindings = {} ! include = map(lambda x: string.lower(x), include) ! exclude = map(lambda x: string.lower(x), exclude) _verbose = self.dst.verbose --- 435,440 ---- self.bindings = {} ! include = map(lambda x: x.lower(), include) ! exclude = map(lambda x: x.lower(), exclude) _verbose = self.dst.verbose *************** *** 464,468 **** def __filter__(self, values, include, exclude): ! cols = map(string.lower, values) if exclude: cols = filter(lambda x, ex=exclude: x not in ex, cols) --- 468,472 ---- def __filter__(self, values, include, exclude): ! cols = map(lambda col: col.lower(), values) if exclude: cols = filter(lambda x, ex=exclude: x not in ex, cols) *************** *** 491,495 **** def transfer(self, src, where="(1=1)", params=[]): ! sql = "select %s from %s where %s" % (string.join(self.columns, ", "), self.table, where) h, d = src.raw(sql, params) if d: --- 495,499 ---- def transfer(self, src, where="(1=1)", params=[]): ! sql = "select %s from %s where %s" % (", ".join(self.columns), self.table, where) h, d = src.raw(sql, params) if d: *************** *** 519,526 **** w = open(self.filename, mode) if self.includeheaders: ! w.write("%s\n" % (string.join(map(lambda x: x[0], headers), self.delimiter))) if results: for a in results: ! w.write("%s\n" % (string.join(map(self.format, a), self.delimiter))) w.flush() w.close() --- 523,530 ---- w = open(self.filename, mode) if self.includeheaders: ! w.write("%s\n" % (self.delimiter.join(map(lambda x: x[0], headers)))) if results: for a in results: ! w.write("%s\n" % (self.delimiter.join(map(self.format, a)))) w.flush() w.close() *************** *** 577,581 **** idxdict = {} # mxODBC returns a row of None's, so filter it out ! idx = map(lambda x: (x[3], string.strip(x[5]), x[6], x[7], x[8]), filter(lambda x: x[5], self.db.results)) def cckmp(x, y): c = cmp(x[1], y[1]) --- 581,585 ---- idxdict = {} # mxODBC returns a row of None's, so filter it out ! idx = map(lambda x: (x[3], x[5].strip(), x[6], x[7], x[8]), filter(lambda x: x[5], self.db.results)) def cckmp(x, y): c = cmp(x[1], y[1]) *************** *** 612,618 **** for a in self.indices: unique = choose(a[0][0], "non-unique", "unique") ! cname = string.join(map(lambda x: x[4], a), ", ") d.append(" %s index {%s} on (%s)" % (unique, a[0][1], cname)) ! return string.join(d, "\n") class IniParser: --- 616,622 ---- for a in self.indices: unique = choose(a[0][0], "non-unique", "unique") ! cname = ", ".join(map(lambda x: x[4], a)) d.append(" %s index {%s} on (%s)" % (unique, a[0][1], cname)) ! return "\n".join(d) class IniParser: *************** *** 629,633 **** data = fp.readlines() fp.close() ! lines = filter(lambda x: len(x) > 0 and x[0] not in ['#', ';'], map(string.strip, data)) current = None for i in range(len(lines)): --- 633,637 ---- data = fp.readlines() fp.close() ! lines = filter(lambda x: len(x) > 0 and x[0] not in ['#', ';'], map(lambda x: x.strip(), data)) current = None for i in range(len(lines)): *************** *** 658,662 **** d.append(chr(int(100 * random.random()) % 26 + ord('A'))) i += 1 ! return string.join(d, "") class ResultSetRow: --- 662,666 ---- d.append(chr(int(100 * random.random()) % 26 + ord('A'))) i += 1 ! return "".join(d) class ResultSetRow: *************** *** 682,686 **** self.results = results def index(self, i): ! return self.headers.index(string.upper(i)) def __getitem__(self, i): return ResultSetRow(self, self.results[i]) --- 686,690 ---- self.results = results def index(self, i): ! return self.headers.index(i.upper()) def __getitem__(self, i): return ResultSetRow(self, self.results[i]) |