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


Python anydbm.open方法代码示例

本文整理汇总了Python中anydbm.open方法的典型用法代码示例。如果您正苦于以下问题:Python anydbm.open方法的具体用法?Python anydbm.open怎么用?Python anydbm.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在anydbm的用法示例。


在下文中一共展示了anydbm.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_test_run_time_diff

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [as 别名]
def find_test_run_time_diff(test_id, run_time):
    times_db_path = os.path.join(os.path.join(os.getcwd(), '.testrepository'),
                                 'times.dbm')
    if os.path.isfile(times_db_path):
        try:
            test_times = dbm.open(times_db_path)
        except Exception:
            return False
        try:
            avg_runtime = float(test_times.get(str(test_id), False))
        except Exception:
            try:
                avg_runtime = float(test_times[str(test_id)])
            except Exception:
                avg_runtime = False

        if avg_runtime and avg_runtime > 0:
            run_time = float(run_time.rstrip('s'))
            perc_diff = ((run_time - avg_runtime) / avg_runtime) * 100
            return perc_diff
    return False 
开发者ID:openstack,项目名称:os-testr,代码行数:23,代码来源:subunit_trace.py

示例2: open

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [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

示例3: close

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [as 别名]
def close(self):  # 关闭
        for db in self.open.values():
            db.close()
        self.open.clear()







###############################################################################
#                       全局变量定义 - 配置参数
###############################################################################

# Modul initialization    模块的初始化参数. 
开发者ID:hhstore,项目名称:annotated-py-bottle,代码行数:18,代码来源:bottle.py

示例4: keys

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [as 别名]
def keys(self):
        """
        Return a list of usernames in the database.

        :rtype: list
        :returns: The usernames in the database.
        """
        if self.db == None:
            raise AssertionError("DB not open")

        self.lock.acquire()
        try:
            usernames = self.db.keys()
        finally:
            self.lock.release()
        usernames = [u for u in usernames if not u.startswith("--Reserved--")]
        return usernames 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:19,代码来源:basedb.py

示例5: test_071_anydbm

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [as 别名]
def test_071_anydbm():                          # issue #71 {{{1
    import os
    if sys.version_info[0] == 2:
        import anydbm
    else:
        import dbm as anydbm
    # FIXME: determine path to sdcard. like: path = os.environ[""]
    del os.chmod
    for fname in (
        # failed: this is not SL4A application folder...
        # os.path.join("/data/data/com.googlecode.pythonforandroid",
        #              "files", "test_anydbm.dbm"),
        # OK: _chmod work well.
        # os.path.join("/data/local/abc", "test_anydbm.dbm"),
        # failed: _chmod not worked in FAT (SD card)
        os.path.join("/sdcard", "sl4a", "test_anydbm.dbm"),
    ):
        try:
            os.remove(fname + ".dat")
        except:
            pass
        anydbm.open(fname, "n")
        os.remove(fname + ".dat")
    return True 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:26,代码来源:test.py

示例6: test_107_large_file_report

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [as 别名]
def test_107_large_file_report():               # issue #107 {{{1
    import os

    errors = []
    fname = "sample.bin"
    for n in (4294967294, 4294967297):
        fp = open(fname, "wb")
        fp.seek(n)
        fp.write("1".encode("utf-8"))
        fp.close()

        ans = os.path.getsize(fname)
        if ans != (n + 1):
            errors.append("%s(answer) vs %s(expected)" % (ans, n + 1))
        os.remove(fname)

    if not errors:
        return True
    print("can't get size collectly with %s" % str(errors))
    return False 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:22,代码来源:test.py

示例7: __contains__

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [as 别名]
def __contains__(self, username):
        """Check if the database contains the specified username.

        @type username: str
        @param username: The username to check for.

        @rtype: bool
        @return: True if the database contains the username, False
        otherwise.

        """
        if self.db == None:
            raise AssertionError("DB not open")

        self.lock.acquire()
        try:
            return self.db.has_key(username)
        finally:
            self.lock.release() 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:21,代码来源:BaseDB.py

示例8: keys

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [as 别名]
def keys(self):
        """Return a list of usernames in the database.

        @rtype: list
        @return: The usernames in the database.
        """
        if self.db == None:
            raise AssertionError("DB not open")

        self.lock.acquire()
        try:
            usernames = self.db.keys()
        finally:
            self.lock.release()
        usernames = [u for u in usernames if not u.startswith("--Reserved--")]
        return usernames 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:18,代码来源:BaseDB.py

示例9: create_shelf_multi_csv

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [as 别名]
def create_shelf_multi_csv(self, uris, key_col, dialect):
        # sanity check inputs
        assert uris is not None
        assert len(uris) > 0

        # Shelve creates a file with specific database. Using a temp file requires a workaround to open it.
        # dumbdbm creates an empty database file. In this way shelve can open it properly.

        #note: this file is never deleted!
        filename = tempfile.NamedTemporaryFile(delete=True).name
        shelf = shelve.Shelf(dict=dbm.open(filename, 'n'))
        for uri in uris:
            with URLZSource(uri).open() as f_obj:
                f_obj = codecs.getreader("utf-8")(f_obj)
                for row in csv.DictReader(f_obj, dialect=dialect):
                    key_value = row[key_col]
                    key = self.str_hook(key_value)
                    if key is not None:
                        row_dict = dict(row)
                        del row_dict[key_col]
                        existing = shelf.get(key,[])
                        existing.append(row_dict)
                        shelf[key] = existing
        return shelf 
开发者ID:opentargets,项目名称:data_pipeline,代码行数:26,代码来源:Drug.py

示例10: create_shelf_csv

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [as 别名]
def create_shelf_csv(self, uris, key_col, dialect):
        # sanity check inputs
        assert uris is not None
        assert len(uris) > 0

        # Shelve creates a file with specific database. Using a temp file requires a workaround to open it.
        # dumbdbm creates an empty database file. In this way shelve can open it properly.

        #note: this file is never deleted!
        filename = tempfile.NamedTemporaryFile(delete=True).name
        shelf = shelve.Shelf(dict=dbm.open(filename, 'n'))
        for uri in uris:
            with URLZSource(uri).open() as f_obj:
                f_obj = codecs.getreader("utf-8")(f_obj)
                for row in csv.DictReader(f_obj, dialect=dialect):
                    key_value = row[key_col]
                    key = self.str_hook(key_value)
                    if key is not None:
                        if key in shelf:
                            raise ValueError("Duplicate key %s in uri %s" % (key,uri))
                        row_dict = dict(row)
                        del row_dict[key_col]
                        shelf[key] = row_dict
        return shelf 
开发者ID:opentargets,项目名称:data_pipeline,代码行数:26,代码来源:Drug.py

示例11: open

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [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

示例12: __init__

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [as 别名]
def __init__(self, filename, flag='c', protocol=None, writeback=False):
        import anydbm
        Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback) 
开发者ID:glmcdona,项目名称:meddle,代码行数:5,代码来源:shelve.py

示例13: open

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [as 别名]
def open(filename, flag='c', protocol=None, writeback=False):
    """Open a persistent dictionary for reading and writing.

    The filename parameter is the base filename for the underlying
    database.  As a side-effect, an extension may be added to the
    filename and more than one file may be created.  The optional flag
    parameter has the same interpretation as the flag parameter of
    anydbm.open(). The optional protocol parameter specifies the
    version of the pickle protocol (0, 1, or 2).

    See the module's __doc__ string for an overview of the interface.
    """

    return DbfilenameShelf(filename, flag, protocol, writeback) 
开发者ID:glmcdona,项目名称:meddle,代码行数:16,代码来源:shelve.py

示例14: test_open_existing_hash

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [as 别名]
def test_open_existing_hash(self):
        # Verify we can open a file known to be a hash v2 file
        db = bsddb185.hashopen(findfile("185test.db"))
        self.assertEqual(db["1"], "1")
        db.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_bsddb185.py

示例15: test_anydbm_create

# 需要导入模块: import anydbm [as 别名]
# 或者: from anydbm import open [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


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