Commits

Ronny Pfannschmidt committed 26d3c54

update xmlgen object tag name clash handling

Comments (0)

Files changed (1)

 # HG changeset patch
-# Parent 1b68b3728002cdbfd2ac00cc7befa65bc40aed28
+# Parent 0bc29913774dede5c4242e7c419433e02b4b8f03
 special case for tags in xmlgen to work for the object tag, fixes #13
 
 diff --git a/CHANGELOG b/CHANGELOG
 diff --git a/py/_xmlgen.py b/py/_xmlgen.py
 --- a/py/_xmlgen.py
 +++ b/py/_xmlgen.py
-@@ -117,12 +117,16 @@ class SimpleUnicodeVisitor(object):
-         try:
-             visitmethod = self.cache[cls]
-         except KeyError:
--            for subclass in cls.__mro__:
--                visitmethod = getattr(self, subclass.__name__, None)
--                if visitmethod is not None:
--                    break
-+            if Tag in cls.__mro__:
-+                #special case to avoid trouble with the tag name object
-+                visitmethod = self.Tag
+@@ -122,11 +122,13 @@ class SimpleUnicodeVisitor(object):
+                 if visitmethod is not None:
+                     break
              else:
 -                visitmethod = self.object
-+                for subclass in cls.__mro__:
-+                    visitmethod = getattr(self, subclass.__name__, None)
-+                    if visitmethod is not None:
-+                        break
-+                else:
-+                    visitmethod = self.object
++                visitmethod = self.__object
              self.cache[cls] = visitmethod
          visitmethod(node)
  
+-    def object(self, obj):
++    # the default fallback handler is marked private
++    # to avoid clashes with the tag name object
++    def __object(self, obj):
+         #self.write(obj)
+         self.write(escape(unicode(obj)))
+ 
 diff --git a/testing/root/test_xmlgen.py b/testing/root/test_xmlgen.py
 --- a/testing/root/test_xmlgen.py
 +++ b/testing/root/test_xmlgen.py