"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "roundup/backends/sessions_dbm.py" between
roundup-1.6.1.tar.gz and roundup-2.0.0.tar.gz

About: Roundup is an highly customisable issue-tracking system with command-line, web and e-mail interfaces (written in Python).

sessions_dbm.py  (roundup-1.6.1):sessions_dbm.py  (roundup-2.0.0)
"""This module defines a very basic store that's used by the CGI interface """This module defines a very basic store that's used by the CGI interface
to store session and one-time-key information. to store session and one-time-key information.
Yes, it's called "sessions" - because originally it only defined a session Yes, it's called "sessions" - because originally it only defined a session
class. It's now also used for One Time Key handling too. class. It's now also used for One Time Key handling too.
""" """
__docformat__ = 'restructuredtext' __docformat__ = 'restructuredtext'
import os, marshal, time import os, marshal, time
from cgi import escape from roundup.anypy.html import html_escape as escape
from roundup import hyperdb from roundup import hyperdb
from roundup.i18n import _ from roundup.i18n import _
from roundup.anypy.dbm_ import anydbm, whichdb from roundup.anypy.dbm_ import anydbm, whichdb
class BasicDatabase: class BasicDatabase:
''' Provide a nice encapsulation of an anydbm store. ''' Provide a nice encapsulation of an anydbm store.
Keys are id strings, values are automatically marshalled data. Keys are id strings, values are automatically marshalled data.
''' '''
_db_type = None _db_type = None
skipping to change at line 70 skipping to change at line 71
_marker = [] _marker = []
def get(self, infoid, value, default=_marker): def get(self, infoid, value, default=_marker):
db = self.opendb('c') db = self.opendb('c')
try: try:
if infoid in db: if infoid in db:
values = marshal.loads(db[infoid]) values = marshal.loads(db[infoid])
else: else:
if default != self._marker: if default != self._marker:
return default return default
raise KeyError('No such %s "%s"'%(self.name, escape(infoid))) raise KeyError('No such %s "%s"' % (self.name, escape(infoid)))
return values.get(value, None) return values.get(value, None)
finally: finally:
db.close() db.close()
def getall(self, infoid): def getall(self, infoid):
db = self.opendb('c') db = self.opendb('c')
try: try:
try: try:
d = marshal.loads(db[infoid]) d = marshal.loads(db[infoid])
del d['__timestamp'] del d['__timestamp']
return d return d
except KeyError: except KeyError:
raise KeyError('No such %s "%s"'%(self.name, escape(infoid))) raise KeyError('No such %s "%s"' % (self.name, escape(infoid)))
finally: finally:
db.close() db.close()
def set(self, infoid, **newvalues): def set(self, infoid, **newvalues):
db = self.opendb('c') db = self.opendb('c')
try: try:
if infoid in db: if infoid in db:
values = marshal.loads(db[infoid]) values = marshal.loads(db[infoid])
else: else:
values = {'__timestamp': time.time()} values = {'__timestamp': time.time()}
skipping to change at line 131 skipping to change at line 132
self.cache_db_type(path) self.cache_db_type(path)
db_type = self._db_type db_type = self._db_type
# new database? let anydbm pick the best dbm # new database? let anydbm pick the best dbm
if not db_type: if not db_type:
return anydbm.open(path, 'c') return anydbm.open(path, 'c')
# open the database with the correct module # open the database with the correct module
dbm = __import__(db_type) dbm = __import__(db_type)
return dbm.open(path, mode)
retries_left = 15
while True:
try:
handle = dbm.open(path, mode)
break
except OSError:
# Primarily we want to catch and retry:
# [Errno 11] Resource temporarily unavailable retry
# FIXME: make this more specific
if retries_left < 0:
# We have used up the retries. Reraise the exception
# that got us here.
raise
else:
# delay retry a bit
time.sleep(0.01)
retries_left = retries_left - 1
continue # the while loop
return handle
def commit(self): def commit(self):
pass pass
def close(self): def close(self):
pass pass
def updateTimestamp(self, sessid): def updateTimestamp(self, sessid):
''' don't update every hit - once a minute should be OK ''' ''' don't update every hit - once a minute should be OK '''
sess = self.get(sessid, '__timestamp', None) sess = self.get(sessid, '__timestamp', None)
 End of changes. 4 change blocks. 
4 lines changed or deleted 24 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)