How to use the persistent.interfaces 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 / grok / src / grok / ftests / utility / local.py View on Github external
grok.implements(IFireplace)

class Club(object):
    grok.implements(IClub)

class SpikyClub(object):
    grok.implements(IClub, ISpiky)

class Mammoth(grok.LocalUtility):
    grok.implements(IMammoth, IClub)

class SabretoothTiger(grok.LocalUtility):
    grok.implements(IMammoth, IClub)
    grok.provides(IMammoth)

class IPainting(persistent.interfaces.IPersistent):
    pass

class CavePainting(grok.LocalUtility):
    grok.implements(IPainting)

class ColoredCavePainting(grok.LocalUtility):
    grok.implements(IPainting)
    grok.provides(IPainting)

class Cave(grok.Model, grok.Site):
    grok.local_utility(Fireplace)
    grok.local_utility(Club)
    grok.local_utility(SpikyClub, provides=IClub, name='spiky')
    grok.local_utility(Mammoth, provides=IMammoth)
    grok.local_utility(SabretoothTiger, name='tiger')
    grok.local_utility(CavePainting, name='blackandwhite', provides=IPainting)
github zopefoundation / persistent / persistent / persistence.py View on Github external
def _get_state(self):
        # Note the use of OGA and caching to avoid recursive calls to __getattribute__:
        # __getattribute__ calls _p_accessed calls cache.mru() calls _p_state
        if _OGA(self, '_Persistent__jar') is None:
            return interfaces.UPTODATE
        flags = _OGA(self, '_Persistent__flags')
        if flags is None:
            return interfaces.GHOST
        if flags & _CHANGED:
            result = interfaces.CHANGED
        else:
            result = interfaces.UPTODATE
        if flags & _STICKY:
            return interfaces.STICKY
        return result
github zopefoundation / persistent / persistent / persistence.py View on Github external
def _get_state(self):
        # Note the use of OGA and caching to avoid recursive calls to __getattribute__:
        # __getattribute__ calls _p_accessed calls cache.mru() calls _p_state
        if _OGA(self, '_Persistent__jar') is None:
            return interfaces.UPTODATE
        flags = _OGA(self, '_Persistent__flags')
        if flags is None:
            return interfaces.GHOST
        if flags & _CHANGED:
            result = interfaces.CHANGED
        else:
            result = interfaces.UPTODATE
        if flags & _STICKY:
            return interfaces.STICKY
        return result
github zopefoundation / persistent / persistent / persistence.py View on Github external
_OSA(self, '_Persistent__flags', 0)
            jar = oga(self, '_Persistent__jar')
            if jar is None:
                return
            oid = oga(self, '_Persistent__oid')
            if oid is None:
                return

            # If we're actually going to execute a set-state,
            # mark as changed to prevent any recursive call
            # (actually, our earlier check that we're a ghost should
            # prevent this, but the C implementation sets it to changed
            # while calling jar.setstate, and this is observable to clients).
            # The main point of this is to prevent changes made during
            # setstate from registering the object with the jar.
            _OSA(self, '_Persistent__flags', interfaces.CHANGED)
            try:
                jar.setstate(self)
            except:
                _OSA(self, '_Persistent__flags', before)
                raise
            else:
                # If we succeed, no matter what the implementation
                # of setstate did, mark ourself as up-to-date. The
                # C implementation unconditionally does this.
                _OSA(self, '_Persistent__flags', 0) # up-to-date