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


Python dumb.open方法代码示例

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


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

示例1: test_dumbdbm_creation_mode

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def test_dumbdbm_creation_mode(self):
        try:
            old_umask = os.umask(0o002)
            f = dumbdbm.open(_fname, 'c', 0o637)
            f.close()
        finally:
            os.umask(old_umask)

        expected_mode = 0o635
        if os.name != 'posix':
            # Windows only supports setting the read-only attribute.
            # This shouldn't fail, but doesn't work like Unix either.
            expected_mode = 0o666

        import stat
        st = os.stat(_fname + '.dat')
        self.assertEqual(stat.S_IMODE(st.st_mode), expected_mode)
        st = os.stat(_fname + '.dir')
        self.assertEqual(stat.S_IMODE(st.st_mode), expected_mode) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_dbm_dumb.py

示例2: test_line_endings

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def test_line_endings(self):
        # test for bug #1172763: dumbdbm would die if the line endings
        # weren't what was expected.
        f = dumbdbm.open(_fname)
        f[b'1'] = b'hello'
        f[b'2'] = b'hello2'
        f.close()

        # Mangle the file by changing the line separator to Windows or Unix
        with io.open(_fname + '.dir', 'rb') as file:
            data = file.read()
        if os.linesep == '\n':
            data = data.replace(b'\n', b'\r\n')
        else:
            data = data.replace(b'\r\n', b'\n')
        with io.open(_fname + '.dir', 'wb') as file:
            file.write(data)

        f = dumbdbm.open(_fname)
        self.assertEqual(f[b'1'], b'hello')
        self.assertEqual(f[b'2'], b'hello2') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_dbm_dumb.py

示例3: test_random

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def test_random(self):
        import random
        d = {}  # mirror the database
        for dummy in range(5):
            f = dumbdbm.open(_fname)
            for dummy in range(100):
                k = random.choice('abcdefghijklm')
                if random.random() < 0.2:
                    if k in d:
                        del d[k]
                        del f[k]
                else:
                    v = random.choice((b'a', b'b', b'c')) * random.randrange(10000)
                    d[k] = v
                    f[k] = v
                    self.assertEqual(f[k], v)
            f.close()

            f = dumbdbm.open(_fname)
            expected = sorted((k.encode("latin-1"), v) for k, v in d.items())
            got = sorted(f.items())
            self.assertEqual(expected, got)
            f.close() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:test_dbm_dumb.py

示例4: test_check_closed

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def test_check_closed(self):
        f = dumbdbm.open(_fname, 'c')
        f.close()

        for meth in (partial(operator.delitem, f),
                     partial(operator.setitem, f, 'b'),
                     partial(operator.getitem, f),
                     partial(operator.contains, f)):
            with self.assertRaises(dumbdbm.error) as cm:
                meth('test')
            self.assertEqual(str(cm.exception),
                             "DBM object has already been closed")

        for meth in (operator.methodcaller('keys'),
                     operator.methodcaller('iterkeys'),
                     operator.methodcaller('items'),
                     len):
            with self.assertRaises(dumbdbm.error) as cm:
                meth(f)
            self.assertEqual(str(cm.exception),
                             "DBM object has already been closed") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_dbm_dumb.py

示例5: test_line_endings

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def test_line_endings(self):
        # test for bug #1172763: dumbdbm would die if the line endings
        # weren't what was expected.
        f = dumbdbm.open(_fname)
        f[b'1'] = b'hello'
        f[b'2'] = b'hello2'
        f.close()

        # Mangle the file by changing the line separator to Windows or Unix
        with io.open(_fname + '.dir', 'rb') as file:
            data = file.read()
        if os.linesep == '\n':
            data = data.replace(b'\n', b'\r\n')
        else:
            data = data.replace(b'\r\n', b'\n')
        with io.open(_fname + '.dir', 'wb') as file:
            file.write(data)

        f = dumbdbm.open(_fname)
        self.assertEqual(f[b'1'], b'hello')
        self.assertEqual(f[b'2'], b'hello2')
        f.close() 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:24,代码来源:test_dbm_dumb.py

示例6: test_dumbdbm_read

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def test_dumbdbm_read(self):
        self.init_db()
        f = dumbdbm.open(_fname, 'r')
        self.read_helper(f)
        with self.assertWarnsRegex(DeprecationWarning,
                                   'The database is opened for reading only'):
            f[b'g'] = b'x'
        with self.assertWarnsRegex(DeprecationWarning,
                                   'The database is opened for reading only'):
            del f[b'a']
        # get() works as in the dict interface
        self.assertEqual(f.get(b'b'), self._dict[b'b'])
        self.assertEqual(f.get(b'xxx', b'foo'), b'foo')
        self.assertIsNone(f.get(b'xxx'))
        with self.assertRaises(KeyError):
            f[b'xxx']
        f.close() 
