From 27bbd81f491492e72d0ba07d8defcf3bd0b4c545 Mon Sep 17 00:00:00 2001 From: Christian Wehrli Date: Fri, 19 Nov 2021 12:55:01 +0000 Subject: [PATCH 01/11] Translated using Weblate (German) Currently translated at 100.0% (45 of 45 strings) Translation: YunoHost/moulinette Translate-URL: https://translate.yunohost.org/projects/yunohost/moulinette/de/ --- locales/de.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/locales/de.json b/locales/de.json index 590f8159..277f5bdc 100644 --- a/locales/de.json +++ b/locales/de.json @@ -3,7 +3,7 @@ "authentication_required": "Anmeldung erforderlich", "confirm": "Bestätige {prompt}", "error": "Fehler:", - "file_not_exist": "Datei ist nicht vorhanden: '{path}'", + "file_not_exist": "Datei ist nicht vorhanden: '{path}'", "folder_exists": "Ordner existiert bereits: '{path}'", "instance_already_running": "Es läuft bereits eine YunoHost-Operation. Bitte warte, bis sie fertig ist, bevor du eine weitere startest.", "invalid_argument": "Argument ungültig '{argument}': {error}", @@ -42,5 +42,6 @@ "error_changing_file_permissions": "Fehler beim Ändern der Berechtigungen für {path}: {error}", "error_removing": "Fehler beim Entfernen {path}: {error}", "error_writing_file": "Fehler beim Schreiben von Datei {file}: {error}", - "corrupted_toml": "Beschädigtes TOML gelesen von {ressource} (reason: {error})" -} \ No newline at end of file + "corrupted_toml": "Beschädigtes TOML gelesen von {ressource} (reason: {error})", + "edit_text_question": "{}. Diesen Text bearbeiten ? [yN]: " +} From 5b506a5f70417cf157f28ecaf79a98e91083f6fb Mon Sep 17 00:00:00 2001 From: Radek S Date: Fri, 19 Nov 2021 17:39:06 +0000 Subject: [PATCH 02/11] Translated using Weblate (Czech) Currently translated at 100.0% (45 of 45 strings) Translation: YunoHost/moulinette Translate-URL: https://translate.yunohost.org/projects/yunohost/moulinette/cs/ --- locales/cs.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/locales/cs.json b/locales/cs.json index 027cffbd..87a8207c 100644 --- a/locales/cs.json +++ b/locales/cs.json @@ -8,7 +8,7 @@ "download_unknown_error": "Chyba při stahování dat z {url}: {error}", "download_timeout": "{url} příliš dlouho neodpovídá, akce přerušena.", "download_ssl_error": "SSL chyba při spojení s {url}", - "invalid_url": "Špatný odkaz {url} (je vůbec dostupný?)", + "invalid_url": "Špatný odkaz {url} (je vůbec dostupný?).", "error_changing_file_permissions": "Chyba při nastavování oprávnění pro {path}: {error}", "error_removing": "Chyba při přesunu {path}: {error}", "error_writing_file": "Chyba při zápisu souboru/ů {file}: {error}", @@ -42,5 +42,6 @@ "deprecated_command": "'{prog} {command}' je zastaralý a bude odebrán v budoucích verzích", "confirm": "Potvrdit {prompt}", "authentication_required": "Vyžadováno ověření", - "argument_required": "Je vyžadován argument '{argument}'" -} \ No newline at end of file + "argument_required": "Je vyžadován argument '{argument}'", + "edit_text_question": "{}. Upravit tento text? [yN]: " +} From a53dd3d1753c86d43386ab5a487d87b38302d7f7 Mon Sep 17 00:00:00 2001 From: maique madeira Date: Fri, 19 Nov 2021 23:57:18 +0000 Subject: [PATCH 03/11] Translated using Weblate (Portuguese) Currently translated at 100.0% (45 of 45 strings) Translation: YunoHost/moulinette Translate-URL: https://translate.yunohost.org/projects/yunohost/moulinette/pt/ --- locales/pt.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/locales/pt.json b/locales/pt.json index 2c43d0b0..69962143 100644 --- a/locales/pt.json +++ b/locales/pt.json @@ -42,5 +42,6 @@ "warn_the_user_about_waiting_lock_again": "Ainda esperando...", "warn_the_user_about_waiting_lock": "Outro comando YunoHost está sendo executado agora, estamos aguardando o término antes de executar este", "corrupted_toml": "TOML corrompido lido em {ressource} (motivo: {error})", - "info": "Informações:" -} \ No newline at end of file + "info": "Informações:", + "edit_text_question": "{}. Editar este texto ? [yN]: " +} From 265753aef7e1aff591253fba6c7e5651b9c519e2 Mon Sep 17 00:00:00 2001 From: Valentin von Guttenberg Date: Mon, 29 Nov 2021 15:39:55 +0000 Subject: [PATCH 04/11] Translated using Weblate (German) Currently translated at 100.0% (45 of 45 strings) Translation: YunoHost/moulinette Translate-URL: https://translate.yunohost.org/projects/yunohost/moulinette/de/ --- locales/de.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locales/de.json b/locales/de.json index 277f5bdc..1309231e 100644 --- a/locales/de.json +++ b/locales/de.json @@ -43,5 +43,5 @@ "error_removing": "Fehler beim Entfernen {path}: {error}", "error_writing_file": "Fehler beim Schreiben von Datei {file}: {error}", "corrupted_toml": "Beschädigtes TOML gelesen von {ressource} (reason: {error})", - "edit_text_question": "{}. Diesen Text bearbeiten ? [yN]: " + "edit_text_question": "{}. Diesen Text bearbeiten? [yN]: " } From 8127e7cd1ae4c039712cc4173a3d17d7d8fc030e Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Fri, 24 Dec 2021 01:18:03 +0100 Subject: [PATCH 05/11] [mod] run pyupgrade on source code --- moulinette/actionsmap.py | 22 ++++++++++----------- moulinette/core.py | 2 +- moulinette/interfaces/__init__.py | 6 +++--- moulinette/interfaces/api.py | 10 +++++----- moulinette/interfaces/cli.py | 6 +++--- moulinette/utils/filesystem.py | 14 ++++++------- moulinette/utils/text.py | 2 +- test/conftest.py | 6 +++--- test/test_actionsmap.py | 4 ++-- test/test_i18n_format_consistency.py | 6 +++--- test/test_serialize.py | 2 +- test/test_translation_format_consistency.py | 6 +++--- 12 files changed, 43 insertions(+), 43 deletions(-) diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index 386018ec..b0b4b2bc 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -410,7 +410,7 @@ class ActionsMap(object): for n in self.get_namespaces(): logger.debug("loading actions map namespace '%s'", n) - actionsmap_yml = "%s/actionsmap/%s.yml" % (DATA_DIR, n) + actionsmap_yml = "{}/actionsmap/{}.yml".format(DATA_DIR, n) actionsmap_yml_stat = os.stat(actionsmap_yml) actionsmap_pkl = "%s/actionsmap/%s-%d-%d.pkl" % ( CACHE_DIR, @@ -428,7 +428,7 @@ class ActionsMap(object): actionsmap = read_yaml(actionsmap_yml) # Delete old cache files - for old_cache in glob.glob("%s/actionsmap/%s-*.pkl" % (CACHE_DIR, n)): + for old_cache in glob.glob("{}/actionsmap/{}-*.pkl".format(CACHE_DIR, n)): os.remove(old_cache) # at installation, cachedir might not exists @@ -479,7 +479,7 @@ class ActionsMap(object): auth_method = self.default_authentication # Load and initialize the authenticator module - auth_module = "%s.authenticators.%s" % (self.main_namespace, auth_method) + auth_module = "{}.authenticators.{}".format(self.main_namespace, auth_method) logger.debug(f"Loading auth module {auth_module}") try: mod = import_module(auth_module) @@ -532,12 +532,12 @@ class ActionsMap(object): # Retrieve action information if len(tid) == 4: namespace, category, subcategory, action = tid - func_name = "%s_%s_%s" % ( + func_name = "{}_{}_{}".format( category, subcategory.replace("-", "_"), action.replace("-", "_"), ) - full_action_name = "%s.%s.%s.%s" % ( + full_action_name = "{}.{}.{}.{}".format( namespace, category, subcategory, @@ -547,22 +547,22 @@ class ActionsMap(object): assert len(tid) == 3 namespace, category, action = tid subcategory = None - func_name = "%s_%s" % (category, action.replace("-", "_")) - full_action_name = "%s.%s.%s" % (namespace, category, action) + func_name = "{}_{}".format(category, action.replace("-", "_")) + full_action_name = "{}.{}.{}".format(namespace, category, action) # Lock the moulinette for the namespace with MoulinetteLock(namespace, timeout): start = time() try: mod = __import__( - "%s.%s" % (namespace, category), + "{}.{}".format(namespace, category), globals=globals(), level=0, fromlist=[func_name], ) logger.debug( "loading python module %s took %.3fs", - "%s.%s" % (namespace, category), + "{}.{}".format(namespace, category), time() - start, ) func = getattr(mod, func_name) @@ -570,7 +570,7 @@ class ActionsMap(object): import traceback traceback.print_exc() - error_message = "unable to load function %s.%s because: %s" % ( + error_message = "unable to load function {}.{} because: {}".format( namespace, func_name, e, @@ -619,7 +619,7 @@ class ActionsMap(object): # Look for all files that match the given patterns in the actionsmap dir for namespace_pattern in NAMESPACE_PATTERNS: namespaces.extend( - glob.glob("%s/actionsmap/%s.yml" % (DATA_DIR, namespace_pattern)) + glob.glob("{}/actionsmap/{}.yml".format(DATA_DIR, namespace_pattern)) ) # Keep only the filenames with extension diff --git a/moulinette/core.py b/moulinette/core.py index 6f6fddd7..9dfcd7f8 100644 --- a/moulinette/core.py +++ b/moulinette/core.py @@ -230,7 +230,7 @@ class Moulinette18n(object): # Create new Translator object lib_dir = env["LIB_DIR"] translator = Translator( - "%s/%s/locales" % (lib_dir, namespace), self.default_locale + "{}/{}/locales".format(lib_dir, namespace), self.default_locale ) translator.set_locale(self.locale) self._namespaces[namespace] = translator diff --git a/moulinette/interfaces/__init__.py b/moulinette/interfaces/__init__.py index d8bed853..9a5a353a 100644 --- a/moulinette/interfaces/__init__.py +++ b/moulinette/interfaces/__init__.py @@ -211,7 +211,7 @@ class _CallbackAction(argparse.Action): import traceback traceback.print_exc() - raise ValueError("unable to import method {0}".format(self.callback_method)) + raise ValueError("unable to import method {}".format(self.callback_method)) self._callback = func def __call__(self, parser, namespace, values, option_string=None): @@ -226,7 +226,7 @@ class _CallbackAction(argparse.Action): except Exception as e: error_message = ( "cannot get value from callback method " - "'{0}': {1}".format(self.callback_method, e) + "'{}': {}".format(self.callback_method, e) ) logger.exception(error_message) raise MoulinetteError(error_message, raw_msg=True) @@ -562,7 +562,7 @@ class PositionalsFirstHelpFormatter(argparse.HelpFormatter): usage = "\n".join(lines) # prefix with 'usage:' - return "%s%s\n\n" % (prefix, usage) + return "{}{}\n\n".format(prefix, usage) class JSONExtendedEncoder(JSONEncoder): diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index 7be0c3b4..4bfc51fe 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -38,9 +38,9 @@ logger = log.getLogger("moulinette.interface.api") # We define a global variable to manage in a dirty way the upload... UPLOAD_DIR = None -CSRF_TYPES = set( - ["text/plain", "application/x-www-form-urlencoded", "multipart/form-data"] -) +CSRF_TYPES = { + "text/plain", "application/x-www-form-urlencoded", "multipart/form-data" +} def is_csrf(): @@ -667,7 +667,7 @@ class ActionsMapParser(BaseActionsMapParser): # Retrieve the tid for the route _, parser = self._parsers[route] except KeyError as e: - error_message = "no argument parser found for route '%s': %s" % (route, e) + error_message = "no argument parser found for route '{}': {}".format(route, e) logger.error(error_message) raise MoulinetteValidationError(error_message, raw_msg=True) @@ -684,7 +684,7 @@ class ActionsMapParser(BaseActionsMapParser): # Retrieve the parser for the route _, parser = self._parsers[route] except KeyError as e: - error_message = "no argument parser found for route '%s': %s" % (route, e) + error_message = "no argument parser found for route '{}': {}".format(route, e) logger.error(error_message) raise MoulinetteValidationError(error_message, raw_msg=True) ret = argparse.Namespace() diff --git a/moulinette/interfaces/cli.py b/moulinette/interfaces/cli.py index a27f5dc1..4ad659a0 100644 --- a/moulinette/interfaces/cli.py +++ b/moulinette/interfaces/cli.py @@ -251,7 +251,7 @@ class TTYHandler(logging.StreamHandler): # add translated level name before message level = "%s " % m18n.g(record.levelname.lower()) color = self.LEVELS_COLOR.get(record.levelno, "white") - msg = "{0}{1}{2}{3}".format(colors_codes[color], level, END_CLI_COLOR, msg) + msg = "{}{}{}{}".format(colors_codes[color], level, END_CLI_COLOR, msg) if self.formatter: # use user-defined formatter record.__dict__[self.message_key] = msg @@ -403,7 +403,7 @@ class ActionsMapParser(BaseActionsMapParser): except SystemExit: raise except Exception as e: - error_message = "unable to parse arguments '%s' because: %s" % ( + error_message = "unable to parse arguments '{}' because: {}".format( " ".join(args), e, ) @@ -435,7 +435,7 @@ class ActionsMapParser(BaseActionsMapParser): except SystemExit: raise except Exception as e: - error_message = "unable to parse arguments '%s' because: %s" % ( + error_message = "unable to parse arguments '{}' because: {}".format( " ".join(args), e, ) diff --git a/moulinette/utils/filesystem.py b/moulinette/utils/filesystem.py index 208987a8..36a447ba 100644 --- a/moulinette/utils/filesystem.py +++ b/moulinette/utils/filesystem.py @@ -24,7 +24,7 @@ def read_file(file_path, file_mode="r"): """ assert isinstance( file_path, str - ), "Error: file_path '%s' should be a string but is of type '%s' instead" % ( + ), "Error: file_path '{}' should be a string but is of type '{}' instead".format( file_path, type(file_path), ) @@ -121,7 +121,7 @@ def write_to_file(file_path, data, file_mode="w"): """ assert ( isinstance(data, str) or isinstance(data, bytes) or isinstance(data, list) - ), "Error: data '%s' should be either a string or a list but is of type '%s'" % ( + ), "Error: data '{}' should be either a string or a list but is of type '{}'".format( data, type(data), ) @@ -130,7 +130,7 @@ def write_to_file(file_path, data, file_mode="w"): ) assert os.path.isdir( os.path.dirname(file_path) - ), "Error: the path ('%s') base dir ('%s') is not a dir" % ( + ), "Error: the path ('{}') base dir ('{}') is not a dir".format( file_path, os.path.dirname(file_path), ) @@ -140,7 +140,7 @@ def write_to_file(file_path, data, file_mode="w"): for element in data: assert isinstance( element, str - ), "Error: element '%s' should be a string but is of type '%s' instead" % ( + ), "Error: element '{}' should be a string but is of type '{}' instead".format( element, type(element), ) @@ -179,13 +179,13 @@ def write_to_json(file_path, data, sort_keys=False, indent=None): # Assumptions assert isinstance( file_path, str - ), "Error: file_path '%s' should be a string but is of type '%s' instead" % ( + ), "Error: file_path '{}' should be a string but is of type '{}' instead".format( file_path, type(file_path), ) assert isinstance(data, dict) or isinstance( data, list - ), "Error: data '%s' should be a dict or a list but is of type '%s' instead" % ( + ), "Error: data '{}' should be a dict or a list but is of type '{}' instead".format( data, type(data), ) @@ -194,7 +194,7 @@ def write_to_json(file_path, data, sort_keys=False, indent=None): ) assert os.path.isdir( os.path.dirname(file_path) - ), "Error: the path ('%s') base dir ('%s') is not a dir" % ( + ), "Error: the path ('{}') base dir ('{}') is not a dir".format( file_path, os.path.dirname(file_path), ) diff --git a/moulinette/utils/text.py b/moulinette/utils/text.py index 8e959a78..2da101a5 100644 --- a/moulinette/utils/text.py +++ b/moulinette/utils/text.py @@ -59,7 +59,7 @@ def searchf(pattern, path, count=0, flags=re.MULTILINE): def prependlines(text, prepend): """Prepend a string to each line of a text""" lines = text.splitlines(True) - return "%s%s" % (prepend, prepend.join(lines)) + return "{}{}".format(prepend, prepend.join(lines)) # Randomize ------------------------------------------------------------ diff --git a/test/conftest.py b/test/conftest.py index d40e1116..51ea6f33 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -40,7 +40,7 @@ def patch_translate(moulinette): def patch_logging(moulinette): """Configure logging to use the custom logger.""" - handlers = set(["tty", "api"]) + handlers = {"tty", "api"} root_handlers = set(handlers) level = "INFO" @@ -97,8 +97,8 @@ def moulinette(tmp_path_factory): moulinette.env["DATA_DIR"] = tmp_data moulinette.env["LIB_DIR"] = tmp_lib shutil.copytree("./test/actionsmap", "%s/actionsmap" % tmp_data) - shutil.copytree("./test/src", "%s/%s" % (tmp_lib, namespace)) - shutil.copytree("./test/locales", "%s/%s/locales" % (tmp_lib, namespace)) + shutil.copytree("./test/src", "{}/{}".format(tmp_lib, namespace)) + shutil.copytree("./test/locales", "{}/{}/locales".format(tmp_lib, namespace)) patch_init(moulinette) patch_translate(moulinette) diff --git a/test/test_actionsmap.py b/test/test_actionsmap.py index 0abdd7f4..87f7ae17 100644 --- a/test/test_actionsmap.py +++ b/test/test_actionsmap.py @@ -192,7 +192,7 @@ def test_extra_argument_parser_add_argument_bad_arg(iface): with pytest.raises(MoulinetteError) as exception: extra_argument_parse.add_argument("_global", "foo", {"ask": 1}) - expected_msg = "unable to validate extra parameter '%s' for argument '%s': %s" % ( + expected_msg = "unable to validate extra parameter '{}' for argument '{}': {}".format( "ask", "foo", "parameter value must be a string, got 1", @@ -266,7 +266,7 @@ def test_actions_map_import_error(mocker): with pytest.raises(MoulinetteError) as exception: amap.process({}, timeout=30, route=("GET", "/test-auth/none")) - expected_msg = "unable to load function % s.%s because: %s" % ( + expected_msg = "unable to load function {: }.{} because: {}".format( "moulitest", "testauth_none", "Yoloswag", diff --git a/test/test_i18n_format_consistency.py b/test/test_i18n_format_consistency.py index 86d1c327..bfd0e3ae 100644 --- a/test/test_i18n_format_consistency.py +++ b/test/test_i18n_format_consistency.py @@ -26,10 +26,10 @@ def find_inconsistencies(locale_file): # Then we check that every "{stuff}" (for python's .format()) # should also be in the translated string, otherwise the .format # will trigger an exception! - subkeys_in_ref = set(k[0] for k in re.findall(r"{(\w+)(:\w)?}", string)) - subkeys_in_this_locale = set( + subkeys_in_ref = {k[0] for k in re.findall(r"{(\w+)(:\w)?}", string)} + subkeys_in_this_locale = { k[0] for k in re.findall(r"{(\w+)(:\w)?}", this_locale[key]) - ) + } if any(k not in subkeys_in_ref for k in subkeys_in_this_locale): yield """\n diff --git a/test/test_serialize.py b/test/test_serialize.py index 0935967b..d3901bb7 100644 --- a/test/test_serialize.py +++ b/test/test_serialize.py @@ -5,7 +5,7 @@ from moulinette.interfaces import JSONExtendedEncoder def test_json_extended_encoder(caplog): encoder = JSONExtendedEncoder() - assert encoder.default(set([1, 2, 3])) == [1, 2, 3] + assert encoder.default({1, 2, 3}) == [1, 2, 3] assert encoder.default(dt(1917, 3, 8)) == "1917-03-08T00:00:00+00:00" diff --git a/test/test_translation_format_consistency.py b/test/test_translation_format_consistency.py index 86d1c327..bfd0e3ae 100644 --- a/test/test_translation_format_consistency.py +++ b/test/test_translation_format_consistency.py @@ -26,10 +26,10 @@ def find_inconsistencies(locale_file): # Then we check that every "{stuff}" (for python's .format()) # should also be in the translated string, otherwise the .format # will trigger an exception! - subkeys_in_ref = set(k[0] for k in re.findall(r"{(\w+)(:\w)?}", string)) - subkeys_in_this_locale = set( + subkeys_in_ref = {k[0] for k in re.findall(r"{(\w+)(:\w)?}", string)} + subkeys_in_this_locale = { k[0] for k in re.findall(r"{(\w+)(:\w)?}", this_locale[key]) - ) + } if any(k not in subkeys_in_ref for k in subkeys_in_this_locale): yield """\n From 9855b6d7f5c65176c869a8902695011a20b21970 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Fri, 24 Dec 2021 01:18:11 +0100 Subject: [PATCH 06/11] [mod] stop using old style class --- doc/ldif2dot-0.1.py | 4 ++-- moulinette/__init__.py | 2 +- moulinette/actionsmap.py | 6 +++--- moulinette/authentication.py | 2 +- moulinette/core.py | 6 +++--- moulinette/interfaces/__init__.py | 2 +- moulinette/interfaces/api.py | 4 ++-- moulinette/utils/log.py | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/ldif2dot-0.1.py b/doc/ldif2dot-0.1.py index e016d22b..11165474 100644 --- a/doc/ldif2dot-0.1.py +++ b/doc/ldif2dot-0.1.py @@ -34,7 +34,7 @@ ldapsearch -x -b 'dc=nodomain' | \\ import sys -class Element(object): +class Element: """Represents an LDIF entry.""" def __init__(self): @@ -109,7 +109,7 @@ class Element(object): return TABLE_TEMPLATE % (self.index, '\n '.join(_format(self.attributes)), self.edge(dnmap)) -class Converter(object): +class Converter: """An LDIF to DOT converter.""" def __init__(self): diff --git a/moulinette/__init__.py b/moulinette/__init__.py index 7c39a673..5cdf7410 100755 --- a/moulinette/__init__.py +++ b/moulinette/__init__.py @@ -31,7 +31,7 @@ __all__ = ["init", "api", "cli", "m18n", "MoulinetteError", "Moulinette"] m18n = Moulinette18n() -class classproperty(object): +class classproperty: def __init__(self, f): self.f = f diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index b0b4b2bc..62ae5ca1 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -30,7 +30,7 @@ logger = logging.getLogger("moulinette.actionsmap") # Extra parameters definition -class _ExtraParameter(object): +class _ExtraParameter: """ Argument parser for an extra parameter. @@ -261,7 +261,7 @@ extraparameters_list = [ # Extra parameters argument Parser -class ExtraArgumentParser(object): +class ExtraArgumentParser: """ Argument validator and parser for the extra parameters. @@ -373,7 +373,7 @@ class ExtraArgumentParser(object): # Main class ---------------------------------------------------------- -class ActionsMap(object): +class ActionsMap: """Validate and process actions defined into an actions map diff --git a/moulinette/authentication.py b/moulinette/authentication.py index afe2c47d..4db1acc5 100644 --- a/moulinette/authentication.py +++ b/moulinette/authentication.py @@ -10,7 +10,7 @@ logger = logging.getLogger("moulinette.authenticator") # Base Class ----------------------------------------------------------- -class BaseAuthenticator(object): +class BaseAuthenticator: """Authenticator base representation diff --git a/moulinette/core.py b/moulinette/core.py index 9dfcd7f8..af043083 100644 --- a/moulinette/core.py +++ b/moulinette/core.py @@ -30,7 +30,7 @@ def during_unittests_run(): # Internationalization ------------------------------------------------- -class Translator(object): +class Translator: """Internationalization class @@ -190,7 +190,7 @@ class Translator(object): return True -class Moulinette18n(object): +class Moulinette18n: """Internationalization service for the moulinette @@ -312,7 +312,7 @@ class MoulinetteAuthenticationError(MoulinetteError): http_code = 401 -class MoulinetteLock(object): +class MoulinetteLock: """Locker for a moulinette instance diff --git a/moulinette/interfaces/__init__.py b/moulinette/interfaces/__init__.py index 9a5a353a..eeb0a97a 100644 --- a/moulinette/interfaces/__init__.py +++ b/moulinette/interfaces/__init__.py @@ -22,7 +22,7 @@ CALLBACKS_PROP = "_callbacks" # Base Class ----------------------------------------------------------- -class BaseActionsMapParser(object): +class BaseActionsMapParser: """Actions map's base Parser diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index 4bfc51fe..7ce813ee 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -101,7 +101,7 @@ class APIQueueHandler(logging.Handler): sleep(0) -class _HTTPArgumentParser(object): +class _HTTPArgumentParser: """Argument parser for HTTP requests @@ -275,7 +275,7 @@ class Session: response.delete_cookie(f"session.{Session.actionsmap_name}") -class _ActionsMapPlugin(object): +class _ActionsMapPlugin: """Actions map Bottle Plugin diff --git a/moulinette/utils/log.py b/moulinette/utils/log.py index 375affc2..283c121e 100644 --- a/moulinette/utils/log.py +++ b/moulinette/utils/log.py @@ -167,7 +167,7 @@ def getActionLogger(name=None, logger=None, action_id=None): return logger -class ActionFilter(object): +class ActionFilter: """Extend log record for an optionnal action From 37d43d1bdfe43b1af6c0b9cd04c7cbed106cf83d Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 29 Dec 2021 00:40:01 +0100 Subject: [PATCH 07/11] Fix weird format syntax --- test/test_actionsmap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_actionsmap.py b/test/test_actionsmap.py index 87f7ae17..02cf8166 100644 --- a/test/test_actionsmap.py +++ b/test/test_actionsmap.py @@ -266,7 +266,7 @@ def test_actions_map_import_error(mocker): with pytest.raises(MoulinetteError) as exception: amap.process({}, timeout=30, route=("GET", "/test-auth/none")) - expected_msg = "unable to load function {: }.{} because: {}".format( + expected_msg = "unable to load function {}.{} because: {}".format( "moulitest", "testauth_none", "Yoloswag", From ea6eaa6b1e3aed941260e880da955087b3a8ea91 Mon Sep 17 00:00:00 2001 From: alexAubin Date: Tue, 28 Dec 2021 23:46:17 +0000 Subject: [PATCH 08/11] :art: Format Python code with Black --- moulinette/actionsmap.py | 4 +++- moulinette/interfaces/__init__.py | 5 ++--- moulinette/interfaces/api.py | 12 +++++++----- test/test_actionsmap.py | 10 ++++++---- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index 62ae5ca1..cf7c9944 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -428,7 +428,9 @@ class ActionsMap: actionsmap = read_yaml(actionsmap_yml) # Delete old cache files - for old_cache in glob.glob("{}/actionsmap/{}-*.pkl".format(CACHE_DIR, n)): + for old_cache in glob.glob( + "{}/actionsmap/{}-*.pkl".format(CACHE_DIR, n) + ): os.remove(old_cache) # at installation, cachedir might not exists diff --git a/moulinette/interfaces/__init__.py b/moulinette/interfaces/__init__.py index eeb0a97a..d7753eae 100644 --- a/moulinette/interfaces/__init__.py +++ b/moulinette/interfaces/__init__.py @@ -224,9 +224,8 @@ class _CallbackAction(argparse.Action): # Execute callback and get returned value value = self.callback(namespace, values, **self.callback_kwargs) except Exception as e: - error_message = ( - "cannot get value from callback method " - "'{}': {}".format(self.callback_method, e) + error_message = "cannot get value from callback method " "'{}': {}".format( + self.callback_method, e ) logger.exception(error_message) raise MoulinetteError(error_message, raw_msg=True) diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index 7ce813ee..abc0fd93 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -38,9 +38,7 @@ logger = log.getLogger("moulinette.interface.api") # We define a global variable to manage in a dirty way the upload... UPLOAD_DIR = None -CSRF_TYPES = { - "text/plain", "application/x-www-form-urlencoded", "multipart/form-data" -} +CSRF_TYPES = {"text/plain", "application/x-www-form-urlencoded", "multipart/form-data"} def is_csrf(): @@ -667,7 +665,9 @@ class ActionsMapParser(BaseActionsMapParser): # Retrieve the tid for the route _, parser = self._parsers[route] except KeyError as e: - error_message = "no argument parser found for route '{}': {}".format(route, e) + error_message = "no argument parser found for route '{}': {}".format( + route, e + ) logger.error(error_message) raise MoulinetteValidationError(error_message, raw_msg=True) @@ -684,7 +684,9 @@ class ActionsMapParser(BaseActionsMapParser): # Retrieve the parser for the route _, parser = self._parsers[route] except KeyError as e: - error_message = "no argument parser found for route '{}': {}".format(route, e) + error_message = "no argument parser found for route '{}': {}".format( + route, e + ) logger.error(error_message) raise MoulinetteValidationError(error_message, raw_msg=True) ret = argparse.Namespace() diff --git a/test/test_actionsmap.py b/test/test_actionsmap.py index 02cf8166..10ce4795 100644 --- a/test/test_actionsmap.py +++ b/test/test_actionsmap.py @@ -192,10 +192,12 @@ def test_extra_argument_parser_add_argument_bad_arg(iface): with pytest.raises(MoulinetteError) as exception: extra_argument_parse.add_argument("_global", "foo", {"ask": 1}) - expected_msg = "unable to validate extra parameter '{}' for argument '{}': {}".format( - "ask", - "foo", - "parameter value must be a string, got 1", + expected_msg = ( + "unable to validate extra parameter '{}' for argument '{}': {}".format( + "ask", + "foo", + "parameter value must be a string, got 1", + ) ) assert expected_msg in str(exception) From 8b05fcf2fde32bc4dde184e2280f0a71deec7a75 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 29 Dec 2021 01:09:02 +0100 Subject: [PATCH 09/11] Update changelog fro 4.3.3 --- debian/changelog | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/debian/changelog b/debian/changelog index 9aa7948b..6c5f70ee 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +moulinette (4.3.3) stable; urgency=low + + - [enh] quality: Apply pyupgrade ([#312](https://github.com/YunoHost/moulinette/pull/312)) + - [i18n] Translations updated for Czech, German, Portuguese + + Thanks to all contributors <3 ! (Bram, Christian Wehrli, maique madeira, Radek S, Valentin von Guttenberg) + + -- Alexandre Aubin Wed, 29 Dec 2021 01:08:10 +0100 + moulinette (4.3.2.2) stable; urgency=low Aaaaaand typoed 'testing' instead of 'stable' in previous changelog From 29d0d0cfc1eb92b6890d194d4b9b2429534f85f3 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Thu, 30 Dec 2021 14:39:30 +0100 Subject: [PATCH 10/11] add lgtm badge --- README.md | 1 + 1 file changed, 1 insertion(+) 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) From be0006fdb977b965dec3735061085a4ac03351d8 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Thu, 30 Dec 2021 14:39:38 +0100 Subject: [PATCH 11/11] fix some warnings --- moulinette/interfaces/__init__.py | 2 +- moulinette/interfaces/api.py | 5 ++++- moulinette/utils/log.py | 13 +++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) 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)