[Zope-Checkins] CVS: Zope/lib/python/OFS - Application.py:1.167

Chris McDonough chrism@zope.com
Tue, 20 Nov 2001 15:38:55 -0500


Update of /cvs-repository/Zope/lib/python/OFS
In directory cvs.zope.org:/tmp/cvs-serv5239

Modified Files:
	Application.py 
Log Message:
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.


=== Zope/lib/python/OFS/Application.py 1.166 => 1.167 ===
     tf = app.temp_folder
     if not hasattr(tf, 'session_data'):
+        env_has = os.environ.get
         from Products.Transience.Transience import TransientObjectContainer
-        addnotify = os.environ.get('ZSESSION_ADD_NOTIFY', '/session_add')
-        delnotify = os.environ.get('ZSESSION_DEL_NOTIFY', '/session_del')
-        if app.unrestrictedTraverse(addnotify,None) is None: addnotify=None
-        if app.unrestrictedTraverse(delnotify,None) is None: delnotify=None
+        addnotify = env_has('ZSESSION_ADD_NOTIFY', None)
+        delnotify = env_has('ZSESSION_DEL_NOTIFY', None)
+        if addnotify and app.unrestrictedTraverse(addnotify, None) is 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',
-            'Session Data Container', addNotification=addnotify,
-            delNotification = delnotify)
+              'Session Data Container', addNotification = addnotify,
+              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)
-        get_transaction().note('Added session_data to '
-            'temp_folder')
+        get_transaction().note('Added session_data to temp_folder')
         get_transaction().commit()
         del toc
         del addnotify
         del delnotify
-
+        del timeout_spec
+        del env_has
+        
     del tf
 
     # b/c: Ensure that a browser ID manager exists