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