当前位置: 首页>>代码示例>>Python>>正文


Python Unpickler.persistent_load方法代码示例

本文整理汇总了Python中cPickle.Unpickler.persistent_load方法的典型用法代码示例。如果您正苦于以下问题:Python Unpickler.persistent_load方法的具体用法?Python Unpickler.persistent_load怎么用?Python Unpickler.persistent_load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cPickle.Unpickler的用法示例。


在下文中一共展示了Unpickler.persistent_load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: deserialize

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
    def deserialize(self, event, state):
        assert IFullDeserializationEvent.isImplementedBy(event)
        assert isinstance(event.obj, Persistent)

        # Set up to resolve cyclic references to the object.
        event.deserialized('self', event.obj)

        state = state.strip()
        if state:
            if state.startswith('#'):
                # Text-encoded pickles start with a pound sign.
                # (A pound sign is not a valid pickle opcode.)
                data = decode_from_text(state)
            else:
                data = state
            infile = StringIO(data)
            u = Unpickler(infile)
            u.persistent_load = event.resolve_internal
            s = u.load()
            if not hasattr(s, 'items'):
                # Turn the list back into a dictionary
                s_list = s
                s = {}
                for key, value in s_list:
                    s[key] = value
            event.obj.__dict__.update(s)
            try:
                unmanaged = u.load()
            except EOFError:
                # old pickle with no list of unmanaged objects
                pass
            else:
                event.upos.extend(unmanaged)
开发者ID:goschtl,项目名称:zope,代码行数:35,代码来源:serializers.py

示例2: cloneByPickle

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
def cloneByPickle(obj, ignore_list=()):
    """Makes a copy of a ZODB object, loading ghosts as needed.

    Ignores specified objects along the way, replacing them with None
    in the copy.
    """
    ignore_dict = {}
    for o in ignore_list:
        ignore_dict[id(o)] = o

    def persistent_id(ob, ignore_dict=ignore_dict):
        if ignore_dict.has_key(id(ob)):
            return 'ignored'
        if getattr(ob, '_p_changed', 0) is None:
            ob._p_changed = 0
        return None

    def persistent_load(ref):
        assert ref == 'ignored'
        # Return a placeholder object that will be replaced by
        # removeNonVersionedData().
        placeholder = SimpleItem()
        placeholder.id = "ignored_subobject"
        return placeholder

    stream = StringIO()
    p = Pickler(stream, 1)
    p.persistent_id = persistent_id
    p.dump(obj)
    stream.seek(0)
    u = Unpickler(stream)
    u.persistent_load = persistent_load
    return u.load()
开发者ID:jean,项目名称:Products.ZopeVersionControl,代码行数:35,代码来源:Version.py

示例3: setstate

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
 def setstate(self, object):
     """
     Unlike the 'stock' Connection class' setstate, this method
     doesn't raise ConflictErrors.  This is potentially dangerous
     for applications that need absolute consistency, but
     sessioning is not one of those.
     """
     oid=object._p_oid
     invalid = self._invalid
     if invalid(None):
         # only raise a conflict if there was
         # a mass invalidation, but not if we see this
         # object's oid as invalid
         raise ConflictError, `oid`
     p, serial = self._storage.load(oid, self._version)
     file=StringIO(p)
     unpickler=Unpickler(file)
     unpickler.persistent_load=self._persistent_load
     unpickler.load()
     state = unpickler.load()
     if hasattr(object, '__setstate__'):
         object.__setstate__(state)
     else:
         d=object.__dict__
         for k,v in state.items(): d[k]=v
     object._p_serial=serial
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:28,代码来源:LowConflictConnection.py

示例4: deserialize

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
    def deserialize(self, message, task_id=None):
        """Deserialize an object

        :param message: A serialized object (string).
        :param deferred: When true load deferreds. When false
            raise an error if the message contains deferreds.
        """
        fail = []
        if task_id is None:
            def persistent_load(task_id):
                raise UnpicklingError('message contained references to '
                    'external objects: %s' % task_id)
        else:
            args = self._queue.get_arguments(task_id)
            args = {k: loads(v) for k, v in args.items()}

            def persistent_load(arg_id):
                value = args[arg_id]
                if isinstance(value, TaskFailure):
                    fail.append(value)
                return value
        data = StringIO(message)
        pickle = Unpickler(data)
        pickle.persistent_load = persistent_load
        obj = pickle.load()
        if fail and not obj.on_error_pass:
            # TODO detect errors earlier, fail earlier, cancel enqueued tasks
            self.set_result(obj, fail[0])
            obj = None
        return obj
