本文整理汇总了Python中durus.connection.Connection.get方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.get方法的具体用法?Python Connection.get怎么用?Python Connection.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类durus.connection.Connection
的用法示例。
在下文中一共展示了Connection.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_oid_reuse
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get [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: interactive_client
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get [as 别名]
def interactive_client(file, host, port, cache_size, readonly, repair,
startup):
if file:
storage = FileStorage(file, readonly=readonly, repair=repair)
description = file
else:
wait_for_server(host, port)
storage = ClientStorage(host=host, port=port)
description = "%s:%s" % (host, port)
connection = Connection(storage, cache_size=cache_size)
namespace = {'connection': connection,
'root': connection.get(0),
'get': connection.get,
'sys': sys,
'os': os,
'p64': p64,
'u64': u64,
'pp': pprint}
configure_readline(namespace, os.path.expanduser("~/.durushistory"))
console = InteractiveConsole(namespace)
if startup:
console.runsource('execfile("%s")' % os.path.expanduser(startup))
help = (' connection -> the connection\n'
' root -> get(0)\n'
' get(oid) -> get an object\n'
' pp(object) -> pretty-print')
console.interact('Durus (%s)\n%s' % (description, help))
示例3: check_conflict
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get [as 别名]
def check_conflict(self):
b = Connection(self._get_storage())
c = Connection(self._get_storage())
rootb = b.get(int8_to_str(0))
rootb['b'] = Persistent()
rootc = c.get(int8_to_str(0))
rootc['c'] = Persistent()
c.commit()
raises(ConflictError, b.commit)
raises(KeyError, rootb.__getitem__, 'c')
transaction_serial = b.transaction_serial
b.abort()
assert b.get_transaction_serial() > transaction_serial
assert rootb._p_is_ghost()
rootc['d'] = Persistent()
c.commit()
rootb['d']
示例4: repickle_storage
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get [as 别名]
def repickle_storage(storage):
"""(storage: FileStorage)
Force very object to be loaded and re-pickled.
This also packs, so that all of the old pickles are removed.
"""
connection = Connection(storage)
for j, oid in enumerate(storage.index):
obj = connection.get(oid)
obj._p_note_change()
if j and j % 10000 == 0:
connection.commit()
connection.commit()
storage.pack()
示例5: a
# 需要导入模块: from durus.connection import Connection [as 别名]
# 或者: from durus.connection.Connection import get [as 别名]
def a(self):
f = File(prefix='shelftest')
name = f.get_name()
f.close()
s = FileStorage(name)
c = Connection(s)
r = c.get_root()
for x in range(10):
r["a%s" % x] = Persistent()
c.commit()
deleted_oids = [
r['a0']._p_oid, r['a2']._p_oid, r['a7']._p_oid, r['a8']._p_oid]
del r['a0']
del r['a2']
del r['a7']
del r['a8']
c.commit()
c.pack()
c.abort()
assert c.get(deleted_oids[0])._p_is_ghost()
assert c.get(deleted_oids[1])._p_is_ghost()
raises(ReadConflictError, getattr, c.get(deleted_oids[0]), 'a')
assert len([repr(oid) for oid, record in s.gen_oid_record()]) == 7
c.commit()
c.pack()
new_oid = s.new_oid()
assert new_oid == deleted_oids[-1], (new_oid, deleted_oids)
new_oid = s.new_oid()
assert new_oid == deleted_oids[-2], (new_oid, deleted_oids)
new_oid = s.new_oid()
assert new_oid == deleted_oids[-3], (new_oid, deleted_oids)
new_oid = s.new_oid()
assert new_oid == deleted_oids[-4], (new_oid, deleted_oids)
new_oid = s.new_oid()
assert new_oid == int8_to_str(11), repr(new_oid)
new_oid = s.new_oid()
assert new_oid == int8_to_str(12), repr(new_oid)