diff --git a/README.md b/README.md index ee0fe44a..2e7e2fb6 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ ![Version](https://img.shields.io/github/v/tag/yunohost/moulinette?label=version&sort=semver) [![Tests status](https://github.com/YunoHost/moulinette/actions/workflows/tox.yml/badge.svg)](https://github.com/YunoHost/moulinette/actions/workflows/tox.yml) +[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/YunoHost/moulinette.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/YunoHost/moulinette/context:python) [![GitHub license](https://img.shields.io/github/license/YunoHost/moulinette)](https://github.com/YunoHost/moulinette/blob/dev/LICENSE) diff --git a/moulinette/interfaces/__init__.py b/moulinette/interfaces/__init__.py index d7753eae..02e0447b 100644 --- a/moulinette/interfaces/__init__.py +++ b/moulinette/interfaces/__init__.py @@ -331,7 +331,7 @@ class ExtendedArgumentParser(argparse.ArgumentParser): c.execute(namespace, v) try: delattr(namespace, CALLBACKS_PROP) - except: + except AttributeError: pass def _get_callbacks_queue(self, namespace, create=True): diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index abc0fd93..60d85ec7 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -237,6 +237,7 @@ class Session: secret = random_ascii() actionsmap_name = None # This is later set to the actionsmap name + @staticmethod def set_infos(infos): assert isinstance(infos, dict) @@ -250,6 +251,7 @@ class Session: # samesite="strict", # Bottle 0.12 doesn't support samesite, to be added in next versions ) + @staticmethod def get_infos(raise_if_no_session_exists=True): try: @@ -673,13 +675,14 @@ class ActionsMapParser(BaseActionsMapParser): return parser.authentication - def parse_args(self, args, route, **kwargs): + def parse_args(self, args, **kwargs): """Parse arguments Keyword arguments: - route -- The action route as a 2-tuple (method, path) """ + route = kwargs["route"] try: # Retrieve the parser for the route _, parser = self._parsers[route] diff --git a/moulinette/utils/log.py b/moulinette/utils/log.py index 283c121e..02f8a30a 100644 --- a/moulinette/utils/log.py +++ b/moulinette/utils/log.py @@ -1,5 +1,4 @@ import os -import logging # import all constants because other modules try to import them from this # module because SUCCESS is defined in this module @@ -70,8 +69,11 @@ def configure_logging(logging_config=None): def getHandlersByClass(classinfo, limit=0): """Retrieve registered handlers of a given class.""" + + from logging import _handlers + handlers = [] - for ref in logging._handlers.itervaluerefs(): + for ref in _handlers.itervaluerefs(): o = ref() if o is not None and isinstance(o, classinfo): if limit == 1: @@ -102,14 +104,17 @@ class MoulinetteLogger(Logger): def findCaller(self, *args): """Override findCaller method to consider this source file.""" - f = logging.currentframe() + + from logging import currentframe, _srcfile + + f = currentframe() if f is not None: f = f.f_back rv = "(unknown file)", 0, "(unknown function)" while hasattr(f, "f_code"): co = f.f_code filename = os.path.normcase(co.co_filename) - if filename == logging._srcfile or filename == __file__: + if filename == _srcfile or filename == __file__: f = f.f_back continue rv = (co.co_filename, f.f_lineno, co.co_name)