本文整理汇总了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)
示例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')
示例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()
示例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")
示例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()
示例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()
示例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)
示例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))
示例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]
示例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
示例11: __setstate__
# 需要导入模块: from dbm import dumb [as 别名]
# 或者: from dbm.dumb import open [as 别名]
def __setstate__(self, d):
self.__dict__.update(d)
self.open()
示例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='')
示例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()
示例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()
示例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()