开发者ID:llazzaro,项目名称:WorQ,代码行数:32,代码来源:core.py

示例5: _cloneByPickle

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
def _cloneByPickle(self, obj):
    """Returns a deep copy of a ZODB object, loading ghosts as needed.
    """
    modifier = getToolByName(self, 'portal_modifier')
    callbacks = modifier.getOnCloneModifiers(obj)
    if callbacks is not None:
        pers_id, pers_load, inside_orefs, outside_orefs = callbacks[0:4]
    else:
        inside_orefs, outside_orefs = (), ()

    stream = StringIO()
    p = Pickler(stream, 1)
    if callbacks is not None:
        p.persistent_id = pers_id
    cmf_uid = getattr(obj, 'cmf_uid', None)
    if IUniqueIdAnnotation.providedBy(cmf_uid):
        setattr(obj, 'cmf_uid', cmf_uid())
    try:
        p.dump(aq_base(obj))
    except TypeError:
        # just try again, this then seems to work
        # WTF?
        p.dump(aq_base(obj))
    approxSize = stream.tell()
    stream.seek(0)
    u = Unpickler(stream)
    if callbacks is not None:
        u.persistent_load = pers_load
    return approxSize, u.load(), inside_orefs, outside_orefs
开发者ID:syslabcom,项目名称:gfb.policy,代码行数:31,代码来源:cmfeditions_patch.py

示例6: loads

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
 def loads(self, s):
     up = Unpickler(BytesIO(s))
     up.persistent_load = self._get_object
     try:
         return up.load()
     except KeyError, e:
         raise UnpicklingError("Could not find Node class for %s" % e)
开发者ID:NaturalSolutions,项目名称:ecoReleve-Concepts,代码行数:9,代码来源:store.py

示例7: zodb_unpickle

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
def zodb_unpickle(data):
    """Unpickle an object stored using the format expected by ZODB."""
    f = StringIO(data)
    u = Unpickler(f)
    u.persistent_load = persistent_load
    klass_info = u.load()
    if isinstance(klass_info, tuple):
        if isinstance(klass_info[0], type):
            # Unclear:  what is the second part of klass_info?
            klass, xxx = klass_info
            assert not xxx
        else:
            if isinstance(klass_info[0], tuple):
                modname, klassname = klass_info[0]
            else:
                modname, klassname = klass_info
            if modname == "__main__":
                ns = globals()
            else:
                mod = import_helper(modname)
                ns = mod.__dict__
            try:
                klass = ns[klassname]
            except KeyError:
                print >> sys.stderr, "can't find %s in %r" % (klassname, ns)
        inst = klass()
    else:
        raise ValueError("expected class info: %s" % repr(klass_info))
    state = u.load()
    inst.__setstate__(state)
    return inst
开发者ID:grodniewicz,项目名称:oship,代码行数:33,代码来源:StorageTestBase.py

示例8: setklassstate

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
    def setklassstate(self, object):
        try:
            oid=object._p_oid
            __traceback_info__=oid
            p, serial = self._storage.load(oid, self._version)
            file=StringIO(p)
            unpickler=Unpickler(file)
            unpickler.persistent_load=self._persistent_load

            copy = unpickler.load()

            klass, args = copy

            if klass is not ExtensionKlass:
                LOG('ZODB',ERROR,
                    "Unexpected klass when setting class state on %s"
                    % getattr(object,'__name__','(?)'))
                return

            copy=apply(klass,args)
            object.__dict__.clear()
            object.__dict__.update(copy.__dict__)

            object._p_oid=oid
            object._p_jar=self
            object._p_changed=0
            object._p_serial=serial
        except:
            LOG('ZODB',ERROR, 'setklassstate failed', error=sys.exc_info())
            raise
开发者ID:OS2World,项目名称:APP-SERVER-Zope,代码行数:32,代码来源:Connection.py

示例9: oldstate

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
 def oldstate(self, object, serial):
     oid=object._p_oid
     p = self._storage.loadSerial(oid, serial)
     file=StringIO(p)
     unpickler=Unpickler(file)
     unpickler.persistent_load=self._persistent_load
     unpickler.load()
     return  unpickler.load()
开发者ID:OS2World,项目名称:APP-SERVER-Zope,代码行数:10,代码来源:Connection.py

