[Zope-Checkins]
SVN: Zope/trunk/lib/python/Products/Sessions/SessionDataManager.py
On a tip from Dieter,
ensure that our hasattr replacement doesn't invoke __len__ on objects
retrieved by getattr due to Python boolean magic!
Chris McDonough
chrism at plope.com
Wed Aug 4 19:05:24 EDT 2004
Log message for revision 26908:
On a tip from Dieter, ensure that our hasattr replacement doesn't invoke __len__ on objects retrieved by getattr due to Python boolean magic!
I wish a miserable plague upon boolean magic that calls __len__ and the exception-hiding behavior of hasattr.
Changed:
U Zope/trunk/lib/python/Products/Sessions/SessionDataManager.py
-=-
Modified: Zope/trunk/lib/python/Products/Sessions/SessionDataManager.py
===================================================================
--- Zope/trunk/lib/python/Products/Sessions/SessionDataManager.py 2004-08-04 19:41:05 UTC (rev 26907)
+++ Zope/trunk/lib/python/Products/Sessions/SessionDataManager.py 2004-08-04 23:05:23 UTC (rev 26908)
@@ -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