devtools/testlib.py
changeset 10689 49a62b8f6d43
parent 10687 d394bfcd8c25
child 10700 a6d9d27f4253
equal deleted inserted replaced
10688:fa29f3628a1b 10689:49a62b8f6d43
   959                 if content_type is None:
   959                 if content_type is None:
   960                     content_type = view.content_type
   960                     content_type = view.content_type
   961         if content_type is None:
   961         if content_type is None:
   962             content_type = 'text/html'
   962             content_type = 'text/html'
   963         if content_type in ('text/html', 'application/xhtml+xml') and output:
   963         if content_type in ('text/html', 'application/xhtml+xml') and output:
   964             if output.startswith('<!DOCTYPE html>'):
   964             if output.startswith(b'<!DOCTYPE html>'):
   965                 # only check XML well-formness since HTMLValidator isn't html5
   965                 # only check XML well-formness since HTMLValidator isn't html5
   966                 # compatible and won't like various other extensions
   966                 # compatible and won't like various other extensions
   967                 default_validator = htmlparser.XMLSyntaxValidator
   967                 default_validator = htmlparser.XMLSyntaxValidator
   968             elif output.startswith('<?xml'):
   968             elif output.startswith(b'<?xml'):
   969                 default_validator = htmlparser.DTDValidator
   969                 default_validator = htmlparser.DTDValidator
   970             else:
   970             else:
   971                 default_validator = htmlparser.HTMLValidator
   971                 default_validator = htmlparser.HTMLValidator
   972         else:
   972         else:
   973             default_validator = None
   973             default_validator = None
  1004 
  1004 
  1005             try:
  1005             try:
  1006                 str_exc = str(exc)
  1006                 str_exc = str(exc)
  1007             except Exception:
  1007             except Exception:
  1008                 str_exc = 'undisplayable exception'
  1008                 str_exc = 'undisplayable exception'
  1009             msg += str_exc
  1009             msg += str_exc.encode(sys.getdefaultencoding(), 'replace')
  1010             if content is not None:
  1010             if content is not None:
  1011                 position = getattr(exc, "position", (0,))[0]
  1011                 position = getattr(exc, "position", (0,))[0]
  1012                 if position:
  1012                 if position:
  1013                     # define filter
  1013                     # define filter
  1014                     if isinstance(content, str):
  1014                     if isinstance(content, str):