[z3-checkins] r14440 - z3/Five/trunk

philikon at codespeak.net philikon at codespeak.net
Fri Jul 8 20:55:41 CEST 2005


Author: philikon
Date: Fri Jul  8 20:55:37 2005
New Revision: 14440

Modified:
   z3/Five/trunk/eventconfigure.py
   z3/Five/trunk/fiveconfigure.py
   z3/Five/trunk/sizeconfigure.py
Log:
generalize monkey cleanup into a killMonkey() function;
added cleanup for other monkeys. they haven't been hooked
into the tests yet, though.


Modified: z3/Five/trunk/eventconfigure.py
==============================================================================
--- z3/Five/trunk/eventconfigure.py	(original)
+++ z3/Five/trunk/eventconfigure.py	Fri Jul  8 20:55:37 2005
@@ -107,25 +107,17 @@
         )
 
 # clean up code
+from Products.Five.fiveconfigure import killMonkey
+from zope.testing.cleanup import addCleanUp
 
 def unsendEvents(class_):
     """Restore class's initial state with respect to sending events"""
     for name in ['manage_afterAdd', 'manage_beforeDelete']:
-        method = getattr(class_, name, None)
-        if isFiveMethod(method):
-            original = getattr(class_, '__five_original_' + name, None)
-            if original is None:
-                try:
-                    delattr(class_, name)
-                except AttributeError:
-                    pass
-            else:                
-                setattr(class_, name, original)
+        killMonkey(class_, name, '__five_original_'+name)
 
 def cleanUp():
     for class_ in _monkied:
         unsendEvents(class_)
 
-from zope.testing.cleanup import addCleanUp
 addCleanUp(cleanUp)
 del addCleanUp

Modified: z3/Five/trunk/fiveconfigure.py
==============================================================================
--- z3/Five/trunk/fiveconfigure.py	(original)
+++ z3/Five/trunk/fiveconfigure.py	Fri Jul  8 20:55:37 2005
@@ -80,6 +80,7 @@
 def isFiveMethod(m):
     return hasattr(m, '__five_method__')
 
+_traversable_monkies = []
 def classTraversable(class_):
     # If a class already has this attribute, it means it is either a
     # subclass of Traversable or was already processed with this
@@ -105,6 +106,8 @@
     setattr(class_, '__bobo_traverse__',
             Traversable.__bobo_traverse__.im_func)
     setattr(class_, '__five_traversable__', True)
+    # remember class for clean up
+    _traversable_monkies.append(class_)
 
 def traversable(_context, class_):
     _context.action(
@@ -113,6 +116,7 @@
         args = (class_,)
         )
 
+_defaultviewable_monkies = []
 def classDefaultViewable(class_):
     # If a class already has this attribute, it means it is either a
     # subclass of DefaultViewable or was already processed with this
@@ -137,6 +141,8 @@
     setattr(class_, '__browser_default__',
             Viewable.__browser_default__.im_func)
     setattr(class_, '__five_viewable__', True)
+    # remember class for clean up
+    _defaultviewable_monkies.append(class_)
 
 def defaultViewable(_context, class_):
     _context.action(
@@ -201,4 +207,44 @@
         page(_context, name=name, permission=permission,
              layer=layer, for_=for_, template=fname)
 
+# clean up code
 
+def killMonkey(class_, name, fallback, attr=None):
+    """Die monkey, die!"""
+    method = getattr(class_, name, None)
+    if isFiveMethod(method):
+        original = getattr(class_, fallback, None)
+        if original is None:
+            try:
+                delattr(class_, name)
+            except AttributeError:
+                pass
+        else:                
+            setattr(class_, name, original)
+
+    if attr is not None:
+        try:
+            delattr(class_, attr)
+        except AttributeError:
+            pass
+
+def untraversable(class_):
+    """Restore class's initial state with respect to traversability"""
+    killMonkey(class_, '__bobo_traverse__', '__fallback_traverse__',
+               '__five_traversable__')
+
+def undefaultViewable(class_):
+    """Restore class's initial state with respect to being default
+    viewable."""
+    killMonkey(class_, '__browser_default__', '__fallback_default__',
+               '__five_viewable__')
+
+def cleanUp():
+    for class_ in _traversable_monkies:
+        untraversable(class_)
+    for class_ in _defaultviewable_monkies:
+        undefaultViewable(class_)
+
+from zope.testing.cleanup import addCleanUp
+addCleanUp(cleanUp)
+del addCleanUp

Modified: z3/Five/trunk/sizeconfigure.py
==============================================================================
--- z3/Five/trunk/sizeconfigure.py	(original)
+++ z3/Five/trunk/sizeconfigure.py	Fri Jul  8 20:55:37 2005
@@ -44,3 +44,18 @@
         callable = classSizable,
         args=(class_,)
         )
+
+# clean up code
+from Products.Five.fiveconfigure import killMonkey
+from zope.testing.cleanup import addCleanUp
+
+def unsizable(class_):
+    """Restore class's initial state with respect to being sizable"""
+    killMonkey(class_, 'get_size', '__five_original_get_size')
+
+def cleanUp():
+    for class_ in _monkied:
+        unsizable(class_)
+
+addCleanUp(cleanUp)
+del addCleanUp


More information about the z3-checkins mailing list