Python pickle.PickleError() Examples

The following are 30 code examples of pickle.PickleError(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pickle , or try the search function .
Example #1
Source File: cache.py    From Building-Recommendation-Systems-with-Python with MIT License 6 votes vote down vote up
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 
Example #2
Source File: cache.py    From jbox with MIT License 6 votes vote down vote up
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 
Example #3
Source File: cache.py    From recruit with Apache License 2.0 6 votes vote down vote up
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 
Example #4
Source File: test_gevent_pool.py    From mars with Apache License 2.0 6 votes vote down vote up
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',)) 
Example #5
Source File: sqla.py    From malwareHunter with GNU General Public License v2.0 6 votes vote down vote up
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 
Example #6
Source File: test_gevent_pool.py    From mars with Apache License 2.0 6 votes vote down vote up
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',)) 
Example #7
Source File: cache.py    From planespotter with MIT License 6 votes vote down vote up
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 
Example #8
Source File: cache.py    From Flask-P2P with MIT License 6 votes vote down vote up
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 
Example #9
Source File: database.py    From malwareHunter with GNU General Public License v2.0 6 votes vote down vote up
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 
Example #10
Source File: cache.py    From lambda-packs with MIT License 6 votes vote down vote up
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 
Example #11
Source File: locmem.py    From GTDWeb with GNU General Public License v2.0 6 votes vote down vote up
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 
Example #12
Source File: redis.py    From cachelib with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 
Example #13
Source File: cache.py    From Financial-Portfolio-Flask with MIT License 6 votes vote down vote up
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 
Example #14
Source File: exceptions.py    From aioamqp_consumer with MIT License 6 votes vote down vote up
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))) 
Example #15
Source File: pickletester.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
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 
Example #16
Source File: qt_clipboard.py    From exopy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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')) 
Example #17
Source File: qt_clipboard.py    From exopy with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 
Example #18
Source File: pickletester.py    From BinderFilter with MIT License 6 votes vote down vote up
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 
Example #19
Source File: cache.py    From RSSNewsGAE with Apache License 2.0 6 votes vote down vote up
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 
Example #20
Source File: cache.py    From scylla with Apache License 2.0 6 votes vote down vote up
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 
Example #21
Source File: pickletester.py    From oss-ftp with MIT License 6 votes vote down vote up
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 
Example #22
Source File: pickletester.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #23
Source File: cache.py    From Building-Recommendation-Systems-with-Python with MIT License 6 votes vote down vote up
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 
Example #24
Source File: cache.py    From Building-Recommendation-Systems-with-Python with MIT License 5 votes vote down vote up
def get(self, key):
        try:
            expires, value = self._cache[key]
            if expires == 0 or expires > time():
                return pickle.loads(value)
        except (KeyError, pickle.PickleError):
            return None 
Example #25
Source File: cache.py    From Building-Recommendation-Systems-with-Python with MIT License 5 votes vote down vote up
def get(self, key):
        filename = self._get_filename(key)
        try:
            with open(filename, "rb") as f:
                pickle_time = pickle.load(f)
                if pickle_time == 0 or pickle_time >= time():
                    return pickle.load(f)
                else:
                    os.remove(filename)
                    return None
        except (IOError, OSError, pickle.PickleError):
            return None 
Example #26
Source File: cache.py    From planespotter with MIT License 5 votes vote down vote up
def has(self, key):
        filename = self._get_filename(key)
        try:
            with open(filename, 'rb') as f:
                pickle_time = pickle.load(f)
                if pickle_time == 0 or pickle_time >= time():
                    return True
                else:
                    os.remove(filename)
                    return False
        except (IOError, OSError, pickle.PickleError):
            return False 
Example #27
Source File: cache.py    From scylla with Apache License 2.0 5 votes vote down vote up
def get(self, key):
        try:
            expires, value = self._cache[key]
            if expires == 0 or expires > time():
                return pickle.loads(value)
        except (KeyError, pickle.PickleError):
            return None 
Example #28
Source File: cache.py    From planespotter with MIT License 5 votes vote down vote up
def get(self, key):
        filename = self._get_filename(key)
        try:
            with open(filename, 'rb') as f:
                pickle_time = pickle.load(f)
                if pickle_time == 0 or pickle_time >= time():
                    return pickle.load(f)
                else:
                    os.remove(filename)
                    return None
        except (IOError, OSError, pickle.PickleError):
            return None 
Example #29
Source File: message_test.py    From coremltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testPickleRepeatedScalarContainer(self, message_module):
    # TODO(tibell): The pure-Python implementation support pickling of
    #   scalar containers in *some* cases. For now the cpp2 version
    #   throws an exception to avoid a segfault. Investigate if we
    #   want to support pickling of these fields.
    #
    # For more information see: https://b2.corp.google.com/u/0/issues/18677897
    if (api_implementation.Type() != 'cpp' or
        api_implementation.Version() == 2):
      return
    m = message_module.TestAllTypes()
    with self.assertRaises(pickle.PickleError) as _:
      pickle.dumps(m.repeated_int32, pickle.HIGHEST_PROTOCOL) 
Example #30
Source File: cache.py    From scylla with Apache License 2.0 5 votes vote down vote up
def get(self, key):
        filename = self._get_filename(key)
        try:
            with open(filename, "rb") as f:
                pickle_time = pickle.load(f)
                if pickle_time == 0 or pickle_time >= time():
                    return pickle.load(f)
                else:
                    os.remove(filename)
                    return None
        except (IOError, OSError, pickle.PickleError):
            return None