Eradicate more safeJID calls
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
7c7523e0ab
commit
d8638d5e31
3 changed files with 18 additions and 11 deletions
|
@ -32,9 +32,8 @@ import functools
|
|||
import logging
|
||||
from typing import Optional, List, Union
|
||||
|
||||
from slixmpp import JID
|
||||
from slixmpp import InvalidJID, JID
|
||||
from slixmpp.plugins.xep_0048 import Bookmarks, Conference, URL
|
||||
from poezio.common import safeJID
|
||||
from poezio.config import config
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -288,7 +287,10 @@ class BookmarkList:
|
|||
return
|
||||
rooms = rooms.split(':')
|
||||
for room in rooms:
|
||||
jid = safeJID(room)
|
||||
try:
|
||||
jid = JID(room)
|
||||
except InvalidJID:
|
||||
continue
|
||||
if jid.bare == '':
|
||||
continue
|
||||
if jid.resource != '':
|
||||
|
|
|
@ -13,8 +13,7 @@ from collections import defaultdict
|
|||
import logging
|
||||
from typing import Dict, Iterator, List, Optional, Union
|
||||
|
||||
from poezio.common import safeJID
|
||||
from slixmpp import JID
|
||||
from slixmpp import InvalidJID, JID
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -134,8 +133,12 @@ class Contact:
|
|||
return self.__item['subscription']
|
||||
|
||||
def __contains__(self, value):
|
||||
return value in self.__item.resources or safeJID(
|
||||
value).resource in self.__item.resources
|
||||
try:
|
||||
resource = JID(value).resource
|
||||
except InvalidJID:
|
||||
resource = None
|
||||
return value in self.__item.resources or \
|
||||
(resource is not None and resource in self.__item.resources)
|
||||
|
||||
def __len__(self) -> int:
|
||||
"""Number of resources"""
|
||||
|
@ -147,7 +150,10 @@ class Contact:
|
|||
|
||||
def __getitem__(self, key) -> Optional[Resource]:
|
||||
"""Return the corresponding Resource object, or None"""
|
||||
res = safeJID(key).resource
|
||||
try:
|
||||
res = JID(key).resource
|
||||
except InvalidJID:
|
||||
return None
|
||||
resources = self.__item.resources
|
||||
item = resources.get(res, None) or resources.get(key, None)
|
||||
return Resource(key, item) if item else None
|
||||
|
|
|
@ -35,7 +35,6 @@ from poezio import timed_events
|
|||
from poezio import windows
|
||||
|
||||
from poezio.bookmarks import BookmarkList
|
||||
from poezio.common import safeJID
|
||||
from poezio.config import config, firstrun
|
||||
from poezio.contact import Contact, Resource
|
||||
from poezio.daemon import Executor
|
||||
|
@ -1019,7 +1018,7 @@ class Core:
|
|||
If fallback_barejid is True, then this method will seek other
|
||||
tabs with the same barejid, instead of searching only by fulljid.
|
||||
"""
|
||||
jid = safeJID(jid)
|
||||
jid = JID(jid)
|
||||
# We first check if we have a static conversation opened
|
||||
# with this precise resource
|
||||
conversation = self.tabs.by_name_and_class(jid.full,
|
||||
|
@ -1164,7 +1163,7 @@ class Core:
|
|||
provided, we open a StaticConversationTab, else a
|
||||
DynamicConversationTab
|
||||
"""
|
||||
if safeJID(jid).resource:
|
||||
if jid.resource:
|
||||
new_tab = tabs.StaticConversationTab(self, jid)
|
||||
else:
|
||||
new_tab = tabs.DynamicConversationTab(self, jid)
|
||||
|
|
Loading…
Reference in a new issue