How to use the persistent.persistence.Persistent 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 zopefoundation / persistent / persistent / persistence.py View on Github external
if _OGA(self, '_Persistent__flags') is not None:
            _OSA(self, '_Persistent__flags', None)

        if clear:
            try:
                idict = _OGA(self, '__dict__')
            except AttributeError:
                pass
            else:
                idict.clear()
            type_ = type(self)
            # for backward-compatibility reason we release __slots__ only if
            # class does not override __new__
            if type_.__new__ is Persistent.__new__:
                for slotname in Persistent._slotnames(self, _v_exclude=False):
                    try:
                        getattr(type_, slotname).__delete__(self)
                    except AttributeError:
                        # AttributeError means slot variable was not initialized at all -
                        # - we can simply skip its deletion.
                        pass

        # Implementation detail: deactivating/invalidating
        # updates the size of the cache (if we have one)
        # by telling it this object no longer takes any bytes
        # (-1 is a magic number to compensate for the implementation,
        # which always adds one to the size given)
        try:
            cache = jar._cache
        except AttributeError:
            pass
github zopefoundation / persistent / persistent / persistence.py View on Github external
return

        if _OGA(self, '_Persistent__flags') is not None:
            _OSA(self, '_Persistent__flags', None)

        if clear:
            try:
                idict = _OGA(self, '__dict__')
            except AttributeError:
                pass
            else:
                idict.clear()
            type_ = type(self)
            # for backward-compatibility reason we release __slots__ only if
            # class does not override __new__
            if type_.__new__ is Persistent.__new__:
                for slotname in Persistent._slotnames(self, _v_exclude=False):
                    try:
                        getattr(type_, slotname).__delete__(self)
                    except AttributeError:
                        # AttributeError means slot variable was not initialized at all -
                        # - we can simply skip its deletion.
                        pass

        # Implementation detail: deactivating/invalidating
        # updates the size of the cache (if we have one)
        # by telling it this object no longer takes any bytes
        # (-1 is a magic number to compensate for the implementation,
        # which always adds one to the size given)
        try:
            cache = jar._cache
        except AttributeError:
github zopefoundation / persistent / persistent / persistence.py View on Github external
if isinstance(oid, bytes) and len(oid) == 8:
                    oid_str = ' oid 0x%x' % (_OID_UNPACK(oid)[0],)
                else:
                    oid_str = ' oid %r' % (oid,)
            except Exception as e:
                oid_str = ' oid %r' % (e,)

        if jar is not None:
            try:
                jar_str = ' in %r' % (jar,)
            except Exception as e:
                jar_str = ' in %r' % (e,)

        return '<%s.%s object at 0x%x%s%s%s>' % (
            # Match the C name for this exact class
            type(self).__module__ if type(self) is not Persistent else 'persistent',
            type(self).__name__ if type(self) is not Persistent else 'Persistent',
            id(self),
            oid_str, jar_str, p_repr_str
        )
github zopefoundation / persistent / persistent / persistence.py View on Github external
def __new__(cls, *args, **kw):
        inst = super(Persistent, cls).__new__(cls)
        # We bypass the __setattr__ implementation of this object
        # at __new__ time, just like the C implementation does. This
        # makes us compatible with subclasses that want to access
        # properties like _p_changed in their setattr implementation
        _OSA(inst, '_Persistent__jar', None)
        _OSA(inst, '_Persistent__oid', None)
        _OSA(inst, '_Persistent__serial', None)
        _OSA(inst, '_Persistent__flags', None)
        _OSA(inst, '_Persistent__size', 0)
        _OSA(inst, '_Persistent__ring', None)
        return inst