From 5e736f4b978414c111062ffb220e38eb40765db6 Mon Sep 17 00:00:00 2001 From: Nathan Fritz Date: Fri, 29 Jan 2010 23:57:57 -0800 Subject: fixed setup.py issue with unicode in 3.x --- setup.py | 19 ++++++--- sleekxmpp/plugins/xep_0060.py | 2 +- sleekxmpp/xmlstream/tostring.py | 60 --------------------------- sleekxmpp/xmlstream/tostring/__init__.py | 60 +++++++++++++++++++++++++++ sleekxmpp/xmlstream/tostring26.py | 65 ------------------------------ sleekxmpp/xmlstream/tostring26/__init__.py | 65 ++++++++++++++++++++++++++++++ testall.py | 2 +- 7 files changed, 140 insertions(+), 133 deletions(-) delete mode 100644 sleekxmpp/xmlstream/tostring.py create mode 100644 sleekxmpp/xmlstream/tostring/__init__.py delete mode 100644 sleekxmpp/xmlstream/tostring26.py create mode 100644 sleekxmpp/xmlstream/tostring26/__init__.py diff --git a/setup.py b/setup.py index 7dbd619b..163cb8c6 100644 --- a/setup.py +++ b/setup.py @@ -37,6 +37,18 @@ CLASSIFIERS = [ 'Intended Audience :: Developers', 'Topic :: Software Development :: Libraries :: Python Modules', ] +packages = [ 'sleekxmpp', + 'sleekxmpp/plugins', + 'sleekxmpp/stanza', + 'sleekxmpp/xmlstream', + 'sleekxmpp/xmlstream/matcher', + 'sleekxmpp/xmlstream/handler' ] + +if sys.version_info < (3, 0): + packages.append('sleekxmpp/xmlstream/tostring26') +else: + packages.append('sleekxmpp/xmlstream/tostring') + setup( name = "sleekxmpp", version = VERSION, @@ -47,12 +59,7 @@ setup( url = 'http://code.google.com/p/sleekxmpp', license = 'GPLv2', platforms = [ 'any' ], - packages = [ 'sleekxmpp', - 'sleekxmpp/plugins', - 'sleekxmpp/stanza', - 'sleekxmpp/xmlstream', - 'sleekxmpp/xmlstream/matcher', - 'sleekxmpp/xmlstream/handler' ], + packages = packages, requires = [ 'tlslite', 'pythondns' ], ) diff --git a/sleekxmpp/plugins/xep_0060.py b/sleekxmpp/plugins/xep_0060.py index 837d0ad4..999b8197 100644 --- a/sleekxmpp/plugins/xep_0060.py +++ b/sleekxmpp/plugins/xep_0060.py @@ -63,7 +63,7 @@ class xep_0060(base.base_plugin): iq = self.xmpp.makeIqSet(pubsub) iq.attrib['to'] = jid iq.attrib['from'] = self.xmpp.fulljid - id = iq.get('id') + id = iq['id'] result = self.xmpp.send(iq, "" % id) if result is False or result is None or result.get('type') == 'error': return False return True diff --git a/sleekxmpp/xmlstream/tostring.py b/sleekxmpp/xmlstream/tostring.py deleted file mode 100644 index 6603cbb8..00000000 --- a/sleekxmpp/xmlstream/tostring.py +++ /dev/null @@ -1,60 +0,0 @@ - -class ToString(object): - 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("" % (itag, )) - if xml.tail: - newoutput.append(self.xmlesc(xml.tail)) - elif xml.text: - newoutput.append(">%s" % (self.xmlesc(xml.text), itag)) - else: - newoutput.append(" />") - return ''.join(newoutput) - - def xmlesc(self, text): - text = list(text) - cc = 0 - matches = ('&', '<', '"', '>', "'") - for c in text: - if c in matches: - if c == '&': - text[cc] = '&' - elif c == '<': - text[cc] = '<' - elif c == '>': - text[cc] = '>' - elif c == "'": - text[cc] = ''' - else: - text[cc] = '"' - cc += 1 - return ''.join(text) diff --git a/sleekxmpp/xmlstream/tostring/__init__.py b/sleekxmpp/xmlstream/tostring/__init__.py new file mode 100644 index 00000000..6603cbb8 --- /dev/null +++ b/sleekxmpp/xmlstream/tostring/__init__.py @@ -0,0 +1,60 @@ + +class ToString(object): + 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("" % (itag, )) + if xml.tail: + newoutput.append(self.xmlesc(xml.tail)) + elif xml.text: + newoutput.append(">%s" % (self.xmlesc(xml.text), itag)) + else: + newoutput.append(" />") + return ''.join(newoutput) + + def xmlesc(self, text): + text = list(text) + cc = 0 + matches = ('&', '<', '"', '>', "'") + for c in text: + if c in matches: + if c == '&': + text[cc] = '&' + elif c == '<': + text[cc] = '<' + elif c == '>': + text[cc] = '>' + elif c == "'": + text[cc] = ''' + else: + text[cc] = '"' + cc += 1 + return ''.join(text) diff --git a/sleekxmpp/xmlstream/tostring26.py b/sleekxmpp/xmlstream/tostring26.py deleted file mode 100644 index 9711c300..00000000 --- a/sleekxmpp/xmlstream/tostring26.py +++ /dev/null @@ -1,65 +0,0 @@ -import types - -class ToString(object): - 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 != u'' and ixmlns != self.namespace: - if self.stream is not None and ixmlns in self.stream.namespace_map: - if self.stream.namespace_map[ixmlns] != u'': - 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(u">") - 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(u"" % (itag, )) - if xml.tail: - newoutput.append(self.xmlesc(xml.tail)) - elif xml.text: - newoutput.append(">%s" % (self.xmlesc(xml.text), itag)) - else: - newoutput.append(" />") - return u''.join(newoutput) - - def xmlesc(self, text): - if type(text) != types.UnicodeType: - text = list(unicode(text, 'utf-8', 'ignore')) - else: - text = list(text) - - cc = 0 - matches = (u'&', u'<', u'"', u'>', u"'") - for c in text: - if c in matches: - if c == u'&': - text[cc] = u'&' - elif c == u'<': - text[cc] = u'<' - elif c == u'>': - text[cc] = u'>' - elif c == u"'": - text[cc] = u''' - else: - text[cc] = u'"' - cc += 1 - return ''.join(text) diff --git a/sleekxmpp/xmlstream/tostring26/__init__.py b/sleekxmpp/xmlstream/tostring26/__init__.py new file mode 100644 index 00000000..9711c300 --- /dev/null +++ b/sleekxmpp/xmlstream/tostring26/__init__.py @@ -0,0 +1,65 @@ +import types + +class ToString(object): + 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 != u'' and ixmlns != self.namespace: + if self.stream is not None and ixmlns in self.stream.namespace_map: + if self.stream.namespace_map[ixmlns] != u'': + 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(u">") + 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(u"" % (itag, )) + if xml.tail: + newoutput.append(self.xmlesc(xml.tail)) + elif xml.text: + newoutput.append(">%s" % (self.xmlesc(xml.text), itag)) + else: + newoutput.append(" />") + return u''.join(newoutput) + + def xmlesc(self, text): + if type(text) != types.UnicodeType: + text = list(unicode(text, 'utf-8', 'ignore')) + else: + text = list(text) + + cc = 0 + matches = (u'&', u'<', u'"', u'>', u"'") + for c in text: + if c in matches: + if c == u'&': + text[cc] = u'&' + elif c == u'<': + text[cc] = u'<' + elif c == u'>': + text[cc] = u'>' + elif c == u"'": + text[cc] = u''' + else: + text[cc] = u'"' + cc += 1 + return ''.join(text) diff --git a/testall.py b/testall.py index bf5e1a99..bf0b4c76 100644 --- a/testall.py +++ b/testall.py @@ -13,7 +13,7 @@ class testoverall(unittest.TestCase): 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)) + self.failUnless(compileall.compile_dir('.' + os.sep + 'sleekxmpp', rx=re.compile('/[.]svn|.*26\Z'), quiet=True)) def testTabNanny(self): """Invoking the tabnanny""" -- cgit v1.2.3