Commit b8f3f7a0 authored by Chris McDonough's avatar Chris McDonough

Changed transient object invalidate() method to search acquisition

chain for its transient object container.

Changed session data manager to splice itself into the transient
object container's acquisition path before returning a session
data object via getSessionData.

Updated unit tests to reflect changes.
parent 712bdd92
...@@ -172,14 +172,20 @@ class SessionDataManager(Item, Implicit, Persistent, RoleManager, Owned, Tabs): ...@@ -172,14 +172,20 @@ class SessionDataManager(Item, Implicit, Persistent, RoleManager, Owned, Tabs):
def _getSessionDataObject(self, key): def _getSessionDataObject(self, key):
""" returns new or existing session data object """ """ returns new or existing session data object """
container = self._getSessionDataContainer() container = self._getSessionDataContainer()
ob = aq_base(container.new_or_existing(key)) ob = container.new_or_existing(key)
if hasattr(ob, '__of__') and hasattr(ob, 'aq_parent'):
# splice ourselves into the acquisition chain
return ob.__of__(self.__of__(ob.aq_parent))
return ob.__of__(self) return ob.__of__(self)
def _getSessionDataObjectByKey(self, key): def _getSessionDataObjectByKey(self, key):
""" returns new or existing session data object """ """ returns new or existing session data object """
container = self._getSessionDataContainer() container = self._getSessionDataContainer()
ob = aq_base(container.get(key)) ob = container.get(key)
if ob is not None: if ob is not None:
if hasattr(ob, '__of__') and hasattr(ob, 'aq_parent'):
# splice ourselves into the acquisition chain
return ob.__of__(self.__of__(ob.aq_parent))
return ob.__of__(self) return ob.__of__(self)
def _getSessionDataContainer(self): def _getSessionDataContainer(self):
...@@ -260,3 +266,5 @@ class SessionDataManagerTraverser(Persistent): ...@@ -260,3 +266,5 @@ class SessionDataManagerTraverser(Persistent):
return return
if self._requestSessionName is not None: if self._requestSessionName is not None:
request.set_lazy(self._requestSessionName, getSessionData) request.set_lazy(self._requestSessionName, getSessionData)
Globals.InitializeClass(SessionDataManager)
...@@ -127,10 +127,13 @@ class TestSessionManager(TestBase): ...@@ -127,10 +127,13 @@ class TestSessionManager(TestBase):
sd = self.app.session_data_manager.getSessionData() sd = self.app.session_data_manager.getSessionData()
assert self.app.session_data_manager.hasSessionData() assert self.app.session_data_manager.hasSessionData()
def testSessionDataWrappedInSDM(self): def testSessionDataWrappedInSDMandTOC(self):
sd = self.app.session_data_manager.getSessionData(1) sd = self.app.session_data_manager.getSessionData(1)
assert aq_base(sd.aq_parent) is \ assert aq_base(sd.aq_parent) is \
aq_base(self.app.session_data_manager), sd.aq_parent aq_base(getattr(self.app, 'session_data_manager')), sd.aq_parent
assert aq_base(sd.aq_parent.aq_parent) is \
aq_base(getattr(self.app.temp_folder, toc_name)), \
sd.aq_parent.aq_parent
def testNewSessionDataObjectIsValid(self): def testNewSessionDataObjectIsValid(self):
sdType = type(TransientObject(1)) sdType = type(TransientObject(1))
...@@ -138,12 +141,6 @@ class TestSessionManager(TestBase): ...@@ -138,12 +141,6 @@ class TestSessionManager(TestBase):
assert type(getattr(sd, 'aq_base', sd)) is sdType assert type(getattr(sd, 'aq_base', sd)) is sdType
assert not hasattr(sd, '_invalid') assert not hasattr(sd, '_invalid')
def testInvalidateSessionDataObject(self):
sd = self.app.session_data_manager.getSessionData()
sd.invalidate()
assert hasattr(sd, '_invalid')
assert not sd.isValid()
def testBrowserIdIsSet(self): def testBrowserIdIsSet(self):
sd = self.app.session_data_manager.getSessionData() sd = self.app.session_data_manager.getSessionData()
mgr = getattr(self.app, idmgr_name) mgr = getattr(self.app, idmgr_name)
......
...@@ -13,16 +13,17 @@ ...@@ -13,16 +13,17 @@
""" """
Simple ZODB-based transient object implementation. Simple ZODB-based transient object implementation.
$Id: TransientObject.py,v 1.7 2002/06/21 01:51:43 chrism Exp $ $Id: TransientObject.py,v 1.8 2002/06/24 19:31:16 chrism Exp $
""" """
__version__='$Revision: 1.7 $'[11:-2] __version__='$Revision: 1.8 $'[11:-2]
from Persistence import Persistent from Persistence import Persistent
from Acquisition import Implicit from Acquisition import Implicit
import time, random, sys import time, random, sys
from TransienceInterfaces import ItemWithId, Transient, DictionaryLike,\ from TransienceInterfaces import ItemWithId, Transient, DictionaryLike,\
TTWDictionary, ImmutablyValuedMappingOfPickleableObjects TTWDictionary, ImmutablyValuedMappingOfPickleableObjects,\
TransientItemContainer
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
import Globals import Globals
from zLOG import LOG, BLATHER, INFO from zLOG import LOG, BLATHER, INFO
...@@ -77,7 +78,13 @@ class TransientObject(Persistent, Implicit): ...@@ -77,7 +78,13 @@ class TransientObject(Persistent, Implicit):
if hasattr(self, '_invalid'): if hasattr(self, '_invalid'):
# we dont want to invalidate twice # we dont want to invalidate twice
return return
trans_ob_container = getattr(self, 'aq_parent', None) trans_ob_container = None
# search our acquisition chain for a transient object container
# and delete ourselves from it.
for ob in getattr(self, 'aq_chain', []):
if TransientItemContainer.isImplementedBy(ob):
trans_ob_container = ob
break
if trans_ob_container is not None: if trans_ob_container is not None:
if trans_ob_container.has_key(self.token): if trans_ob_container.has_key(self.token):
del trans_ob_container[self.token] del trans_ob_container[self.token]
......
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