Python pickle.PickleError() Examples

The following are code examples for showing how to use pickle.PickleError(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: pyblish-win   Author: pyblish   File: pickletester.py    GNU Lesser 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 (AttributeError, pickle.PickleError, cPickle.PickleError):
                pass
            try:
                self.dumps(D(), proto)
            except (AttributeError, pickle.PickleError, cPickle.PickleError):
                pass 
Example 2
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: cache.py    Apache License 2.0 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 3
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: cache.py    Apache License 2.0 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 4
Project: flasky   Author: RoseOu   File: cache.py    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 5
Project: Pancas   Author: Sup3Roque   File: t0mm0_common_addon.py    GNU General Public License v2.0 6 votes vote down vote up
def save_data(self, filename, data):
        '''
        Saves the data structure using pickle. If the addon data path does 
        not exist it will be automatically created. This save function has
        the same restrictions as the pickle module.
        Args:
            filename (string): name of the file you want to save data to. This 
            file will be saved in your addon's profile directory.
            data (data object/string): you want to save.
        Returns:
            True on success
            False on failure
        '''
        profile_path = self.get_profile()
        try: os.makedirs(profile_path)
        except: pass
        save_path = os.path.join(profile_path, filename)
        try: pickle.dump(data, open(save_path, 'wb')); return True
        except pickle.PickleError: return False 
Example 6
Project: Flask_Blog   Author: sugarguo   File: cache.py    GNU General Public License v3.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 7
Project: Health-Checker   Author: KriAga   File: cache.py    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
Project: recruit   Author: Frank-qlu   File: cache.py    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 9
Project: tesismometro   Author: joapaspe   File: cache.py    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 10
Project: cct   Author: awacha   File: iotool.py    BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setRootDir(self, rootdir: str):
        self.rootdir = rootdir
        configfile = os.path.join(self.rootdir, 'config', 'cct.pickle')
        try:
            with open(configfile, 'rb') as f:
                self.cctConfigChanged.emit(pickle.load(f))
        except FileNotFoundError:
            QtWidgets.QMessageBox.warning(self, 'Error while loading config file',
                                          'Error while loading config file: {} not found. Using a default config.'.format(
                                              configfile))
            self.cctConfigChanged.emit(self._default_config)
            return False
        except pickle.PickleError:
            QtWidgets.QMessageBox.critical(self, 'Error while loading config file',
                                           'Error while loading config file: {} is malformed'.format(configfile))
            return False
        self.reloadPushButton.setEnabled(True)
        self.rootDirLineEdit.setText(os.path.normpath(rootdir))
        return True 
Example 11
Project: drastic-cli   Author: UMD-DRASTIC   File: drastic.py    GNU Affero General Public License v3.0 6 votes vote down vote up
def get_client(self, args):
        """Return a DrasticClient.

        This may be achieved by loading a DrasticClient with a previously saved
        session.
        """
        try:
            # Load existing session, so as to keep current dir etc.
            with open(self.session_path, 'rb') as fh:
                client = pickle.load(fh)
        except (IOError, pickle.PickleError):
            # Init a new DrasticClient
            client = self.create_client(args)
        if args['--url']:
            if client.url != args['--url']:
                # Init a fresh DrasticClient
                client = self.create_client(args)
        client.session = requests.Session()
        return client 
Example 12
Project: jbox   Author: jpush   File: cache.py    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 13
Project: ntu-scanner-py   Author: NTUOSC   File: session.py    Apache License 2.0 6 votes vote down vote up
def request(self, *args, **kwargs):
        """Maintains the existing api for Session.request.
        Used by all of the higher level methods, e.g. Session.get.
        The background_callback param allows you to do some processing on the
        response in the background, e.g. call resp.json() so that json parsing
        happens in the background thread.
        """
        if self.session:
            func = self.session.request
        else:
            # avoid calling super to not break pickled method
            func = partial(Session.request, self)

        background_callback = kwargs.pop('background_callback', None)
        if background_callback:
            func = partial(wrap, self, func, background_callback)

        if isinstance(self.executor, ProcessPoolExecutor):
            # verify function can be pickled
            try:
                dumps(func)
            except (TypeError, PickleError):
                raise RuntimeError(PICKLE_ERROR)

        return self.executor.submit(func, *args, **kwargs) 
Example 14
Project: AneMo   Author: jspargo   File: cache.py    GNU General Public License v2.0 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 15
Project: mars   Author: mars-project   File: test_gevent_pool.py    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 16
Project: mars   Author: mars-project   File: test_gevent_pool.py    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 17
Project: Mahjong-Solitaire   Author: MEASHY   File: cache.py    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 18
Project: Mahjong-Solitaire   Author: MEASHY   File: cache.py    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 19
Project: GTDWeb   Author: lanbing510   File: locmem.py    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 20
Project: cachelib   Author: pallets   File: redis.py    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 21
Project: sam-s-club-auctions   Author: sameer2800   File: cache.py    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 22
Project: XMorbid   Author: NMTech0x90   File: cache.py    GNU General Public License v3.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 23
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: cache.py    Apache License 2.0 5 votes vote down vote up
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 (if not specified,
                        it uses the default timeout).
        :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 
Example 24
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: cache.py    Apache License 2.0 5 votes vote down vote up
def get(self, key):
        try:
            expires, value = self._cache[key]
            if expires > time():
                return pickle.loads(value)
        except (KeyError, pickle.PickleError):
            return None 
Example 25
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: cache.py    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:
                if pickle.load(f) >= time():
                    return pickle.load(f)
                else:
                    os.remove(filename)
                    return None
        except (IOError, OSError, pickle.PickleError):
            return None 
Example 26
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: cache.py    Apache License 2.0 5 votes vote down vote up
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 (if not specified,
                        it uses the default timeout).
        :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 
Example 27
Project: Flask-Python-GAE-Login-Registration   Author: orymeyer   File: cache.py    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:
                if pickle.load(f) >= time():
                    return pickle.load(f)
                else:
                    os.remove(filename)
                    return None
        except (IOError, OSError, pickle.PickleError):
            return None 
Example 28
Project: plugin.video.lynda   Author: davejm   File: util.py    GNU General Public License v2.0 5 votes vote down vote up
def save_data(addon, filename, data):
    profile_path = get_profile(addon)
    try:
        os.makedirs(profile_path)
    except:
        pass
    save_path = os.path.join(profile_path, filename)
    try:
        pickle.dump(data, open(save_path, 'wb'))
        return True
    except pickle.PickleError:
        return False 
Example 29
Project: flasky   Author: RoseOu   File: cache.py    MIT License 5 votes vote down vote up
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 (if not specified,
                        it uses the default timeout).
        :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 
Example 30
Project: flasky   Author: RoseOu   File: cache.py    MIT License 5 votes vote down vote up
def get(self, key):
        try:
            expires, value = self._cache[key]
            if expires > time():
                return pickle.loads(value)
        except (KeyError, pickle.PickleError):
            return None 
Example 31
Project: flasky   Author: RoseOu   File: cache.py    MIT License 5 votes vote down vote up
def get(self, key):
        filename = self._get_filename(key)
        try:
            with open(filename, 'rb') as f:
                if pickle.load(f) >= time():
                    return pickle.load(f)
                else:
                    os.remove(filename)
                    return None
        except (IOError, OSError, pickle.PickleError):
            return None 
Example 32
Project: bigquerylayers   Author: smandaric   File: message_test.py    GNU General Public License v3.0 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 33
Project: opentracing-python   Author: opentracing   File: binary_propagator.py    Apache License 2.0 5 votes vote down vote up
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 
Example 34
Project: Pancas   Author: Sup3Roque   File: common_addon.py    GNU General Public License v2.0 5 votes vote down vote up
def save_data(self, filename, data):
        '''
        Saves the data structure using pickle. If the addon data path does 
        not exist it will be automatically created. This save function has
        the same restrictions as the pickle module.
        
        Args:
            filename (string): name of the file you want to save data to. This 
            file will be saved in your addon's profile directory.
            
            data (data object/string): you want to save.
            
        Returns:
            True on success
            False on failure
        '''
        profile_path = self.get_profile()
        try:
            os.makedirs(profile_path)
        except:
            pass
        save_path = os.path.join(profile_path, filename)
        try:
            pickle.dump(data, open(save_path, 'wb'))
            return True
        except pickle.PickleError:
            return False 
Example 35
Project: Flask_Blog   Author: sugarguo   File: cache.py    GNU General Public License v3.0 5 votes vote down vote up
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 (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 
Example 36
Project: Flask_Blog   Author: sugarguo   File: cache.py    GNU General Public License v3.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 37
Project: Flask_Blog   Author: sugarguo   File: cache.py    GNU General Public License v3.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 
Example 38
Project: Flask_Blog   Author: sugarguo   File: cache.py    GNU General Public License v3.0 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 39
Project: Health-Checker   Author: KriAga   File: cache.py    MIT License 5 votes vote down vote up
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 
Example 40
Project: Health-Checker   Author: KriAga   File: cache.py    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 41
Project: Health-Checker   Author: KriAga   File: cache.py    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 42
Project: Health-Checker   Author: KriAga   File: cache.py    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 43
Project: recruit   Author: Frank-qlu   File: cache.py    Apache License 2.0 5 votes vote down vote up
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 
Example 44
Project: recruit   Author: Frank-qlu   File: cache.py    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 45
Project: recruit   Author: Frank-qlu   File: cache.py    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 
Example 46
Project: recruit   Author: Frank-qlu   File: cache.py    Apache License 2.0 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 47
Project: tesismometro   Author: joapaspe   File: cache.py    MIT License 5 votes vote down vote up
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 (if not specified,
                        it uses the default timeout).
        :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 
Example 48
Project: tesismometro   Author: joapaspe   File: cache.py    MIT License 5 votes vote down vote up
def get(self, key):
        try:
            expires, value = self._cache[key]
            if expires > time():
                return pickle.loads(value)
        except (KeyError, pickle.PickleError):
            return None 
Example 49
Project: tesismometro   Author: joapaspe   File: cache.py    MIT License 5 votes vote down vote up
def get(self, key):
        filename = self._get_filename(key)
        try:
            with open(filename, 'rb') as f:
                if pickle.load(f) >= time():
                    return pickle.load(f)
                else:
                    os.remove(filename)
                    return None
        except (IOError, OSError, pickle.PickleError):
            return None 
Example 50
Project: jbox   Author: jpush   File: cache.py    MIT License 5 votes vote down vote up
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 (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 
Example 51
Project: jbox   Author: jpush   File: cache.py    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 52
Project: jbox   Author: jpush   File: cache.py    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 53
Project: jbox   Author: jpush   File: cache.py    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 54
Project: AneMo   Author: jspargo   File: cache.py    GNU General Public License v2.0 5 votes vote down vote up
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 (if not specified,
                        it uses the default timeout).
        :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 
Example 55
Project: AneMo   Author: jspargo   File: cache.py    GNU General Public License v2.0 5 votes vote down vote up
def get(self, key):
        try:
            expires, value = self._cache[key]
            if expires > time():
                return pickle.loads(value)
        except (KeyError, pickle.PickleError):
            return None 
Example 56
Project: AneMo   Author: jspargo   File: cache.py    GNU General Public License v2.0 5 votes vote down vote up
def get(self, key):
        filename = self._get_filename(key)
        try:
            with open(filename, 'rb') as f:
                if pickle.load(f) >= time():
                    return pickle.load(f)
                else:
                    os.remove(filename)
                    return None
        except (IOError, OSError, pickle.PickleError):
            return None 
Example 57
Project: paramz   Author: sods   File: caching.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __getstate__(self, memo=None):
        raise PickleError("Trying to pickle Cacher object with function {}, pickling functions not possible.".format(str(self.operation))) 
Example 58
Project: paramz   Author: sods   File: caching.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __setstate__(self, memo=None):
        raise PickleError("Trying to pickle Cacher object with function {}, pickling functions not possible.".format(str(self.operation))) 
Example 59
Project: paramz   Author: sods   File: cacher_tests.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_pickling(self):
        self.assertRaises(PickleError, self.cached.__getstate__)
        self.assertRaises(PickleError, self.cached.__setstate__) 
Example 60
Project: Mahjong-Solitaire   Author: MEASHY   File: cache.py    MIT License 5 votes vote down vote up
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 (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 
Example 61
Project: Mahjong-Solitaire   Author: MEASHY   File: cache.py    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 62
Project: Mahjong-Solitaire   Author: MEASHY   File: cache.py    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 63
Project: Mahjong-Solitaire   Author: MEASHY   File: cache.py    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 64
Project: Mahjong-Solitaire   Author: MEASHY   File: cache.py    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 65
Project: Mahjong-Solitaire   Author: MEASHY   File: cache.py    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 66
Project: Mahjong-Solitaire   Author: MEASHY   File: cache.py    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 67
Project: cachelib   Author: pallets   File: file.py    BSD 3-Clause "New" or "Revised" 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 68
Project: cachelib   Author: pallets   File: file.py    BSD 3-Clause "New" or "Revised" 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 69
Project: cachelib   Author: pallets   File: simple.py    BSD 3-Clause "New" or "Revised" 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 70
Project: sam-s-club-auctions   Author: sameer2800   File: cache.py    Apache License 2.0 5 votes vote down vote up
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 (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 
Example 71
Project: sam-s-club-auctions   Author: sameer2800   File: cache.py    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 72
Project: sam-s-club-auctions   Author: sameer2800   File: cache.py    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 
Example 73
Project: sam-s-club-auctions   Author: sameer2800   File: cache.py    Apache License 2.0 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 74
Project: FUTU_Stop_Loss   Author: BigtoC   File: message_test.py    MIT 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 75
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: message_test.py    MIT 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 76
Project: XMorbid   Author: NMTech0x90   File: cache.py    GNU General Public License v3.0 5 votes vote down vote up
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 
Example 77
Project: XMorbid   Author: NMTech0x90   File: cache.py    GNU General Public License v3.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 78
Project: XMorbid   Author: NMTech0x90   File: cache.py    GNU General Public License v3.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 
Example 79
Project: XMorbid   Author: NMTech0x90   File: cache.py    GNU General Public License v3.0 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 80
Project: trio-run-in-process   Author: ethereum   File: test_open_in_process.py    MIT License 5 votes vote down vote up
def test_open_proc_unpickleable_params(touch_path):
    async def takes_open_file(f):
        pass

    with trio.fail_after(2):
        with pytest.raises(pickle.PickleError):
            with open(touch_path, "w") as touch_file:
                async with open_in_process(takes_open_file, touch_file):
                    # this code block shouldn't get executed
                    assert False