extract function: sgml_attributes
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 27 Jul 2009 18:36:51 +0200
changeset 2516 b58826130680
parent 2515 5d3cd163e2db
child 2517 d664652b7f9c
extract function: sgml_attributes
common/uilib.py
--- a/common/uilib.py	Mon Jul 27 18:36:30 2009 +0200
+++ b/common/uilib.py	Mon Jul 27 18:36:51 2009 +0200
@@ -212,6 +212,11 @@
 HTML4_EMPTY_TAGS = frozenset(('base', 'meta', 'link', 'hr', 'br', 'param',
                               'img', 'area', 'input', 'col'))
 
+def sgml_attributes(attrs):
+    return u' '.join(u'%s="%s"' % (attr, xml_escape(unicode(value)))
+                     for attr, value in sorted(attrs.items())
+                     if value is not None)
+
 def simple_sgml_tag(tag, content=None, escapecontent=True, **attrs):
     """generation of a simple sgml tag (eg without children tags) easier
 
@@ -223,9 +228,7 @@
             attrs['class'] = attrs.pop('klass')
         except KeyError:
             pass
-        value += u' ' + u' '.join(u'%s="%s"' % (attr, xml_escape(unicode(value)))
-                                  for attr, value in sorted(attrs.items())
-                                  if value is not None)
+        value += u' ' + sgml_attributes(attrs)
     if content:
         if escapecontent:
             content = xml_escape(unicode(content))