mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Merge pull request #317 from YunoHost/actions/black
Format Python code with Black
This commit is contained in:
commit
7e2da7a897
8 changed files with 26 additions and 30 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -13,6 +13,7 @@ logger = logging.getLogger("moulinette.core")
|
|||
def during_unittests_run():
|
||||
return "TESTS_RUN" in os.environ
|
||||
|
||||
|
||||
# Internationalization -------------------------------------------------
|
||||
|
||||
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue