1- #$Id: sessions.py,v 1.4 2003-02-25 10:19:32 richard Exp $
1+ #$Id: sessions.py,v 1.5 2003-06-24 06:47:44 anthonybaxter Exp $
22'''
33This module defines a very basic store that's used by the CGI interface
44to store session and one-time-key information.
@@ -15,6 +15,8 @@ class BasicDatabase:
1515
1616 Keys are id strings, values are automatically marshalled data.
1717 '''
18+ _db_type = None
19+
1820 def __init__ (self , config ):
1921 self .config = config
2022 self .dir = config .DATABASE
@@ -28,8 +30,10 @@ def clear(self):
2830 elif os .path .exists (path + '.db' ): # dbm appends .db
2931 os .remove (path + '.db' )
3032
31- def determine_db_type (self , path ):
32- ''' determine which DB wrote the class file
33+ def cache_db_type (self , path ):
34+ ''' determine which DB wrote the class file, and cache it as an
35+ attribute of __class__ (to allow for subclassed DBs to be
36+ different sorts)
3337 '''
3438 db_type = ''
3539 if os .path .exists (path ):
@@ -40,7 +44,7 @@ def determine_db_type(self, path):
4044 # if the path ends in '.db', it's a dbm database, whether
4145 # anydbm says it's dbhash or not!
4246 db_type = 'dbm'
43- return db_type
47+ self . __class__ . _db_type = db_type
4448
4549 def get (self , infoid , value ):
4650 db = self .opendb ('c' )
@@ -93,7 +97,10 @@ def opendb(self, mode):
9397 '''
9498 # figure the class db type
9599 path = os .path .join (os .getcwd (), self .dir , self .name )
96- db_type = self .determine_db_type (path )
100+ if self ._db_type is None :
101+ self .cache_db_type (path )
102+
103+ db_type = self ._db_type
97104
98105 # new database? let anydbm pick the best dbm
99106 if not db_type :
0 commit comments