本文整理汇总了Python中whichdb.whichdb方法的典型用法代码示例。如果您正苦于以下问题:Python whichdb.whichdb方法的具体用法?Python whichdb.whichdb怎么用?Python whichdb.whichdb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类whichdb
的用法示例。
在下文中一共展示了whichdb.whichdb方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: import whichdb [as 别名]
# 或者: from whichdb import whichdb [as 别名]
def open(file, flag = 'r', mode = 0666):
# guess the type of an existing database
from whichdb import whichdb
result=whichdb(file)
if result is None:
# db doesn't exist
if 'c' in flag or 'n' in flag:
# file doesn't exist and the new
# flag was used so use default type
mod = _defaultmod
else:
raise error, "need 'c' or 'n' flag to open new db"
elif result == "":
# db type cannot be determined
raise error, "db type could not be determined"
else:
mod = __import__(result)
return mod.open(file, flag, mode)
示例2: __setup_database_connections
# 需要导入模块: import whichdb [as 别名]
# 或者: from whichdb import whichdb [as 别名]
def __setup_database_connections(self, silent): # {{{3
if not silent:
self.logger.info("Using data files %r and %r.", self.metastore_file, self.datastore_file)
# Open the key/value store containing the data blocks.
if not os.path.exists(self.metastore_file):
self.blocks = self.__open_datastore(True)
else:
from whichdb import whichdb
created_by_gdbm = whichdb(self.metastore_file) == 'gdbm'
self.blocks = self.__open_datastore(created_by_gdbm)
# Open an SQLite database connection with manual transaction management.
self.conn = sqlite3.connect(self.metastore_file, isolation_level=None)
# Use the built in row factory to enable named attributes.
self.conn.row_factory = sqlite3.Row
# Return regular strings instead of Unicode objects.
self.conn.text_factory = str
# Don't bother releasing any locks since there's currently no point in
# having concurrent reading/writing of the file system database.
self.conn.execute('PRAGMA locking_mode = EXCLUSIVE')
示例3: open
# 需要导入模块: import whichdb [as 别名]
# 或者: from whichdb import whichdb [as 别名]
def open(file, flag='r', mode=0666):
"""Open or create database at path given by *file*.
Optional argument *flag* can be 'r' (default) for read-only access, 'w'
for read-write access of an existing database, 'c' for read-write access
to a new or existing database, and 'n' for read-write access to a new
database.
Note: 'r' and 'w' fail if the database doesn't exist; 'c' creates it
only if it doesn't exist; and 'n' always creates a new database.
"""
# guess the type of an existing database
from whichdb import whichdb
result=whichdb(file)
if result is None:
# db doesn't exist
if 'c' in flag or 'n' in flag:
# file doesn't exist and the new
# flag was used so use default type
mod = _defaultmod
else:
raise error, "need 'c' or 'n' flag to open new db"
elif result == "":
# db type cannot be determined
raise error, "db type could not be determined"
else:
mod = __import__(result)
return mod.open(file, flag, mode)
示例4: test_whichdb
# 需要导入模块: import whichdb [as 别名]
# 或者: from whichdb import whichdb [as 别名]
def test_whichdb(self):
# Verify that whichdb correctly sniffs the known hash v2 file
self.assertEqual(whichdb.whichdb(findfile("185test.db")), "bsddb185")
示例5: test_anydbm_create
# 需要导入模块: import whichdb [as 别名]
# 或者: from whichdb import whichdb [as 别名]
def test_anydbm_create(self):
# Verify that anydbm.open does *not* create a bsddb185 file
tmpdir = tempfile.mkdtemp()
try:
dbfile = os.path.join(tmpdir, "foo.db")
anydbm.open(dbfile, "c").close()
ftype = whichdb.whichdb(dbfile)
self.assertNotEqual(ftype, "bsddb185")
finally:
shutil.rmtree(tmpdir)
示例6: test_whichdb_name
# 需要导入模块: import whichdb [as 别名]
# 或者: from whichdb import whichdb [as 别名]
def test_whichdb_name(self, name=name, mod=mod):
# Check whether whichdb correctly guesses module name
# for databases opened with module mod.
# Try with empty files first
f = mod.open(_fname, 'c')
f.close()
self.assertEqual(name, whichdb.whichdb(_fname))
# Now add a key
f = mod.open(_fname, 'w')
f["1"] = "1"
f.close()
self.assertEqual(name, whichdb.whichdb(_fname))