jtoolkit-cvs Mailing List for jToolkit (Page 5)
Brought to you by:
davidfraser,
friedelwolff
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(15) |
Oct
(12) |
Nov
|
Dec
(4) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
|
Feb
(100) |
Mar
(27) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <dav...@us...> - 2004-02-09 13:41:38
|
Update of /cvsroot/jtoolkit/jToolkit/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2948 Modified Files: session.py Log Message: added unicode handling for md5, cookies... Index: session.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/web/session.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** session.py 9 Feb 2004 13:28:15 -0000 1.6 --- session.py 9 Feb 2004 13:38:18 -0000 1.7 *************** *** 24,27 **** --- 24,28 ---- def md5hexdigest(text): + if type(text) == unicode: text = text.encode('iso8859') return md5.md5(text).hexdigest() *************** *** 112,116 **** cookiedict = {} for key, morsel in cookie.iteritems(): ! cookiedict[key] = morsel.value return cookiedict --- 113,117 ---- cookiedict = {} for key, morsel in cookie.iteritems(): ! cookiedict[key] = morsel.value.decode('iso8859') return cookiedict *************** *** 120,123 **** --- 121,125 ---- cookie = Cookie.SimpleCookie() for key, value in cookiedict.iteritems(): + if type(value) == unicode: value = value.encode('iso8859') cookie[key] = value # add the cookie headers to req.headers_out |
From: <dav...@us...> - 2004-02-09 13:34:08
|
Update of /cvsroot/jtoolkit/jToolkit/widgets In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1485 Modified Files: widgets.py Log Message: modified gethtml to handle unicode contents/attribs... Index: widgets.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/widgets/widgets.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** widgets.py 9 Feb 2004 12:28:40 -0000 1.6 --- widgets.py 9 Feb 2004 13:30:48 -0000 1.7 *************** *** 35,39 **** def gethtml(self): ! return "<%s %s>%s</%s>\r" % (self.tagname, self.gethtmlattribs(), self.getcontents(), self.tagname) def getcontents(self): --- 35,46 ---- def gethtml(self): ! attribs = self.gethtmlattribs() ! contents = self.getcontents() ! tagname = self.tagname ! if type(attribs) == unicode or type(contents) == unicode: ! tagname = tagname.decode('iso8859') ! if type(attribs) == str: attribs = attribs.decode('iso8859') ! if type(contents) == str: contents = contents.decode('iso8859') ! return u"<%s %s>%s</%s>\r" % (tagname, attribs, contents, tagname) def getcontents(self): |
From: <dav...@us...> - 2004-02-09 13:32:26
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1097 Modified Files: dates.py Log Message: added TODO about Python 2.3 datetime support Index: dates.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/dates.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dates.py 9 Feb 2004 13:22:43 -0000 1.6 --- dates.py 9 Feb 2004 13:29:13 -0000 1.7 *************** *** 24,27 **** --- 24,31 ---- import time + # TODO: support Python 2.3 datetime + # see http://radio.weblogs.com/0124960/2003/09/11.html + # aDateObj = datetime.datetime.fromtimestamp(time.mktime(time.strptime(aDateString, dateParseFormat))) + # we have copied _strptime from Python2.3 so that it can be used in earlier versions if not hasattr(time, 'strptime'): |
From: <dav...@us...> - 2004-02-09 13:31:28
|
Update of /cvsroot/jtoolkit/jToolkit/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv972 Modified Files: session.py Log Message: added support for checking if a user exists by name (e.g. before login) Index: session.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/web/session.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** session.py 9 Feb 2004 12:22:35 -0000 1.5 --- session.py 9 Feb 2004 13:28:15 -0000 1.6 *************** *** 347,354 **** return self.db.singlevalue(sql) ! def userexists(self): """checks whether user username exists""" sql = "select count(*) from users where %s(username)='%s'" % \ ! (self.db.dblowerfn(), self.username.lower()) count = self.db.singlevalue(sql) return count > 0 --- 347,356 ---- return self.db.singlevalue(sql) ! def userexists(self, username=None): """checks whether user username exists""" + if username is None: + username = self.username sql = "select count(*) from users where %s(username)='%s'" % \ ! (self.db.dblowerfn(), username.lower()) count = self.db.singlevalue(sql) return count > 0 |
From: <dav...@us...> - 2004-02-09 13:30:06
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv631 Modified Files: database.py Log Message: added more error logging to help diagnose problems with date parsing Index: database.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/database.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** database.py 9 Feb 2004 13:12:37 -0000 1.12 --- database.py 9 Feb 2004 13:26:54 -0000 1.13 *************** *** 296,300 **** return 'null' if (type(value) == str or type(value) == unicode) and formattype.lower() not in ('', 'attachment'): ! value = dates.parsedate(value, formattype) return dates.dbdatestring(value, self.DBTYPE) elif type(value).__name__ == 'DateTime': --- 296,304 ---- return 'null' if (type(value) == str or type(value) == unicode) and formattype.lower() not in ('', 'attachment'): ! try: ! value = dates.parsedate(value, formattype) ! except: ! self.errorhandler.logerror("Error parsing date: value=%r, formattype=%r" % (value, formattype)) ! raise return dates.dbdatestring(value, self.DBTYPE) elif type(value).__name__ == 'DateTime': |
From: <dav...@us...> - 2004-02-09 13:28:15
|
Update of /cvsroot/jtoolkit/jToolkit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32704 Modified Files: errors.py Log Message: added time trace Index: errors.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/errors.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** errors.py 25 Sep 2003 17:36:55 -0000 1.3 --- errors.py 9 Feb 2004 13:25:01 -0000 1.4 *************** *** 58,61 **** --- 58,66 ---- self.writelog(self.instance.tracefile, msg) + def logtracewithtime(self, msg): + t = time.time() + ms = int((t - int(t))*1000.0) + self.writelog(self.instance.tracefile, ".%03d: %s" % (ms, msg)) + def logaudit(self, msg, recorddict=None): if recorddict is not None: |
From: <dav...@us...> - 2004-02-09 13:25:58
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32290 Modified Files: dates.py Log Message: adjusted pgdateparseformat so time zone is optional, handle pure times properly in dateparser Index: dates.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/dates.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dates.py 9 Feb 2004 12:33:09 -0000 1.5 --- dates.py 9 Feb 2004 13:22:43 -0000 1.6 *************** *** 135,139 **** nosepdateparseformat = "(?P<Y>\d{4})(?P<M>\d{2})(?P<D>\d{2})(?P<h>\d{2})(?P<m>\d{2})(?P<s>\d{2})" # yyyy-mm-dd hh:mi:ss+TZ ! pgdateparseformat = "(?P<Y>\d{4})-(?P<M>\d{2})-(?P<D>\d{2}) (?P<h>\d{2}):(?P<m>\d{2}):(?P<s>\d{2})[+-]\d{2}" # standard parsers stddateparser = dateparser(stddateparseformat) --- 135,139 ---- nosepdateparseformat = "(?P<Y>\d{4})(?P<M>\d{2})(?P<D>\d{2})(?P<h>\d{2})(?P<m>\d{2})(?P<s>\d{2})" # yyyy-mm-dd hh:mi:ss+TZ ! pgdateparseformat = "(?P<Y>\d{4})-(?P<M>\d{2})-(?P<D>\d{2}) (?P<h>\d{2}):(?P<m>\d{2}):(?P<s>\d{2})([+-]\d{2}|)" # standard parsers stddateparser = dateparser(stddateparseformat) *************** *** 159,162 **** --- 159,165 ---- else: timevalue = time.strptime(value, formattype) + # handle pure times properly (otherwise you get a range error from mxDateTime because of zero day) + if timevalue[2] == 0: + timevalue = timevalue[:2] + (1,) + timevalue[3:] return apply(date, timevalue[:6]) except ValueError: |
From: <dav...@us...> - 2004-02-09 13:24:29
|
Update of /cvsroot/jtoolkit/jToolkit/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32040 Modified Files: safeapache.py Log Message: made it an error if we cannot import mod_python modules (no longer need to fake them...) Index: safeapache.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/web/safeapache.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** safeapache.py 14 Oct 2003 15:50:06 -0000 1.4 --- safeapache.py 9 Feb 2004 13:21:14 -0000 1.5 *************** *** 56,59 **** --- 56,60 ---- except: apache = FakeApache() + raise try: *************** *** 61,63 **** --- 62,65 ---- except: util = FakeUtil() + raise |
From: <dav...@us...> - 2004-02-09 13:18:37
|
Update of /cvsroot/jtoolkit/jToolkit/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30874 Modified Files: __init__.py Log Message: removed general dependency on safeapache by moving the import inside the handler function Index: __init__.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/web/__init__.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** __init__.py 14 Oct 2003 15:47:25 -0000 1.6 --- __init__.py 9 Feb 2004 13:15:24 -0000 1.7 *************** *** 20,28 **** import sys - from jToolkit.web import safeapache from jToolkit.web import httpcodes # list of modules in this package ! __all__ = ["safeapache", "server", "session"] # the global list of application servers, used to remember the server based on the fullinstancename --- 20,27 ---- import sys from jToolkit.web import httpcodes # list of modules in this package ! __all__ = ["server", "session"] # the global list of application servers, used to remember the server based on the fullinstancename *************** *** 30,34 **** servers = {} ! logtimes = 0 def logtimetofile(message): --- 29,33 ---- servers = {} ! logtimes = 1 def logtimetofile(message): *************** *** 57,61 **** thread = blank() thread.get_ident = thread_get_ident ! logfilename = '/tmp/threads.log' logtime = logtimetofile else: --- 56,60 ---- thread = blank() thread.get_ident = thread_get_ident ! logfilename = 'c:\\temp\\trace.log' logtime = logtimetofile else: *************** *** 93,96 **** --- 92,97 ---- """the standard handler which locates the instance, creates the server if neccessary, and hands off to it""" logtime('handler start: ' + req.uri) + # import safeapache here to prevent others from importing it + from jToolkit.web import safeapache apache_options = req.get_options() modulename = apache_options['jToolkit.module'] |
From: <dav...@us...> - 2004-02-09 13:17:42
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30716 Modified Files: PyADO.py Log Message: cleaned up blank spaces... Index: PyADO.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/PyADO.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PyADO.py 9 Feb 2004 12:51:52 -0000 1.4 --- PyADO.py 9 Feb 2004 13:14:29 -0000 1.5 *************** *** 286,290 **** def close(self): """Close the cursor now (rather than whenever __del__ is called).""" - # if called before Execute, will fail self.rs.Close() --- 286,289 ---- *************** *** 372,376 **** self.description = self.describefields() return 1 - # do we need this? in case it closes down? # if self.rs.State == 0: self.rs.Open() --- 371,374 ---- *************** *** 420,421 **** --- 418,420 ---- sqlParam = [{'tablename':'tag_storage_defs'}, {'tablename':'tag_ticker_cols'}, {'tablename':'onesec'}] testcase(dsn='dummy', user='Admin', password='',database=database, provider='Microsoft.Jet.OLEDB.4.0', sql=sql, sqlBase=sqlBase, sqlParam=sqlParam) + |
From: <dav...@us...> - 2004-02-09 13:15:50
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30275 Modified Files: database.py Log Message: changed sqlstats to show how many rows where asked for & got Index: database.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/database.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** database.py 9 Feb 2004 13:11:58 -0000 1.11 --- database.py 9 Feb 2004 13:12:37 -0000 1.12 *************** *** 437,441 **** if sql not in self.sqlstats: self.sqlstats[sql] = timecache.timecache(300) ! self.sqlstats[sql][time.localtime(t1)] = ms # handle the result if row is None: --- 437,441 ---- if sql not in self.sqlstats: self.sqlstats[sql] = timecache.timecache(300) ! self.sqlstats[sql][time.localtime(t1)] = (ms, None) # handle the result if row is None: *************** *** 466,470 **** if sql not in self.sqlstats: self.sqlstats[sql] = timecache.timecache(300) ! self.sqlstats[sql][time.localtime(t1)] = ms # handle the result self.setallrowscache(sql, rows, cursor.description) --- 466,470 ---- if sql not in self.sqlstats: self.sqlstats[sql] = timecache.timecache(300) ! self.sqlstats[sql][time.localtime(t1)] = (ms, len(rows)) # handle the result self.setallrowscache(sql, rows, cursor.description) *************** *** 492,496 **** if sql not in self.sqlstats: self.sqlstats[sql] = timecache.timecache(300) ! self.sqlstats[sql][time.localtime(t1)] = ms # handle the result if withdescription: --- 492,496 ---- if sql not in self.sqlstats: self.sqlstats[sql] = timecache.timecache(300) ! self.sqlstats[sql][time.localtime(t1)] = (ms, (minrows, maxrows)) # handle the result if withdescription: |
From: <dav...@us...> - 2004-02-09 13:15:19
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30117 Modified Files: database.py Log Message: added somerow, somerowdicts for when you don't want all of the results... (note: a more complex version of this which was able to skip unwanted rows at the start is an a branch, try-skip-rows but it requires non-standard extensions to the Python DB-API) Index: database.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/database.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** database.py 9 Feb 2004 12:58:31 -0000 1.10 --- database.py 9 Feb 2004 13:11:58 -0000 1.11 *************** *** 473,476 **** --- 473,501 ---- return rows + def somerows(self, sql, minrows=None, maxrows=None, withdescription=0): + """runs sql and retrieves some of the rows""" + # note: since we can't skip rows using the Python DB-API, we just read them and discard... + t1 = time.time() + cursor = self.query(sql) + if minrows is None and maxrows is None: + rows = cursor.fetchall() + elif minrows is None: + rows = cursor.fetchmany(maxrows) + elif maxrows is None: + rows = cursor.fetchall() + rows = rows[minrows:] + else: + rows = cursor.fetchmany(maxrows) + rows = rows[minrows:] + # calculate stats... + ms = (time.time() - t1) * 1000 + if sql not in self.sqlstats: + self.sqlstats[sql] = timecache.timecache(300) + self.sqlstats[sql][time.localtime(t1)] = ms + # handle the result + if withdescription: + return rows, cursor.description + return rows + def singlerowdict(self, sql, keymap=None, valuemap=None): """runs sql, retrieves a row and converts it to a dictionary, using field names as keys *************** *** 485,488 **** --- 510,519 ---- return [self.row2dict(row, description, keymap, valuemap) for row in allrows] + def somerowdicts(self, sql, keymap=None, valuemap=None, minrow=None, maxrow=None): + """runs sql, retrieves indicated rows, converts to dictionaries, using field names as keys + mapping functions can be supplied for keys and values as keymap and valuemap""" + somerows, description = self.somerows(sql, minrow, maxrow, 1) + return [self.row2dict(row, description, keymap, valuemap) for row in somerows] + def rows2dict(self, sql, keynamefield, valuefield, keymap=None, valuemap=None): """runs sql, converts cursor into a dictionary where each row of the cursor |
From: <dav...@us...> - 2004-02-09 13:09:26
|
Update of /cvsroot/jtoolkit/jToolkit/widgets In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28959 Modified Files: grid.py Log Message: updated to set style on Link rather than putting a Font object there for it (for text foreground colors) added more explicit logic in canmerge to make it clearer how to trace errors Index: grid.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/widgets/grid.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** grid.py 14 Oct 2003 09:38:25 -0000 1.4 --- grid.py 9 Feb 2004 13:06:08 -0000 1.5 *************** *** 68,72 **** contents = text else: ! contents = widgets.Link(href, widgets.Font(text, newattribs={'style':style}), {'target':hreftarget}) return table.TableCell(contents, newattribs={'valign':'top','style':style}) --- 68,72 ---- contents = text else: ! contents = widgets.Link(href, text, {'target':hreftarget,'style':style}) return table.TableCell(contents, newattribs={'valign':'top','style':style}) *************** *** 86,92 **** # the links are usable from another row return self.canmerge(widget1.contents, widget2.contents) elif type(widget1) in (str, unicode): return widget1 == widget2 ! return 0 def gethtmlstyle(self, textcolor, backcolor, font): --- 86,103 ---- # the links are usable from another row return self.canmerge(widget1.contents, widget2.contents) + else: + # unknown class... + return 0 + else: + # mismatched class + return 0 elif type(widget1) in (str, unicode): return widget1 == widget2 ! else: ! # unknown type ! return 0 ! else: ! # mismatched types ! return 0 def gethtmlstyle(self, textcolor, backcolor, font): |
From: <dav...@us...> - 2004-02-09 13:01:48
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27762 Modified Files: database.py dbtable.py Log Message: fixed dbtable.rowidparamstring so it works with immutable sequences (tuples) as rowid Index: database.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/database.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** database.py 9 Feb 2004 12:32:09 -0000 1.9 --- database.py 9 Feb 2004 12:58:31 -0000 1.10 *************** *** 187,190 **** --- 187,191 ---- import os os.environ['NLS_LANG'] = self.instance.NLS_LANG + self.errorhandler.logtrace("set NLS_LANG to %r" % self.instance.NLS_LANG) if self.DBTYPE in ('access', 'oracle', 'sqlserver'): self.driver, self.dberror = importPyADO() *************** *** 264,267 **** --- 265,275 ---- raise ValueError, "unknown database type %r in dblowerfn" % (self.DBTYPE) + def dbstrconcat(self, *strexprs): + """returns an expression that concatenates all the string expressions in the list""" + if self.DBTYPE == 'access': + return " + ".join(strexprs) + else: + return " || ".join(strexprs) + def dbstrequalityexpr(self, expr1, expr2): """return a sql expression that returns false if expr1 != expr2, true if expr1 == expr2 *************** *** 347,354 **** elif action == 'append': # this is for appending to text fields... ! updates.append("%s=%s || '\n' || %s" % (key, key, valuerepr)) elif action == 'prepend': # this is for prepending to text fields... ! updates.append("%s=%s || '\n' || %s" % (key, valuerepr, key)) else: raise ValueError, "unknown action %r in update" % action --- 355,362 ---- elif action == 'append': # this is for appending to text fields... ! updates.append("%s=%s" % (key, self.dbstrconcat(key, "'\n'", valuerepr))) elif action == 'prepend': # this is for prepending to text fields... ! updates.append("%s=%s" % (key, self.dbstrconcat(valuerepr, "'\n'", key))) else: raise ValueError, "unknown action %r in update" % action Index: dbtable.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/dbtable.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** dbtable.py 9 Feb 2004 12:24:15 -0000 1.6 --- dbtable.py 9 Feb 2004 12:58:31 -0000 1.7 *************** *** 59,64 **** return "%s=%s" % (self.rowidcols[0], rowid) else: for n in range(len(rowid)): ! if type(rowid[n]) == unicode: rowid[n] = rowid[n].encode('iso8859') return "&".join(["%s=%s" % (self.rowidcols[n], rowid[n]) for n in range(len(self.rowidcols))]) --- 59,66 ---- return "%s=%s" % (self.rowidcols[0], rowid) else: + newrowid = [] for n in range(len(rowid)): ! if type(rowid[n]) == unicode: newrowid.append(rowid[n].encode('iso8859')) ! else: newrowid.append(rowid[n]) return "&".join(["%s=%s" % (self.rowidcols[n], rowid[n]) for n in range(len(self.rowidcols))]) |
From: <dav...@us...> - 2004-02-09 12:55:21
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26453 Modified Files: PyADO.py Log Message: cache the value of self.rs.Fields before looping through (COM attribute accesses are slow!) Index: PyADO.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/PyADO.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PyADO.py 9 Feb 2004 12:37:05 -0000 1.3 --- PyADO.py 9 Feb 2004 12:51:52 -0000 1.4 *************** *** 237,241 **** self.rs.Open(operation, ActiveConnection = self.PassConn) # cache the fields. this must be done before describefields ! self.Fields = [self.rs.Fields.Item(col) for col in range(self.rs.Fields.Count)] # now describe the results self.description = self.describefields() --- 237,242 ---- self.rs.Open(operation, ActiveConnection = self.PassConn) # cache the fields. this must be done before describefields ! rsFields = self.rs.Fields ! self.Fields = [rsFields.Item(col) for col in range(rsFields.Count)] # now describe the results self.description = self.describefields() *************** *** 352,356 **** self.rs = self.rsList[0] # cache the fields. this must be done before describefields ! self.Fields = [self.rs.Fields.Item(col) for col in range(self.rs.Fields.Count)] # initialize the description for the first rowset self.description = self.describefields() --- 353,358 ---- self.rs = self.rsList[0] # cache the fields. this must be done before describefields ! rsFields = self.rs.Fields ! self.Fields = [rsFields.Item(col) for col in range(rsFields.Count)] # initialize the description for the first rowset self.description = self.describefields() *************** *** 365,369 **** self.rs = self.rsList[self.rsListPos] # cache the fields. this must be done before describefields ! self.Fields = [self.rs.Fields.Item(col) for col in range(self.rs.Fields.Count)] # redo the description as this rowset might be different self.description = self.describefields() --- 367,372 ---- self.rs = self.rsList[self.rsListPos] # cache the fields. this must be done before describefields ! rsFields = self.rs.Fields ! self.Fields = [rsFields.Item(col) for col in range(rsFields.Count)] # redo the description as this rowset might be different self.description = self.describefields() |
From: <dav...@us...> - 2004-02-09 12:40:18
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23527 Modified Files: PyADO.py Log Message: moved all field code lookups into a dictionary (why didn't we do this before!) cleaned up spacing Index: PyADO.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/PyADO.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PyADO.py 25 Aug 2003 12:16:45 -0000 1.2 --- PyADO.py 9 Feb 2004 12:37:05 -0000 1.3 *************** *** 45,49 **** database Database name (optional) provider OLE DB Provider name (optional paramater, but required to work)""" - NewConn = Connection() NewConn.connect(dsn,user=user,password=password,host=host,database=database,provider=provider) --- 45,48 ---- *************** *** 102,106 **** else: raise ! def connect(self, dsn,user=None,password=None,host=None,database=None,provider=None): """open the connection. this is called from the connect function outside this class""" --- 101,105 ---- else: raise ! def connect(self, dsn,user=None,password=None,host=None,database=None,provider=None): """open the connection. this is called from the connect function outside this class""" *************** *** 134,142 **** # return whether this succeeded return isConnected ! def cursor(self): """Return a new Cursor Object using the connection.""" return Cursor(self.Conn) ! def close(self): """Close the connection now (rather than whenever __del__ is called). --- 133,141 ---- # return whether this succeeded return isConnected ! def cursor(self): """Return a new Cursor Object using the connection.""" return Cursor(self.Conn) ! def close(self): """Close the connection now (rather than whenever __del__ is called). *************** *** 145,151 **** if any operation is attempted with the connection. The same applies to all cursor objects trying to use the connection.""" ! self.Conn.Close() ! class Cursor: """PyADO cursor, which is used to manage the context of a fetch operation (DatabaseAPI-2.0) --- 144,199 ---- if any operation is attempted with the connection. The same applies to all cursor objects trying to use the connection.""" ! self.Conn.Close() ! ! fieldtypecodes = { \ ! adBigInt: NUMBER, # An 8-byte signed integer (DBTYPE_I8). ! adBinary: BINARY, # A binary value (DBTYPE_BYTES). ! adBoolean: NUMBER, # A Boolean value (DBTYPE_BOOL). ! adBSTR: STRING, # A null-terminated character string (Unicode) (DBTYPE_BSTR). ! adChar: STRING, # A String value (DBTYPE_STR). ! adCurrency: NUMBER, # A currency value (DBTYPE_CY). ! # Currency is a fixed-point number with four digits to the right of the decimal point. ! # It is stored in an 8-byte signed integer scaled by 10,000. ! adDate: DATETIME, # A Date value (DBTYPE_DATE). ! # A date is stored as a Double, the whole part of which ! # is the number of days since December 30, 1899, ! # and the fractional part of which is the fraction of a day. ! adDBDate: DATETIME, # A date value (yyyymmdd) (DBTYPE_DBDATE). ! adDBTime: DATETIME, # A time value (hhmmss) (DBTYPE_DBTIME). ! adDBTimeStamp: DATETIME, # A date-time stamp (yyyymmddhhmmss + billionths/s) (DBTYPE_DBTIMESTAMP). ! adDecimal: NUMBER, # An exact numeric value with a fixed precision and scale (DBTYPE_DECIMAL). ! adDouble: NUMBER, # A double-precision floating point value (DBTYPE_R8). ! adEmpty: UNKNOWN, # I HAVE NO IDEA ! # No value was specified (DBTYPE_EMPTY). ! adError: UNKNOWN, # I HAVE NO IDEA ! # A 32-bit error code (DBTYPE_ERROR). ! adGUID: BINARY, # THINK ABOUT THIS ! # A globally unique identifier (GUID) (DBTYPE_GUID). ! adIDispatch: BINARY, # THINK ABOUT THIS ! # A pointer to an IDispatch interface on an OLE object (DBTYPE_IDISPATCH). ! adInteger: NUMBER, # A 4-byte signed integer (DBTYPE_I4). ! adIUnknown: BINARY, # THINK ABOUT THIS ! # A pointer to an IUnknown interface on an OLE object (DBTYPE_IUNKNOWN). ! adLongVarBinary: BINARY, # A long binary value (Parameter object only). ! adLongVarChar: STRING, # A long String value (Parameter object only). ! adLongVarWChar: STRING, # A long null-terminated string value (Parameter object only). ! adNumeric: NUMBER, # An exact numeric value with a fixed precision and scale (DBTYPE_NUMERIC). ! adSingle: NUMBER, # A single-precision floating point value (DBTYPE_R4). ! adSmallInt: NUMBER, # A 2-byte signed integer (DBTYPE_I2). ! adTinyInt: NUMBER, # A 1-byte signed integer (DBTYPE_I1). ! adUnsignedBigInt: NUMBER, # An 8-byte unsigned integer (DBTYPE_UI8). ! adUnsignedInt: NUMBER, # A 4-byte unsigned integer (DBTYPE_UI4). ! adUnsignedSmallInt: NUMBER, # A 2-byte unsigned integer (DBTYPE_UI2). ! adUnsignedTinyInt: NUMBER, # A 1-byte unsigned integer (DBTYPE_UI1). ! adUserDefined: UNKNOWN, # THINK ABOUT THIS ! # A user-defined variable (DBTYPE_UDT). ! adVarBinary: BINARY, # A binary value (Parameter object only). ! adVarChar: STRING, # A String value (Parameter object only). ! adVariant: UNKNOWN, # An Automation Variant (DBTYPE_VARIANT). ! adVarWChar: STRING, # A null-terminated Unicode character string (Parameter object only). ! adWChar: STRING # A null-terminated Unicode character string (DBTYPE_WSTR). ! } ! class Cursor: """PyADO cursor, which is used to manage the context of a fetch operation (DatabaseAPI-2.0) *************** *** 166,170 **** setoutputsize(size[,column]) used before executeXXX() to set column buffer size [not implemented] """ - def __init__(self, Conn): """Initialises the internal Recordset object from the Connection using win32com""" --- 214,217 ---- *************** *** 176,185 **** self.rsListPos = 0 self.description = [] ! def execute(self, operation, parameters=None): """Prepare and execute a database operation (query or command). Parameters may be provided as sequence or mapping and will be bound to variables in the operation.""" - self.rs = win32com.client.Dispatch("ADODB.Recordset") self.rsList = [self.rs] --- 223,231 ---- self.rsListPos = 0 self.description = [] ! def execute(self, operation, parameters=None): """Prepare and execute a database operation (query or command). Parameters may be provided as sequence or mapping and will be bound to variables in the operation.""" self.rs = win32com.client.Dispatch("ADODB.Recordset") self.rsList = [self.rs] *************** *** 220,302 **** # and a pointer to data of the other type (DBTYPE_VECTOR). fieldtype = fieldtype & (~adVector) ! ! ! type_code = UNKNOWN ! if fieldtype == adBigInt: type_code = NUMBER ! # An 8-byte signed integer (DBTYPE_I8). ! elif fieldtype == adBinary: type_code = BINARY ! # A binary value (DBTYPE_BYTES). ! elif fieldtype == adBoolean: type_code = NUMBER ! # A Boolean value (DBTYPE_BOOL). ! elif fieldtype == adBSTR: type_code = STRING ! # A null-terminated character string (Unicode) (DBTYPE_BSTR). ! elif fieldtype == adChar: type_code = STRING ! # A String value (DBTYPE_STR). ! elif fieldtype == adCurrency: type_code = NUMBER ! # A currency value (DBTYPE_CY). ! # Currency is a fixed-point number with four digits to the right of the decimal point. ! # It is stored in an 8-byte signed integer scaled by 10,000. ! elif fieldtype == adDate: type_code = DATETIME ! # A Date value (DBTYPE_DATE). ! # A date is stored as a Double, the whole part of which ! # is the number of days since December 30, 1899, ! # and the fractional part of which is the fraction of a day. ! elif fieldtype == adDBDate: type_code = DATETIME ! # A date value (yyyymmdd) (DBTYPE_DBDATE). ! elif fieldtype == adDBTime: type_code = DATETIME ! # A time value (hhmmss) (DBTYPE_DBTIME). ! elif fieldtype == adDBTimeStamp: type_code = DATETIME ! # A date-time stamp (yyyymmddhhmmss plus a fraction in billionths) (DBTYPE_DBTIMESTAMP). ! elif fieldtype == adDecimal: type_code = NUMBER ! # An exact numeric value with a fixed precision and scale (DBTYPE_DECIMAL). ! elif fieldtype == adDouble: type_code = NUMBER ! # A double-precision floating point value (DBTYPE_R8). ! elif fieldtype == adEmpty: type_code = UNKNOWN # I HAVE NO IDEA ! # No value was specified (DBTYPE_EMPTY). ! elif fieldtype == adError: type_code = UNKNOWN # I HAVE NO IDEA ! # A 32-bit error code (DBTYPE_ERROR). ! elif fieldtype == adGUID: type_code = BINARY # THINK ABOUT THIS ! # A globally unique identifier (GUID) (DBTYPE_GUID). ! elif fieldtype == adIDispatch: type_code = BINARY # THINK ABOUT THIS ! # A pointer to an IDispatch interface on an OLE object (DBTYPE_IDISPATCH). ! elif fieldtype == adInteger: type_code = NUMBER ! # A 4-byte signed integer (DBTYPE_I4). ! elif fieldtype == adIUnknown: type_code = BINARY # THINK ABOUT THIS ! # A pointer to an IUnknown interface on an OLE object (DBTYPE_IUNKNOWN). ! elif fieldtype == adLongVarBinary: type_code = BINARY ! # A long binary value (Parameter object only). ! elif fieldtype == adLongVarChar: type_code = STRING ! # A long String value (Parameter object only). ! elif fieldtype == adLongVarWChar: type_code = STRING ! # A long null-terminated string value (Parameter object only). ! elif fieldtype == adNumeric: type_code = NUMBER ! # An exact numeric value with a fixed precision and scale (DBTYPE_NUMERIC). ! elif fieldtype == adSingle: type_code = NUMBER ! # A single-precision floating point value (DBTYPE_R4). ! elif fieldtype == adSmallInt: type_code = NUMBER ! # A 2-byte signed integer (DBTYPE_I2). ! elif fieldtype == adTinyInt: type_code = NUMBER ! # A 1-byte signed integer (DBTYPE_I1). ! elif fieldtype == adUnsignedBigInt: type_code = NUMBER ! # An 8-byte unsigned integer (DBTYPE_UI8). ! elif fieldtype == adUnsignedInt: type_code = NUMBER ! # A 4-byte unsigned integer (DBTYPE_UI4). ! elif fieldtype == adUnsignedSmallInt: type_code = NUMBER ! # A 2-byte unsigned integer (DBTYPE_UI2). ! elif fieldtype == adUnsignedTinyInt: type_code = NUMBER ! # A 1-byte unsigned integer (DBTYPE_UI1). ! elif fieldtype == adUserDefined: type_code = UNKNOWN # THINK ABOUT THIS ! # A user-defined variable (DBTYPE_UDT). ! elif fieldtype == adVarBinary: type_code = BINARY ! # A binary value (Parameter object only). ! elif fieldtype == adVarChar: type_code = STRING ! # A String value (Parameter object only). ! elif fieldtype == adVariant: type_code = UNKNOWN ! # An Automation Variant (DBTYPE_VARIANT). ! elif fieldtype == adVarWChar: type_code = STRING ! # A null-terminated Unicode character string (Parameter object only). ! elif fieldtype == adWChar: type_code = STRING ! # A null-terminated Unicode character string (DBTYPE_WSTR). ! internal_size = field.DefinedSize # this may sometimes fail, for example, if there is no record... --- 266,270 ---- # and a pointer to data of the other type (DBTYPE_VECTOR). fieldtype = fieldtype & (~adVector) ! type_code = fieldtypecodes.get(fieldtype, UNKNOWN) internal_size = field.DefinedSize # this may sometimes fail, for example, if there is no record... *************** *** 309,313 **** scale = field.NumericScale null_ok = field.Attributes & adFldMayBeNull - # add this column to the description list description.append((name,type_code,display_size,internal_size, --- 277,280 ---- *************** *** 315,319 **** # return the list of all descriptions return description ! def close(self): """Close the cursor now (rather than whenever __del__ is called).""" --- 282,286 ---- # return the list of all descriptions return description ! def close(self): """Close the cursor now (rather than whenever __del__ is called).""" *************** *** 338,342 **** def fetchall(self): """Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples).""" - # if called before Execute, will fail rows = [] --- 305,308 ---- *************** *** 358,362 **** """Fetch the next set of rows of a query result, returning a sequence of sequences (e.g. a list of tuples). An empty sequence is returned when no more rows are available.""" - # if called before Execute, will fail if size == None: size = self.arraysize --- 324,327 ---- *************** *** 373,377 **** self.rs.MoveNext() return rows ! def executemany(self, operation, parameters=None): """Execute operation (query or command) against all parameter sequences or mappings --- 338,342 ---- self.rs.MoveNext() return rows ! def executemany(self, operation, parameters=None): """Execute operation (query or command) against all parameter sequences or mappings |
From: <dav...@us...> - 2004-02-09 12:36:33
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22581 Modified Files: dates.py Log Message: updated to handle normal struct_time Index: dates.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/dates.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** dates.py 14 Oct 2003 09:30:58 -0000 1.4 --- dates.py 9 Feb 2004 12:33:09 -0000 1.5 *************** *** 181,185 **** elif value is None or value == '': return '' ! elif type(value) == tuple: return time.strftime(dateformat, value) else: --- 181,185 ---- elif value is None or value == '': return '' ! elif type(value) in (tuple, time.struct_time): return time.strftime(dateformat, value) else: |
From: <dav...@us...> - 2004-02-09 12:35:21
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22315 Modified Files: database.py Log Message: modified to store time struct in sqlstats instead of float Index: database.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/database.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** database.py 9 Feb 2004 12:29:26 -0000 1.8 --- database.py 9 Feb 2004 12:32:09 -0000 1.9 *************** *** 429,433 **** if sql not in self.sqlstats: self.sqlstats[sql] = timecache.timecache(300) ! self.sqlstats[sql][t1] = ms # handle the result if row is None: --- 429,433 ---- if sql not in self.sqlstats: self.sqlstats[sql] = timecache.timecache(300) ! self.sqlstats[sql][time.localtime(t1)] = ms # handle the result if row is None: *************** *** 458,462 **** if sql not in self.sqlstats: self.sqlstats[sql] = timecache.timecache(300) ! self.sqlstats[sql][t1] = ms # handle the result self.setallrowscache(sql, rows, cursor.description) --- 458,462 ---- if sql not in self.sqlstats: self.sqlstats[sql] = timecache.timecache(300) ! self.sqlstats[sql][time.localtime(t1)] = ms # handle the result self.setallrowscache(sql, rows, cursor.description) |
From: <dav...@us...> - 2004-02-09 12:32:38
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21631 Modified Files: database.py Log Message: added code to produce statistics on sql queries that are actually run Index: database.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/database.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** database.py 9 Feb 2004 12:23:36 -0000 1.7 --- database.py 9 Feb 2004 12:29:26 -0000 1.8 *************** *** 27,30 **** --- 27,31 ---- import types import atexit + import time try: *************** *** 103,106 **** --- 104,109 ---- self.lower = lower self.dbtypenames = dbtypenames[self.DBTYPE] + # record statistics for optimisation + self.sqlstats = {} # set up caches self.cachetables = [] *************** *** 419,424 **** --- 422,434 ---- return cachedrow, description return cachedrow + t1 = time.time() cursor = self.query(sql) row = cursor.fetchone() + # calculate stats... + ms = (time.time() - t1) * 1000 + if sql not in self.sqlstats: + self.sqlstats[sql] = timecache.timecache(300) + self.sqlstats[sql][t1] = ms + # handle the result if row is None: # return None for each field *************** *** 441,446 **** --- 451,463 ---- return cachedrows, description return cachedrows + t1 = time.time() cursor = self.query(sql) rows = cursor.fetchall() + # calculate stats... + ms = (time.time() - t1) * 1000 + if sql not in self.sqlstats: + self.sqlstats[sql] = timecache.timecache(300) + self.sqlstats[sql][t1] = ms + # handle the result self.setallrowscache(sql, rows, cursor.description) if withdescription: |
From: <dav...@us...> - 2004-02-09 12:31:52
|
Update of /cvsroot/jtoolkit/jToolkit/widgets In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21457 Modified Files: widgets.py Log Message: added some list widgets Index: widgets.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/widgets/widgets.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** widgets.py 9 Feb 2004 12:26:24 -0000 1.5 --- widgets.py 9 Feb 2004 12:28:40 -0000 1.6 *************** *** 141,144 **** --- 141,152 ---- self.overrideattribs(newattribs) + class Item(ContentWidget): + def __init__(self, contents, newattribs = {}): + ContentWidget.__init__(self, "li", contents, newattribs) + + class UList(ContentWidget): + def __init__(self, contents, newattribs = {}): + ContentWidget.__init__(self, "ul", contents, newattribs) + class Option(ContentWidget): def __init__(self, value, description, selected=0): |
From: <dav...@us...> - 2004-02-09 12:29:36
|
Update of /cvsroot/jtoolkit/jToolkit/widgets In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20884 Modified Files: widgets.py Log Message: modified Select object to be a ContentWidget Index: widgets.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/widgets/widgets.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** widgets.py 14 Oct 2003 09:39:48 -0000 1.4 --- widgets.py 9 Feb 2004 12:26:24 -0000 1.5 *************** *** 123,127 **** return self.getcontents() - class Font(ContentWidget): def __init__(self, contents, newattribs={}): --- 123,126 ---- *************** *** 142,146 **** self.overrideattribs(newattribs) ! class Select(Widget): # Represents a combo box or Select type. Parameters include a list of options which are made # available when the user clicks on the down arrow. The value of the selection --- 141,151 ---- self.overrideattribs(newattribs) ! class Option(ContentWidget): ! def __init__(self, value, description, selected=0): ! ContentWidget.__init__(self, "OPTION", description, {'VALUE': value}) ! if selected: ! self.attribs["selected"] = None ! ! class Select(ContentWidget): # Represents a combo box or Select type. Parameters include a list of options which are made # available when the user clicks on the down arrow. The value of the selection *************** *** 150,170 **** # the description as the second element. def __init__(self, newattribs = {}, options = []): ! Widget.__init__(self,"SELECT") ! self.attribs = {'name':'NewCombo', 'value':''} self.overrideattribs(newattribs) - self.options = options - - def getcontents(self): - # Return the html for this combo. and store the result in the output string. - html = "" selectedvalue = self.attribs['value'].lower() ! for value, description in self.options: if type(value) not in (str, unicode): value = str(value) selected = "" ! if value.lower() == selectedvalue: ! selected = " SELECTED" ! html += ' <OPTION VALUE="%s"%s>%s </OPTION>\r' % (value, selected, description) ! return html class Input(Widget): --- 155,168 ---- # the description as the second element. def __init__(self, newattribs = {}, options = []): ! ContentWidget.__init__(self, "SELECT", [], {'name':'NewCombo', 'value':''}) self.overrideattribs(newattribs) selectedvalue = self.attribs['value'].lower() ! for value, description in options: if type(value) not in (str, unicode): value = str(value) selected = "" ! selected = (value.lower() == selectedvalue) ! optionwidget = Option(value, description, selected) ! self.addcontents(optionwidget) class Input(Widget): |
From: <dav...@us...> - 2004-02-09 12:27:34
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20497 Modified Files: dbtable.py Log Message: changed create/drop queries from query to execute (they change the database!) Index: dbtable.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/dbtable.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dbtable.py 14 Oct 2003 15:44:43 -0000 1.5 --- dbtable.py 9 Feb 2004 12:24:15 -0000 1.6 *************** *** 126,130 **** sql += ")" try: ! self.db.query(sql) return 1 except Exception: --- 126,130 ---- sql += ")" try: ! self.db.execute(sql) return 1 except Exception: *************** *** 135,139 **** sql = "drop table %s" % self.tablename try: ! self.db.query(sql) return 1 except Exception: --- 135,139 ---- sql = "drop table %s" % self.tablename try: ! self.db.execute(sql) return 1 except Exception: |
From: <dav...@us...> - 2004-02-09 12:26:49
|
Update of /cvsroot/jtoolkit/jToolkit/data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20348 Modified Files: database.py Log Message: updated caching logic to clear '' caches whenever clearing (we don't know what other tables are involved...) rearranged so all caching code is together Index: database.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/data/database.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** database.py 9 Feb 2004 12:19:59 -0000 1.6 --- database.py 9 Feb 2004 12:23:36 -0000 1.7 *************** *** 115,130 **** def clearcache(self, cachetables): """clears all the caches for the given sql command""" ! if len(cachetables) == 0: ! self.singlerowcaches[''].clear() ! self.allrowscaches[''].clear() ! else: ! for cachetable in cachetables: ! # TODO: handle ripple-through effects... ! if not cachetable in self.cachetables: ! self.singlerowcaches[''].clear() ! self.allrowscaches[''].clear() ! else: ! self.singlerowcaches[cachetable].clear() ! self.allrowscaches[cachetable].clear() def getcachetables(self, sql): --- 115,125 ---- def clearcache(self, cachetables): """clears all the caches for the given sql command""" ! self.singlerowcaches[''].clear() ! self.allrowscaches[''].clear() ! for cachetable in cachetables: ! # TODO: handle ripple-through effects... ! if cachetable in self.cachetables: ! self.singlerowcaches[cachetable].clear() ! self.allrowscaches[cachetable].clear() def getcachetables(self, sql): *************** *** 137,140 **** --- 132,183 ---- return cachetables + def getsinglerowcache(self, sql): + """returns cached single row result for the sql statement""" + cachetables = self.getcachetables(sql) + if len(cachetables) == 0: + cachedrow, description = self.singlerowcaches[''].get(sql, (None, None)) + elif len(cachetables) == 1: + cachedrow, description = self.singlerowcaches.get(cachetables[0], self.singlerowcaches['']).get(sql, (None, None)) + else: + # TODO: check that it's the same for all of them + cachedrow, description = self.singlerowcaches.get(cachetables[0], self.singlerowcaches['']).get(sql, (None, None)) + return cachedrow, description + + def setsinglerowcache(self, sql, cachedrow, description): + """caches single row result for the sql statement""" + cachetables = self.getcachetables(sql) + if len(cachetables) == 0: + self.singlerowcaches[''][sql] = (cachedrow, description) + else: + for cachetable in cachetables: + if cachetable in self.cachetables: + self.singlerowcaches[cachetables][sql] = (cachedrow, description) + else: + self.singlerowcaches[''][sql] = (cachedrow, description) + + def getallrowscache(self, sql): + """returns cached all rows result for the sql statement""" + cachetables = self.getcachetables(sql) + if len(cachetables) == 0: + cachedrows, description = self.allrowscaches[''].get(sql, (None, None)) + elif len(cachetables) == 1: + cachedrows, description = self.allrowscaches.get(cachetables[0], self.allrowscaches['']).get(sql, (None, None)) + else: + # TODO: check that it's the same for all of them + cachedrows, description = self.allrowscaches.get(cachetables[0], self.allrowscaches['']).get(sql, (None, None)) + return cachedrows, description + + def setallrowscache(self, sql, cachedrows, description): + """caches all rows result for the sql statement""" + cachetables = self.getcachetables(sql) + if len(cachetables) == 0: + self.allrowscaches[''][sql] = (cachedrows, description) + else: + for cachetable in cachetables: + if cachetable in self.cachetables: + self.allrowscaches[cachetables][sql] = (cachedrows, description) + else: + self.allrowscaches[''][sql] = (cachedrows, description) + def importdriver(self): if self.DBTYPE == 'oracle' and hasattr(self.instance, 'NLS_LANG'): *************** *** 190,194 **** try: cursor = self.db.cursor() - self.errorhandler.logtrace("uncacheable sql query: " + str(sql)) cursor.execute(sql) self.db.commit() --- 233,236 ---- *************** *** 370,397 **** print - def getsinglerowcache(self, sql): - """returns cached single row result for the sql statement""" - cachetables = self.getcachetables(sql) - if len(cachetables) == 0: - cachedrow, description = self.singlerowcaches[''].get(sql, (None, None)) - elif len(cachetables) == 1: - cachedrow, description = self.singlerowcaches.get(cachetables[0], self.singlerowcaches['']).get(sql, (None, None)) - else: - # TODO: check that it's the same for all of them - cachedrow, description = self.singlerowcaches.get(cachetables[0], self.singlerowcaches['']).get(sql, (None, None)) - return cachedrow, description - - def setsinglerowcache(self, sql, cachedrow, description): - """caches single row result for the sql statement""" - cachetables = self.getcachetables(sql) - if len(cachetables) == 0: - self.singlerowcaches[''][sql] = (cachedrow, description) - else: - for cachetable in cachetables: - if cachetable in self.cachetables: - self.singlerowcaches[cachetables][sql] = (cachedrow, description) - else: - self.singlerowcaches[''][sql] = (cachedrow, description) - def singlerow(self, sql, withdescription=0): """runs sql and retrieves a single row""" --- 412,415 ---- *************** *** 416,443 **** return row[0] - def getallrowscache(self, sql): - """returns cached all rows result for the sql statement""" - cachetables = self.getcachetables(sql) - if len(cachetables) == 0: - cachedrows, description = self.allrowscaches[''].get(sql, (None, None)) - elif len(cachetables) == 1: - cachedrows, description = self.allrowscaches.get(cachetables[0], self.allrowscaches['']).get(sql, (None, None)) - else: - # TODO: check that it's the same for all of them - cachedrows, description = self.allrowscaches.get(cachetables[0], self.allrowscaches['']).get(sql, (None, None)) - return cachedrows, description - - def setallrowscache(self, sql, cachedrows, description): - """caches all rows result for the sql statement""" - cachetables = self.getcachetables(sql) - if len(cachetables) == 0: - self.allrowscaches[''][sql] = (cachedrows, description) - else: - for cachetable in cachetables: - if cachetable in self.cachetables: - self.allrowscaches[cachetables][sql] = (cachedrows, description) - else: - self.allrowscaches[''][sql] = (cachedrows, description) - def allrows(self, sql, withdescription=0): """runs sql and retrieves all rows""" --- 434,437 ---- |
From: <dav...@us...> - 2004-02-09 12:25:48
|
Update of /cvsroot/jtoolkit/jToolkit/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20176 Modified Files: session.py Log Message: updated to make user checking simpler, sql queries more cacheable Index: session.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/web/session.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** session.py 14 Oct 2003 15:48:09 -0000 1.4 --- session.py 9 Feb 2004 12:22:35 -0000 1.5 *************** *** 342,355 **** else: username = username.lower() ! sql = "select passwdhash from users where %s(username)='%s'" % (self.db.dblowerfn(), username) ! try: ! q = self.db.query(sql) ! except IndexError: ! # couldn't find username ! raise ! row = q.fetchone() ! if row is None: raise IndexError, self.localize("user does not exist (%r)") % username ! return row[0] def userexists(self): --- 342,349 ---- else: username = username.lower() ! if not self.userexists(username): raise IndexError, self.localize("user does not exist (%r)") % username ! sql = "select passwdhash from users where %s(username)='%s'" % (self.db.dblowerfn(), username) ! return self.db.singlevalue(sql) def userexists(self): *************** *** 357,362 **** sql = "select count(*) from users where %s(username)='%s'" % \ (self.db.dblowerfn(), self.username.lower()) ! q = self.db.query(sql) ! count = int(q.fetchone()[0]) return count > 0 --- 351,355 ---- sql = "select count(*) from users where %s(username)='%s'" % \ (self.db.dblowerfn(), self.username.lower()) ! count = self.db.singlevalue(sql) return count > 0 |
From: <dav...@us...> - 2004-02-09 12:24:58
|
Update of /cvsroot/jtoolkit/jToolkit/web In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19983 Modified Files: server.py Log Message: added support for specifying cache tables Index: server.py =================================================================== RCS file: /cvsroot/jtoolkit/jToolkit/web/server.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** server.py 14 Oct 2003 15:47:25 -0000 1.7 --- server.py 9 Feb 2004 12:21:43 -0000 1.8 *************** *** 260,277 **** class DBAppServer(AppServer): """basic App Server that also handles connection to the database...""" ! def __init__(self, instance, sessioncache=None, errorhandler=None): """constructs a Server for a given instance, using the given session cache and error handler""" super(DBAppServer, self).__init__(instance, sessioncache, errorhandler) self.instance = instance if not hasattr(self.instance, 'db'): ! self.instance.db = database.dbwrapper(instance, self.errorhandler) class LoginAppServer(DBAppServer): """AppServer that includes a login facility""" ! def __init__(self, instance, sessioncache=None, errorhandler=None, loginpageclass=LoginPage): """constructs a Server for a given instance, using the given session cache and error handler""" if sessioncache is None: sessioncache = session.SessionCache(sessionclass=session.LoginSession) ! super(LoginAppServer, self).__init__(instance, sessioncache, errorhandler) if not hasattr(self.instance, 'checkshift'): self.instance.checkshift = self.checkshift --- 260,277 ---- class DBAppServer(AppServer): """basic App Server that also handles connection to the database...""" ! def __init__(self, instance, sessioncache=None, errorhandler=None, cachetables=None): """constructs a Server for a given instance, using the given session cache and error handler""" super(DBAppServer, self).__init__(instance, sessioncache, errorhandler) self.instance = instance if not hasattr(self.instance, 'db'): ! self.instance.db = database.dbwrapper(instance, self.errorhandler, cachetables) class LoginAppServer(DBAppServer): """AppServer that includes a login facility""" ! def __init__(self, instance, sessioncache=None, errorhandler=None, loginpageclass=LoginPage, cachetables=None): """constructs a Server for a given instance, using the given session cache and error handler""" if sessioncache is None: sessioncache = session.SessionCache(sessionclass=session.LoginSession) ! super(LoginAppServer, self).__init__(instance, sessioncache, errorhandler, cachetables) if not hasattr(self.instance, 'checkshift'): self.instance.checkshift = self.checkshift *************** *** 311,320 **** class MultiAppServer(LoginAppServer): """serves multiple instances in subdirectories...""" ! def __init__(self, instance, sessioncache=None, errorhandler=None, loginpageclass=LoginPage): """constructs the multi-app server""" if sessioncache is None: # we don't need a sessioncache as we don't do login... sessioncache = {} ! super(MultiAppServer, self).__init__(instance, sessioncache, errorhandler, loginpageclass) self.instances = self.instance.instances self.servers = {} --- 311,320 ---- class MultiAppServer(LoginAppServer): """serves multiple instances in subdirectories...""" ! def __init__(self, instance, sessioncache=None, errorhandler=None, loginpageclass=LoginPage, cachetables=None): """constructs the multi-app server""" if sessioncache is None: # we don't need a sessioncache as we don't do login... sessioncache = {} ! super(MultiAppServer, self).__init__(instance, sessioncache, errorhandler, loginpageclass, cachetables) self.instances = self.instance.instances self.servers = {} *************** *** 406,414 **** class SharedLoginMultiAppServer(MultiAppServer): """allows multiple instance to share login credentials...""" ! def __init__(self, instance, sessioncache=None, errorhandler=None, loginpageclass=LoginPage): """constructs the multi-app server""" if sessioncache is None: sessioncache = session.SessionCache(sessionclass=session.LoginSession,sessioncookiename=instance.__name__+'session') ! super(SharedLoginMultiAppServer, self).__init__(instance, sessioncache, errorhandler, loginpageclass) self.instances = self.instance.instances self.servers = {} --- 406,414 ---- class SharedLoginMultiAppServer(MultiAppServer): """allows multiple instance to share login credentials...""" ! def __init__(self, instance, sessioncache=None, errorhandler=None, loginpageclass=LoginPage, cachetables=None): """constructs the multi-app server""" if sessioncache is None: sessioncache = session.SessionCache(sessionclass=session.LoginSession,sessioncookiename=instance.__name__+'session') ! super(SharedLoginMultiAppServer, self).__init__(instance, sessioncache, errorhandler, loginpageclass, cachetables) self.instances = self.instance.instances self.servers = {} |