summaryrefslogtreecommitdiff
path: root/src/common.py
diff options
context:
space:
mode:
authorlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-08-31 23:11:02 +0000
committerlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-08-31 23:11:02 +0000
commite84b23d1ad7dcb3afa3754ff3b1c1eca27a90548 (patch)
treec56b10c3ba46be749755b201ba69a72c1891fb28 /src/common.py
parentd2fef9112d71c7cee2b5a29cb5887e37fb3c990e (diff)
downloadpoezio-e84b23d1ad7dcb3afa3754ff3b1c1eca27a90548.tar.gz
poezio-e84b23d1ad7dcb3afa3754ff3b1c1eca27a90548.tar.bz2
poezio-e84b23d1ad7dcb3afa3754ff3b1c1eca27a90548.tar.xz
poezio-e84b23d1ad7dcb3afa3754ff3b1c1eca27a90548.zip
Switch to Sleekxmpp. fixed #1768
Diffstat (limited to 'src/common.py')
-rw-r--r--src/common.py42
1 files changed, 15 insertions, 27 deletions
diff --git a/src/common.py b/src/common.py
index 93eca601..75a0b940 100644
--- a/src/common.py
+++ b/src/common.py
@@ -47,8 +47,6 @@ import errno
import time
import traceback
-import xmpp
-
ROOM_STATE_NONE = 11
ROOM_STATE_CURRENT = 10
ROOM_STATE_PRIVATE = 15
@@ -120,20 +118,11 @@ def is_in_path(command, return_abs_path=False):
pass
return False
-def get_stripped_jid(jid):
- """
- Return the stripped JID (bare representation)
- nick@server/resource -> nick@server
- """
- if isinstance(jid, basestring):
- jid = xmpp.JID(jid)
- return jid.getStripped()
-
def is_jid(jid):
"""
Return True if this is a valid JID
"""
- if xmpp.JID(jid).getNode() != '':
+ if jid.find('@') != -1:
return True
return False
@@ -141,35 +130,34 @@ def jid_get_node(jid):
"""
nick@server/resource -> nick
"""
- if isinstance(jid, basestring):
- jid = xmpp.JID(jid)
- return jid.getNode()
+ return jid.split('@', 1)[0]
def jid_get_domain(jid):
"""
nick@server/resource -> server
"""
- if isinstance(jid, basestring):
- jid = xmpp.JID(jid)
- return jid.getDomain()
+ return jid.split('@',1)[-1].split('/', 1)[0]
-def jid_get_resource(jid):
+def jid_get_resource(fulljid):
"""
nick@server/resource -> resource
"""
- if isinstance(jid, basestring):
- jid = xmpp.JID(jid)
- return jid.getResource()
+ if '/' in fulljid:
+ return fulljid.split('/', 1)[-1]
+ else:
+ return ''
+
+def jid_get_bare(fulljid):
+ """
+ nick@server/resource -> nick@server
+ """
+ return '%s@%s' % (jid_get_domain(fulljid), jid_get_node(fulljid))
def is_jid_the_same(a, b):
"""
Compare two bare jids
"""
- if isinstance(a, basestring):
- a = xmpp.JID(a)
- if isinstance(b, basestring):
- b = xmpp.JID(b)
- return a.bareMatch(b)
+ return jid_get_bare(a) == jid_get_bare(a)
DISTRO_INFO = {
'Arch Linux': '/etc/arch-release',