本文整理汇总了Python中ZEO.ClientStorage.ClientStorage.load方法的典型用法代码示例。如果您正苦于以下问题:Python ClientStorage.load方法的具体用法?Python ClientStorage.load怎么用?Python ClientStorage.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZEO.ClientStorage.ClientStorage
的用法示例。
在下文中一共展示了ClientStorage.load方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkZEOInvalidation
# 需要导入模块: from ZEO.ClientStorage import ClientStorage [as 别名]
# 或者: from ZEO.ClientStorage.ClientStorage import load [as 别名]
def checkZEOInvalidation(self):
addr = self._storage._addr
storage2 = ClientStorage(addr, wait=1, min_disconnect_poll=0.1)
try:
oid = self._storage.new_oid()
ob = MinPO('first')
revid1 = self._dostore(oid, data=ob)
data, serial = storage2.load(oid, '')
self.assertEqual(zodb_unpickle(data), MinPO('first'))
self.assertEqual(serial, revid1)
revid2 = self._dostore(oid, data=MinPO('second'), revid=revid1)
for n in range(3):
# Let the server and client talk for a moment.
# Is there a better way to do this?
asyncore.poll(0.1)
data, serial = storage2.load(oid, '')
self.assertEqual(zodb_unpickle(data), MinPO('second'),
'Invalidation message was not sent!')
self.assertEqual(serial, revid2)
finally:
storage2.close()
示例2: checkZEOInvalidation
# 需要导入模块: from ZEO.ClientStorage import ClientStorage [as 别名]
# 或者: from ZEO.ClientStorage.ClientStorage import load [as 别名]
def checkZEOInvalidation(self):
addr = self._storage._addr
storage2 = ClientStorage(addr, wait=1, min_disconnect_poll=0.1)
try:
oid = self._storage.new_oid()
ob = MinPO("first")
revid1 = self._dostore(oid, data=ob)
data, serial = storage2.load(oid, "")
self.assertEqual(zodb_unpickle(data), MinPO("first"))
self.assertEqual(serial, revid1)
revid2 = self._dostore(oid, data=MinPO("second"), revid=revid1)
# Now, storage 2 should eventually get the new data. It
# will take some time, although hopefully not much.
# We'll poll till we get it and whine if we time out:
for n in range(30):
time.sleep(0.1)
data, serial = storage2.load(oid, "")
if serial == revid2 and zodb_unpickle(data) == MinPO("second"):
break
else:
raise AssertionError("Invalidation message was not sent!")
finally:
storage2.close()
示例3: check_server
# 需要导入模块: from ZEO.ClientStorage import ClientStorage [as 别名]
# 或者: from ZEO.ClientStorage.ClientStorage import load [as 别名]
def check_server(addr, storage, write):
t0 = time.time()
if ZEO_VERSION == 2:
# TODO: should do retries w/ exponential backoff.
cs = ClientStorage(addr, storage=storage, wait=0,
read_only=(not write))
else:
cs = ClientStorage(addr, storage=storage, debug=1,
wait_for_server_on_startup=1)
# _startup() is an artifact of the way ZEO 1.0 works. The
# ClientStorage doesn't get fully initialized until registerDB()
# is called. The only thing we care about, though, is that
# registerDB() calls _startup().
if write:
db = ZODB.DB(cs)
cn = db.open()
root = cn.root()
try:
# We store the data in a special `monitor' dict under the root,
# where other tools may also store such heartbeat and bookkeeping
# type data.
monitor = root.get('monitor')
if monitor is None:
monitor = root['monitor'] = PersistentMapping()
obj = monitor['zeoup'] = monitor.get('zeoup', MinPO(0))
obj.value += 1
transaction.commit()
except ConflictError:
pass
cn.close()
db.close()
else:
data, serial = cs.load("\0\0\0\0\0\0\0\0", "")
cs.close()
t1 = time.time()
print "Elapsed time: %.2f" % (t1 - t0)
示例4: Shelf
# 需要导入模块: from ZEO.ClientStorage import ClientStorage [as 别名]
# 或者: from ZEO.ClientStorage.ClientStorage import load [as 别名]
#.........这里部分代码省略.........
def getDBConnection(self):
return self._getConnObject()
def isConnected(self):
return hasattr(self._conn, 'conn') and self._conn.conn is not None
def getDBConnCache(self):
conn = self._getConnObject()
return conn._cache
def getDBClassFactory(self):
return self._db.classFactory
def commit(self, sub=False):
import StringIO
import transaction._transaction
transaction._transaction.StringIO = StringIO.StringIO
if (sub):
transaction.savepoint()
else:
transaction.commit()
def commitZODBOld(self, sub=False):
transaction.commit(sub)
def abort(self):
transaction.abort()
def sync(self):
self._getConnObject().sync()
def pack(self, days=1):
self._storage.pack(days=days)
def undoInfo(self, stepNumber=0):
# One step is made of 1000 transactions. First step is 0 and returns
# transactions 0 to 999.
return self._db.undoInfo(stepNumber*1000, (stepNumber+1)*1000)
def undo(self, trans_id):
self._db.undo(trans_id)
def getDBSize(self):
"""Return an approximate size of the database, in bytes."""
return self._storage.getSize()
def loadObject(self, oid, version):
return self._storage.load(oid, version)
def storeObject(self, oid, serial, data, version, trans):
return self._storage.store(oid, serial, data, version, trans)
def tpcBegin(self, trans):
self._storage.tpc_begin(trans)
def tpcVote(self, trans):
self._storage.tpc_vote(trans)
def tpcFinish(self, trans):
self._storage.tpc_finish(trans)
@contextmanager
def transaction(self, sync=False):
"""
context manager (`with`)
"""
if sync:
self.sync()
yield self.getDBConnection()
self.commit()
@contextmanager
def global_connection(self, commit=False):
"""Helper if you NEED a connection and don't know if one is available or not.
Useful e.g. in flask code that runs outside a request"""
if self.isConnected():
yield
else:
self.startRequest()
try:
yield
finally:
self.endRequest(commit)
# ZODB version check
try:
zodbPkg = pkg_resources.require('ZODB3')[0]
zodbVersion = zodbPkg.parsed_version
zodbVersion = (int(zodbVersion[0]), int(zodbVersion[1]))
except pkg_resources.DistributionNotFound:
# Very old versions, in which ZODB didn't register
# with pkg_resources
import ZODB
zodbVersion = ZODB.__version__.split('.')
if int(zodbVersion[0]) < 3:
raise Exception("ZODB 3 required! %s found" % zodbPkg.version)
elif int(zodbVersion[1]) < 7:
commit = commitZODBOld
示例5: Shelf
# 需要导入模块: from ZEO.ClientStorage import ClientStorage [as 别名]
# 或者: from ZEO.ClientStorage.ClientStorage import load [as 别名]
#.........这里部分代码省略.........
def endRequest( self, commit=True ):
"""Closes the DB and commits changes.
"""
if commit:
self.commit()
else:
self.abort()
#modification vendredi 010907
# try:
# self._conn.close()
# self._conn=None
# except:
# pass
self._getConnObject().close()
self._delConnObject()
def getDBConnection( self ):
conn = self._getConnObject()
if conn == None:
raise Exception( _("request not started"))
return conn
def isConnected( self ):
if self._getConnObject() == None:
return False
else:
return True
def getDBConnCache(self):
conn = self._getConnObject()
if conn == None:
raise Exception( _("request not started"))
return conn._cache
def getDBClassFactory(self):
return self._db.classFactory
def commit(self, sub=False):
if (sub):
transaction.savepoint()
else:
transaction.commit()
def commitZODBOld(self, sub=False):
transaction.commit(sub)
def abort(self):
transaction.abort()
def sync(self):
self._getConnObject().sync()
def pack( self, days=1 ):
self._storage.pack(days=days)
def undoInfo(self, stepNumber=0):
# One step is made of 1000 transactions. First step is 0 and returns
# transactions 0 to 999.
return self._db.undoInfo(stepNumber*1000, (stepNumber+1)*1000)
def undo(self, trans_id):
self._db.undo(trans_id)
def getDBSize( self ):
"""Return an approximate size of the database, in bytes."""
return self._storage.getSize()
def loadObject(self, oid, version):
return self._storage.load(oid, version)
def storeObject(self, oid, serial, data, version, trans):
return self._storage.store(oid, serial, data, version, trans)
def tpcBegin(self, trans):
self._storage.tpc_begin(trans)
def tpcVote(self, trans):
self._storage.tpc_vote(trans)
def tpcFinish(self, trans):
self._storage.tpc_finish(trans)
# ZODB version check
try:
zodbPkg = pkg_resources.require('ZODB3')[0]
zodbVersion = zodbPkg.parsed_version
zodbVersion = (int(zodbVersion[0]), int(zodbVersion[1]))
except pkg_resources.DistributionNotFound:
# Very old versions, in which ZODB didn't register
# with pkg_resources
import ZODB
zodbVersion = ZODB.__version__.split('.')
if int(zodbVersion[0]) < 3:
raise Exception("ZODB 3 required! %s found" % zodbPkg.version)
elif int(zodbVersion[1]) < 7:
commit = commitZODBOld