Commit 8075ac22 authored by Chris McDonough's avatar Chris McDonough

Added ZSESSION_TIMEOUT_MINS environment option, usable to set

timeout of default session_data container.

Improved error handling and logging of errors during the creation
of a transient object container.
parent 3f801c51
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
############################################################################## ##############################################################################
__doc__='''Application support __doc__='''Application support
$Id: Application.py,v 1.166 2001/11/19 19:43:30 amos Exp $''' $Id: Application.py,v 1.167 2001/11/20 20:38:55 chrism Exp $'''
__version__='$Revision: 1.166 $'[11:-2] __version__='$Revision: 1.167 $'[11:-2]
import Globals,Folder,os,sys,App.Product, App.ProductRegistry, misc_ import Globals,Folder,os,sys,App.Product, App.ProductRegistry, misc_
import time, traceback, os, string, Products import time, traceback, os, string, Products
...@@ -431,23 +431,54 @@ def initialize(app): ...@@ -431,23 +431,54 @@ def initialize(app):
# b/c: Ensure that there is a transient container in the temp folder # b/c: Ensure that there is a transient container in the temp folder
tf = app.temp_folder tf = app.temp_folder
if not hasattr(tf, 'session_data'): if not hasattr(tf, 'session_data'):
env_has = os.environ.get
from Products.Transience.Transience import TransientObjectContainer from Products.Transience.Transience import TransientObjectContainer
addnotify = os.environ.get('ZSESSION_ADD_NOTIFY', '/session_add') addnotify = env_has('ZSESSION_ADD_NOTIFY', None)
delnotify = os.environ.get('ZSESSION_DEL_NOTIFY', '/session_del') delnotify = env_has('ZSESSION_DEL_NOTIFY', None)
if app.unrestrictedTraverse(addnotify,None) is None: addnotify=None if addnotify and app.unrestrictedTraverse(addnotify, None) is None:
if app.unrestrictedTraverse(delnotify,None) is None: delnotify=None LOG('Zope Default Object Creation', WARNING,
('failed to use nonexistent "%s" script as '
'ZSESSION_ADD_NOTIFY' % addnotify))
addnotify=None
elif addnotify:
LOG('Zope Default Object Creation', INFO,
'using %s as add notification script' % addnotify)
if delnotify and app.unrestrictedTraverse(delnotify, None) is None:
LOG('Zope Default Object Creation', WARNING,
('failed to use nonexistent "%s" script as '
'ZSESSION_DEL_NOTIFY' % delnotify))
delnotify=None
elif delnotify:
LOG('Zope Default Object Creation', INFO,
'using %s as delete notification script' % delnotify)
toc = TransientObjectContainer('session_data', toc = TransientObjectContainer('session_data',
'Session Data Container', addNotification=addnotify, 'Session Data Container', addNotification = addnotify,
delNotification = delnotify) delNotification = delnotify)
timeout_spec = env_has('ZSESSION_TIMEOUT_MINS', '')
if timeout_spec:
try:
timeout_spec = int(timeout_spec)
except ValueError:
LOG('Zope Default Object Creation', WARNING,
('"%s" is an illegal value for ZSESSION_TIMEOUT_MINS, '
'using default timeout instead.' % timeout_spec))
else:
LOG('Zope Default Object Creation', INFO,
('using ZSESSION_TIMEOUT_MINS-specified session timeout '
'value of %s' % timeout_spec))
toc = TransientObjectContainer('session_data',
'Session Data Container', timeout_mins = timeout_spec,
addNotification=addnotify, delNotification = delnotify)
tf._setObject('session_data', toc) tf._setObject('session_data', toc)
get_transaction().note('Added session_data to ' get_transaction().note('Added session_data to temp_folder')
'temp_folder')
get_transaction().commit() get_transaction().commit()
del toc del toc
del addnotify del addnotify
del delnotify del delnotify
del timeout_spec
del env_has
del tf del tf
# b/c: Ensure that a browser ID manager exists # b/c: Ensure that a browser ID manager exists
......
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