开发者ID:bkerler,项目名称:android_universal,代码行数:19,代码来源:test_dbm_dumb.py

示例7: upload_dists

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def upload_dists(self, distfilenames):
        to_upload = []
        for distfilename in distfilenames:
            if os.path.isfile(distfilename) and \
                    (distfilename.lower().endswith('.whl') or
                     distfilename.lower().endswith('.tar.gzXXX')):
                to_upload.append(distfilename)
            else:
                _logger.debug("skipped %s: not a python distribution",
                              distfilename)
        with contextlib.closing(dumbdbm.open(self.cache, 'c')) as dbm:
            for distfilename in sorted(to_upload, key=_split_filename):
                self.upload_dist(distfilename, dbm) 
开发者ID:OCA,项目名称:maintainer-tools,代码行数:15,代码来源:pypi_upload.py

示例8: cache_print_errors

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def cache_print_errors(self):
        with contextlib.closing(dumbdbm.open(self.cache, 'r')) as dbm:
            for key, value in dbm.items():
                if not self._key_match(key):
                    continue
                if value:
                    wheel = self._key_to_wheel(key)
                    click.echo(u"{}: {}".format(wheel, value)) 
开发者ID:OCA,项目名称:maintainer-tools,代码行数:10,代码来源:pypi_upload.py

示例9: cache_rm

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def cache_rm(self, distfilenames):
        with contextlib.closing(dumbdbm.open(self.cache, 'w')) as dbm:
            for distfilename in distfilenames:
                distfilename = os.path.basename(distfilename)
                key = self._make_key(distfilename)
                if key in dbm:
                    del dbm[key] 
开发者ID:OCA,项目名称:maintainer-tools,代码行数:9,代码来源:pypi_upload.py

示例10: __enter__

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def __enter__(self):
        assert(not self.is_open)
        self.is_open = True
        self._ui.debug('ENTER CALLED ON RUNCONTEXT')
        raw_db = dumb_dbm.open(self.file_context.file_name)
        self.db = shelve.Shelf(raw_db, writeback=True)
        if not hasattr(self, 'partitions'):
            self.partitions = []
        return self 
开发者ID:datarobot,项目名称:batch-scoring,代码行数:11,代码来源:writer.py

示例11: __setstate__

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def __setstate__(self, d):
        self.__dict__.update(d)
        self.open() 
开发者ID:datarobot,项目名称:batch-scoring,代码行数:5,代码来源:writer.py

示例12: open

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def open(self):
        if self.is_open:
            self._ui.debug('OPEN CALLED ON ALREADY OPEN RUNCONTEXT')
            return
        self.is_open = True
        self._ui.debug('OPEN CALLED ON RUNCONTEXT')
        csv.register_dialect('dataset_dialect', **self.dialect)
        csv.register_dialect('writer_dialect', **self.writer_dialect)
        self.dialect = csv.get_dialect('dataset_dialect')
        self.writer_dialect = csv.get_dialect('writer_dialect')
        self.db = shelve.open(self.file_context.file_name, writeback=True)
        if six.PY2:
            self.out_stream = open(self.out_file, 'ab')
        elif six.PY3:
            self.out_stream = open(self.out_file, 'a', newline='') 
开发者ID:datarobot,项目名称:batch-scoring,代码行数:17,代码来源:writer.py

示例13: test_dumbdbm_creation

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def test_dumbdbm_creation(self):
        f = dumbdbm.open(_fname, 'c')
        self.assertEqual(list(f.keys()), [])
        for key in self._dict:
            f[key] = self._dict[key]
        self.read_helper(f)
        f.close() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_dbm_dumb.py

示例14: test_close_twice

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def test_close_twice(self):
        f = dumbdbm.open(_fname)
        f[b'a'] = b'b'
        self.assertEqual(f[b'a'], b'b')
        f.close()
        f.close() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_dbm_dumb.py

示例15: test_dumbdbm_modification

# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def test_dumbdbm_modification(self):
        self.init_db()
        f = dumbdbm.open(_fname, 'w')
        self._dict[b'g'] = f[b'g'] = b"indented"
        self.read_helper(f)
        f.close() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_dbm_dumb.py


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