diff --git a/moulinette/__init__.py b/moulinette/__init__.py index 900d924a..b4135d9a 100755 --- a/moulinette/__init__.py +++ b/moulinette/__init__.py @@ -74,10 +74,7 @@ def api(host="localhost", port=80, routes={}, actionsmap=None, locales_dir=None) Api( routes=routes, actionsmap=actionsmap, - ).run( - host, - port - ) + ).run(host, port) except MoulinetteError as e: import logging @@ -90,7 +87,9 @@ def api(host="localhost", port=80, routes={}, actionsmap=None, locales_dir=None) return 0 -def cli(args, top_parser, output_as=None, timeout=None, actionsmap=None, locales_dir=None): +def cli( + args, top_parser, output_as=None, timeout=None, actionsmap=None, locales_dir=None +): """Command line interface Execute an action with the moulinette from the CLI and print its @@ -113,11 +112,7 @@ def cli(args, top_parser, output_as=None, timeout=None, actionsmap=None, locales top_parser=top_parser, load_only_category=load_only_category, actionsmap=actionsmap, - ).run( - args, - output_as=output_as, - timeout=timeout - ) + ).run(args, output_as=output_as, timeout=timeout) except MoulinetteError as e: import logging diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index 0c10c6cb..deacd5cc 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -418,7 +418,9 @@ class ActionsMap: return actionsmap # Delete old cache files - for old_cache in glob.glob(f"{actionsmap_yml_dir}/.{actionsmap_yml_file}.*.pkl"): + for old_cache in glob.glob( + f"{actionsmap_yml_dir}/.{actionsmap_yml_file}.*.pkl" + ): os.remove(old_cache) # at installation, cachedir might not exists @@ -622,9 +624,7 @@ class ActionsMap: self.namespace = _global["namespace"] self.enable_lock = _global.get("lock", True) - self.default_authentication = _global["authentication"][ - interface_type - ] + self.default_authentication = _global["authentication"][interface_type] if top_parser.has_global_parser(): top_parser.add_global_arguments(_global["arguments"]) @@ -710,9 +710,7 @@ class ActionsMap: action_parser.authentication = self.default_authentication if interface_type in authentication: - action_parser.authentication = authentication[ - interface_type - ] + action_parser.authentication = authentication[interface_type] logger.debug("building parser took %.3fs", time() - start) return top_parser diff --git a/moulinette/core.py b/moulinette/core.py index 0f80291c..aaf23978 100644 --- a/moulinette/core.py +++ b/moulinette/core.py @@ -13,6 +13,7 @@ logger = logging.getLogger("moulinette.core") def during_unittests_run(): return "TESTS_RUN" in os.environ + # Internationalization ------------------------------------------------- diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index 0af98baf..3f1960af 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -480,7 +480,9 @@ class _ActionsMapPlugin: UPLOAD_DIR = None # Close opened WebSocket by putting StopIteration in the queue - profile = request.params.get("profile", self.actionsmap.default_authentication) + profile = request.params.get( + "profile", self.actionsmap.default_authentication + ) authenticator = self.actionsmap.get_authenticator(profile) try: s_id = authenticator.get_session_cookie()["id"] diff --git a/moulinette/interfaces/cli.py b/moulinette/interfaces/cli.py index 712f786e..ac6da9d6 100644 --- a/moulinette/interfaces/cli.py +++ b/moulinette/interfaces/cli.py @@ -461,7 +461,13 @@ class Interface: type = "cli" - def __init__(self, top_parser=None, load_only_category=None, actionsmap=None, locales_dir=None): + def __init__( + self, + top_parser=None, + load_only_category=None, + actionsmap=None, + locales_dir=None, + ): # Set user locale m18n.set_locale(get_locale()) @@ -563,8 +569,10 @@ class Interface: ) if help: + def bottom_toolbar(): return [("class:", help)] + else: bottom_toolbar = None diff --git a/test/src/authenticators/dummy.py b/test/src/authenticators/dummy.py index e82e6b17..fde2a0c6 100644 --- a/test/src/authenticators/dummy.py +++ b/test/src/authenticators/dummy.py @@ -53,9 +53,7 @@ class Authenticator(BaseAuthenticator): from bottle import request try: - infos = request.get_cookie( - "moulitest", secret=session_secret, default={} - ) + infos = request.get_cookie("moulitest", secret=session_secret, default={}) except Exception: if not raise_if_no_session_exists: return {"id": random_ascii()} @@ -75,4 +73,3 @@ class Authenticator(BaseAuthenticator): response.set_cookie("moulitest", "", max_age=-1) response.delete_cookie("moulitest") - diff --git a/test/src/authenticators/yoloswag.py b/test/src/authenticators/yoloswag.py index 9c9eba8b..40dffd12 100644 --- a/test/src/authenticators/yoloswag.py +++ b/test/src/authenticators/yoloswag.py @@ -53,9 +53,7 @@ class Authenticator(BaseAuthenticator): from bottle import request try: - infos = request.get_cookie( - "moulitest", secret=session_secret, default={} - ) + infos = request.get_cookie("moulitest", secret=session_secret, default={}) except Exception: if not raise_if_no_session_exists: return {"id": random_ascii()} @@ -75,4 +73,3 @@ class Authenticator(BaseAuthenticator): response.set_cookie("moulitest", "", max_age=-1) response.delete_cookie("moulitest") - diff --git a/test/test_auth.py b/test/test_auth.py index 5563a92e..b5537bb7 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -85,9 +85,7 @@ class TestAuthAPI: "CSRF protection" in self.login(moulinette_webapi, csrf=True, status=403).text ) - assert not any( - c.name == "moulitest" for c in moulinette_webapi.cookiejar - ) + assert not any(c.name == "moulitest" for c in moulinette_webapi.cookiejar) def test_login_then_legit_request_without_cookies(self, moulinette_webapi): self.login(moulinette_webapi)