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


Python dbm.whichdb方法代码示例

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


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

示例1: test_compat_pickle

# 需要导入模块: import dbm [as 别名]
# 或者: from dbm import whichdb [as 别名]
def test_compat_pickle(self):
        tests = [
            (range(1, 7), '__builtin__', 'xrange'),
            (map(int, '123'), 'itertools', 'imap'),
            (functools.reduce, '__builtin__', 'reduce'),
            (dbm.whichdb, 'whichdb', 'whichdb'),
            (Exception(), 'exceptions', 'Exception'),
            (collections.UserDict(), 'UserDict', 'IterableUserDict'),
            (collections.UserList(), 'UserList', 'UserList'),
            (collections.defaultdict(), 'collections', 'defaultdict'),
        ]
        for val, mod, name in tests:
            for proto in range(3):
                with self.subTest(type=type(val), proto=proto):
                    pickled = self.dumps(val, proto)
                    self.assertIn(('c%s\n%s' % (mod, name)).encode(), pickled)
                    self.assertIs(type(self.loads(pickled)), type(val)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:pickletester.py

示例2: test_compat_unpickle

# 需要导入模块: import dbm [as 别名]
# 或者: from dbm import whichdb [as 别名]
def test_compat_unpickle(self):
        # xrange(1, 7)
        pickled = b'\x80\x02c__builtin__\nxrange\nK\x01K\x07K\x01\x87R.'
        unpickled = self.loads(pickled)
        self.assertIs(type(unpickled), range)
        self.assertEqual(unpickled, range(1, 7))
        self.assertEqual(list(unpickled), [1, 2, 3, 4, 5, 6])
        # reduce
        pickled = b'\x80\x02c__builtin__\nreduce\n.'
        self.assertIs(self.loads(pickled), functools.reduce)
        # whichdb.whichdb
        pickled = b'\x80\x02cwhichdb\nwhichdb\n.'
        self.assertIs(self.loads(pickled), dbm.whichdb)
        # Exception(), StandardError()
        for name in (b'Exception', b'StandardError'):
            pickled = (b'\x80\x02cexceptions\n' + name + b'\nU\x03ugh\x85R.')
            unpickled = self.loads(pickled)
            self.assertIs(type(unpickled), Exception)
            self.assertEqual(str(unpickled), 'ugh')
        # UserDict.UserDict({1: 2}), UserDict.IterableUserDict({1: 2})
        for name in (b'UserDict', b'IterableUserDict'):
            pickled = (b'\x80\x02(cUserDict\n' + name +
                       b'\no}U\x04data}K\x01K\x02ssb.')
            unpickled = self.loads(pickled)
            self.assertIs(type(unpickled), collections.UserDict)
            self.assertEqual(unpickled, collections.UserDict({1: 2})) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:28,代码来源:pickletester.py

示例3: execute

# 需要导入模块: import dbm [as 别名]
# 或者: from dbm import whichdb [as 别名]
def execute(self, opt_values, pos_args):
        dep_file = opt_values['dep_file']
        db_type = whichdb(dep_file)
        print("DBM type is '%s'" % db_type)
        if db_type in ('dbm', 'dbm.ndbm'): # pragma: no cover
            raise InvalidCommand('ndbm does not support iteration of elements')
        data = dbm.open(dep_file)
        for key, value_str in dbm_iter(data):
            value_dict = json.loads(value_str.decode('utf-8'))
            value_fmt = pprint.pformat(value_dict, indent=4, width=100)
            print("{key} -> {value}".format(key=key, value=value_fmt)) 
开发者ID:pydoit,项目名称:doit,代码行数:13,代码来源:cmd_dumpdb.py

示例4: dep_manager_fixture

# 需要导入模块: import dbm [as 别名]
# 或者: from dbm import whichdb [as 别名]
def dep_manager_fixture(request, dep_class, tmp_path_factory):
    filename = str(tmp_path_factory.mktemp('x', True) / 'testdb')
    dep_file = Dependency(dep_class, filename)
    dep_file.whichdb = whichdb(dep_file.name) if dep_class is DbmDB else 'XXX'
    dep_file.name_ext = db_ext.get(dep_file.whichdb, [''])

    def remove_depfile():
        if not dep_file._closed:
            dep_file.close()
        remove_db(dep_file.name)
    request.addfinalizer(remove_depfile)

    return dep_file 
开发者ID:pydoit,项目名称:doit,代码行数:15,代码来源:conftest.py

示例5: create_cache_with_backend

# 需要导入模块: import dbm [as 别名]
# 或者: from dbm import whichdb [as 别名]
def create_cache_with_backend(name, pkgname='astropy'):
    dldir, urlmapfn = _get_download_cache_locs(pkgname)
    e = dbm.whichdb(urlmapfn)
    if e is not None:
        raise IOError(f"Cache already exists in format {e} ({name} requested)")
    try:
        m = import_module(name)
    except ImportError:
        pytest.skip(f"Module {name} not available")
    with m.open(urlmapfn, "c"):
        pass 
开发者ID:holzschu,项目名称:Carnets,代码行数:13,代码来源:test_data.py


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