summaryrefslogtreecommitdiff
path: root/src/common.py
diff options
context:
space:
mode:
authorlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-07-01 21:32:44 +0000
committerlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-07-01 21:32:44 +0000
commit33c291c9a945da009ab6849855dc3c66ecc103fa (patch)
treee2381d3dd80c4487d58e454a1d3c3e6685683367 /src/common.py
parent450c234cd3c21032fe7dd10f754fbda0855ef2ac (diff)
downloadpoezio-33c291c9a945da009ab6849855dc3c66ecc103fa.tar.gz
poezio-33c291c9a945da009ab6849855dc3c66ecc103fa.tar.bz2
poezio-33c291c9a945da009ab6849855dc3c66ecc103fa.tar.xz
poezio-33c291c9a945da009ab6849855dc3c66ecc103fa.zip
server on /join can be omitted, fixed #1525 Also reorganize various functions in common.py and update CHANGELOG
Diffstat (limited to 'src/common.py')
-rw-r--r--src/common.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/common.py b/src/common.py
index d5851bed..3edc9e14 100644
--- a/src/common.py
+++ b/src/common.py
@@ -43,6 +43,7 @@ import curses
import sys
import select
import errno
+import xmpp
def debug(string):
"""
@@ -103,6 +104,57 @@ 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() != '':
+ return True
+ return False
+
+def jid_get_node(jid):
+ """
+ nick@server/resource -> nick
+ """
+ if isinstance(jid, basestring):
+ jid = xmpp.JID(jid)
+ return jid.getNode()
+
+def jid_get_domain(jid):
+ """
+ nick@server/resource -> server
+ """
+ if isinstance(jid, basestring):
+ jid = xmpp.JID(jid)
+ return jid.getDomain()
+
+def jid_get_resource(jid):
+ """
+ nick@server/resource -> resource
+ """
+ if isinstance(jid, basestring):
+ jid = xmpp.JID(jid)
+ return jid.getResource()
+
+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)
+
DISTRO_INFO = {
'Arch Linux': '/etc/arch-release',
'Aurox Linux': '/etc/aurox-release',