change test_parse encoding to UTF-8

This commit is contained in:
Petr Dlouhý 2019-07-22 19:59:37 +01:00 committed by Chris Mayo
parent 2c3c794e52
commit b5111453d8
2 changed files with 12 additions and 12 deletions

View file

@ -99,7 +99,7 @@ class HtmlPrettyPrinter (object):
@type attrs: dict
@return: None
"""
self._start_element(tag, attrs, ">")
self._start_element(tag, attrs, u">")
def start_end_element (self, tag, attrs, element_text=None):
"""
@ -111,7 +111,7 @@ class HtmlPrettyPrinter (object):
@type attrs: dict
@return: None
"""
self._start_element(tag, attrs, "/>")
self._start_element(tag, attrs, u"/>")
def _start_element (self, tag, attrs, end):
"""
@ -125,12 +125,12 @@ class HtmlPrettyPrinter (object):
@type end: string
@return: None
"""
self.fd.write("<%s" % tag.replace("/", ""))
self.fd.write(u"<%s" % tag.replace("/", ""))
for key, val in attrs.items():
if val is None:
self.fd.write(" %s" % key)
self.fd.write(u" %s" % key)
else:
self.fd.write(' %s="%s"' % (key, quote_attrval(val)))
self.fd.write(u' %s="%s"' % (key, quote_attrval(val)))
self.fd.write(end)
def end_element (self, tag):

View file

@ -1,4 +1,4 @@
# -*- coding: iso-8859-1 -*-
# -*- coding: utf8 -*-
# Copyright (C) 2004-2012 Bastian Kleineidam
#
# This program is free software; you can redistribute it and/or modify
@ -54,9 +54,9 @@ parsetests = [
("""< a >""", """< a >"""),
("""<>""", """<>"""),
("""< >""", """< >"""),
("""<aä>""", u"""<aä></aä>"""),
("""<a aä="b">""", u"""<a aä="b"></a>"""),
("""<a a="">""", u"""<a a="b&#228;"></a>"""),
("""<aä>""", u"""<aä></aä>"""),
("""<a aä="b">""", u"""<a aä="b"></a>"""),
("""<a a="">""", u"""<a a="b&#228;"></a>"""),
# multiple attribute names should be ignored...
("""<a b="c" b="c" >""", """<a b="c"></a>"""),
# ... but which one wins - in our implementation the last one
@ -97,7 +97,7 @@ parsetests = [
("""</a >""", """"""),
("""< / a>""", """< / a>"""),
("""< /a>""", """< /a>"""),
("""</aä>""", """"""),
("""</aä>""", """"""),
# start and end tag (HTML doctype assumed)
("""<a/>""", """<a></a>"""),
("""<meta/>""", """<meta/>"""),
@ -144,8 +144,8 @@ parsetests = [
# note that \u8156 is not valid encoding and therefore gets removed
("""<a href="&#8156;ailto:" >""", """<a href="&#8156;ailto:"></a>"""),
# non-ascii characters
("""<Üzgür> fahr </langsamer> ¿¿¿¿¿¿{""",
u"""<Üzgür> fahr ¿¿¿¿¿¿{"""),
("""<Üzgür> fahr </langsamer> żżżżżż{""",
u"""<Üzgür> fahr żżżżżż{"""),
# mailto link
("""<a href=mailto:calvin@LocalHost?subject=Hallo&to=michi>1</a>""",
"""<a href="mailto:calvin@LocalHost?subject=Hallo&amp;to=michi">1</a>"""),