def depot_tween(config, dummy_request): """Sets up the Depot tween and patches Depot's ``set_middleware`` to suppress exceptions on subsequent calls. Yields the ``DepotManager``.""" from depot.manager import DepotManager from kotti.filedepot import TweenFactory from kotti.filedepot import uploaded_file_response from kotti.filedepot import uploaded_file_url dummy_request.__class__.uploaded_file_response = uploaded_file_response dummy_request.__class__.uploaded_file_url = uploaded_file_url _set_middleware = DepotManager.set_middleware TweenFactory(None, config.registry) # noinspection PyDecorator @classmethod def set_middleware_patched(cls, mw): pass DepotManager.set_middleware = set_middleware_patched yield DepotManager DepotManager.set_middleware = _set_middleware
def depot_tween(request, config, dummy_request): """ Sets up the Depot tween and patches Depot's ``set_middleware`` to suppress exceptions on subsequent calls """ from depot.manager import DepotManager from kotti.filedepot import TweenFactory from kotti.filedepot import uploaded_file_response from kotti.filedepot import uploaded_file_url dummy_request.__class__.uploaded_file_response = uploaded_file_response dummy_request.__class__.uploaded_file_url = uploaded_file_url _set_middleware = DepotManager.set_middleware TweenFactory(None, config.registry) @classmethod def set_middleware_patched(cls, mw): pass DepotManager.set_middleware = set_middleware_patched def restore(): DepotManager.set_middleware = _set_middleware request.addfinalizer(restore)