diff --git a/py4web/core.py b/py4web/core.py index 28cc0dcf..e5e37a0c 100644 --- a/py4web/core.py +++ b/py4web/core.py @@ -123,22 +123,17 @@ # hold all framework hooks in one place # NOTE: `after_request` hooks are not currently used -REQUEST_HOOKS = type("Object", (), dict(before=[])) # pylint: disable=invalid-name +_REQUEST_HOOKS = types.SimpleNamespace(before=[]) -# set to true to debug issues with fixtures -DEBUG = False +def _before_request(*args, **kw): + [h(*args, **kw) for h in _REQUEST_HOOKS.before] -def register_hooks(): - """register hooks with ombott if they exist""" - if not REQUEST_HOOKS.before: - return - bottle.default_app().add_hook( - "before_request", - lambda *args, **kwargs: [ - func(*args, **kwargs) for func in REQUEST_HOOKS.before - ], - ) + +bottle.default_app().add_hook("before_request", _before_request) + +# set to true to debug issues with fixtures +DEBUG = False def module2filename(module): @@ -1362,7 +1357,7 @@ def hook(*args, **kwargs): # pylint: disable=unused-argument ## APP_WATCH tasks, if used by any app try_app_watch_tasks() - REQUEST_HOOKS.before.append(hook) + _REQUEST_HOOKS.before.append(hook) @staticmethod def clear_routes(app_names=None): @@ -1747,8 +1742,6 @@ def start_server(kwargs): if not hasattr(_ssl, "sslwrap"): _ssl.sslwrap = new_sslwrap - register_hooks() - if kwargs["watch"] != "off": watch(apps_folder, server_config, kwargs["watch"])