本文整理汇总了Python中durus.connection.Connection.get_root方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.get_root方法的具体用法?Python Connection.get_root怎么用?Python Connection.get_root使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类durus.connection.Connection
的用法示例。
在下文中一共展示了Connection.get_root方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_oid_reuse
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def check_oid_reuse(self):
# Requires ShelfStorage oid reuse pack semantics
s1 = ClientStorage(address=self.address)
s1.oid_pool_size = 1
c1 = Connection(s1)
r1 = c1.get_root()
s2 = ClientStorage(address=self.address)
s2.oid_pool_size = 1
c2 = Connection(s2)
r2 = c2.get_root()
r1['a'] = PersistentDict()
r1['b'] = PersistentDict()
c1.commit()
c2.abort()
a_oid = r1['a']._p_oid
assert 'a' in r1 and 'b' in r1 and len(r1['b']) == 0
assert 'a' in r2 and 'b' in r2 and len(r2['b']) == 0
del r2['a'] # remove only reference to a
c2.commit()
c2.pack() # force relinquished oid back into availability
sleep(0.5) # Give time for pack to complete
c2.abort()
assert c2.get(a_oid) is None
c1.abort()
assert c1.get(a_oid)._p_is_ghost()
r2['b']['new'] = Persistent()
r2['b']['new'].bogus = 1
c2.commit()
assert c2.get(a_oid) is r2['b']['new']
c1.abort()
assert c1.get(a_oid).__class__ == PersistentDict
r1['b']['new'].bogus
assert c1.get(a_oid).__class__ == Persistent
s1.close()
示例2: _scenario
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def _scenario(self):
c1 = Connection(self._get_storage())
c2 = Connection(self._get_storage())
c1.get_root()['A'] = Persistent()
c1.get_root()['B'] = Persistent()
c1.get_root()['A'].a = 1
c1.commit()
c2.abort()
c1.cache.recent_objects.discard(c1.get_root()['A'])
# Imagine c1 has been running for a while, and
# cache management, for example, has caused the
# cache reference to be weak.
return c1, c2
示例3: __init__
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
class TestBackend:
def __init__(self, filename, mode):
self.mode = mode
if mode == "w":
self.storage = FileStorage(filename)
self.connection = Connection(self.storage)
self.test_db_items = self.connection.get_root()
elif mode == "r":
self.storage = FileStorage(filename)
self.connection = Connection(self.storage)
self.test_db_items = self.connection.get_root()
self.next_rec_num = 0 # Initialise next record counter
self.num_records = len(self.test_db_items)
def __setitem__(self, key, value):
self.test_db_items[key] = value
def __getitem__(self, key):
return self.test_db_items[str(key)]
def __len__(self):
return len(self.test_db_items)
def first(self):
return self.test_db_items[0]
def iteritems(self):
while(self.next_rec_num < self.num_records):
value = self.test_db_items[self.next_rec_num]
self.next_rec_num += 1
yield value
def close(self):
self.connection.commit()
self.storage.close()
def getTestDBItems(self):
return self.test_db_items.values()
示例4: create_durus_publisher
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def create_durus_publisher():
global connection
filename = os.path.join(tempfile.gettempdir(), 'quixote-demo.durus')
print 'Opening %r as a Durus database.' % filename
connection = Connection(FileStorage(filename))
root = connection.get_root()
session_manager = root.get('session_manager', None)
if session_manager is None:
session_manager = PersistentSessionManager()
connection.get_root()['session_manager'] = session_manager
connection.commit()
return Publisher(RootDirectory(),
session_manager=session_manager,
display_exceptions='plain')
示例5: check_oid_reuse_with_invalidation
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def check_oid_reuse_with_invalidation(self):
connection = Connection(ClientStorage(address=self.address))
root = connection.get_root()
root['x'] = Persistent()
connection.commit()
connection = Connection(ClientStorage(address=self.address))
root = connection.get_root()
root['x'] = Persistent()
connection.commit()
connection.pack()
sleep(1) # Make sure pack finishes.
connection = Connection(ClientStorage(address=self.address))
root = connection.get_root()
root['x'] = Persistent()
connection.commit()
示例6: run_trials
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def run_trials():
numTrials = 3000
gens = 1000
from multiprocessing.pool import ThreadPool as Pool
pool = Pool(50)
jids = pool.map(f,[gens]*numTrials)
print "Done spawning trials. Retrieving results..."
results = pool.map(cloud_result, jids)
firstLocusFreqsHists = zeros((numTrials,gens+1), dtype='float')
lastLocusFreqsHists = zeros((numTrials,gens+1), dtype='float')
print "Done retrieving results. Press Enter to serialize..."
raw_input()
for i, result in enumerate(results):
firstLocusFreqsHists[i, :], lastLocusFreqsHists[i, :] = result
with closing(FileStorage("soda_results.durus")) as durus:
conn = Connection(durus)
conn.get_root()[str(int(floor(time.time())))] = (firstLocusFreqsHists, lastLocusFreqsHists)
conn.commit()
pool.close()
pool.join()
示例7: render_results
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def render_results(timestamp=None):
with closing(FileStorage("soda_results.durus")) as durus:
conn = Connection(durus)
db = conn.get_root()
if not timestamp:
timestamp = sorted(db.keys())[-1]
firstLocusFreqsHists, lastLocusFreqsHists = db[timestamp]
print "Done deserializing results. Plotting..."
x = [(2, 'First', firstLocusFreqsHists, "effective"),
(3, 'Last', lastLocusFreqsHists, "non-effective")]
for i, pos, freqsHists, filename in x :
freqsHists = freqsHists[:,:801]
f = figure(i)
hold(False)
plot(transpose(freqsHists), color='grey')
hold(True)
maxGens = freqsHists.shape[1]-1
plot([0, maxGens], [.05,.05], 'k--')
plot([0, maxGens], [.95,.95], 'k--')
axis([0, maxGens, 0, 1])
xlabel('Generation')
ylabel('1-Frequency of the '+pos+' Locus')
f.canvas.draw()
f.show()
savefig(filename+'.png', format='png', dpi=200)
示例8: end_protocol_error
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def end_protocol_error(self):
s1 = ClientStorage(address=self.address)
c1 = Connection(s1)
r1 = c1.get_root()
s1.s = FakeSocket('\0\0\0\0?')
r1._p_note_change()
raises(ProtocolError, c1.commit)
示例9: check_storage_tools
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def check_storage_tools(self):
connection = Connection(self._get_storage())
root = connection.get_root()
root['a'] = Persistent()
root['b'] = Persistent()
connection.commit()
index = get_reference_index(connection.get_storage())
assert index == {
int8_to_str(1): [int8_to_str(0)], int8_to_str(2): [int8_to_str(0)]}
census = get_census(connection.get_storage())
assert census == {as_bytes('PersistentDict'):1, as_bytes('Persistent'):2}
references = list(gen_referring_oid_record(connection.get_storage(),
int8_to_str(1)))
assert references == [
(int8_to_str(0), connection.get_storage().load(int8_to_str(0)))]
class Fake(object):
pass
s = Fake()
s.__class__ = Storage
raises(RuntimeError, s.__init__)
raises(NotImplementedError, s.load, None)
raises(NotImplementedError, s.begin)
raises(NotImplementedError, s.store, None, None)
raises(NotImplementedError, s.end)
raises(NotImplementedError, s.sync)
g = s.gen_oid_record()
raises(NotImplementedError, next, g)
示例10: check_write_conflict
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def check_write_conflict(self):
s1 = ClientStorage(address=self.address)
c1 = Connection(s1)
r1 = c1.get_root()
s1.s = FakeSocket('\0\0\0\0', STATUS_INVALID)
r1._p_note_change()
raises(WriteConflictError, c1.commit)
示例11: interactive_client
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def interactive_client(file, address, cache_size, readonly, repair,
startup, storage_class=None):
if file:
storage = get_storage(file, storage_class=storage_class,
readonly=readonly, repair=repair)
description = file
else:
socket_address = SocketAddress.new(address)
wait_for_server(address=socket_address)
storage = ClientStorage(address=socket_address)
description = socket_address
connection = Connection(storage, cache_size=cache_size)
console_module = ModuleType('__console__')
sys.modules['__console__'] = console_module
namespace = {'connection': connection,
'root': connection.get_root(),
'get': connection.get,
'sys': sys,
'os': os,
'int8_to_str': int8_to_str,
'str_to_int8': str_to_int8,
'pp': pprint}
vars(console_module).update(namespace)
configure_readline(
vars(console_module), os.path.expanduser("~/.durushistory"))
console = InteractiveConsole(vars(console_module))
if startup:
console.runsource('execfile("%s")' % os.path.expanduser(startup))
help = (' connection -> the Connection\n'
' root -> the root instance')
console.interact('Durus %s\n%s' % (description, help))
示例12: interactive_client
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def interactive_client(file, address, cache_size, readonly, repair,
startup):
if file:
storage = FileStorage(file, readonly=readonly, repair=repair)
description = file
else:
socket_address = SocketAddress.new(address)
wait_for_server(address=socket_address)
storage = ClientStorage(address=socket_address)
description = socket_address
connection = Connection(storage, cache_size=cache_size)
console_module = ModuleType('__console__')
sys.modules['__console__'] = console_module
namespace = {'connection': connection,
'root': connection.get_root(),
'get': connection.get,
'sys': sys,
'os': os,
'int8_to_str': int8_to_str,
'str_to_int8': str_to_int8,
'pp': pprint}
vars(console_module).update(namespace)
configure_readline(
vars(console_module), os.path.expanduser("~/.durushistory"))
console = InteractiveConsole(vars(console_module))
if startup:
src = '''with open('{fn}', 'rb') as _:
_ = compile(_.read(), '{fn}', 'exec')
exec(globals().pop('_'))
'''.format(fn = os.path.expanduser(startup)).rstrip()
console.runsource(src, '-stub-', 'exec')
help = (' connection -> the Connection\n'
' root -> the root instance')
console.interact('Durus %s\n%s' % (description, help))
示例13: get_config
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def get_config():
connection = Connection(FileStorage("/var/tmp/test.durus"))
root = connection.get_root() # connection set as shown above.
if not root.has_key("_pconfig"):
cf = GenericConfiguration()
root["_pconfig"] = cf
root["_pconfig"]["default"] = SECTION()
connection.commit()
return root["_pconfig"]
示例14: open_document
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def open_document(db_path):
conn = Connection(FileStorage(db_path))
db_root = conn.get_root()
if 'doc' not in db_root:
db_root['doc'] = Document()
db_root['version'] = updates.current_version
conn.commit()
updates.do_updates(conn)
h = DocumentHandler(conn)
return h.doc
示例15: main
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get_root [as 别名]
def main(old_file, new_file):
if old_file.startswith('-'):
usage()
if new_file.startswith('-'):
usage()
assert not exists(new_file)
connection = Connection(sys.argv[1])
tmpfile = TemporaryFile()
print("pickling from " + old_file)
dump(connection.get_root().__getstate__(), tmpfile, 2)
connection = None
tmpfile.seek(0)
connection2 = Connection(sys.argv[2])
print("unpickling")
connection2.get_root().__setstate__(load(tmpfile))
connection2.get_root()._p_note_change()
print("commit to " + new_file)
connection2.commit()
print("pack")
connection2.pack()