def __init__(self, name, path=db_path, prefix_subdir=0, create_new=True, strict_path=True, name_fmt=None): # use prefix subdir with value: if prefix_subdir: path = pathjoin(path, name[:prefix_subdir]) name = name[prefix_subdir:] # verify that name and path are safe/inclusive: if strict_path: valid, common = path_valid(path, pathjoin(path, name)) if not valid: return PathNotValidException('%s is not valid/allowed' % (pathjoin(path, name))) self.dbname = '%s' % (name, ) self.db = db.get(self.dbname, path=path, name_fmt=name_fmt) # create new dir if create_new is True if not self.db and create_new: self.db = db.new(self.dbname, path=path, name_fmt=name_fmt)
name = 'test_db{}'.format(random.random()*1000) print('writing to', name) d = Store(name) for i in range(1000000): u = uuid.uuid4() d[i] = u.bytes def test_reads(name): print('reading', name) d = Store(name) for i in range(1000000): u = uuid.uuid4() d[i] if __name__ == '__main__': """simple tool to display key-value pairs in Store files""" import sys import os import pprint import pickle name = os.path.basename(sys.argv[1]) dirname = os.path.dirname(sys.argv[1]) s = db.get(name=name, path=dirname, read_only=True) k = s.db.firstkey() while k is not None: pprint.pprint(dict([(pickle.loads(k), pickle.loads(s.db[k]))])) k = s.db.nextkey(k)
name = 'test_db{}'.format(random.random() * 1000) print('writing to', name) d = Store(name) for i in range(1000000): u = uuid.uuid4() d[i] = u.bytes def test_reads(name): print('reading', name) d = Store(name) for i in range(1000000): u = uuid.uuid4() d[i] if __name__ == '__main__': """simple tool to display key-value pairs in Store files""" import sys import os import pprint import pickle name = os.path.basename(sys.argv[1]) dirname = os.path.dirname(sys.argv[1]) s = db.get(name=name, path=dirname, read_only=True) k = s.db.firstkey() while k is not None: pprint.pprint(dict([(pickle.loads(k), pickle.loads(s.db[k]))])) k = s.db.nextkey(k)