Commit f4a9cd52 authored by Chris McDonough's avatar Chris McDonough

On a tip from Dieter, ensure that our hasattr replacement doesn't invoke...

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.
parent ed926a38
...@@ -179,8 +179,10 @@ class SessionDataManager(Item, Implicit, Persistent, RoleManager, Owned, Tabs): ...@@ -179,8 +179,10 @@ class SessionDataManager(Item, Implicit, Persistent, RoleManager, Owned, Tabs):
""" returns new or existing session data object """ """ returns new or existing session data object """
container = self._getSessionDataContainer() container = self._getSessionDataContainer()
ob = container.new_or_existing(key) ob = container.new_or_existing(key)
# hasattr hides conflicts # hasattr hides conflicts; be explicit by comparing to None
if getattr(ob, '__of__', None) and getattr(ob, 'aq_parent', 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 # splice ourselves into the acquisition chain
return ob.__of__(self.__of__(ob.aq_parent)) return ob.__of__(self.__of__(ob.aq_parent))
return ob.__of__(self) return ob.__of__(self)
...@@ -190,8 +192,11 @@ class SessionDataManager(Item, Implicit, Persistent, RoleManager, Owned, Tabs): ...@@ -190,8 +192,11 @@ class SessionDataManager(Item, Implicit, Persistent, RoleManager, Owned, Tabs):
container = self._getSessionDataContainer() container = self._getSessionDataContainer()
ob = container.get(key) ob = container.get(key)
if ob is not None: if ob is not None:
# hasattr hides conflicts # hasattr hides conflicts; be explicit by comparing to None
if getattr(ob, '__of__', None) and getattr(ob, 'aq_parent', 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 # splice ourselves into the acquisition chain
return ob.__of__(self.__of__(ob.aq_parent)) return ob.__of__(self.__of__(ob.aq_parent))
return ob.__of__(self) return ob.__of__(self)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment