[Zodb-checkins] SVN: ZODB/branches/tseaver-python_picklecache-2/src/persistent/ Document additional methods / attributes as part of IPersistent.

Tres Seaver tseaver at palladion.com
Tue Feb 15 17:08:27 EST 2011


Log message for revision 120359:
  Document additional methods / attributes as part of IPersistent.

Changed:
  U   ZODB/branches/tseaver-python_picklecache-2/src/persistent/interfaces.py
  U   ZODB/branches/tseaver-python_picklecache-2/src/persistent/pypersistent.py

-=-
Modified: ZODB/branches/tseaver-python_picklecache-2/src/persistent/interfaces.py
===================================================================
--- ZODB/branches/tseaver-python_picklecache-2/src/persistent/interfaces.py	2011-02-15 22:08:25 UTC (rev 120358)
+++ ZODB/branches/tseaver-python_picklecache-2/src/persistent/interfaces.py	2011-02-15 22:08:26 UTC (rev 120359)
@@ -12,18 +12,23 @@
 #
 ##############################################################################
 """Persistence Interfaces
-
-$Id$
 """
 
 from zope.interface import Interface
 from zope.interface import Attribute
 
 try:
-    from cPersistence import GHOST, UPTODATE, CHANGED, STICKY
+    from cPersistence import GHOST
+    from cPersistence import UPTODATE
+    from cPersistence import CHANGED
+    from cPersistence import STICKY
 except ImportError:
-    GHOST, UPTODATE, CHANGED, STICKY = range(4)
+    from pypersistence import GHOST
+    from pypersistence import UPTODATE
+    from pypersistence import CHANGED
+    from pypersistence import STICKY
 
+
 class IPersistent(Interface):
     """Python persistent interface
 
@@ -164,17 +169,24 @@
         """The data manager for the object.
 
         The data manager implements the IPersistentDataManager interface.
+
         If there is no data manager, then this is None.
+
+        Once assigned to a data manager, an object cannot be re-assigned
+        to another.
         """)
 
     _p_oid = Attribute(
         """The object id.
 
         It is up to the data manager to assign this.
+
         The special value None is reserved to indicate that an object
         id has not been assigned.  Non-None object ids must be non-empty
         strings.  The 8-byte string '\0'*8 (8 NUL bytes) is reserved to
         identify the database root object.
+
+        Once assigned an OID, an object cannot be re-assigned another.
         """)
 
     _p_changed = Attribute(
@@ -216,6 +228,25 @@
         This is an 8-byte string (not Unicode).
         """)
 
+    _p_mtime = Attribute(
+        """The object's modification time (read-only).
+
+        This is a float, representing seconds since the epoch (as returned
+        by time.time).
+        """)
+
+    _p_state = Attribute(
+        """The object's persistence state token.
+
+        Must be one of GHOST, UPTODATE, CHANGED, or STICKY.
+        """)
+
+    _p_estimated_size = Attribute(
+        """An estimate of the object's size in bytes.
+
+        May be set by the data manager.
+        """)
+
     def __getstate__():
         """Get the object data.
 
@@ -227,6 +258,10 @@
         """Set the object data.
         """
 
+    def __reduce__():
+        """Reduce an object to contituent parts for serialization.
+        """
+
     def _p_activate():
         """Activate the object.
 
