diff options
author | Lance Stout <lancestout@gmail.com> | 2010-08-05 20:26:41 -0400 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2010-08-05 20:26:41 -0400 |
commit | e077204a16c76df4af90ba067e94c31af3d9e372 (patch) | |
tree | 96d725f14af0f26f19241984a3d85d4555cf1111 /sleekxmpp/xmlstream/tostring26/__init__.py | |
parent | 58f77d898f82ab108fa17d562a32c68d3ea35306 (diff) | |
download | slixmpp-e077204a16c76df4af90ba067e94c31af3d9e372.tar.gz slixmpp-e077204a16c76df4af90ba067e94c31af3d9e372.tar.bz2 slixmpp-e077204a16c76df4af90ba067e94c31af3d9e372.tar.xz slixmpp-e077204a16c76df4af90ba067e94c31af3d9e372.zip |
Replaced the ToString class with a tostring function.
The sleekxmpp.xmlstream.tostring and sleekxmpp.xmlstream.tostring26 packages
have been merged to sleekxmpp.xmlstream.tostring. The __init__.py file will
import the appropriate tostring function depending on the Python version.
The setup.py file has been updated with the package changes.
ElementBase is now a direct descendent of object and does not subclass ToString.
Stanza objects now return their XML contents for __repr__.
Diffstat (limited to 'sleekxmpp/xmlstream/tostring26/__init__.py')
-rw-r--r-- | sleekxmpp/xmlstream/tostring26/__init__.py | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/sleekxmpp/xmlstream/tostring26/__init__.py b/sleekxmpp/xmlstream/tostring26/__init__.py deleted file mode 100644 index 9711c300..00000000 --- a/sleekxmpp/xmlstream/tostring26/__init__.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"</%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 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) |