summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Fritz <fritzy@netflint.net>2010-01-29 02:04:15 -0800
committerNathan Fritz <fritzy@netflint.net>2010-01-29 02:04:15 -0800
commit395618d3d37c5c4092466f4c5ea6919925fda681 (patch)
tree9566643ad99c9c23167f880bbfd6444d73b30884
parent980005db5835786d0e8917d5a04b13646cc005fe (diff)
downloadslixmpp-395618d3d37c5c4092466f4c5ea6919925fda681.tar.gz
slixmpp-395618d3d37c5c4092466f4c5ea6919925fda681.tar.bz2
slixmpp-395618d3d37c5c4092466f4c5ea6919925fda681.tar.xz
slixmpp-395618d3d37c5c4092466f4c5ea6919925fda681.zip
fixed unicode problems in 2.6
-rw-r--r--LICENSE0
-rw-r--r--sleekxmpp/xmlstream/stanzabase.py68
-rw-r--r--testall.py5
3 files changed, 12 insertions, 61 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/LICENSE
diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py
index feb9b268..480e9602 100644
--- a/sleekxmpp/xmlstream/stanzabase.py
+++ b/sleekxmpp/xmlstream/stanzabase.py
@@ -1,6 +1,12 @@
from xml.etree import cElementTree as ET
import logging
import traceback
+import sys
+
+if sys.version_info < (3,0):
+ from . import tostring26 as tostring
+else:
+ from . import tostring
xmltester = type(ET.Element('xml'))
@@ -23,7 +29,7 @@ class JID(object):
def __str__(self):
return self.jid
-class ElementBase(object):
+class ElementBase(tostring.ToString):
name = 'stanza'
plugin_attrib = 'plugin'
namespace = 'jabber:client'
@@ -333,63 +339,5 @@ class StanzaBase(ElementBase):
logging.error(traceback.format_tb(e))
def send(self):
- self.stream.sendRaw(str(self))
-
- def __str__(self, xml=None, xmlns='', stringbuffer=''):
- if xml is None:
- xml = self.xml
- newoutput = [stringbuffer]
- #TODO respect ET mapped namespaces
- itag = xml.tag.split('}', 1)[-1]
- if '}' in xml.tag:
- ixmlns = xml.tag.split('}', 1)[0][1:]
- else:
- ixmlns = ''
- nsbuffer = ''
- if xmlns != ixmlns and ixmlns != '' and ixmlns != self.namespace:
- if self.stream is not None and ixmlns in self.stream.namespace_map:
- if self.stream.namespace_map[ixmlns] != '':
- itag = "%s:%s" % (self.stream.namespace_map[ixmlns], itag)
- else:
- nsbuffer = """ xmlns="%s\"""" % ixmlns
- if ixmlns not in ('', xmlns, self.namespace):
- nsbuffer = """ xmlns="%s\"""" % ixmlns
- newoutput.append("<%s" % itag)
- newoutput.append(nsbuffer)
- for attrib in xml.attrib:
- if '{' not in attrib:
- newoutput.append(""" %s="%s\"""" % (attrib, self.xmlesc(xml.attrib[attrib])))
- if len(xml) or xml.text or xml.tail:
- newoutput.append(">")
- if xml.text:
- newoutput.append(self.xmlesc(xml.text))
- if len(xml):
- for child in xml.getchildren():
- newoutput.append(self.__str__(child, ixmlns))
- newoutput.append("</%s>" % (itag, ))
- if xml.tail:
- newoutput.append(self.xmlesc(xml.tail))
- elif xml.text:
- newoutput.append(">%s</%s>" % (self.xmlesc(xml.text), itag))
- else:
- newoutput.append(" />")
- return ''.join(newoutput)
+ self.stream.sendRaw(self.__str__())
- def xmlesc(self, text):
- text = list(text)
- cc = 0
- matches = ('&', '<', '"', '>', "'")
- for c in text:
- if c in matches:
- if c == '&':
- text[cc] = '&amp;'
- elif c == '<':
- text[cc] = '&lt;'
- elif c == '>':
- text[cc] = '&gt;'
- elif c == "'":
- text[cc] = '&apos;'
- else:
- text[cc] = '&quot;'
- cc += 1
- return ''.join(text)
diff --git a/testall.py b/testall.py
index 00c463b9..bf5e1a99 100644
--- a/testall.py
+++ b/testall.py
@@ -10,7 +10,10 @@ class testoverall(unittest.TestCase):
"""Testing all modules by compiling them"""
import compileall
import re
- self.failUnless(compileall.compile_dir('.' + os.sep + 'sleekxmpp', rx=re.compile('/[.]svn'), quiet=True))
+ if sys.version_info < (3,0):
+ self.failUnless(compileall.compile_dir('.' + os.sep + 'sleekxmpp', rx=re.compile('/[.]svn'), quiet=True))
+ else:
+ self.failUnless(compileall.compile_dir('.' + os.sep + 'sleekxmpp', rx=re.compile('/[.]svn|26.py'), quiet=True))
def testTabNanny(self):
"""Invoking the tabnanny"""