@@ -251,6 +286,40 @@
         object data to be reloaded.
         """
 
+    def _p_getattr(name):
+        """Test whether the base class must handle the name
+   
+        The method unghostifies the object, if necessary.
+        The method records the object access, if necessary.
+ 
+        This method should be called by subclass __getattribute__
+        implementations before doing anything else. If the method
+        returns True, then __getattribute__ implementations must delegate
+        to the base class, Persistent.
+        """
+
+    def _p_setattr(name, value):
+        """Save persistent meta data
+
+        This method should be called by subclass __setattr__ implementations
+        before doing anything else.  If it returns true, then the attribute
+        was handled by the base class.
+
+        The method unghostifies the object, if necessary.
+        The method records the object access, if necessary.
+        """
+
+    def _p_delattr(name):
+        """Delete persistent meta data
+
+        This method should be called by subclass __delattr__ implementations
+        before doing anything else.  If it returns true, then the attribute
+        was handled by the base class.
+
+        The method unghostifies the object, if necessary.
+        The method records the object access, if necessary.
+        """
+
 # TODO:  document conflict resolution.
 
 class IPersistentDataManager(Interface):

Modified: ZODB/branches/tseaver-python_picklecache-2/src/persistent/pypersistent.py
===================================================================
--- ZODB/branches/tseaver-python_picklecache-2/src/persistent/pypersistent.py	2011-02-15 22:08:25 UTC (rev 120358)
+++ ZODB/branches/tseaver-python_picklecache-2/src/persistent/pypersistent.py	2011-02-15 22:08:26 UTC (rev 120359)
@@ -140,6 +140,41 @@
 
     _p_changed = property(_get_changed, _set_changed, _del_changed)
 
+    # _p_mtime
+    def _get_mtime(self):
+        if self.__serial is not None:
+            when = datetime.datetime(*parseTimestamp(self.__serial))
+            return time.mktime(when.timetuple())
+
+    _p_mtime = property(_get_mtime)
+
+    # _p_state
+    def _get_state(self):
+        if self.__flags is None:
+            if self.__jar is None:
+                return UPTODATE
+            return GHOST
+        if self.__flags & _CHANGED:
+            if self.__jar is None:
+                return UPTODATE
+            result = CHANGED
+        else:
+            result = UPTODATE
+        if self.__flags & _STICKY:
+            return STICKY
+        return result
+
+    _p_state = property(_get_state)
+
+    # _p_estimated_size:  XXX don't want to reserve the space?
+    def _get_estimated_size(self):
+        return 0
+
+    def _set_estimated_size(self, value):
+        pass
+
+    _p_estimated_size = property(_get_estimated_size, _set_estimated_size)
+
     # The '_p_sticky' property is not (yet) part of the API:  for now,
     # it exists to simplify debugging and testing assertions.
     def _get_sticky(self):
@@ -174,40 +209,6 @@
 
     _p_status = property(_get_status)
 
-    # These attributes are defined by the C type, but not IPersistent.
-    def _get_mtime(self):
-        if self.__serial is not None:
-            when = datetime.datetime(*parseTimestamp(self.__serial))
-            return time.mktime(when.timetuple())
-    _p_mtime = property(_get_mtime)
-
-    # _p_state
-    def _get_state(self):
-        if self.__flags is None:
-            if self.__jar is None:
-                return UPTODATE
-            return GHOST
-        if self.__flags & _CHANGED:
-            if self.__jar is None:
-                return UPTODATE
-            result = CHANGED
-        else:
-            result = UPTODATE
-        if self.__flags & _STICKY:
-            return STICKY
-        return result
-
-    _p_state = property(_get_state)
-
-    # _p_estimated_size:  XXX don't want to reserve the space?
-    def _get_estimated_size(self):
-        return 0
-
-    def _set_estimated_size(self, value):
-        pass
-
-    _p_estimated_size = property(_get_estimated_size, _set_estimated_size)
-
     # Methods from IPersistent.
     def __getstate__(self):
         """ See IPersistent.
@@ -220,6 +221,12 @@
         if state != ():
             raise ValueError('No state allowed on base Persistent class')
 
+    def __reduce__(self):
+        """ See IPersistent.
+        """
+        gna = getattr(self, '__getnewargs__', lambda: ())
+        return ((type(self),) + gna(), self.__getstate__())
+
     def _p_activate(self):
         """ See IPersistent.
         """
@@ -241,18 +248,8 @@
             raise ValueError('Sticky')
         self.__flags = None
 
-    # Methods defined in C, not part of IPersistent
     def _p_getattr(self, name):
-        """\
-        _p_getattr(name) -- Test whether the base class must handle the name
-   
-        The method unghostifies the object, if necessary.
-        The method records the object access, if necessary.
- 
-        This method should be called by subclass __getattribute__
-        implementations before doing anything else. If the method
-        returns True, then __getattribute__ implementations must delegate
-        to the base class, Persistent.
+        """ See IPersistent.
         """
         if name.startswith('_p_') or name in SPECIAL_NAMES:
             return True
@@ -261,14 +258,7 @@
         return False
 
     def _p_setattr(self, name, value):
-        """_p_setattr(name, value) -- Save persistent meta data
-
-        This method should be called by subclass __setattr__ implementations
-        before doing anything else.  If it returns true, then the attribute
-        was handled by the base class.
-
-        The method unghostifies the object, if necessary.
-        The method records the object access, if necessary.
+        """ See IPersistent.
         """
         if name.startswith('_p_'):
             setattr(self, name, value)
@@ -278,14 +268,7 @@
         return False
 
     def _p_delattr(self, name):
-        """_p_delattr(name) -- Delete persistent meta data
-
-        This method should be called by subclass __delattr__ implementations
-        before doing anything else.  If it returns true, then the attribute
-        was handled by the base class.
-
-        The method unghostifies the object, if necessary.
-        The method records the object access, if necessary.
+        """ See IPersistent.
         """
         if name.startswith('_p_'):
             delattr(self, name)
@@ -294,12 +277,6 @@
         # TODO set the object as acceessed with the jar's cache.
         return False
 
-    def __reduce__(self):
-        """Reduce an object to contituent parts for serialization.
-        """
-        gna = getattr(self, '__getnewargs__', lambda: ())
-        return ((type(self),) + gna(), self.__getstate__())
-
     # Helper methods:  not APIs
     def _register(self):
         if self.__jar is not None and self.__oid is not None:



More information about the Zodb-checkins mailing list