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(
|
Api(
|
||||||
routes=routes,
|
routes=routes,
|
||||||
actionsmap=actionsmap,
|
actionsmap=actionsmap,
|
||||||
).run(
|
).run(host, port)
|
||||||
host,
|
|
||||||
port
|
|
||||||
)
|
|
||||||
except MoulinetteError as e:
|
except MoulinetteError as e:
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -90,7 +87,9 @@ def api(host="localhost", port=80, routes={}, actionsmap=None, locales_dir=None)
|
||||||
return 0
|
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
|
"""Command line interface
|
||||||
|
|
||||||
Execute an action with the moulinette from the CLI and print its
|
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,
|
top_parser=top_parser,
|
||||||
load_only_category=load_only_category,
|
load_only_category=load_only_category,
|
||||||
actionsmap=actionsmap,
|
actionsmap=actionsmap,
|
||||||
).run(
|
).run(args, output_as=output_as, timeout=timeout)
|
||||||
args,
|
|
||||||
output_as=output_as,
|
|
||||||
timeout=timeout
|
|
||||||
)
|
|
||||||
except MoulinetteError as e:
|
except MoulinetteError as e:
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
|
@ -418,7 +418,9 @@ class ActionsMap:
|
||||||
return actionsmap
|
return actionsmap
|
||||||
|
|
||||||
# Delete old cache files
|
# 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)
|
os.remove(old_cache)
|
||||||
|
|
||||||
# at installation, cachedir might not exists
|
# at installation, cachedir might not exists
|
||||||
|
@ -622,9 +624,7 @@ class ActionsMap:
|
||||||
|
|
||||||
self.namespace = _global["namespace"]
|
self.namespace = _global["namespace"]
|
||||||
self.enable_lock = _global.get("lock", True)
|
self.enable_lock = _global.get("lock", True)
|
||||||
self.default_authentication = _global["authentication"][
|
self.default_authentication = _global["authentication"][interface_type]
|
||||||
interface_type
|
|
||||||
]
|
|
||||||
|
|
||||||
if top_parser.has_global_parser():
|
if top_parser.has_global_parser():
|
||||||
top_parser.add_global_arguments(_global["arguments"])
|
top_parser.add_global_arguments(_global["arguments"])
|
||||||
|
@ -710,9 +710,7 @@ class ActionsMap:
|
||||||
|
|
||||||
action_parser.authentication = self.default_authentication
|
action_parser.authentication = self.default_authentication
|
||||||
if interface_type in authentication:
|
if interface_type in authentication:
|
||||||
action_parser.authentication = authentication[
|
action_parser.authentication = authentication[interface_type]
|
||||||
interface_type
|
|
||||||
]
|
|
||||||
|
|
||||||
logger.debug("building parser took %.3fs", time() - start)
|
logger.debug("building parser took %.3fs", time() - start)
|
||||||
return top_parser
|
return top_parser
|
||||||
|
|
|
@ -13,6 +13,7 @@ logger = logging.getLogger("moulinette.core")
|
||||||
def during_unittests_run():
|
def during_unittests_run():
|
||||||
return "TESTS_RUN" in os.environ
|
return "TESTS_RUN" in os.environ
|
||||||
|
|
||||||
|
|
||||||
# Internationalization -------------------------------------------------
|
# Internationalization -------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -480,7 +480,9 @@ class _ActionsMapPlugin:
|
||||||
UPLOAD_DIR = None
|
UPLOAD_DIR = None
|
||||||
|
|
||||||
# Close opened WebSocket by putting StopIteration in the queue
|
# 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)
|
authenticator = self.actionsmap.get_authenticator(profile)
|
||||||
try:
|
try:
|
||||||
s_id = authenticator.get_session_cookie()["id"]
|
s_id = authenticator.get_session_cookie()["id"]
|
||||||
|
|
|
@ -461,7 +461,13 @@ class Interface:
|
||||||
|
|
||||||
type = "cli"
|
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
|
# Set user locale
|
||||||
m18n.set_locale(get_locale())
|
m18n.set_locale(get_locale())
|
||||||
|
@ -563,8 +569,10 @@ class Interface:
|
||||||
)
|
)
|
||||||
|
|
||||||
if help:
|
if help:
|
||||||
|
|
||||||
def bottom_toolbar():
|
def bottom_toolbar():
|
||||||
return [("class:", help)]
|
return [("class:", help)]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
bottom_toolbar = None
|
bottom_toolbar = None
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,7 @@ class Authenticator(BaseAuthenticator):
|
||||||
from bottle import request
|
from bottle import request
|
||||||
|
|
||||||
try:
|
try:
|
||||||
infos = request.get_cookie(
|
infos = request.get_cookie("moulitest", secret=session_secret, default={})
|
||||||
"moulitest", secret=session_secret, default={}
|
|
||||||
)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
if not raise_if_no_session_exists:
|
if not raise_if_no_session_exists:
|
||||||
return {"id": random_ascii()}
|
return {"id": random_ascii()}
|
||||||
|
@ -75,4 +73,3 @@ class Authenticator(BaseAuthenticator):
|
||||||
|
|
||||||
response.set_cookie("moulitest", "", max_age=-1)
|
response.set_cookie("moulitest", "", max_age=-1)
|
||||||
response.delete_cookie("moulitest")
|
response.delete_cookie("moulitest")
|
||||||
|
|
||||||
|
|
|
@ -53,9 +53,7 @@ class Authenticator(BaseAuthenticator):
|
||||||
from bottle import request
|
from bottle import request
|
||||||
|
|
||||||
try:
|
try:
|
||||||
infos = request.get_cookie(
|
infos = request.get_cookie("moulitest", secret=session_secret, default={})
|
||||||
"moulitest", secret=session_secret, default={}
|
|
||||||
)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
if not raise_if_no_session_exists:
|
if not raise_if_no_session_exists:
|
||||||
return {"id": random_ascii()}
|
return {"id": random_ascii()}
|
||||||
|
@ -75,4 +73,3 @@ class Authenticator(BaseAuthenticator):
|
||||||
|
|
||||||
response.set_cookie("moulitest", "", max_age=-1)
|
response.set_cookie("moulitest", "", max_age=-1)
|
||||||
response.delete_cookie("moulitest")
|
response.delete_cookie("moulitest")
|
||||||
|
|
||||||
|
|
|
@ -85,9 +85,7 @@ class TestAuthAPI:
|
||||||
"CSRF protection"
|
"CSRF protection"
|
||||||
in self.login(moulinette_webapi, csrf=True, status=403).text
|
in self.login(moulinette_webapi, csrf=True, status=403).text
|
||||||
)
|
)
|
||||||
assert not any(
|
assert not any(c.name == "moulitest" for c in moulinette_webapi.cookiejar)
|
||||||
c.name == "moulitest" for c in moulinette_webapi.cookiejar
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_login_then_legit_request_without_cookies(self, moulinette_webapi):
|
def test_login_then_legit_request_without_cookies(self, moulinette_webapi):
|
||||||
self.login(moulinette_webapi)
|
self.login(moulinette_webapi)
|
||||||
|
|
Loading…
Reference in a new issue