Source

py-patches / xmlgen-object

# HG changeset patch
# Parent 0bc29913774dede5c4242e7c419433e02b4b8f03
special case for tags in xmlgen to work for the object tag, fixes #13

diff --git a/CHANGELOG b/CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,8 @@
+Changes between 1.4.7 and 1.4.8
+==================================================
+
+- fix issue 13 - correct handling of the tag name object in xmlgen
+
 Changes between 1.4.6 and 1.4.7
 ==================================================
 
diff --git a/py/_xmlgen.py b/py/_xmlgen.py
--- a/py/_xmlgen.py
+++ b/py/_xmlgen.py
@@ -122,11 +122,13 @@ class SimpleUnicodeVisitor(object):
                 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
@@ -134,3 +134,6 @@ def test_inline():
     assert (h.unicode(indent=2) ==
             '<div><span>foo</span><span>bar</span></div>')
 
+def test_object_tags():
+    o = html.object(html.object())
+    assert o.unicode(indent=0) == '<object><object></object></object>'