[Zope3-checkins] CVS: Zope3/src/zope/app - location.py:1.1.2.4

Fred L. Drake, Jr. fred at zope.com
Tue Sep 9 17:06:05 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app
In directory cvs.zope.org:/tmp/cvs-serv25370

Modified Files:
      Tag: parentgeddon-branch
	location.py 
Log Message:
make CopyPersistent always return the same id for an outside object,
instead of assigning it multiple ids if seen multiple times


=== Zope3/src/zope/app/location.py 1.1.2.3 => 1.1.2.4 ===
--- Zope3/src/zope/app/location.py:1.1.2.3	Tue Sep  9 15:45:02 2003
+++ Zope3/src/zope/app/location.py	Tue Sep  9 16:06:04 2003
@@ -259,7 +259,6 @@
     >>> c3.o4 is o1.o2.o4
     1
 
-
     """
     tmp = tempfile.TemporaryFile()
     persistent = CopyPersistent(loc)
@@ -310,6 +309,12 @@
     >>> id4 is id3
     0
 
+    If we ask for the id of an outside location more than once, we
+    always get the same id back:
+
+    >> persistent.id(o4) == id4
+    1
+
     We also provide a load function that returns the objects for which
     we were given ids:
 
@@ -322,15 +327,18 @@
 
     def __init__(self, location):
         self.location = location
-        self.others = {}
-        self.load = self.others.get
+        self.pids_by_id = {}
+        self.others_by_pid = {}
+        self.load = self.others_by_pid.get
 
     def id(self, object):
         if ILocation.isImplementedBy(object):
             if not inside(object, self.location):
-                others = self.others
-                pid = len(others)
-                others[pid] = object
+                if id(object) in self.pids_by_id:
+                    return self.pids_by_id[id(object)]
+                pid = len(self.others_by_pid)
+                self.pids_by_id[id(object)] = pid
+                self.others_by_pid[pid] = object
                 return pid
 
         return None




More information about the Zope3-Checkins mailing list