How to use the persistent.wref.WeakRef function in persistent

To help you get started, we’ve selected a few persistent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Nexedi / erp5 / product / ERP5Type / dynamic / persistent_migration.py View on Github external
def getOid(self, obj):
    if isinstance(obj, (Persistent, type, wref.WeakRef)):
      return getattr(obj, '_p_oid', None)
github zopefoundation / Zope / lib / python / ZODB / serialize.py View on Github external
# XXX should be done by connection
            obj._p_oid = oid
            obj._p_jar = self._conn
            # When an object is created, it is put in the UPTODATE
            # state.  We must explicitly deactivate it to turn it into
            # a ghost.
            obj._p_changed = None

            self._cache[oid] = obj
            return obj

        elif isinstance(oid, list):
            # see weakref.py
            [oid] = oid
            obj = WeakRef.__new__(WeakRef)
            obj.oid = oid
            obj.dm = self._conn
            return obj

        obj = self._cache.get(oid, None)
        if obj is not None:
            return obj
        return self._conn.get(oid)
github zopefoundation / Zope / lib / python / ZODB / serialize.py View on Github external
>>> writer.persistent_id(42)
        >>> writer.persistent_id(object())

        Check that a classic class doesn't get identified improperly:

        >>> class ClassicClara:
        ...    pass
        >>> clara = ClassicClara()

        >>> writer.persistent_id(clara)
        """

        # Most objects are not persistent. The following cheap test
        # identifies most of them.  For these, we return None,
        # signalling that the object should be pickled normally.
        if not isinstance(obj, (Persistent, type, WeakRef)):
            # Not persistent, pickle normally
            return None

        # Any persistent object must have an oid:
        try:
            oid = obj._p_oid
        except AttributeError:
            # Not persistent, pickle normally
            return None

        if not (oid is None or isinstance(oid, str)):
            # Deserves a closer look:

            # Make sure it's not a descr
            if hasattr(oid, '__get__'):
                # The oid is a decriptor.  That means obj is a non-persistent
github zopefoundation / persistent / persistent / wref.py View on Github external
def __getitem__(self, key):
        return self.data[WeakRef(key)]
github zopefoundation / persistent / persistent / wref.py View on Github external
def update(self, adict):
        if isinstance(adict, PersistentWeakKeyDictionary):
            self.data.update(adict.data)
        else:
            for k, v in adict.items():
                self.data[WeakRef(k)] = v
github zopefoundation / persistent / persistent / wref.py View on Github external
def __eq__(self, other):
        if not isinstance(other, WeakRef):
            return False
        self = self()
        if self is None:
            raise TypeError('Weakly-referenced object has gone away')
        other = other()
        if other is None:
            raise TypeError('Weakly-referenced object has gone away')

        return self == other
github zopefoundation / persistent / persistent / wref.py View on Github external
def get(self, key, default=None):
        """D.get(k[, d]) -> D[k] if k in D, else d.
        """
        return self.data.get(WeakRef(key), default)
github zopefoundation / persistent / persistent / wref.py View on Github external
def __delitem__(self, key):
        del self.data[WeakRef(key)]
github zopefoundation / persistent / persistent / wref.py View on Github external
def __setitem__(self, key, value):
        self.data[WeakRef(key)] = value