[py-svn] r31236 - in py/dist/py/xmlobj: . testing
guido at codespeak.net
guido at codespeak.net
Thu Aug 10 17:59:13 CEST 2006
Author: guido
Date: Thu Aug 10 17:59:12 2006
New Revision: 31236
Modified:
py/dist/py/xmlobj/html.py
py/dist/py/xmlobj/testing/test_html.py
py/dist/py/xmlobj/visit.py
Log:
(jan, guido) Fixed problem in HTML generation, where certain tags must be
closed using an explicit closing tag, and others must be a singleton.
Modified: py/dist/py/xmlobj/html.py
==============================================================================
--- py/dist/py/xmlobj/html.py (original)
+++ py/dist/py/xmlobj/html.py Thu Aug 10 17:59:12 2006
@@ -6,6 +6,9 @@
from py.__.xmlobj.visit import SimpleUnicodeVisitor
class HtmlVisitor(SimpleUnicodeVisitor):
+
+ singletons = ['area', 'link']
+
def repr_attribute(self, attrs, name):
if name == 'class_':
value = getattr(attrs, name)
@@ -13,6 +16,9 @@
return
return super(HtmlVisitor, self).repr_attribute(attrs, name)
+ def _issingleton(self, tagname):
+ return tagname in self.singletons
+
class HtmlTag(Tag):
def unicode(self, indent=2):
l = []
Modified: py/dist/py/xmlobj/testing/test_html.py
==============================================================================
--- py/dist/py/xmlobj/testing/test_html.py (original)
+++ py/dist/py/xmlobj/testing/test_html.py Thu Aug 10 17:59:12 2006
@@ -39,3 +39,10 @@
'<li style="background: grey">world</li>'
'<li style="background: white">42</li>'
'</ul>')
+
+def test_singleton():
+ h = html.head(html.link(href="foo"))
+ assert unicode(h) == '<head><link href="foo"/></head>'
+
+ h = html.head(html.script(src="foo"))
+ assert unicode(h) == '<head><script src="foo"></script></head>'
Modified: py/dist/py/xmlobj/visit.py
==============================================================================
--- py/dist/py/xmlobj/visit.py (original)
+++ py/dist/py/xmlobj/visit.py Thu Aug 10 17:59:12 2006
@@ -59,7 +59,7 @@
self.curindent -= self.indent
else:
nameattr = tagname+self.attributes(tag)
- if self.shortempty:
+ if self._issingleton(tagname):
self.write(u'<%s/>' % (nameattr,))
else:
self.write(u'<%s></%s>' % (nameattr, tagname))
@@ -93,4 +93,7 @@
stylelist = [x+': ' + y for x,y in styledict.items()]
return [u' style="%s"' % u'; '.join(stylelist)]
+ def _issingleton(self, tagname):
+ """can (and will) be overridden in subclasses"""
+ return self.shortempty
More information about the pytest-commit
mailing list