本文整理汇总了Python中dumbdbm.open方法的典型用法代码示例。如果您正苦于以下问题:Python dumbdbm.open方法的具体用法?Python dumbdbm.open怎么用?Python dumbdbm.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dumbdbm
的用法示例。
在下文中一共展示了dumbdbm.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dumbdbm_creation_mode
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm import open [as 别名]
def test_dumbdbm_creation_mode(self):
try:
old_umask = os.umask(0002)
f = dumbdbm.open(_fname, 'c', 0637)
f.close()
finally:
os.umask(old_umask)
expected_mode = 0635
if os.name != 'posix' or sys.platform == 'cli':
# Windows and IronPython only support setting the read-only attribute.
# This shouldn't fail, but doesn't work like Unix either.
expected_mode = 0666
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
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm 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['1'] = 'hello'
f['2'] = 'hello2'
f.close()
# Mangle the file by adding \r before each newline
with open(_fname + '.dir') as f:
data = f.read()
data = data.replace('\n', '\r\n')
with open(_fname + '.dir', 'wb') as f:
f.write(data)
f = dumbdbm.open(_fname)
self.assertEqual(f['1'], 'hello')
self.assertEqual(f['2'], 'hello2')
f.close()
示例3: test_random
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm 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('abc') * random.randrange(10000)
d[k] = v
f[k] = v
self.assertEqual(f[k], v)
f.close()
f = dumbdbm.open(_fname)
expected = d.items()
expected.sort()
got = f.items()
got.sort()
self.assertEqual(expected, got)
f.close()
示例4: test_dumbdbm_creation_mode
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm import open [as 别名]
def test_dumbdbm_creation_mode(self):
# On platforms without chmod, don't do anything.
if not (hasattr(os, 'chmod') and hasattr(os, 'umask')):
return
try:
old_umask = os.umask(0002)
f = dumbdbm.open(_fname, 'c', 0637)
f.close()
finally:
os.umask(old_umask)
expected_mode = 0635
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 = 0666
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)
示例5: test_line_endings
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm 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['1'] = 'hello'
f['2'] = 'hello2'
f.close()
# Mangle the file by adding \r before each newline
data = open(_fname + '.dir').read()
data = data.replace('\n', '\r\n')
open(_fname + '.dir', 'wb').write(data)
f = dumbdbm.open(_fname)
self.assertEqual(f['1'], 'hello')
self.assertEqual(f['2'], 'hello2')
示例6: test_dumbdbm_creation_mode
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm import open [as 别名]
def test_dumbdbm_creation_mode(self):
try:
old_umask = os.umask(0002)
f = dumbdbm.open(_fname, 'c', 0637)
f.close()
finally:
os.umask(old_umask)
expected_mode = 0635
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 = 0666
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)
示例7: test_line_endings
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm 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['1'] = 'hello'
f['2'] = 'hello2'
f.close()
# Mangle the file by adding \r before each newline
fp = open(_fname + '.dir', 'r+')
data = fp.read()
data = data.replace('\n', '\r\n')
fp.seek(0)
fp.truncate()
fp.write(data)
fp.close()
f = dumbdbm.open(_fname)
self.assertEqual(f['1'], 'hello')
self.assertEqual(f['2'], 'hello2')
f.close()
示例8: upload_dists
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm 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)
示例9: cache_print_errors
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm 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))
示例10: cache_rm
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm 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]
示例11: test_dumbdbm_creation
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm import open [as 别名]
def test_dumbdbm_creation(self):
f = dumbdbm.open(_fname, 'c')
self.assertEqual(f.keys(), [])
for key in self._dict:
f[key] = self._dict[key]
self.read_helper(f)
f.close()
示例12: test_close_twice
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm import open [as 别名]
def test_close_twice(self):
f = dumbdbm.open(_fname)
f['a'] = 'b'
self.assertEqual(f['a'], 'b')
f.close()
f.close()
示例13: test_dumbdbm_modification
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm import open [as 别名]
def test_dumbdbm_modification(self):
self.init_db()
f = dumbdbm.open(_fname, 'w')
self._dict['g'] = f['g'] = "indented"
self.read_helper(f)
f.close()
示例14: test_dumbdbm_read
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm import open [as 别名]
def test_dumbdbm_read(self):
self.init_db()
f = dumbdbm.open(_fname, 'r')
self.read_helper(f)
f.close()
示例15: test_write_write_read
# 需要导入模块: import dumbdbm [as 别名]
# 或者: from dumbdbm import open [as 别名]
def test_write_write_read(self):
# test for bug #482460
f = dumbdbm.open(_fname)
f['1'] = 'hello'
f['1'] = 'hello2'
f.close()
f = dumbdbm.open(_fname)
self.assertEqual(f['1'], 'hello2')
f.close()