Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6d29b33

Browse files
author
James Graham
committed
Handle utf8 better
1 parent0437f25 commit6d29b33

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

‎html5lib/tests/support.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
importos
22
importsys
3+
importcodecs
34
importglob
45

56
base_path=os.path.split(__file__)[0]
@@ -74,7 +75,7 @@ def __getitem__(self, key):
7475

7576
classTestData(object):
7677
def__init__(self,filename,newTestHeading="data"):
77-
self.f=open(filename)
78+
self.f=codecs.open(filename,encoding="utf8")
7879
self.newTestHeading=newTestHeading
7980

8081
def__iter__(self):

‎html5lib/tests/test_parser.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,20 @@ def runParserTest(self, innerHTML, input, expected, errors, treeClass,
8484
p=html5parser.HTMLParser(tree=treeClass,
8585
namespaceHTMLElements=namespaceHTMLElements)
8686
exceptconstants.DataLossWarning:
87-
return
87+
return
8888

89-
errors= [item.decode("utf-8")foriteminerrors]
90-
9189
try:
9290
ifinnerHTML:
93-
document=p.parseFragment(StringIO.StringIO(input),innerHTML)
91+
document=p.parseFragment(input,innerHTML)
9492
else:
9593
try:
96-
document=p.parse(StringIO.StringIO(input))
94+
document=p.parse(input)
9795
exceptconstants.DataLossWarning:
9896
return
9997
except:
100-
errorMsg="\n".join(["\n\nInput:",input,"\nExpected:",expected,
101-
"\nTraceback:",traceback.format_exc()])
102-
self.assertTrue(False,errorMsg)
98+
errorMsg=u"\n".join([u"\n\nInput:",input,u"\nExpected:",expected,
99+
u"\nTraceback:",traceback.format_exc()])
100+
self.assertTrue(False,errorMsg.encode("utf8"))
103101

104102
output=convertTreeDump(p.tree.testSerializer(document))
105103
output=attrlist.sub(sortattrs,output)
@@ -109,9 +107,9 @@ def runParserTest(self, innerHTML, input, expected, errors, treeClass,
109107
ifnamespaceHTMLElements:
110108
expected=namespaceExpected(r"\1<html \2>",expected)
111109

112-
errorMsg="\n".join(["\n\nInput:",input,"\nExpected:",expected,
113-
"\nReceived:",output])
114-
self.assertEquals(expected,output,errorMsg.encode("utf-8"))
110+
errorMsg=u"\n".join([u"\n\nInput:",input,u"\nExpected:",expected,
111+
u"\nReceived:",output])
112+
self.assertEquals(expected,output,errorMsg.encode("utf8"))
115113
errStr= [u"Line: %i Col: %i %s"%(line,col,
116114
constants.E[errorcode]%datavarsifisinstance(datavars,dict)else (datavars,))for
117115
((line,col),errorcode,datavars)inp.errors]
@@ -152,6 +150,8 @@ def testFunc(self, innerHTML=innerHTML, input=input,
152150
testFunc.__name__="test_%s_%d_%s_%s"% (testName,index+1,treeName,namespaceHTMLElementsand"namespaced"or"no_html_namespace")
153151
setattr(TestCase,testFunc.__name__,
154152
testFunc)
153+
break
154+
break
155155

156156
returnunittest.TestLoader().loadTestsFromTestCase(TestCase)
157157

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp