# HG changeset patch # User Sylvain Thénault # Date 1248712611 -7200 # Node ID b58826130680d0bdef6292735889f00ecb9da5ac # Parent 5d3cd163e2db8bfa5129a20d31ac5a8572e88eec extract function: sgml_attributes diff -r 5d3cd163e2db -r b58826130680 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))