[Zope-Checkins] CVS: Products/Sessions - SessionDataManager.py:1.23.68.3

Chris McDonough chrism at plope.com
Wed Aug 4 18:55:49 EDT 2004


Update of /cvs-repository/Products/Sessions
In directory cvs.zope.org:/tmp/cvs-serv16874

Modified Files:
      Tag: Zope-2_7-branch
	SessionDataManager.py 
Log Message:
On a tip from Dieter, ensure that our hasattr replacement is very explicit: don't allow the __len__ method of the result of getattr to be called implicitly in a boolean context.

I wish a plague upon the house of the implicit behavior of both __len__ and hasattr!


=== Products/Sessions/SessionDataManager.py 1.23.68.2 => 1.23.68.3 ===
--- Products/Sessions/SessionDataManager.py:1.23.68.2	Wed May 26 07:01:34 2004
+++ Products/Sessions/SessionDataManager.py	Wed Aug  4 18:55:49 2004
@@ -179,8 +179,10 @@
         """ returns new or existing session data object """
         container = self._getSessionDataContainer()
         ob = container.new_or_existing(key)
-        # hasattr hides conflicts
-        if getattr(ob, '__of__', None) and getattr(ob, 'aq_parent', None):
+        # hasattr hides conflicts; be explicit by comparing to None
+        # because otherwise __len__ of the requested object might be called!
+        if ( getattr(ob, '__of__', None) is not None and
+             getattr(ob, 'aq_parent', None) is not None ):
             # splice ourselves into the acquisition chain
             return ob.__of__(self.__of__(ob.aq_parent))
         return ob.__of__(self)
@@ -190,8 +192,11 @@
         container = self._getSessionDataContainer()
         ob = container.get(key)
         if ob is not None:
-            # hasattr hides conflicts
-            if getattr(ob, '__of__', None) and getattr(ob, 'aq_parent', None):
+            # hasattr hides conflicts; be explicit by comparing to None
+            # because otherwise __len__ of the requested object might be
+            # called!
+            if ( getattr(ob, '__of__', None) is not None and
+                 getattr(ob, 'aq_parent', None) is not None ):
                 # splice ourselves into the acquisition chain
                 return ob.__of__(self.__of__(ob.aq_parent))
             return ob.__of__(self)



More information about the Zope-Checkins mailing list