From bddca0c62c2e564855c90c2f5029f2746aafb4e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 8 Apr 2019 23:45:05 +0100 Subject: core/commands: remove more safeJID calls; add type hints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- poezio/core/commands.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'poezio/core') 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: -- cgit v1.2.3