Ronny Pfannschmidt avatar 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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.