@@ -443,11 +443,10 @@ def html4_cgi_escape_attrs(**attrs):
443443 <input required ..> not <input required="required" ...>
444444 The latter is xhtml. Recognize booleans by:
445445 value is None
446- value is the same as the attribute
447- Code can use either method to indicate a pure boolean.
446+ Code can use None to indicate a pure boolean.
448447 '''
449448 return ' ' .join (['%s="%s"' % (k ,html_escape (str (v ), True ))
450- if v != None and k != v else '%s' % (k )
449+ if v != None else '%s' % (k )
451450 for k ,v in sorted (attrs .items ())])
452451
453452def xhtml_cgi_escape_attrs (** attrs ):
@@ -457,8 +456,7 @@ def xhtml_cgi_escape_attrs(**attrs):
457456 <input required="required" ...> not <input required ..>
458457 The latter is html4 or 5. Recognize booleans by:
459458 value is None
460- value is the same as the atribute
461- Code can use either method to indicate a pure boolean.
459+ Code can use None to indicate a pure boolean.
462460 '''
463461 return ' ' .join (['%s="%s"' % (k ,html_escape (str (v ), True ))
464462 if v != None else '%s="%s"' % (k ,k )
@@ -480,11 +478,12 @@ def __init__(self):
480478 html_version = 'html4'
481479 if hasattr (self ._client .instance .config , 'HTML_VERSION' ):
482480 html_version = self ._client .instance .config .HTML_VERSION
483- # HTML-4 allows attributes like required=required, so for now
484- # revert the change that optimizes this and breaks rendering of
485- # non-boolean attributes (like name="name").
486- self .input = input_xhtml
487- self .cgi_escape_attrs = xhtml_cgi_escape_attrs
481+ if html_version == 'xhtml' :
482+ self .input = input_xhtml
483+ self .cgi_escape_attrs = xhtml_cgi_escape_attrs
484+ else :
485+ self .input = input_html4
486+ self .cgi_escape_attrs = html4_cgi_escape_attrs
488487 # self._context is used for translations.
489488 # will be initialized by the first call to .gettext()
490489 self ._context = None
0 commit comments