当前位置: 首页>>代码示例>>Python>>正文


Python whichdb.whichdb方法代码示例

本文整理汇总了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) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,代码来源:anydbm.py

示例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') 
开发者ID:SlavikMIPT,项目名称:tgcloud,代码行数:21,代码来源:dedupfs.py

示例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) 
开发者ID:glmcdona,项目名称:meddle,代码行数:31,代码来源:anydbm.py

示例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") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_bsddb185.py

示例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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_bsddb185.py

示例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)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_whichdb.py


注:本文中的whichdb.whichdb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。