0001"""
0002A mostly dummy class to simulate the Webware Application object.
0003"""
0004
0005from wkcommon import NoDefault
0006import threading
0007try:
0008    from TaskKit.Scheduler import Scheduler
0009except ImportError:
0010    Scheduler = None
0011
0012_taskManager = None
0013_makeTaskManagerLock = threading.Lock()
0014
0015def taskManager():
0016    global _taskManager
0017    if _taskManager is None:
0018        if Scheduler is None:
0019            assert 0, (
0020                "FakeWebware is not installed, and/or TaskKit is "
0021                "not available")
0022        _makeTaskManagerLock.acquire()
0023        try:
0024            if _taskManager is None:
0025                _taskManager = Scheduler(1)
0026                _taskManager.start()
0027        finally:
0028            _makeTaskManagerLock.release()
0029    return _taskManager
0030
0031class Application(object):
0032
0033    def __init__(self, transaction):
0034        self._transaction = transaction
0035
0036    def forward(self, trans, url, context=None):
0037        assert context is None, "Contexts are not supported"
0038        trans.forward(url)
0039
0040    def setting(self, setting, default=NoDefault):
0041        assert default is not NoDefault, "No settings are defined"
0042        return default
0043
0044    def taskManager(self):
0045        return taskManager()