From c8481857096a28562bdc18ccb2b793b73e868e53 Mon Sep 17 00:00:00 2001 From: alexAubin Date: Fri, 27 Aug 2021 16:44:39 +0000 Subject: [PATCH] :art: Format Python code with Black --- moulinette/__init__.py | 19 ++++++++----------- moulinette/interfaces/api.py | 18 ++++++++++++++---- moulinette/interfaces/cli.py | 8 ++++---- test/test_actionsmap.py | 2 +- test/test_auth.py | 4 +++- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/moulinette/__init__.py b/moulinette/__init__.py index ad4f6531..1dfeb213 100755 --- a/moulinette/__init__.py +++ b/moulinette/__init__.py @@ -26,32 +26,27 @@ __credits__ = """ You should have received a copy of the GNU Affero General Public License along with this program; if not, see http://www.gnu.org/licenses """ -__all__ = [ - "init", - "api", - "cli", - "m18n", - "MoulinetteError", - "Moulinette" -] +__all__ = ["init", "api", "cli", "m18n", "MoulinetteError", "Moulinette"] m18n = Moulinette18n() + class classproperty(object): def __init__(self, f): self.f = f + def __get__(self, obj, owner): return self.f(owner) -class Moulinette(): + +class Moulinette: _interface = None def prompt(*args, **kwargs): return Moulinette.interface.prompt(*args, **kwargs) - def display(*args, **kwargs): return Moulinette.interface.display(*args, **kwargs) @@ -133,7 +128,9 @@ def cli(args, top_parser, output_as=None, timeout=None): try: load_only_category = args[0] if args and not args[0].startswith("-") else None - Cli(top_parser=top_parser, load_only_category=load_only_category).run(args, output_as=output_as, timeout=timeout) + Cli(top_parser=top_parser, load_only_category=load_only_category).run( + args, output_as=output_as, timeout=timeout + ) except MoulinetteError as e: import logging diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index db942649..fdf9ef67 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -230,7 +230,7 @@ class _HTTPArgumentParser(object): raise MoulinetteValidationError(message, raw_msg=True) -class Session(): +class Session: secret = random_ascii() actionsmap_name = None # This is later set to the actionsmap name @@ -239,12 +239,19 @@ class Session(): assert isinstance(infos, dict) - response.set_cookie(f"session.{Session.actionsmap_name}", infos, secure=True, secret=Session.secret) + response.set_cookie( + f"session.{Session.actionsmap_name}", + infos, + secure=True, + secret=Session.secret, + ) def get_infos(): try: - infos = request.get_cookie(f"session.{Session.actionsmap_name}", secret=Session.secret, default={}) + infos = request.get_cookie( + f"session.{Session.actionsmap_name}", secret=Session.secret, default={} + ) except Exception: infos = {} @@ -388,7 +395,9 @@ class _ActionsMapPlugin(object): authenticator = self.actionsmap.get_authenticator(profile) try: - auth_info = authenticator.authenticate_credentials(credentials, store_session=True) + auth_info = authenticator.authenticate_credentials( + credentials, store_session=True + ) session_infos = Session.get_infos() session_infos[profile] = auth_info except MoulinetteError as e: @@ -523,6 +532,7 @@ class _ActionsMapPlugin(object): def prompt(self, *args, **kwargs): raise NotImplementedError("Prompt is not implemented for this interface") + # HTTP Responses ------------------------------------------------------- diff --git a/moulinette/interfaces/cli.py b/moulinette/interfaces/cli.py index 330dcba8..45039fb9 100644 --- a/moulinette/interfaces/cli.py +++ b/moulinette/interfaces/cli.py @@ -537,7 +537,9 @@ class Interface: """ if not os.isatty(1): - raise MoulinetteError("Not a tty, can't do interactive prompts", raw_msg=True) + raise MoulinetteError( + "Not a tty, can't do interactive prompts", raw_msg=True + ) if is_password: prompt = lambda m: getpass.getpass(colorize(m18n.g("colon", m), color)) @@ -553,9 +555,7 @@ class Interface: return value def display(self, message, style="info"): - """Display a message - - """ + """Display a message""" if style == "success": print("{} {}".format(colorize(m18n.g("success"), "green"), message)) elif style == "warning": diff --git a/test/test_actionsmap.py b/test/test_actionsmap.py index 62e0b4de..4d9befe0 100644 --- a/test/test_actionsmap.py +++ b/test/test_actionsmap.py @@ -17,7 +17,6 @@ from moulinette import m18n, Moulinette @pytest.fixture def iface(): class DummyInterface: - def prompt(): pass @@ -164,6 +163,7 @@ def test_required_paremeter_missing_value(iface, caplog): def test_actions_map_unknown_authenticator(monkeypatch, tmp_path): from moulinette.interfaces.api import ActionsMapParser + amap = ActionsMap(ActionsMapParser()) with pytest.raises(MoulinetteError) as exception: diff --git a/test/test_auth.py b/test/test_auth.py index 70c44ed5..ee6940c5 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -87,7 +87,9 @@ class TestAuthAPI: "CSRF protection" in self.login(moulinette_webapi, csrf=True, status=403).text ) - assert not any(c.name == "session.moulitest" for c in moulinette_webapi.cookiejar) + assert not any( + c.name == "session.moulitest" for c in moulinette_webapi.cookiejar + ) def test_login_then_legit_request_without_cookies(self, moulinette_webapi): self.login(moulinette_webapi)