當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。