[test, html validation] make validator selection somewhat smarter (at least it works properly when content is demoted from xhtml to html, making the XMLDemotingValidator class useless stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 04 Jan 2011 16:34:22 +0100
branchstable
changeset 6772 68bb0943d192
parent 6771 da71f1ad1721
child 6773 bba36f168919
[test, html validation] make validator selection somewhat smarter (at least it works properly when content is demoted from xhtml to html, making the XMLDemotingValidator class useless
devtools/htmlparser.py
devtools/testlib.py
--- a/devtools/htmlparser.py	Tue Jan 04 16:33:01 2011 +0100
+++ b/devtools/htmlparser.py	Tue Jan 04 16:34:22 2011 +0100
@@ -22,6 +22,8 @@
 
 from lxml import etree
 
+from logilab.common.deprecation import class_deprecated
+
 from cubicweb.view import STRICT_DOCTYPE, TRANSITIONAL_DOCTYPE
 
 STRICT_DOCTYPE = str(STRICT_DOCTYPE)
@@ -90,6 +92,7 @@
     this is typically related to the use of external dependencies
     which do not produce valid xhtml (google maps, ...)
     """
+    __metaclass__ = class_deprecated
 
     def preprocess_data(self, data):
         if data.startswith('<?xml'):
--- a/devtools/testlib.py	Tue Jan 04 16:33:01 2011 +0100
+++ b/devtools/testlib.py	Tue Jan 04 16:34:22 2011 +0100
@@ -775,20 +775,21 @@
     @nocoverage
     def _check_html(self, output, view, template='main-template'):
         """raises an exception if the HTML is invalid"""
+        output = output.strip()
         try:
             validatorclass = self.vid_validators[view.__regid__]
         except KeyError:
             if view.content_type in ('text/html', 'application/xhtml+xml'):
-                if template is None:
+                if output.startswith('<?xml'):
+                    default_validator = htmlparser.DTDValidator
+                else:
                     default_validator = htmlparser.HTMLValidator
-                else:
-                    default_validator = htmlparser.DTDValidator
             else:
                 default_validator = None
             validatorclass = self.content_type_validators.get(view.content_type,
                                                               default_validator)
         if validatorclass is None:
-            return output.strip()
+            return 
         validator = validatorclass()
         if isinstance(validator, htmlparser.DTDValidator):
             # XXX remove <canvas> used in progress widget, unknown in html dtd