[Checkins] SVN: keas.pbstate/trunk/src/keas/pbstate/ The _p_changed tests now pass

Shane Hathaway shane at hathawaymix.org
Mon Jan 12 23:25:25 EST 2009


Log message for revision 94716:
  The _p_changed tests now pass
  

Changed:
  U   keas.pbstate/trunk/src/keas/pbstate/README.txt
  U   keas.pbstate/trunk/src/keas/pbstate/meta.py

-=-
Modified: keas.pbstate/trunk/src/keas/pbstate/README.txt
===================================================================
--- keas.pbstate/trunk/src/keas/pbstate/README.txt	2009-01-13 03:01:41 UTC (rev 94715)
+++ keas.pbstate/trunk/src/keas/pbstate/README.txt	2009-01-13 04:25:23 UTC (rev 94716)
@@ -4,7 +4,7 @@
 =====
 
 These are tests of keas.pbstate, a Python package that provides
-a method of storing object state in a Google Protocol Buffer.
+a way to store Python object state in a Google Protocol Buffer.
 These tests also serve as basic documentation of this package.
 This package is designed to be compatible with ZODB, but ZODB is
 not required.
@@ -90,7 +90,7 @@
     >>> c.__getstate__()
     ('\x08\xe9\x07\x12\x08John Doe\x1a#\n\x10100 First Avenue\x1a\x07Toronto2\x06Canada', {})
 
-Create a contact and fill in its state from c.
+Create a contact and copy its state from c.
 
     >>> c_dup = Contact.__new__(Contact)
     >>> c_dup.__setstate__(c.__getstate__())
@@ -152,7 +152,7 @@
     >>> c3 = PersistentContact()
     >>> c3.create_time = 1003
     >>> c3.name = u'Snoopy'
-    >>> c3._p_changed = False
+    >>> c3._p_changed = False; c3.__getstate__() and None
 
 Reading an attribute does not set _p_changed.
 
@@ -169,10 +169,30 @@
 
 Adding to a repeated element sets _p_changed.
 
-    >>> c3._p_changed = False
+    >>> c3._p_changed = False; c3.__getstate__() and None
     >>> c3._p_changed
     False
     >>> c3.guardians.add()
     <keas.pbstate.testclasses_pb2.Ref object at ...>
     >>> c3._p_changed
     True
+    >>> del c3.guardians[0]
+
+A copy of c3 should initially have _p_changed = False; setting an attribute
+should set _p_changed to true.
+
+    >>> c4 = PersistentContact.__new__(PersistentContact)
+    >>> c4.__setstate__(c3.__getstate__())
+    >>> c4._p_changed
+    False
+    >>> c4.name = u'Linus'
+    >>> c4._p_changed
+    True
+
+The tuple returned by __getstate__ is actually a subclass of tuple.  This
+might tell the serializer in ZODB to save the state without pickling.
+
+TODO: __getstate__ returns StateTuple
+
+TODO: mixins
+

Modified: keas.pbstate/trunk/src/keas/pbstate/meta.py
===================================================================
--- keas.pbstate/trunk/src/keas/pbstate/meta.py	2009-01-13 03:01:41 UTC (rev 94715)
+++ keas.pbstate/trunk/src/keas/pbstate/meta.py	2009-01-13 04:25:23 UTC (rev 94716)
@@ -169,6 +169,9 @@
         # Clean up unused references and get the targets mapping.
         used = set(self._protobuf_find_refids(self.protobuf))
         targets = self.protobuf_refs._get_targets(self, used)
+        if hasattr(self, '_p_changed'):
+            # Reset the message's internal _cache_byte_size_dirty flag
+            self.protobuf.ByteSize()
         # Return the state and all reference targets.
         return StateTuple((self.protobuf.SerializeToString(), targets))
 
@@ -184,6 +187,8 @@
         self.protobuf.MergeFromString(data)
         if hasattr(self, '_p_changed'):
             self.protobuf._SetListener(PersistentChangeListener(self))
+            # Reset the message's internal _cache_byte_size_dirty flag
+            self.protobuf.ByteSize()
 
 
 class PersistentChangeListener(object):



More information about the Checkins mailing list