Reformatted code base using black.
This commit is contained in:
parent
56319cbad3
commit
53fdaa9d09
1 changed files with 12604 additions and 8966 deletions
|
|
@ -31,11 +31,13 @@ class EncryptionAlgorithms(base.CommandBase):
|
|||
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 @@ class EncryptionAlgorithms(base.CommandBase):
|
|||
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 @@ class EncryptionGet(base.CommandBase):
|
|||
|
||||
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 @@ class EncryptionGet(base.CommandBase):
|
|||
|
||||
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 @@ class EncryptionStart(base.CommandBase):
|
|||
|
||||
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 @@ class EncryptionStart(base.CommandBase):
|
|||
|
||||
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 @@ class EncryptionStop(base.CommandBase):
|
|||
|
||||
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 EncryptionStop(base.CommandBase):
|
|||
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 @@ class TrustUI(base.CommandBase):
|
|||
|
||||
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 @@ class TrustUI(base.CommandBase):
|
|||
await xmlui.submit_form()
|
||||
self.host.quit()
|
||||
|
||||
|
||||
class EncryptionTrust(base.CommandBase):
|
||||
subcommands = (TrustUI,)
|
||||
|
||||
|
|
@ -222,8 +230,13 @@ class EncryptionTrust(base.CommandBase):
|
|||
|
||||
|
||||
class Encryption(base.CommandBase):
|
||||
subcommands = (EncryptionAlgorithms, EncryptionGet, EncryptionStart, EncryptionStop,
|
||||
EncryptionTrust)
|
||||
subcommands = (
|
||||
EncryptionAlgorithms,
|
||||
EncryptionGet,
|
||||
EncryptionStart,
|
||||
EncryptionStop,
|
||||
EncryptionTrust,
|
||||
)
|
||||
|
||||
def __init__(self, host):
|
||||
super(Encryption, self).__init__(
|
||||
|
|
|
|||
Loading…
Reference in a new issue