Hello everyone,

I originally posted this on the Twisted mailing list, but now it seams to be a more general python/environment problem. If I run the attached example in Eclipse, it works, if I run it from a terminal, it doesn't, I get :

$ python xml_parser_test.py
Traceback (most recent call last):
 File "xml_parser_test.py", line 30, in <module>
   res = rawXmlToElement("<t>reçu</t>")
 File "xml_parser_test.py", line 21, in __call__
   tmp.addRawXml(s)
File "/usr/lib/python2.5/site-packages/twisted/words/xish/domish.py", line 538, in addRawXml
   self.children.append(SerializedXML(rawxmlstring))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128)

Does anyone understand why it doesn't work outside of Eclipse? My OS is Linux (Ubuntu 8.04).

Thank you,
Gabriel
# -*- coding: utf-8 -*-
from twisted.web import sux
from twisted.words.xish import domish

class __RawXmlToElement(object):

    def __call__(self, s):
        self.result = None
        def onStart(el):
            self.result = el
        def onEnd():
            pass
        def onElement(el):
            self.result.addChild(el)

        parser = domish.elementStream()
        parser.DocumentStartEvent = onStart
        parser.ElementEvent = onElement
        parser.DocumentEndEvent = onEnd
        tmp = domish.Element(("", "s"))
        tmp.addRawXml(s)
        parser.parse(tmp.toXml().encode("utf-8"))

        return self.result.firstChildElement()

rawXmlToElement = __RawXmlToElement()

if(__name__ == "__main__"):

    res = rawXmlToElement("<t>reçu</t>")
    print "Result : %s" % res.toXml()
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to