当前位置: 首页>>代码示例>>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;未经允许,请勿转载。