Commits

Anonymous committed 3a9864a

Revert changes from the last commit which caused problems with 2.x

Comments (0)

Files changed (2)

tests/etree13/ElementTree.py

         err.position = value.lineno, value.offset
         raise err
 
+    def _fixtext(self, text):
+        # convert text string to ascii, if possible
+        try:
+            return text.encode("ascii")
+        except UnicodeError:
+            return text
+
     def _fixname(self, key):
         # expand qname, and convert name string to ascii, if possible
         try:
             name = key
             if "}" in name:
                 name = "{" + name
-            self._names[key]
+            self._names[key] = name = self._fixtext(name)
         return name
 
     def _start(self, tag, attrib_in):
         fixname = self._fixname
+        fixtext = self._fixtext
         tag = fixname(tag)
         attrib = {}
         for key, value in attrib_in.items():
-            attrib[fixname(key)] = value
+            attrib[fixname(key)] = fixtext(value)
         return self.target.start(tag, attrib)
 
     def _start_list(self, tag, attrib_in):
         fixname = self._fixname
+        fixtext = self._fixtext
         tag = fixname(tag)
         attrib = {}
         if attrib_in:
             for i in range(0, len(attrib_in), 2):
-                attrib[fixname(attrib_in[i])] = attrib_in[i+1]
+                attrib[fixname(attrib_in[i])] = fixtext(attrib_in[i+1])
         return self.target.start(tag, attrib)
 
     def _data(self, text):
-        return self.target.data(text)
+        return self.target.data(self._fixtext(text))
 
     def _end(self, tag):
         return self.target.end(self._fixname(tag))

tests/test_build_html.py

             br = name.find('}')
             if br > 0:
                 name = name[br+1:]
-            self._names[key] = name
+            self._names[key] = name = self._fixtext(name)
             return name