當前位置: 首頁>>代碼示例>>Python>>正文


Python cPickle.PickleError方法代碼示例

本文整理匯總了Python中cPickle.PickleError方法的典型用法代碼示例。如果您正苦於以下問題:Python cPickle.PickleError方法的具體用法?Python cPickle.PickleError怎麽用?Python cPickle.PickleError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cPickle的用法示例。


在下文中一共展示了cPickle.PickleError方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: load_object

# 需要導入模塊: import cPickle [as 別名]
# 或者: from cPickle 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 cPickle [as 別名]
# 或者: from cPickle 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: dump

# 需要導入模塊: import cPickle [as 別名]
# 或者: from cPickle import PickleError [as 別名]
def dump(self, url, payload):
        # TODO: Ensure a better check for ieee1394/non-cachable address spaces than a bad URL
        try:
            filename = self.filename(url)
        except exceptions.CacheRelativeURLException:
            debug.debug("NOT Dumping url {0} - relative URLs are not yet supported".format(url))
            return

        ## Check that the directory exists
        directory = os.path.dirname(filename)
        if not os.access(directory, os.R_OK | os.W_OK | os.X_OK):
            os.makedirs(directory)

        ## Ensure that the payload is flattened - i.e. all generators are converted to lists for pickling
        try:
            data = pickle.dumps(payload)
            debug.debug("Dumping filename {0}".format(filename))
            fd = open(filename, 'w')
            fd.write(data)
            fd.close()
        except (pickle.PickleError, TypeError):
            # Do nothing if the pickle fails
            debug.debug("NOT Dumping filename {0} - contained a non-picklable class".format(filename))

## This is the central cache object 
開發者ID:virtualrealitysystems,項目名稱:aumfor,代碼行數:27,代碼來源:cache.py

示例4: test_reduce_bad_iterator

# 需要導入模塊: import cPickle [as 別名]
# 或者: from cPickle 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

示例5: load_object

# 需要導入模塊: import cPickle [as 別名]
# 或者: from cPickle 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

示例6: do_open

# 需要導入模塊: import cPickle [as 別名]
# 或者: from cPickle 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

示例7: do_open

# 需要導入模塊: import cPickle [as 別名]
# 或者: from cPickle 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

        item = self.cache.get_by_key_name(self.namespace)

        if not item:
            self._is_new = True
            self.hash = {}
        else:
            self._is_new = False
            try:
                self.hash = cPickle.loads(str(item.data))
            except (IOError, OSError, EOFError, cPickle.PickleError):
                if self.log_debug:
                    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,代碼行數:24,代碼來源:google.py

示例8: do_open

# 需要導入模塊: import cPickle [as 別名]
# 或者: from cPickle 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

示例9: set

# 需要導入模塊: import cPickle [as 別名]
# 或者: from cPickle 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

示例10: get

# 需要導入模塊: import cPickle [as 別名]
# 或者: from cPickle import PickleError [as 別名]
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 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:9,代碼來源:cache.py

示例11: has

# 需要導入模塊: import cPickle [as 別名]
# 或者: from cPickle import PickleError [as 別名]
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 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:cache.py

示例12: set

# 需要導入模塊: import cPickle [as 別名]
# 或者: from cPickle 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 (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:jpush,項目名稱:jbox,代碼行數:17,代碼來源:cache.py


注:本文中的cPickle.PickleError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。