--- a/devtools/htmlparser.py Tue Jan 04 16:33:13 2011 +0100
+++ b/devtools/htmlparser.py Tue Jan 04 16:35:06 2011 +0100
@@ -15,16 +15,17 @@
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
-"""defines a validating HTML parser used in web application tests
-
-"""
+"""defines a validating HTML parser used in web application tests"""
import re
import sys
from lxml import etree
+from logilab.common.deprecation import class_deprecated
+
from cubicweb.view import STRICT_DOCTYPE, TRANSITIONAL_DOCTYPE
+
STRICT_DOCTYPE = str(STRICT_DOCTYPE)
TRANSITIONAL_DOCTYPE = str(TRANSITIONAL_DOCTYPE)
@@ -51,10 +52,7 @@
def __init__(self):
Validator.__init__(self)
# XXX understand what's happening under windows
- validate = True
- if sys.platform == 'win32':
- validate = False
- self.parser = etree.XMLParser(dtd_validation=validate)
+ self.parser = etree.XMLParser(dtd_validation=sys.platform != 'win32')
def preprocess_data(self, data):
"""used to fix potential blockquote mess generated by docutils"""
@@ -87,12 +85,14 @@
Validator.__init__(self)
self.parser = etree.XMLParser()
+
class XMLDemotingValidator(SaxOnlyValidator):
""" some views produce html instead of xhtml, using demote_to_html
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:13 2011 +0100
+++ b/devtools/testlib.py Tue Jan 04 16:35:06 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
--- a/view.py Tue Jan 04 16:33:13 2011 +0100
+++ b/view.py Tue Jan 04 16:35:06 2011 +0100
@@ -40,11 +40,6 @@
NOINDEX = u'<meta name="ROBOTS" content="NOINDEX" />'
NOFOLLOW = u'<meta name="ROBOTS" content="NOFOLLOW" />'
-
-CW_XMLNS = '''[
- <!ATTLIST html xmlns:cubicweb CDATA #FIXED \'http://www.logilab.org/2008/cubicweb\' >
- ]
-'''
CW_XHTML_EXTENSIONS = '''[
<!ATTLIST html xmlns:cubicweb CDATA #FIXED \'http://www.logilab.org/2008/cubicweb\' >
@@ -86,9 +81,9 @@
"> ] '''
TRANSITIONAL_DOCTYPE = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" %s>\n' % CW_XHTML_EXTENSIONS
-TRANSITIONAL_DOCTYPE_NOEXT = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" %s>\n' % CW_XMLNS
+TRANSITIONAL_DOCTYPE_NOEXT = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n'
STRICT_DOCTYPE = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" %s>\n' % CW_XHTML_EXTENSIONS
-STRICT_DOCTYPE_NOEXT = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" %s>\n' % CW_XMLNS
+STRICT_DOCTYPE_NOEXT = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'
# base view object ############################################################