本文整理匯總了Python中pickle.PickleError方法的典型用法代碼示例。如果您正苦於以下問題:Python pickle.PickleError方法的具體用法?Python pickle.PickleError怎麽用?Python pickle.PickleError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pickle
的用法示例。
在下文中一共展示了pickle.PickleError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_object
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def load_object(self, value):
"""The reversal of :meth:`dump_object`. This might be called with
None.
"""
if value is None:
return None
if value.startswith(b"!"):
try:
return pickle.loads(value[1:])
except pickle.PickleError:
return None
try:
return int(value)
except ValueError:
# before 0.8 we did not have serialization. Still support that.
return value
示例2: load_object
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def load_object(self, value):
"""The reversal of :meth:`dump_object`. This might be called with
None.
"""
if value is None:
return None
if value.startswith(b'!'):
try:
return pickle.loads(value[1:])
except pickle.PickleError:
return None
try:
return int(value)
except ValueError:
# before 0.8 we did not have serialization. Still support that.
return value
示例3: testProcessUnpickled
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def testProcessUnpickled(self):
with create_actor_pool(n_process=2, distributor=DummyDistributor(2),
backend='gevent') as pool:
ref1 = pool.create_actor(DummyActor, 1)
with self.assertRaises(pickle.PickleError):
ref1.send(lambda x: x)
ref2 = pool.create_actor(DummyActor, 1, uid='admin-1')
with self.assertRaises(pickle.PickleError):
ref1.send(('send_unpickled', ref2))
with self.assertRaises(pickle.PickleError):
ref1.send(('send', ref2, 'send_unpickled', ref1))
with self.assertRaises(pickle.PickleError):
pool.create_actor(DummyActor, lambda x: x)
with self.assertRaises(pickle.PickleError):
ref1.send(('create_unpickled',))
示例4: testRemoteProcessPoolUnpickled
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def testRemoteProcessPoolUnpickled(self):
with create_actor_pool(address=True, n_process=2, distributor=DummyDistributor(2),
backend='gevent') as pool:
addr = pool.cluster_info.address
client = new_client(backend='gevent')
ref1 = client.create_actor(DummyActor, 1, address=addr)
with self.assertRaises(pickle.PickleError):
ref1.send(lambda x: x)
ref2 = client.create_actor(DummyActor, 1, address=addr, uid='admin-1')
with self.assertRaises(pickle.PickleError):
ref1.send(('send_unpickled', ref2))
with self.assertRaises(pickle.PickleError):
ref1.send(('send', ref2, 'send_unpickled', ref1))
with self.assertRaises(pickle.PickleError):
client.create_actor(DummyActor, lambda x: x, address=addr)
with self.assertRaises(pickle.PickleError):
ref1.send(('create_unpickled',))
示例5: get
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def get(self, key, default=None, version=None, acquire_lock=True):
key = self.make_key(key, version=version)
self.validate_key(key)
pickled = None
with (self._lock.reader() if acquire_lock else dummy()):
if not self._has_expired(key):
pickled = self._cache[key]
if pickled is not None:
try:
return pickle.loads(pickled)
except pickle.PickleError:
return default
with (self._lock.writer() if acquire_lock else dummy()):
try:
del self._cache[key]
del self._expire_info[key]
except KeyError:
pass
return default
示例6: dumps
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def dumps(self):
try:
return self._dumps(self.err)
except settings.PICKLE_ERRORS as exc:
logger.warning(exc, exc_info=exc)
return self._dumps(exc)
except BaseException as exc:
logger.critical(exc, exc_info=exc)
try:
return self._dumps(exc)
except BaseException as exc:
logger.critical(exc, exc_info=exc)
exc_tb = traceback.format_exception(
etype=type(exc),
value=exc,
tb=exc.__traceback__,
)
return self._dumps(pickle.PickleError(''.join(exc_tb)))
示例7: __init__
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def __init__(self, data=None, pickle=False):
QtCore.QMimeData.__init__(self)
# Keep a local reference to be returned if possible.
self._local_instance = data
if pickle:
if data is not None:
# We may not be able to pickle the data.
try:
pdata = dumps(data, -1)
# This format (as opposed to using a single sequence)
# allows the type to be extracted without unpickling
# the data.
self.setData(self.MIME_TYPE, dumps(data.__class__) + pdata)
except (PickleError, TypeError):
# if pickle fails, still try to create a draggable
warnings.warn(("Could not pickle dragged object %s, " +
"using %s mimetype instead") % (repr(data),
self.NOPICKLE_MIME_TYPE), RuntimeWarning)
self.setData(self.NOPICKLE_MIME_TYPE,
str(id(data)).encode('utf8'))
else:
self.setData(self.NOPICKLE_MIME_TYPE, str(id(data)).encode('utf8'))
示例8: instance
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def instance(self):
""" Return the instance.
"""
if self._local_instance is not None:
return self._local_instance
if not self.hasFormat(self.MIME_TYPE):
# We have no pickled python data defined.
return None
io = StringIO(bytes(self.data(self.MIME_TYPE)))
try:
# Skip the type.
load(io)
# Recreate the instance.
return load(io)
except PickleError:
pass
return None
示例9: test_reduce_bad_iterator
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def test_reduce_bad_iterator(self):
# Issue4176: crash when 4th and 5th items of __reduce__()
# are not iterators
class C(object):
def __reduce__(self):
# 4th item is not an iterator
return list, (), None, [], None
class D(object):
def __reduce__(self):
# 5th item is not an iterator
return dict, (), None, None, []
# Protocol 0 is less strict and also accept iterables.
for proto in protocols:
try:
self.dumps(C(), proto)
except (AttributeError, pickle.PickleError, cPickle.PickleError):
pass
try:
self.dumps(D(), proto)
except (AttributeError, pickle.PickleError, cPickle.PickleError):
pass
示例10: test_reduce_bad_iterator
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def test_reduce_bad_iterator(self):
# Issue4176: crash when 4th and 5th items of __reduce__()
# are not iterators
class C(object):
def __reduce__(self):
# 4th item is not an iterator
return list, (), None, [], None
class D(object):
def __reduce__(self):
# 5th item is not an iterator
return dict, (), None, None, []
# Protocol 0 is less strict and also accept iterables.
for proto in protocols:
try:
self.dumps(C(), proto)
except (pickle.PickleError):
pass
try:
self.dumps(D(), proto)
except (pickle.PickleError):
pass
示例11: load_object
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def load_object(self, value):
"""The reversal of :meth:`dump_object`. This might be callde with
None.
"""
if value is None:
return None
if value.startswith(b'!'):
try:
return pickle.loads(value[1:])
except pickle.PickleError:
return None
try:
return int(value)
except ValueError:
# before 0.8 we did not have serialization. Still support that.
return value
示例12: do_open
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def do_open(self, flags, replace):
if self.loaded:
self.flags = flags
return
select = sa.select([self.table.c.data],
(self.table.c.namespace == self.namespace))
result = self.bind.execute(select).fetchone()
if not result:
self._is_new = True
self.hash = {}
else:
self._is_new = False
try:
self.hash = result['data']
except (IOError, OSError, EOFError, cPickle.PickleError,
pickle.PickleError):
log.debug("Couln't load pickle data, creating new storage")
self.hash = {}
self._is_new = True
self.flags = flags
self.loaded = True
示例13: do_open
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def do_open(self, flags, replace):
# If we already loaded the data, don't bother loading it again
if self.loaded:
self.flags = flags
return
cache = self.cache
result = sa.select([cache.c.data],
cache.c.namespace == self.namespace
).execute().fetchone()
if not result:
self._is_new = True
self.hash = {}
else:
self._is_new = False
try:
self.hash = result['data']
except (IOError, OSError, EOFError, cPickle.PickleError,
pickle.PickleError):
log.debug("Couln't load pickle data, creating new storage")
self.hash = {}
self._is_new = True
self.flags = flags
self.loaded = True
示例14: extract
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def extract(self, carrier):
if type(carrier) is not bytearray:
raise InvalidCarrierException()
try:
span_context = pickle.loads(carrier)
except (EOFError, pickle.PickleError):
raise SpanContextCorruptedException()
return span_context
示例15: set
# 需要導入模塊: import pickle [as 別名]
# 或者: from pickle import PickleError [as 別名]
def set(self, key, value, timeout=None):
"""Add a new key/value to the cache (overwrites value, if key already
exists in the cache).
:param key: the key to set
:param value: the value for the key
:param timeout: the cache timeout for the key in seconds (if not
specified, it uses the default timeout). A timeout of
0 idicates that the cache never expires.
:returns: ``True`` if key has been updated, ``False`` for backend
errors. Pickling errors, however, will raise a subclass of
``pickle.PickleError``.
:rtype: boolean
"""
return True