diff libervia/cli/cmd_encryption.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 47401850dec6
children
line wrap: on
line diff
--- a/libervia/cli/cmd_encryption.py	Tue Jun 18 12:06:45 2024 +0200
+++ b/libervia/cli/cmd_encryption.py	Wed Jun 19 18:44:57 2024 +0200
@@ -31,11 +31,13 @@
     def __init__(self, host):
         extra_outputs = {"default": self.default_output}
         super(EncryptionAlgorithms, self).__init__(
-            host, "algorithms",
+            host,
+            "algorithms",
             use_output=C.OUTPUT_LIST_DICT,
             extra_outputs=extra_outputs,
             use_profile=False,
-            help=_("show available encryption algorithms"))
+            help=_("show available encryption algorithms"),
+        )
 
     def add_parser_options(self):
         pass
@@ -44,8 +46,11 @@
         if not plugins:
             self.disp(_("No encryption plugin registered!"))
         else:
-            self.disp(_("Following encryption algorithms are available: {algos}").format(
-                algos=', '.join([p['name'] for p in plugins])))
+            self.disp(
+                _("Following encryption algorithms are available: {algos}").format(
+                    algos=", ".join([p["name"] for p in plugins])
+                )
+            )
 
     async def start(self):
         try:
@@ -63,15 +68,11 @@
 
     def __init__(self, host):
         super(EncryptionGet, self).__init__(
-            host, "get",
-            use_output=C.OUTPUT_DICT,
-            help=_("get encryption session data"))
+            host, "get", use_output=C.OUTPUT_DICT, help=_("get encryption session data")
+        )
 
     def add_parser_options(self):
-        self.parser.add_argument(
-            "jid",
-            help=_("jid of the entity to check")
-        )
+        self.parser.add_argument("jid", help=_("jid of the entity to check"))
 
     async def start(self):
         jids = await self.host.check_jids([self.args.jid])
@@ -84,8 +85,7 @@
 
         session_data = data_format.deserialise(serialised)
         if session_data is None:
-            self.disp(
-                "No encryption session found, the messages are sent in plain text.")
+            self.disp("No encryption session found, the messages are sent in plain text.")
             self.host.quit(C.EXIT_NOT_FOUND)
         await self.output(session_data)
         self.host.quit()
@@ -95,29 +95,34 @@
 
     def __init__(self, host):
         super(EncryptionStart, self).__init__(
-            host, "start",
-            help=_("start encrypted session with an entity"))
+            host, "start", help=_("start encrypted session with an entity")
+        )
 
     def add_parser_options(self):
         self.parser.add_argument(
             "--encrypt-noreplace",
             action="store_true",
-            help=_("don't replace encryption algorithm if an other one is already used"))
+            help=_("don't replace encryption algorithm if an other one is already used"),
+        )
         algorithm = self.parser.add_mutually_exclusive_group()
         algorithm.add_argument(
-            "-n", "--name", help=_("algorithm name (DEFAULT: choose automatically)"))
+            "-n", "--name", help=_("algorithm name (DEFAULT: choose automatically)")
+        )
         algorithm.add_argument(
-            "-N", "--namespace",
-            help=_("algorithm namespace (DEFAULT: choose automatically)"))
+            "-N",
+            "--namespace",
+            help=_("algorithm namespace (DEFAULT: choose automatically)"),
+        )
         self.parser.add_argument(
-            "jid",
-            help=_("jid of the entity to stop encrypted session with")
+            "jid", help=_("jid of the entity to stop encrypted session with")
         )
 
     async def start(self):
         if self.args.name is not None:
             try:
-                namespace = await self.host.bridge.encryption_namespace_get(self.args.name)
+                namespace = await self.host.bridge.encryption_namespace_get(
+                    self.args.name
+                )
             except Exception as e:
                 self.disp(f"can't get encryption namespace: {e}", error=True)
                 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
@@ -131,8 +136,8 @@
 
         try:
             await self.host.bridge.message_encryption_start(
-                jid, namespace, not self.args.encrypt_noreplace,
-                self.profile)
+                jid, namespace, not self.args.encrypt_noreplace, self.profile
+            )
         except Exception as e:
             self.disp(f"can't get encryption namespace: {e}", error=True)
             self.host.quit(C.EXIT_BRIDGE_ERRBACK)
@@ -144,13 +149,12 @@
 
     def __init__(self, host):
         super(EncryptionStop, self).__init__(
-            host, "stop",
-            help=_("stop encrypted session with an entity"))
+            host, "stop", help=_("stop encrypted session with an entity")
+        )
 
     def add_parser_options(self):
         self.parser.add_argument(
-            "jid",
-            help=_("jid of the entity to stop encrypted session with")
+            "jid", help=_("jid of the entity to stop encrypted session with")
         )
 
     async def start(self):
@@ -168,26 +172,28 @@
 class TrustUI(base.CommandBase):
 
     def __init__(self, host):
-        super(TrustUI, self).__init__(
-            host, "ui",
-            help=_("get UI to manage trust"))
+        super(TrustUI, self).__init__(host, "ui", help=_("get UI to manage trust"))
 
     def add_parser_options(self):
         self.parser.add_argument(
-            "jid",
-            help=_("jid of the entity to stop encrypted session with")
+            "jid", help=_("jid of the entity to stop encrypted session with")
         )
         algorithm = self.parser.add_mutually_exclusive_group()
         algorithm.add_argument(
-            "-n", "--name", help=_("algorithm name (DEFAULT: current algorithm)"))
+            "-n", "--name", help=_("algorithm name (DEFAULT: current algorithm)")
+        )
         algorithm.add_argument(
-            "-N", "--namespace",
-            help=_("algorithm namespace (DEFAULT: current algorithm)"))
+            "-N",
+            "--namespace",
+            help=_("algorithm namespace (DEFAULT: current algorithm)"),
+        )
 
     async def start(self):
         if self.args.name is not None:
             try:
-                namespace = await self.host.bridge.encryption_namespace_get(self.args.name)
+                namespace = await self.host.bridge.encryption_namespace_get(
+                    self.args.name
+                )
             except Exception as e:
                 self.disp(f"can't get encryption namespace: {e}", error=True)
                 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
@@ -201,7 +207,8 @@
 
         try:
             xmlui_raw = await self.host.bridge.encryption_trust_ui_get(
-                jid, namespace, self.profile)
+                jid, namespace, self.profile
+            )
         except Exception as e:
             self.disp(f"can't get encryption session trust UI: {e}", error=True)
             self.host.quit(C.EXIT_BRIDGE_ERRBACK)
@@ -212,6 +219,7 @@
             await xmlui.submit_form()
         self.host.quit()
 
+
 class EncryptionTrust(base.CommandBase):
     subcommands = (TrustUI,)
 
@@ -222,8 +230,13 @@
 
 
 class Encryption(base.CommandBase):
-    subcommands = (EncryptionAlgorithms, EncryptionGet, EncryptionStart, EncryptionStop,
-                   EncryptionTrust)
+    subcommands = (
+        EncryptionAlgorithms,
+        EncryptionGet,
+        EncryptionStart,
+        EncryptionStop,
+        EncryptionTrust,
+    )
 
     def __init__(self, host):
         super(Encryption, self).__init__(