From e06cdec81ae8732b496acdbb3e86ad8ef7afe640 Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Thu, 25 Feb 2010 01:12:15 +0000 Subject: [PATCH] fixed some unicode problems for 2.6 --- example.py | 5 +++++ sleekxmpp/basexmpp.py | 7 +++++++ sleekxmpp/xmlstream/stanzabase.py | 5 ++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/example.py b/example.py index bba31a8..71979c5 100644 --- a/example.py +++ b/example.py @@ -1,8 +1,13 @@ +# coding=utf8 + import sleekxmpp import logging from optparse import OptionParser import time +reload(sys) +sys.setdefaultencoding('utf8') + class Example(sleekxmpp.ClientXMPP): def __init__(self, jid, password): diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index 26e513a..92f1f9a 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -39,6 +39,13 @@ from . stanza.error import Error import logging import threading +import sys + +if sys.version_info < (3,0): + reload(sys) + sys.setdefaultencoding('utf8') + + def stanzaPlugin(stanza, plugin): stanza.plugin_attrib_map[plugin.plugin_attrib] = plugin stanza.plugin_tag_map["{%s}%s" % (plugin.namespace, plugin.name)] = plugin diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py index 480e960..7a5ba4a 100644 --- a/sleekxmpp/xmlstream/stanzabase.py +++ b/sleekxmpp/xmlstream/stanzabase.py @@ -18,7 +18,10 @@ class JID(object): if name == 'resource': return self.jid.split('/', 1)[-1] elif name == 'user': - return self.jid.split('@', 1)[0] + if '@' in self.jid: + return self.jid.split('@', 1)[0] + else: + return '' elif name == 'server': return self.jid.split('@', 1)[-1].split('/', 1)[0] elif name == 'full':