From ed6ec070b25a8995bccb3cec1a63cb111e06a6fb Mon Sep 17 00:00:00 2001 From: JINMEI Tatuya Date: Thu, 16 Jun 2011 16:25:53 -0700 Subject: [PATCH] [trac710] make sure in xml_handler() the textual representation of XML is a correct string (not bytes, not a string in the form of "b'XXX'") regardless of whether xml.etree.ElementTree.tostring() returns bytes or string by default. --- src/bin/stats/stats_httpd.py.in | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) mode change 100644 => 100755 src/bin/stats/stats_httpd.py.in diff --git a/src/bin/stats/stats_httpd.py.in b/src/bin/stats/stats_httpd.py.in old mode 100644 new mode 100755 index 72d2fc8f16..a6fd066788 --- a/src/bin/stats/stats_httpd.py.in +++ b/src/bin/stats/stats_httpd.py.in @@ -437,8 +437,15 @@ class StatsHttpd: (k, v) = (str(k), str(v)) elem = xml.etree.ElementTree.Element(k) elem.text = v + # The coding conversion is tricky. xml..tostring() of Python 3.2 + # returns bytes (not string) regardless of the coding, while + # tostring() of Python 3.1 returns a string. To support both + # cases transparently, we first make sure tostring() returns + # bytes by specifying utf-8 and then convert the result to a + # plain string (code below assume it). xml_list.append( - str(xml.etree.ElementTree.tostring(elem))) + str(xml.etree.ElementTree.tostring(elem, encoding='utf-8'), + encoding='us-ascii')) xml_string = "".join(xml_list) self.xml_body = self.open_template(XML_TEMPLATE_LOCATION).substitute( xml_string=xml_string,