[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/versioncontrol/
Fixed bug: findModificationTime wasn't handling locations properly.
Jim Fulton
jim at zope.com
Tue May 24 15:37:05 EDT 2005
Log message for revision 30489:
Fixed bug: findModificationTime wasn't handling locations properly.
Changed:
U Zope3/trunk/src/zope/app/versioncontrol/tests.py
U Zope3/trunk/src/zope/app/versioncontrol/utility.py
-=-
Modified: Zope3/trunk/src/zope/app/versioncontrol/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/versioncontrol/tests.py 2005-05-24 16:08:36 UTC (rev 30488)
+++ Zope3/trunk/src/zope/app/versioncontrol/tests.py 2005-05-24 19:36:35 UTC (rev 30489)
@@ -17,6 +17,7 @@
"""
import sys
import unittest
+import persistent
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.testing import doctest, module
@@ -41,7 +42,57 @@
ps.tearDown()
+class L(persistent.Persistent, zope.app.location.Location):
+ pass
+
+def testLocationSanity_for__findModificationTime():
+ """\
+_findModificationTime should not go outside the location
+
+ >>> import ZODB.tests.util
+ >>> db = ZODB.tests.util.DB()
+ >>> conn = db.open()
+
+
+ >>> ob = L()
+ >>> conn.root()['ob'] = ob
+ >>> ob.y = L()
+ >>> ob.y.__parent__ = ob
+ >>> parent = L()
+ >>> ob.__parent__ = parent
+ >>> x = L()
+ >>> ob.x = x
+
+ >>> import transaction
+ >>> transaction.commit()
+
+ >>> parent.v = 1
+ >>> transaction.commit()
+
+ >>> import zope.app.versioncontrol.utility
+ >>> p = zope.app.versioncontrol.utility._findModificationTime(ob)
+ >>> p == ob._p_serial == ob.y._p_serial
+ True
+
+ >>> ob.x.v = 1
+ >>> transaction.commit()
+
+ >>> p = zope.app.versioncontrol.utility._findModificationTime(ob)
+ >>> p == ob._p_serial == ob.y._p_serial
+ True
+
+ >>> ob.y.v = 1
+ >>> transaction.commit()
+
+ >>> p = zope.app.versioncontrol.utility._findModificationTime(ob)
+ >>> p == ob._p_serial
+ False
+ >>> p == ob.y._p_serial
+ True
+
+"""
+
def testLocationSanity_for_cloneByPickle():
"""\
cloneByPickle should not go outside a location
Modified: Zope3/trunk/src/zope/app/versioncontrol/utility.py
===================================================================
--- Zope3/trunk/src/zope/app/versioncontrol/utility.py 2005-05-24 16:08:36 UTC (rev 30488)
+++ Zope3/trunk/src/zope/app/versioncontrol/utility.py 2005-05-24 19:36:35 UTC (rev 30489)
@@ -16,6 +16,8 @@
$Id$
"""
import time
+from cStringIO import StringIO
+from cPickle import Pickler
import persistent
@@ -72,36 +74,29 @@
themselves version-controlled objects. Note that this will
return None if the object has no modification time."""
- mtime = getattr(object, '_p_serial', None)
- if mtime is None:
- return None
+ serial = [object._p_serial]
- latest = mtime
- conn = object._p_jar
- load = conn._storage.load
- version = conn._version
- refs = referencesf
+ def persistent_id(ob):
+ s = getattr(ob, '_p_serial', None)
+ if not isinstance(s, str):
+ return None
- oids=[object._p_oid]
- done_oids={}
- done=done_oids.has_key
- first = True
+ # XXX obviously no test for this
+ if (zope.app.location.ILocation.providedBy(ob)
+ and not zope.app.location.inside(ob, object)):
+ return '1' # go away
- while oids:
- oid=oids[0]
- del oids[0]
- if done(oid):
- continue
- done_oids[oid]=1
- try: p, serial = load(oid, version)
- except: pass # invalid reference!
- else:
- if first:
- first = False
- else:
- if p.find('U\x0b__vc_info__') == -1:
- if serial > latest:
- latest = serial
- refs(p, oids)
+# The location check above should wake the object
+## if getattr(ob, '_p_changed', 0) is None:
+## ob._p_changed = 0
- return latest
+ serial[0] = max(serial[0], s)
+
+ return None
+
+ stream = StringIO()
+ p = Pickler(stream, 1)
+ p.persistent_id = persistent_id
+ p.dump(object)
+
+ return serial[0]
More information about the Zope3-Checkins
mailing list