Commit db473745 authored by Hanno Schlichting's avatar Hanno Schlichting

Make Sessions/Transience optional dependencies in ZTC.

parent 17089c2a
...@@ -30,15 +30,23 @@ def setupCoreSessions(app): ...@@ -30,15 +30,23 @@ def setupCoreSessions(app):
from Acquisition import aq_base from Acquisition import aq_base
commit = 0 commit = 0
try:
from Products.TemporaryFolder.TemporaryFolder import \
MountedTemporaryFolder
from Products.Transience.Transience import TransientObjectContainer
from Products.Sessions.BrowserIdManager import BrowserIdManager
from Products.Sessions.SessionDataManager import SessionDataManager
except ImportError:
pass
else:
if not hasattr(app, 'temp_folder'): if not hasattr(app, 'temp_folder'):
from Products.TemporaryFolder.TemporaryFolder import MountedTemporaryFolder
tf = MountedTemporaryFolder('temp_folder', 'Temporary Folder') tf = MountedTemporaryFolder('temp_folder', 'Temporary Folder')
app._setObject('temp_folder', tf) app._setObject('temp_folder', tf)
commit = 1 commit = 1
if not hasattr(aq_base(app.temp_folder), 'session_data'): if not hasattr(aq_base(app.temp_folder), 'session_data'):
from Products.Transience.Transience import TransientObjectContainer toc = TransientObjectContainer(
toc = TransientObjectContainer('session_data', 'session_data',
'Session Data Container', 'Session Data Container',
timeout_mins=3, timeout_mins=3,
limit=100) limit=100)
...@@ -46,15 +54,14 @@ def setupCoreSessions(app): ...@@ -46,15 +54,14 @@ def setupCoreSessions(app):
commit = 1 commit = 1
if not hasattr(app, 'browser_id_manager'): if not hasattr(app, 'browser_id_manager'):
from Products.Sessions.BrowserIdManager import BrowserIdManager
bid = BrowserIdManager('browser_id_manager', bid = BrowserIdManager('browser_id_manager',
'Browser Id Manager') 'Browser Id Manager')
app._setObject('browser_id_manager', bid) app._setObject('browser_id_manager', bid)
commit = 1 commit = 1
if not hasattr(app, 'session_data_manager'): if not hasattr(app, 'session_data_manager'):
from Products.Sessions.SessionDataManager import SessionDataManager sdm = SessionDataManager(
sdm = SessionDataManager('session_data_manager', 'session_data_manager',
title='Session Data Manager', title='Session Data Manager',
path='/temp_folder/session_data', path='/temp_folder/session_data',
requestName='SESSION') requestName='SESSION')
...@@ -83,15 +90,18 @@ def importObjectFromFile(container, filename, quiet=0): ...@@ -83,15 +90,18 @@ def importObjectFromFile(container, filename, quiet=0):
from ZopeLite import _print, _patched from ZopeLite import _print, _patched
quiet = quiet or not _patched quiet = quiet or not _patched
start = time.time() start = time.time()
if not quiet: _print("Importing %s ... " % os.path.basename(filename)) if not quiet:
_print("Importing %s ... " % os.path.basename(filename))
container._importObjectFromFile(filename, verify=0) container._importObjectFromFile(filename, verify=0)
transaction.commit() transaction.commit()
if not quiet: _print('done (%.3fs)\n' % (time.time() - start)) if not quiet:
_print('done (%.3fs)\n' % (time.time() - start))
_Z2HOST = None _Z2HOST = None
_Z2PORT = None _Z2PORT = None
def startZServer(number_of_threads=1, log=None): def startZServer(number_of_threads=1, log=None):
'''Starts an HTTP ZServer thread.''' '''Starts an HTTP ZServer thread.'''
global _Z2HOST, _Z2PORT global _Z2HOST, _Z2PORT
...@@ -134,11 +144,11 @@ def makelist(arg): ...@@ -134,11 +144,11 @@ def makelist(arg):
'''Turns arg into a list. Where arg may be '''Turns arg into a list. Where arg may be
list, tuple, or string. list, tuple, or string.
''' '''
if type(arg) == type([]): if isinstance(arg, list):
return arg return arg
if type(arg) == type(()): if isinstance(arg, tuple):
return list(arg) return list(arg)
if type(arg) == type(''): if isinstance(arg, str):
return filter(None, [arg]) return filter(None, [arg])
raise ValueError('Argument must be list, tuple, or string') raise ValueError('Argument must be list, tuple, or string')
...@@ -152,4 +162,3 @@ __all__ = [ ...@@ -152,4 +162,3 @@ __all__ = [
'makerequest', 'makerequest',
'makelist', 'makelist',
] ]
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