示例10: state

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
def state(self, oid, serial, prfactory, p=''):
    p = p or self.loadSerial(oid, serial)
    file = StringIO(p)
    unpickler = Unpickler(file)
    unpickler.find_global = find_global
    unpickler.persistent_load = prfactory.persistent_load
    unpickler.load() # skip the class tuple
    return unpickler.load()
开发者ID:grodniewicz,项目名称:oship,代码行数:10,代码来源:ConflictResolution.py

示例11: state

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
def state(self, oid, serial, prfactory, p=''):
    p = p or self.loadSerial(oid, serial)
    file = StringIO(p)
    unpickler = Unpickler(file)
    unpickler.persistent_load = prfactory.persistent_load
    class_tuple = unpickler.load()
    state = unpickler.load()
    return state
开发者ID:OS2World,项目名称:APP-SERVER-Zope,代码行数:10,代码来源:ConflictResolution.py

示例12: state

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
def state(self, oid, serial, prfactory, p=""):
    p = p or self.loadSerial(oid, serial)
    p = self._crs_untransform_record_data(p)
    file = StringIO(p)
    unpickler = Unpickler(file)
    unpickler.find_global = find_global
    unpickler.persistent_load = prfactory.persistent_load
    unpickler.load()  # skip the class tuple
    return unpickler.load()
开发者ID:toutpt,项目名称:ZODB,代码行数:11,代码来源:ConflictResolution.py

示例13: _get_unpickler

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
 def _get_unpickler(self, file):
     connection = self.connection
     get_instance = connection.get_cache().get_instance
     def persistent_load(oid_klass):
         oid, klass = oid_klass
         return get_instance(oid, klass, connection)
     unpickler = Unpickler(file)
     unpickler.persistent_load = persistent_load
     return unpickler
开发者ID:Schevo,项目名称:schevo,代码行数:11,代码来源:serialize.py

示例14: tryToResolveConflict

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
def tryToResolveConflict(self, oid, committedSerial, oldSerial, newpickle,
                         committedData=''):
    # class_tuple, old, committed, newstate = ('',''), 0, 0, 0
    try:
        prfactory = PersistentReferenceFactory()
        newpickle = self._crs_untransform_record_data(newpickle)
        file = StringIO(newpickle)
        unpickler = Unpickler(file)
        unpickler.find_global = find_global
        unpickler.persistent_load = prfactory.persistent_load
        meta = unpickler.load()
        if isinstance(meta, tuple):
            klass = meta[0]
            newargs = meta[1] or ()
            if isinstance(klass, tuple):
                klass = find_global(*klass)
        else:
            klass = meta
            newargs = ()

        if klass in _unresolvable:
            raise ConflictError

        newstate = unpickler.load()
        inst = klass.__new__(klass, *newargs)

        try:
            resolve = inst._p_resolveConflict
        except AttributeError:
            _unresolvable[klass] = 1
            raise ConflictError

        old = state(self, oid, oldSerial, prfactory)
        committed = state(self, oid, committedSerial, prfactory, committedData)

        resolved = resolve(old, committed, newstate)

        file = StringIO()
        pickler = Pickler(file,1)
        pickler.inst_persistent_id = persistent_id
        pickler.dump(meta)
        pickler.dump(resolved)
        return self._crs_transform_record_data(file.getvalue(1))
    except (ConflictError, BadClassName):
        pass
    except:
        # If anything else went wrong, catch it here and avoid passing an
        # arbitrary exception back to the client.  The error here will mask
        # the original ConflictError.  A client can recover from a
        # ConflictError, but not necessarily from other errors.  But log
        # the error so that any problems can be fixed.
        logger.error("Unexpected error", exc_info=True)

    raise ConflictError(oid=oid, serials=(committedSerial, oldSerial),
                        data=newpickle)
开发者ID:aberke,项目名称:search_engine_2,代码行数:57,代码来源:ConflictResolution.py

示例15: _get_unpickler

# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import persistent_load [as 别名]
 def _get_unpickler(self, file):
     def persistent_load(oid_klass):
         oid, klass = oid_klass
         obj = self.connection.cache_get(oid)
         if obj is None:
             # Go ahead and make the ghost instance.
             obj = klass.__new__(klass)
             obj._p_oid = oid
             obj._p_connection = self.connection
             obj._p_set_status_ghost()
             self.connection.cache_set(oid, obj)
         return obj
     unpickler = Unpickler(file)
     unpickler.persistent_load = persistent_load
     return unpickler
开发者ID:pruan,项目名称:TestDepot,代码行数:17,代码来源:serialize.py


注:本文中的cPickle.Unpickler.persistent_load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。