當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。