[Zope-CVS] CVS: Products/Ape/apelib/zodb3 - serializers.py:1.3
Shane Hathaway
shane@zope.com
Sat, 29 Mar 2003 17:28:21 -0500
Update of /cvs-repository/Products/Ape/apelib/zodb3
In directory cvs.zope.org:/tmp/cvs-serv10503/apelib/zodb3
Modified Files:
serializers.py
Log Message:
Made _p_mtime work. The modification time comes through a gateway and
gets installed by a serializer.
Note that the strategy we're using for SQL is starting to become
burdensome. There is a lot of information we could collect with a
single query rather than several (currently a minimum of four queries
per object). CompositeGateway is perhaps too simple.
Also updated the style of imports in sqlmapper and fsmapper. By
importing modules rather than classes, the import statements are
simpler. I think this is nice but not applicable everywhere.
=== Products/Ape/apelib/zodb3/serializers.py 1.2 => 1.3 ===
--- Products/Ape/apelib/zodb3/serializers.py:1.2 Sat Mar 29 14:24:06 2003
+++ Products/Ape/apelib/zodb3/serializers.py Sat Mar 29 17:27:50 2003
@@ -19,9 +19,11 @@
import os
from cStringIO import StringIO
from cPickle import Pickler, Unpickler, UnpickleableError
+import time
from types import DictType
from Persistence import Persistent, PersistentMapping
+from ZODB.TimeStamp import TimeStamp
from apelib.core.interfaces \
import ISerializer, IFullSerializationEvent, \
@@ -228,4 +230,39 @@
pass
else:
event.addUnmanagedPersistentObjects(unmanaged)
+
+
+class ModTimeAttribute:
+ """Sets the _p_mtime attribute."""
+
+ __implements__ = ISerializer
+
+ schema = FieldSchema('mtime', 'float')
+
+ def getSchema(self):
+ return self.schema
+
+ def canSerialize(self, obj):
+ try:
+ return isinstance(obj, Persistent)
+ except TypeError:
+ # XXX Python 2.1 thinks Persistent is not a class
+ return 0
+
+ def setTime(self, obj, t):
+ """Sets the last modification time of a Persistent obj to float t.
+ """
+ args = time.gmtime(t)[:5] + (t%60,)
+ obj._p_serial = repr(TimeStamp(*args))
+
+ def serialize(self, obj, event):
+ now = time.time()
+ if obj._p_changed:
+ # Indicate that this object just changed. Note that the time
+ # is a guess.
+ self.setTime(obj, now)
+ return now
+
+ def deserialize(self, obj, event, state):
+ self.setTime(obj, state)