plugin_e2ee: Use f-string

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-01-02 10:39:36 +01:00
parent b9abd60673
commit c202e8e2f3

View file

@ -191,8 +191,8 @@ class E2EEPlugin(BasePlugin):
self.encryption_short_name + '_fingerprint', self.encryption_short_name + '_fingerprint',
self._command_show_fingerprints, self._command_show_fingerprints,
usage='[jid]', usage='[jid]',
short='Show %s fingerprint(s) for a JID.' % self.encryption_short_name, short=f'Show {self.encryption_short_name} fingerprint(s) for a JID.',
help='Show %s fingerprint(s) for a JID.' % self.encryption_short_name, help=f'Show {self.encryption_short_name} fingerprint(s) for a JID.',
) )
ConversationTab.add_information_element( ConversationTab.add_information_element(
@ -244,14 +244,14 @@ class E2EEPlugin(BasePlugin):
del self._enabled_tabs[jid] del self._enabled_tabs[jid]
config.remove_and_save('encryption', section=jid) config.remove_and_save('encryption', section=jid)
self.api.information( self.api.information(
'{} encryption disabled for {}'.format(self.encryption_name, jid), f'{self.encryption_name} encryption disabled for {jid}',
'Info', 'Info',
) )
elif self.encryption_short_name: elif self.encryption_short_name:
self._enabled_tabs[jid] = self.encrypt self._enabled_tabs[jid] = self.encrypt
config.set_and_save('encryption', self.encryption_short_name, section=jid) config.set_and_save('encryption', self.encryption_short_name, section=jid)
self.api.information( self.api.information(
'{} encryption enabled for {}'.format(self.encryption_name, jid), f'{self.encryption_name} encryption enabled for {jid}',
'Info', 'Info',
) )
@ -260,7 +260,7 @@ class E2EEPlugin(BasePlugin):
fprs = self.get_fingerprints(jid) fprs = self.get_fingerprints(jid)
if len(fprs) == 1: if len(fprs) == 1:
self.api.information( self.api.information(
'Fingerprint for %s: %s' % (jid, fprs[0]), f'Fingerprint for {jid}: {fprs[0]}',
'Info', 'Info',
) )
elif fprs: elif fprs:
@ -281,9 +281,9 @@ class E2EEPlugin(BasePlugin):
elif args: elif args:
jid = args[0] jid = args[0]
else: else:
shortname = self.encryption_short_name
self.api.information( self.api.information(
'%s_fingerprint: Couldn\'t deduce JID from context' % ( f'{shortname}_fingerprint: Couldn\'t deduce JID from context',
self.encryption_short_name),
'Error', 'Error',
) )
return None return None
@ -299,9 +299,9 @@ class E2EEPlugin(BasePlugin):
return return
jid, fpr = args jid, fpr = args
if state not in self._all_trust_states: if state not in self._all_trust_states:
shortname = self.encryption_short_name
self.api.information( self.api.information(
'Unknown state for plugin %s: %s' % ( f'Unknown state for plugin {shortname}: {state}',
self.encryption_short_name, state),
'Error' 'Error'
) )
return return
@ -324,9 +324,9 @@ class E2EEPlugin(BasePlugin):
return return
fpr = args[0] fpr = args[0]
if state not in self._all_trust_states: if state not in self._all_trust_states:
shortname = self.encryption_short_name
self.api.information( self.api.information(
'Unknown state for plugin %s: %s' % ( f'Unknown state for plugin {shortname}: {state}',
self.encryption_short_name, state),
'Error', 'Error',
) )
return return
@ -384,7 +384,7 @@ class E2EEPlugin(BasePlugin):
async def _decrypt(self, message: Message, tab: ChatTabs, passthrough: bool = True) -> None: async def _decrypt(self, message: Message, tab: ChatTabs, passthrough: bool = True) -> None:
has_eme: bool = False has_eme: bool = False
if message.xml.find('{%s}%s' % (EME_NS, EME_TAG)) is not None and \ if message.xml.find(f'{{{EME_NS}}}{EME_TAG}') is not None and \
message['eme']['namespace'] == self.eme_ns: message['eme']['namespace'] == self.eme_ns:
has_eme = True has_eme = True
@ -392,7 +392,7 @@ class E2EEPlugin(BasePlugin):
if not has_eme and self.encrypted_tags is not None: if not has_eme and self.encrypted_tags is not None:
tmp: bool = True tmp: bool = True
for (namespace, tag) in self.encrypted_tags: for (namespace, tag) in self.encrypted_tags:
tmp = tmp and message.xml.find('{%s}%s' % (namespace, tag)) is not None tmp = tmp and message.xml.find(f'{{{namespace}}}{tag}') is not None
has_encrypted_tag = tmp has_encrypted_tag = tmp
if not has_eme and not has_encrypted_tag: if not has_eme and not has_encrypted_tag:
@ -452,7 +452,7 @@ class E2EEPlugin(BasePlugin):
if self.encrypted_tags is not None: if self.encrypted_tags is not None:
tmp: bool = True tmp: bool = True
for (namespace, tag) in self.encrypted_tags: for (namespace, tag) in self.encrypted_tags:
tmp = tmp and message.xml.find('{%s}%s' % (namespace, tag)) is not None tmp = tmp and message.xml.find(f'{{{namespace}}}{tag}') is not None
has_encrypted_tag = tmp has_encrypted_tag = tmp
if has_encrypted_tag: if has_encrypted_tag:
@ -556,7 +556,7 @@ class E2EEPlugin(BasePlugin):
if self.encrypted_tags is not None: if self.encrypted_tags is not None:
whitelist += self.encrypted_tags whitelist += self.encrypted_tags
tag_whitelist = {'{%s}%s' % tag for tag in whitelist} tag_whitelist = {f'{{{ns}}}{tag}' for (ns, tag) in whitelist}
for elem in message.xml[:]: for elem in message.xml[:]:
if elem.tag not in tag_whitelist: if elem.tag not in tag_whitelist:
@ -567,12 +567,12 @@ class E2EEPlugin(BasePlugin):
def store_trust(self, jid: JID, state: str, fingerprint: str) -> None: def store_trust(self, jid: JID, state: str, fingerprint: str) -> None:
"""Store trust for a fingerprint and a jid.""" """Store trust for a fingerprint and a jid."""
option_name = '%s:%s' % (self.encryption_short_name, fingerprint) option_name = f'{self.encryption_short_name}:{fingerprint}'
config.silent_set(option=option_name, value=state, section=jid) config.silent_set(option=option_name, value=state, section=jid)
def fetch_trust(self, jid: JID, fingerprint: str) -> str: def fetch_trust(self, jid: JID, fingerprint: str) -> str:
"""Fetch trust of a fingerprint and a jid.""" """Fetch trust of a fingerprint and a jid."""
option_name = '%s:%s' % (self.encryption_short_name, fingerprint) option_name = f'{self.encryption_short_name}:{fingerprint}'
return config.getstr(option=option_name, section=jid) return config.getstr(option=option_name, section=jid)
async def decrypt(self, message: Message, jid: Optional[JID], tab: ChatTab): async def decrypt(self, message: Message, jid: Optional[JID], tab: ChatTab):