[Zope3-checkins] CVS: Zope3/src/zope/app/registration/tests - registrationstack.py:1.2

Jim Fulton jim at zope.com
Thu Apr 8 17:02:44 EDT 2004


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

Modified Files:
	registrationstack.py 
Log Message:
Change to make registrations implement IPhysicallyLocatable and
to use real stacks.


=== Zope3/src/zope/app/registration/tests/registrationstack.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/registration/tests/registrationstack.py:1.1	Sat Mar 13 13:01:18 2004
+++ Zope3/src/zope/app/registration/tests/registrationstack.py	Thu Apr  8 17:02:44 2004
@@ -17,100 +17,40 @@
 """
 from zope.app.registration.registration import RegistrationStatusProperty
 from zope.app.container.contained import Contained
+from zope.app.traversing.interfaces import IPhysicallyLocatable
+import zope.interface
 
 __metaclass__ = type
 
 class TestingRegistration(Contained):
+    zope.interface.implements(IPhysicallyLocatable)
+
     status = RegistrationStatusProperty()
 
     def __init__(self, id):
-        self.id = id
+        self.id = str(id)
 
     def __eq__(self, other):
         return self.id == getattr(other, 'id', 0)
 
-class TestingRegistrationStack:
-
-    class_ = TestingRegistration
+    def getPath(self):
+        return self.id
 
-    def __init__(self, *args):
-        self._data = args
+    def __repr__(self):
+        return self.id
 
-    def register(self, registration):
-        cid = registration.id
-
-        if self._data:
-            if cid in self._data:
-                return # already registered
-        else:
-            # Nothing registered. Need to stick None in front so that nothing
-            # is active.
-            self._data = (None, )
-
-        self._data += (cid, )
-
-    def unregister(self, registration):
-        cid = registration.id
-
-        data = self._data
-        if data:
-            if data[0] == cid:
-                # It's active, we need to switch in None
-                self._data = (None, ) + data[1:]
-            else:
-                self._data = tuple([item for item in data if item != cid])
-
-    def registered(self, registration):
-        cid = registration.id
-        return cid in self._data
-
-    def activate(self, registration):
-        if registration is None:
-            self._data = (None,) + filter(None, self._data)
-            if self._data[-1] is None:
-                self._data = self._data[:-1]
-            return
-        cid = registration.id
-        if self._data[0] == cid:
-            return # already active
-
-        if self._data[0] is None:
-            # Remove leading None marker
-            self._data = self._data[1:]
-
-        self._data = (cid, ) + tuple(
-            [item for item in self._data if item != cid]
-            )
-
-    def deactivate(self, registration):
-        cid = registration.id
-        if self._data[0] != cid:
-            return # already inactive
-
-        # Just stick None on the front
-        self._data = (None, ) + self._data
-
-    def active(self):
-        if self._data:
-            return self.class_(self._data[0])
-
-        return None
-
-    def __nonzero__(self):
-        return bool(self._data)
-
-    def info(self):
-        result = [{'id': path,
-                   'active': False,
-                   'registration': self.class_(path),
-                   }
-                  for path in self._data
-                  ]
-
-        if result:
-            if result[0]['registration'] is None:
-                del result[0]
-            else:
-                result[0]['active'] = True
+    def activated(self):
+        pass
 
-        return result
+    deactivated = activated
+    
+from zope.app.registration.registration import RegistrationStack
+
+def TestingRegistrationStack(*regs):
+    regs = list(regs)
+    regs.reverse()
+    stack = RegistrationStack(None)
+    for reg in regs:
+        stack.register(reg)
+        stack.activate(reg)
+    return stack




More information about the Zope3-Checkins mailing list