当前位置: 首页>>代码示例>>Python>>正文


Python pickle.PickleError方法代码示例

本文整理汇总了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 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:cache.py

示例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 
开发者ID:jpush,项目名称:jbox,代码行数:18,代码来源:cache.py

示例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',)) 
开发者ID:mars-project,项目名称:mars,代码行数:21,代码来源:test_gevent_pool.py

示例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',)) 
开发者ID:mars-project,项目名称:mars,代码行数:25,代码来源:test_gevent_pool.py

示例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 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:22,代码来源:locmem.py

示例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))) 
开发者ID:aio-libs,项目名称:aioamqp_consumer,代码行数:24,代码来源:exceptions.py

示例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')) 
开发者ID:Exopy,项目名称:exopy,代码行数:27,代码来源:qt_clipboard.py

示例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 
开发者ID:Exopy,项目名称:exopy,代码行数:25,代码来源:qt_clipboard.py

示例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 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:24,代码来源:pickletester.py

示例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 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:pickletester.py

示例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 
开发者ID:chalasr,项目名称:Flask-P2P,代码行数:18,代码来源:cache.py

示例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 
开发者ID:abdesslem,项目名称:malwareHunter,代码行数:23,代码来源:sqla.py

示例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 
开发者ID:abdesslem,项目名称:malwareHunter,代码行数:26,代码来源:database.py

示例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 
开发者ID:opentracing,项目名称:opentracing-python,代码行数:12,代码来源:binary_propagator.py

示例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 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:17,代码来源:cache.py


注:本文中的pickle.PickleError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。