diff options
author | Maxime “pep” Buquet <pep@bouah.net> | 2019-04-08 23:45:05 +0100 |
---|---|---|
committer | Maxime “pep” Buquet <pep@bouah.net> | 2019-04-08 23:45:05 +0100 |
commit | bddca0c62c2e564855c90c2f5029f2746aafb4e7 (patch) | |
tree | c1a26f74b633cf731e7d4dbc9792e7737d2c6e49 | |
parent | e61b7742bb576533ee295c4df939a035d3a73a7d (diff) | |
download | poezio-bddca0c62c2e564855c90c2f5029f2746aafb4e7.tar.gz poezio-bddca0c62c2e564855c90c2f5029f2746aafb4e7.tar.bz2 poezio-bddca0c62c2e564855c90c2f5029f2746aafb4e7.tar.xz poezio-bddca0c62c2e564855c90c2f5029f2746aafb4e7.zip |
core/commands: remove more safeJID calls; add type hints
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
-rw-r--r-- | poezio/core/commands.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/poezio/core/commands.py b/poezio/core/commands.py index e3c3998f..34ac96b3 100644 --- a/poezio/core/commands.py +++ b/poezio/core/commands.py @@ -8,7 +8,7 @@ log = logging.getLogger(__name__) import asyncio from xml.etree import cElementTree as ET -from typing import List +from typing import List, Optional, Tuple from slixmpp import JID, InvalidJID from slixmpp.exceptions import XMPPError @@ -310,16 +310,19 @@ class CommandCore: nick = tab.own_nick return (room, nick) - def _parse_join_jid(self, jid_string): + def _parse_join_jid(self, jid_string: str) -> Tuple[Optional[str], Optional[str]]: # we try to join a server directly - if jid_string.startswith('@'): - server_root = True - info = safeJID(jid_string[1:]) - else: - info = safeJID(jid_string) - server_root = False + try: + if jid_string.startswith('@'): + server_root = True + info = JID(jid_string[1:]) + else: + info = JID(jid_string) + server_root = False + except InvalidJID: + return (None, None) - set_nick = '' + set_nick = '' # type: Optional[str] if len(jid_string) > 1 and jid_string.startswith('/'): set_nick = jid_string[1:] elif info.resource: @@ -331,7 +334,8 @@ class CommandCore: if not isinstance(tab, tabs.MucTab): room, set_nick = (None, None) else: - room = tab.name + if tab.jid is not None: + room = tab.jid.bare if not set_nick: set_nick = tab.own_nick else: |