[Python-checkins] python/dist/src/Lib whichdb.py,1.12,1.13

montanaro@users.sourceforge.net montanaro@users.sourceforge.net
2002年8月02日 10:12:18 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv12999
Modified Files:
	whichdb.py 
Log Message:
catch the situation where Berkeley DB is used to emulate dbm(3) library
functions. In this case, calling dbm.open("foo", "c") actually creates a
file named "foo.db".
Index: whichdb.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/whichdb.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** whichdb.py	24 Oct 2001 20:33:34 -0000	1.12
--- whichdb.py	2 Aug 2002 17:12:15 -0000	1.13
***************
*** 2,5 ****
--- 2,15 ----
 
 import os
+ import struct
+ 
+ try:
+ import dbm
+ _dbmerror = dbm.error
+ except ImportError:
+ dbm = None
+ # just some sort of valid exception which might be raised in the
+ # dbm test
+ _dbmerror = IOError
 
 def whichdb(filename):
***************
*** 16,21 ****
 """
 
- import struct
- 
 # Check for dbm first -- this has a .pag and a .dir file
 try:
--- 26,29 ----
***************
*** 26,30 ****
 return "dbm"
 except IOError:
! pass
 
 # Check for dumbdbm next -- this has a .dir and and a .dat file
--- 34,51 ----
 return "dbm"
 except IOError:
! # some dbm emulations based on Berkeley DB generate a .db file
! # some do not, but they should be caught by the dbhash checks
! try:
! f = open(filename + os.extsep + "db", "rb")
! f.close()
! # guarantee we can actually open the file using dbm
! # kind of overkill, but since we are dealing with emulations
! # it seems like a prudent step
! if dbm is not None:
! d = dbm.open(filename)
! d.close()
! return "dbm"
! except (IOError, _dbmerror):
! pass
 
 # Check for dumbdbm next -- this has a .dir and and a .dat file

AltStyle によって変換されたページ (->オリジナル) /