diff --git a/sat/memory/params.py b/sat/memory/params.py index 59489435..3635809f 100644 --- a/sat/memory/params.py +++ b/sat/memory/params.py @@ -972,8 +972,12 @@ class Params(object): if not self.checkSecurityLimit(node[1], security_limit): msg = _( - f"{profile!r} is trying to set parameter {name!r} in category " - f"{category!r} without authorization!!!") + "{profile!r} is trying to set parameter {name!r} in category " + "{category!r} without authorization!!!").format( + profile=repr(profile), + name=repr(name), + category=repr(category) + ) log.warning(msg) raise exceptions.PermissionError(msg) @@ -986,8 +990,11 @@ class Params(object): int(value) except ValueError: log.warning(_( - f"Trying to set parameter {name!r} in category {category!r} with" - f"an non-integer value" + "Trying to set parameter {name} in category {category} with" + "an non-integer value" + ).format( + name=repr(name), + category=repr(category) )) return defer.succeed(None) if node[1].hasAttribute("constraint"): diff --git a/sat/plugins/plugin_import.py b/sat/plugins/plugin_import.py index 6d921d05..e7573cf6 100644 --- a/sat/plugins/plugin_import.py +++ b/sat/plugins/plugin_import.py @@ -64,7 +64,7 @@ class ImportPlugin(object): @param name(unicode): import handler name """ assert name == name.lower().strip() - log.info(_(f"initializing {name} import handler")) + log.info(_("initializing {name} import handler").format(name=name)) import_handler.name = name import_handler.register = partial(self.register, import_handler) import_handler.unregister = partial(self.unregister, import_handler) @@ -155,7 +155,7 @@ class ImportPlugin(object): pass except ValueError: raise exceptions.DataError( - _(f"invalid json option: {option}") + _("invalid json option: {option}").format(option=option) ) pubsub_service = jid.JID(pubsub_service) if pubsub_service else None return self.doImport( diff --git a/sat/plugins/plugin_xep_0329.py b/sat/plugins/plugin_xep_0329.py index f6d32852..b8057743 100644 --- a/sat/plugins/plugin_xep_0329.py +++ b/sat/plugins/plugin_xep_0329.py @@ -708,7 +708,8 @@ class XEP_0329(object): ) else: log.warning( - _(f"unexpected element, ignoring: {elt.toXml()}") + _("unexpected element, ignoring: {elt}") + .format(elt=elt.toXml()) ) continue files.append(file_data) diff --git a/sat/tools/common/async_process.py b/sat/tools/common/async_process.py index 85bcf749..3d391175 100644 --- a/sat/tools/common/async_process.py +++ b/sat/tools/common/async_process.py @@ -76,7 +76,7 @@ class CommandProtocol(protocol.ProcessProtocol): def processEnded(self, reason): data = b''.join(self.data) if (reason.value.exitCode == 0): - log.debug(_(f'{self.command_name!r} command succeed')) + log.debug(f'{self.command_name!r} command succeed') # we don't use "replace" on purpose, we want an exception if decoding # is not working properly self._deferred.callback(data) diff --git a/sat_frontends/jp/base.py b/sat_frontends/jp/base.py index aebb93b7..4e2c71a5 100644 --- a/sat_frontends/jp/base.py +++ b/sat_frontends/jp/base.py @@ -153,8 +153,10 @@ class LiberviaCli: background = self.guess_background() if background not in ('dark', 'light'): raise exceptions.ConfigError(_( - f'Invalid value set for "background" ({background!r}), please check ' - f'your settings in libervia.conf')) + 'Invalid value set for "background" ({background}), please check ' + 'your settings in libervia.conf').format( + background=repr(background) + )) if background == 'light': C.A_HEADER = A.FG_MAGENTA C.A_SUBHEADER = A.BOLD + A.FG_RED @@ -449,7 +451,8 @@ class LiberviaCli: if default: if type_ in self.default_output: self.disp( - _(f'there is already a default output for {type_}, ignoring new one') + _('there is already a default output for {type}, ignoring new one') + .format(type=type_) ) else: self.default_output[type_] = name @@ -493,7 +496,8 @@ class LiberviaCli: self.import_plugin_module(module, type_) except ImportError as e: self.disp( - _(f"Can't import {module_path} plugin, ignoring it: {e}"), + _("Can't import {module_path} plugin, ignoring it: {e}") + .format(module_path=module_path, e=e), error=True) except exceptions.CancelError: continue @@ -512,7 +516,10 @@ class LiberviaCli: try: class_names = getattr(module, '__{}__'.format(type_)) except AttributeError: - log.disp(_(f"Invalid plugin module [{type_}] {module}"), error=True) + log.disp( + _("Invalid plugin module [{type}] {module}") + .format(type=type_, module=module), + error=True) raise ImportError else: for class_name in class_names: @@ -601,7 +608,9 @@ class LiberviaCli: if not item_last: self.args.item = uri_item else: - self.parser.error(_(f'XMPP URL is not a pubsub one: {url}')) + self.parser.error( + _('XMPP URL is not a pubsub one: {url}').format(url=url) + ) flags = self.args._cmd._pubsub_flags # we check required arguments here instead of using add_arguments' required option # because the required argument can be set in URL @@ -647,13 +656,15 @@ class LiberviaCli: await self.bridge.bridgeConnect() except Exception as e: if isinstance(e, exceptions.BridgeExceptionNoService): - print((_("Can't connect to SàT backend, are you sure it's launched ?"))) + print(_("Can't connect to SàT backend, are you sure it's launched ?")) self.quit(C.EXIT_BACKEND_NOT_FOUND, raise_exc=False) elif isinstance(e, exceptions.BridgeInitError): - print((_("Can't init bridge"))) + print(_("Can't init bridge")) self.quit(C.EXIT_BRIDGE_ERROR, raise_exc=False) else: - print((_(f"Error while initialising bridge: {e}"))) + print( + _("Error while initialising bridge: {e}").format(e=e) + ) self.quit(C.EXIT_BRIDGE_ERROR, raise_exc=False) return self.version = await self.bridge.getVersion() @@ -844,7 +855,10 @@ class LiberviaCli: self.profile = await self.bridge.profileNameGet(self.args.profile) if not self.profile: - log.error(_(f"The profile [{self.args.profile}] doesn't exist")) + log.error( + _("The profile [{profile}] doesn't exist") + .format(profile=self.args.profile) + ) self.quit(C.EXIT_ERROR) try: @@ -861,9 +875,11 @@ class LiberviaCli: elif not await self.bridge.profileIsSessionStarted(self.profile): if not self.args.connect: self.disp(_( - f"Session for [{self.profile}] is not started, please start it " - f"before using jp, or use either --start-session or --connect " - f"option"), error=True) + "Session for [{profile}] is not started, please start it " + "before using jp, or use either --start-session or --connect " + "option" + .format(profile=self.profile) + ), error=True) self.quit(1) elif not getattr(self.args, "connect", False): return @@ -882,8 +898,10 @@ class LiberviaCli: else: if not await self.bridge.isConnected(self.profile): log.error( - _(f"Profile [{self.profile}] is not connected, please connect it " - f"before using jp, or use --connect option")) + _("Profile [{profile}] is not connected, please connect it " + "before using jp, or use --connect option") + .format(profile=self.profile) + ) self.quit(1) async def get_full_jid(self, param_jid): @@ -1158,7 +1176,7 @@ class CommandBase(object): @param error_msg(unicode): error message as sent by bridge.progressError """ - self.disp(_(f"Error while doing operation: {e}"), error=True) + self.disp(_("Error while doing operation: {e}").format(e=e), error=True) def disp(self, msg, verbosity=0, error=False, end='\n'): return self.host.disp(msg, verbosity, error, end) diff --git a/sat_frontends/jp/cmd_account.py b/sat_frontends/jp/cmd_account.py index 23bdb5f2..ecdef4cc 100644 --- a/sat_frontends/jp/cmd_account.py +++ b/sat_frontends/jp/cmd_account.py @@ -73,7 +73,9 @@ class AccountCreate(base.CommandBase): "--port", type=int, default=0, - help=_(f"server port (default: {C.XMPP_C2S_PORT})"), + help=_("server port (default: {port})").format( + port=C.XMPP_C2S_PORT + ), ) async def start(self): @@ -124,8 +126,12 @@ class AccountCreate(base.CommandBase): self.host.quit(C.EXIT_CONFLICT) else: self.disp( - _(f"Can't create profile {self.args.profile} to associate with jid " - f"{self.args.jid}: {e}"), + _("Can't create profile {profile} to associate with jid " + "{jid}: {e}").format( + profile=self.args.profile, + jid=self.args.jid, + e=e + ), error=True, ) self.host.quit(C.EXIT_BRIDGE_ERRBACK) diff --git a/sat_frontends/jp/cmd_adhoc.py b/sat_frontends/jp/cmd_adhoc.py index 5f916010..db24d42e 100644 --- a/sat_frontends/jp/cmd_adhoc.py +++ b/sat_frontends/jp/cmd_adhoc.py @@ -97,7 +97,8 @@ class Remote(base.CommandBase): for method in methods: path, iface, command = method self.disp( - _(f"Command found: (path:{path}, iface: {iface}) [{command}]"), + _("Command found: (path:{path}, iface: {iface}) [{command}]") + .format(path=path, iface=iface, command=command), 1, ) self.host.quit() diff --git a/sat_frontends/jp/cmd_avatar.py b/sat_frontends/jp/cmd_avatar.py index f7a8a8b2..228a070b 100644 --- a/sat_frontends/jp/cmd_avatar.py +++ b/sat_frontends/jp/cmd_avatar.py @@ -113,7 +113,7 @@ class Set(base.CommandBase): async def start(self): path = self.args.image_path if not os.path.exists(path): - self.disp(_(f"file {path!r} doesn't exist!"), error=True) + self.disp(_("file {path} doesn't exist!").format(path=repr(path)), error=True) self.host.quit(C.EXIT_BAD_ARG) path = os.path.abspath(path) try: diff --git a/sat_frontends/jp/cmd_blog.py b/sat_frontends/jp/cmd_blog.py index 79d8c689..62418eed 100644 --- a/sat_frontends/jp/cmd_blog.py +++ b/sat_frontends/jp/cmd_blog.py @@ -100,7 +100,7 @@ async def guessSyntaxFromPath(host, sat_conf, path): if k and ext == v: return k - # if not found, we use current syntax + # if not found, we use current syntax return await host.bridge.getParamA("Syntax", "Composition", "value", host.profile) @@ -125,15 +125,17 @@ class BlogPublishCommon(object): self.current_syntax = self.args.syntax = syntax except Exception as e: if e.classname == "NotFound": - self.parser.error(_(f"unknown syntax requested ({self.args.syntax})")) + self.parser.error( + _("unknown syntax requested ({syntax})").format( + syntax=self.args.syntax + ) + ) else: raise e return self.args.syntax def add_parser_options(self): - self.parser.add_argument( - "-T", "--title", help=_("title of the item") - ) + self.parser.add_argument("-T", "--title", help=_("title of the item")) self.parser.add_argument( "-t", "--tag", @@ -148,13 +150,22 @@ class BlogPublishCommon(object): comments_group = self.parser.add_mutually_exclusive_group() comments_group.add_argument( - "-C", "--comments", action="store_const", const=True, dest="comments", - help=_("enable comments (default: comments not enabled except if they " - "already exist)") + "-C", + "--comments", + action="store_const", + const=True, + dest="comments", + help=_( + "enable comments (default: comments not enabled except if they " + "already exist)" + ), ) comments_group.add_argument( - "--no-comments", action="store_const", const=False, dest="comments", - help=_("disable comments (will remove comments node if it exist)") + "--no-comments", + action="store_const", + const=False, + dest="comments", + help=_("disable comments (will remove comments node if it exist)"), ) self.parser.add_argument( @@ -182,7 +193,7 @@ class BlogPublishCommon(object): if self.args.comments is not None: mb_data["allow_comments"] = self.args.comments if self.args.tag: - mb_data['tags'] = self.args.tag + mb_data["tags"] = self.args.tag if self.args.title is not None: mb_data["title"] = self.args.title if self.args.language is not None: @@ -222,9 +233,7 @@ class Set(base.CommandBase, BlogPublishCommon): self.profile, ) except Exception as e: - self.disp( - f"can't send item: {e}", error=True - ) + self.disp(f"can't send item: {e}", error=True) self.host.quit(C.EXIT_BRIDGE_ERRBACK) else: self.disp("Item published") @@ -261,12 +270,12 @@ class Get(base.CommandBase): def template_data_mapping(self, data): items, blog_items = data - blog_items['items'] = items + blog_items["items"] = items return {"blog_items": blog_items} def format_comments(self, item, keys): lines = [] - for data in item.get('comments', []): + for data in item.get("comments", []): lines.append(data["uri"]) for k in ("node", "service"): if OUTPUT_OPT_NO_HEADER in self.args.output_opts: @@ -277,7 +286,7 @@ class Get(base.CommandBase): return "\n".join(lines) def format_tags(self, item, keys): - tags = item.pop('tags', []) + tags = item.pop("tags", []) return ", ".join(tags) def format_updated(self, item, keys): @@ -359,7 +368,7 @@ class Get(base.CommandBase): if isinstance(value, bool): value = str(value).lower() self.disp(header + value) - # we want a separation line after each item but the last one + # we want a separation line after each item but the last one if idx < len(items) - 1: print("") @@ -393,7 +402,7 @@ class Get(base.CommandBase): else: author = published = updated = None if verbosity > 1: - tags = item.pop('tags', []) + tags = item.pop("tags", []) else: tags = None content = item.get("content") @@ -428,14 +437,14 @@ class Get(base.CommandBase): self.args.max, self.args.items, self.getPubsubExtra(), - self.profile + self.profile, ) ) except Exception as e: self.disp(f"can't get blog items: {e}", error=True) self.host.quit(C.EXIT_BRIDGE_ERRBACK) else: - items = mb_data.pop('items') + items = mb_data.pop("items") await self.output((items, mb_data)) self.host.quit(C.EXIT_OK) @@ -483,7 +492,8 @@ class Edit(base.CommandBase, BlogPublishCommon, common.BaseEdit): # we first construct metadata from edited item ones and CLI argumments # or re-use the existing one if it exists meta_file_path = content_file_path.with_name( - content_file_path.stem + common.METADATA_SUFF) + content_file_path.stem + common.METADATA_SUFF + ) if meta_file_path.exists(): self.disp("Metadata file already exists, we re-use it") try: @@ -499,20 +509,20 @@ class Edit(base.CommandBase, BlogPublishCommon, common.BaseEdit): else: mb_data = {} if mb_data is None else mb_data.copy() - # in all cases, we want to remove unwanted keys + # in all cases, we want to remove unwanted keys for key in KEY_TO_REMOVE_METADATA: try: del mb_data[key] except KeyError: pass - # and override metadata with command-line arguments + # and override metadata with command-line arguments self.setMbDataFromArgs(mb_data) if self.args.no_publish: mb_data["publish"] = False - # then we create the file and write metadata there, as JSON dict - # XXX: if we port jp one day on Windows, O_BINARY may need to be added here + # then we create the file and write metadata there, as JSON dict + # XXX: if we port jp one day on Windows, O_BINARY may need to be added here with os.fdopen( os.open(meta_file_path, os.O_RDWR | os.O_CREAT | os.O_TRUNC, 0o600), "w+b" ) as f: @@ -556,7 +566,7 @@ class Edit(base.CommandBase, BlogPublishCommon, common.BaseEdit): ) ) - # we launch editor + # we launch editor coroutines.append( self.runEditor( "blog_editor_args", @@ -590,11 +600,9 @@ class Edit(base.CommandBase, BlogPublishCommon, common.BaseEdit): items = [item] if item else [] mb_data = data_format.deserialise( - await self.host.bridge.mbGet( - service, node, 1, items, {}, self.profile - ) + await self.host.bridge.mbGet(service, node, 1, items, {}, self.profile) ) - item = mb_data['items'][0] + item = mb_data["items"][0] try: content = item["content_xhtml"] @@ -612,8 +620,8 @@ class Edit(base.CommandBase, BlogPublishCommon, common.BaseEdit): if content and self.current_syntax == SYNTAX_XHTML: content = content.strip() - if not content.startswith('