[Zope-CVS] CVS: Products/Sessions - BrowserIdManager.py:1.2 RAM_DB.py:1.2 SessionDataManager.py:1.2 __init__.py:1.2
Matthew T. Kromer
matt@zope.com
Thu, 1 Nov 2001 14:21:05 -0500
Update of /cvs-repository/Products/Sessions
In directory cvs.zope.org:/tmp/cvs-serv2132
Modified Files:
BrowserIdManager.py RAM_DB.py SessionDataManager.py
__init__.py
Log Message:
Get Sessions working
=== Products/Sessions/BrowserIdManager.py 1.1 => 1.2 ===
_marker = []
-constructBrowserIdManagerForm = Globals.DTMLFile('addIdManager',globals())
+constructBrowserIdManagerForm = Globals.DTMLFile('dtml/addIdManager',globals())
+
+ADD_BROWSER_ID_MANAGER_PERM="Add Browser ID Manager"
def constructBrowserIdManager(
self, id, title='', tokenkey='_ZopeId', cookiepri=1, formpri=2,
@@ -217,7 +219,7 @@
# non-delegating methods follow
security.declareProtected(MGMT_SCREEN_PERM, 'manage_browseridmgr')
- manage_browseridmgr = Globals.DTMLFile('manageIdManager', globals())
+ manage_browseridmgr = Globals.DTMLFile('dtml/manageIdManager', globals())
security.declareProtected(CHANGE_IDMGR_PERM,
'manage_changeBrowserIdManager')
=== Products/Sessions/RAM_DB.py 1.1 => 1.2 ===
import Globals
+from Globals import HTMLFile
from ZODB.Mount import MountPoint
import string
import OFS
+import os, os.path
+
+ADD_RAMDB_PERM="Add RAM Databases"
+
+
+
+def constructRAMDB(self, id, title=None, REQUEST=None):
+ """ """
+ ms = MountedRAM_DB(id, title)
+ self._setObject(id, ms)
+ if REQUEST is not None:
+ return self.manage_main(self, REQUEST, update_menu=1)
+
+
+constructRAMDBForm=HTMLFile('dtml/addRAMDB', globals())
+
class MountedRAM_DB(MountPoint, OFS.SimpleItem.Item):
"""
@@ -101,13 +118,14 @@
manage_options = ({'label':'Traceback', 'action':'manage_traceback'},)
meta_type = 'Broken Mounted RAM Database'
- def __init__(self, id, params=None):
+ def __init__(self, id, title='', params=None):
self.id = str(id)
- MountPoint.__init__(self, path='/', params)
-
- manage_traceback = Globals.DTMLFile('mountfail', globals())
+ self.title = title
+ MountPoint.__init__(self, path='/') # Eep
- def _createDB(self, db = db):
+ manage_traceback = Globals.DTMLFile('dtml/mountfail', globals())
+
+ def _createDB(self, db=None): # huh? db=db was original
""" Create a mounted RAM database """
from SessionStorage import SessionStorage
from ZODB.DB import DB
@@ -120,9 +138,31 @@
sdc = root.get('folder', None)
if sdc is None:
sdc = root['folder'] = OFS.Folder.Folder()
+ self._populate(sdc, root)
+
return sdc
def mount_error_(self):
return self._v_connect_error
+ def _populate(self, folder, root):
+ # Set up our folder object
+ folder.id = self.id # be a chameleon
+ folder.title = self.title
+
+ folder.icon = "misc_/Sessions/ramdb.gif"
+
+ importdir = os.path.join(Globals.data_dir,self.id+"Imports")
+
+ #conn = folder._p_jar # Can we do that yet?
+ conn = root._p_jar
+
+ try:
+ for file in os.listdir(importdir):
+ if file[-5:] == ".zexp":
+ id = file[:-5]
+ # Import this!
+ ob = conn.importFile(os.path.join(importdir, file))
+ folder._setObject(id, ob)
+ except OSError: pass # (no such dir)
=== Products/Sessions/SessionDataManager.py 1.1 => 1.2 ===
from SessionPermissions import *
from common import DEBUG
+from ZPublisher.BeforeTraverse import registerBeforeTraverse, \
+ unregisterBeforeTraverse, NameCaller
+import traceback
-BID_MGR_NAME = 'browser_id_manager'
+BID_MGR_NAME = 'browser_id_mgr'
bad_path_chars_in=re.compile('[^a-zA-Z0-9-_~\,\. \/]').search
class SessionDataManagerErr(Exception): pass
-constructSessionDataManagerForm = Globals.DTMLFile('addDataManager', globals())
+constructSessionDataManagerForm = Globals.DTMLFile('dtml/addDataManager',
+ globals())
-def constructSessionDataManager(self, id, title='', path=None)
+ADD_SESSION_DATAMANAGER_PERM="Add Session Data Manager"
+
+def constructSessionDataManager(self, id, title='', path=None, automatic=None,
+ REQUEST=None):
""" """
- ob = SessionDataManager(id, path, title)
+ ob = SessionDataManager(id, path, title, automatic)
self._setObject(id, ob)
if REQUEST is not None:
return self.manage_main(self, REQUEST, update_menu=1)
@@ -58,7 +65,8 @@
__implements__ = (SessionInterfaces.SessionDataManagerInterface, )
- manage_sessiondatamgr = Globals.DTMLFile('manageDataManager', globals())
+ manage_sessiondatamgr = Globals.DTMLFile('dtml/manageDataManager',
+ globals())
# INTERFACE METHODS FOLLOW
@@ -92,16 +100,25 @@
# END INTERFACE METHODS
- def __init__(self, id, path=None, title=''):
+ def __init__(self, id, path=None, title='', automatic=None):
self.id = id
self.setContainerPath(path)
self.setTitle(title)
+ if automatic:
+ self._requestSessionName='SESSION'
+ else:
+ self._requestSessionName=None
+
security.declareProtected(CHANGE_DATAMGR_PERM, 'manage_changeSDM')
- def manage_changeSDM(self, title, path=None, REQUEST=None):
+ def manage_changeSDM(self, title, path=None, automatic=None, REQUEST=None):
""" """
self.setContainerPath(path)
self.setTitle(title)
+ if automatic:
+ self.updateTraversalData('SESSION')
+ else:
+ self.updateTraversalData(None)
if REQUEST is not None:
return self.manage_sessiondatamgr(self, REQUEST)
@@ -179,4 +196,54 @@
string.join(self.obpath,'/')
)
-
+ security.declareProtected(MGMT_SCREEN_PERM, 'getAutomatic')
+ def getAutomatic(self):
+ """ """
+ if hasattr(self,'_hasTraversalHook'): return 1
+ return 0
+
+ def manage_afterAdd(self, item, container):
+ """ Add our traversal hook """
+ self.updateTraversalData(self._requestSessionName)
+
+ def manage_beforeDelete(self, item, container):
+ """ Clean up on delete """
+ self.updateTraversalData(None)
+
+ def updateTraversalData(self, requestSessionName=None):
+ # Note this cant be called directly at add -- manage_afterAdd will work
+ # though.
+
+ parent = self.aq_inner.aq_parent
+
+ if getattr(self,'_hasTraversalHook', None):
+ unregisterBeforeTraverse(parent, 'SessionDataManager')
+ del self._hasTraversalHook
+ self._requestSessionName = None
+
+ if requestSessionName:
+ hook = SessionDataManagerTraverser(requestSessionName, self)
+ registerBeforeTraverse(parent, hook, 'SessionDataManager', 50)
+ self._hasTraversalHook = 1
+ self._requestSessionName = requestSessionName
+
+class SessionDataManagerTraverser(NameCaller):
+ meta_type = "Session ID Insertion Traversal Rule"
+
+ def __init__(self, requestSessionName, sdm):
+ self._requestSessionName = requestSessionName
+ self._sessionDataManager = sdm
+
+ def __call__(self, container, request):
+ sdm = self._sessionDataManager.__of__(container)
+ # Yank our session & stuff into request
+ try:
+ session = sdm.getSessionData()
+ except:
+ LOG('Session Tracking', WARNING, 'Session automatic traversal '
+ 'failed to get session data', error=sys.exc_info())
+ return # Throw our hands up but dont fail
+ if self._requestSessionName is not None:
+ request[self._requestSessionName] = session
+
+ NameCaller.__call__(self, container, request)
=== Products/Sessions/__init__.py 1.1.1.1 => 1.2 ===
+#
+# Zope Public License (ZPL) Version 1.0
+# -------------------------------------
+#
+# Copyright (c) Digital Creations. All rights reserved.
+#
+# This license has been certified as Open Source(tm).
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions in source code must retain the above copyright
+# notice, this list of conditions, and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions, and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+#
+# 3. Digital Creations requests that attribution be given to Zope
+# in any manner possible. Zope includes a "Powered by Zope"
+# button that is installed by default. While it is not a license
+# violation to remove this button, it is requested that the
+# attribution remain. A significant investment has been put
+# into Zope, and this effort will continue if the Zope community
+# continues to grow. This is one way to assure that growth.
+#
+# 4. All advertising materials and documentation mentioning
+# features derived from or use of this software must display
+# the following acknowledgement:
+#
+# "This product includes software developed by Digital Creations
+# for use in the Z Object Publishing Environment
+# (http://www.zope.org/)."
+#
+# In the event that the product being advertised includes an
+# intact Zope distribution (with copyright and license included)
+# then this clause is waived.
+#
+# 5. Names associated with Zope or Digital Creations must not be used to
+# endorse or promote products derived from this software without
+# prior written permission from Digital Creations.
+#
+# 6. Modified redistributions of any form whatsoever must retain
+# the following acknowledgment:
+#
+# "This product includes software developed by Digital Creations
+# for use in the Z Object Publishing Environment
+# (http://www.zope.org/)."
+#
+# Intact (re-)distributions of any official Zope release do not
+# require an external acknowledgement.
+#
+# 7. Modifications are encouraged but must be packaged separately as
+# patches to official Zope releases. Distributions that do not
+# clearly separate the patches from the original work must be clearly
+# labeled as unofficial distributions. Modifications which do not
+# carry the name Zope may be packaged in any form, as long as they
+# conform to all of the clauses above.
+#
+#
+# Disclaimer
+#
+# THIS SOFTWARE IS PROVIdED BY DIGITAL CREATIONS ``AS IS'' AND ANY
+# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIdENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+#
+# This software consists of contributions made by Digital Creations and
+# many individuals on behalf of Digital Creations. Specific
+# attributions are listed in the accompanying credits file.
+#
+##############################################################################
+"""
+Session initialization routines
+
+$Id$
+"""
+
+import BrowserIdManager
+import RAM_DB
+import SessionDataManager
+
+def initialize(context):
+ context.registerClass(
+ RAM_DB.MountedRAM_DB,
+ permission=RAM_DB.ADD_RAMDB_PERM,
+ icon='www/ramdb.gif',
+ meta_type='Temporary Folder',
+ constructors=(RAM_DB.constructRAMDBForm,
+ RAM_DB.constructRAMDB)
+ )
+
+ context.registerClass(
+ BrowserIdManager.BrowserIdManager,
+ icon="www/idmgr.gif",
+ permission=BrowserIdManager.ADD_BROWSER_ID_MANAGER_PERM,
+ constructors=(BrowserIdManager.constructBrowserIdManagerForm,
+ BrowserIdManager.constructBrowserIdManager)
+ )
+
+ context.registerClass(
+ SessionDataManager.SessionDataManager,
+ icon='www/datamgr.gif',
+ permission=SessionDataManager.ADD_SESSION_DATAMANAGER_PERM,
+ constructors=(SessionDataManager.constructSessionDataManagerForm,
+ SessionDataManager.constructSessionDataManager)
+ )
+
+
+ context.registerHelp()