[py-svn] r37608 - in py/trunk/py/xmlobj: . testing

guido at codespeak.net guido at codespeak.net
Tue Jan 30 16:42:22 CET 2007


Author: guido
Date: Tue Jan 30 16:42:19 2007
New Revision: 37608

Modified:
   py/trunk/py/xmlobj/html.py
   py/trunk/py/xmlobj/testing/test_html.py
   py/trunk/py/xmlobj/testing/test_xml.py
   py/trunk/py/xmlobj/visit.py
Log:
Added some code to make sure 'inline' elements aren't indented (gotta love
'ignorable' whitespace).


Modified: py/trunk/py/xmlobj/html.py
==============================================================================
--- py/trunk/py/xmlobj/html.py	(original)
+++ py/trunk/py/xmlobj/html.py	Tue Jan 30 16:42:19 2007
@@ -10,6 +10,10 @@
     single = dict([(x, 1) for x in 
                 ('br,img,area,param,col,hr,meta,link,base,'
                     'input,frame').split(',')])
+    inline = dict([(x, 1) for x in
+                ('a abbr acronym b basefont bdo big br cite code dfn em font '
+                 'i img input kbd label q s samp select small span strike '
+                 'strong sub sup textarea tt u var'.split(' '))])
 
     def repr_attribute(self, attrs, name): 
         if name == 'class_':
@@ -21,6 +25,9 @@
     def _issingleton(self, tagname):
         return tagname in self.single
 
+    def _isinline(self, tagname):
+        return tagname in self.inline
+
 class HtmlTag(Tag): 
     def unicode(self, indent=2):
         l = []

Modified: py/trunk/py/xmlobj/testing/test_html.py
==============================================================================
--- py/trunk/py/xmlobj/testing/test_html.py	(original)
+++ py/trunk/py/xmlobj/testing/test_html.py	Tue Jan 30 16:42:19 2007
@@ -46,3 +46,9 @@
     
     h = html.head(html.script(src="foo"))
     assert unicode(h) == '<head><script src="foo"></script></head>'
+
+def test_inline():
+    h = html.div(html.span('foo'), html.span('bar'))
+    assert (h.unicode(indent=2) ==
+            '<div><span>foo</span><span>bar</span></div>')
+

Modified: py/trunk/py/xmlobj/testing/test_xml.py
==============================================================================
--- py/trunk/py/xmlobj/testing/test_xml.py	(original)
+++ py/trunk/py/xmlobj/testing/test_xml.py	Tue Jan 30 16:42:19 2007
@@ -55,3 +55,4 @@
     x = ns.some(py.xml.raw("<p>literal</p>"))
     u = unicode(x)
     assert u == "<some><p>literal</p></some>"
+

Modified: py/trunk/py/xmlobj/visit.py
==============================================================================
--- py/trunk/py/xmlobj/visit.py	(original)
+++ py/trunk/py/xmlobj/visit.py	Tue Jan 30 16:42:19 2007
@@ -50,7 +50,7 @@
             tag.parent = None 
         self.visited[id(tag)] = 1
         tagname = getattr(tag, 'xmlname', tag.__class__.__name__)
-        if self.curindent:
+        if self.curindent and not self._isinline(tagname):
             self.write("\n" + u' ' * self.curindent) 
         if tag:
             self.curindent += self.indent 
@@ -100,3 +100,7 @@
         """can (and will) be overridden in subclasses"""
         return self.shortempty
 
+    def _isinline(self, tagname):
+        """can (and will) be overridden in subclasses"""
+        return False
+



More information about the pytest-commit mailing list