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

Commit22c2b1a

Browse files
committed
Get rid of LintError and just use asserts
All of these properties should always hold per the API, so assertsseem like a good match here.
1 parente0ea899 commit22c2b1a

File tree

1 file changed

+28
-49
lines changed

1 file changed

+28
-49
lines changed

‎html5lib/filters/lint.py

Lines changed: 28 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
spaceCharacters="".join(spaceCharacters)
1010

1111

12-
classLintError(Exception):
13-
pass
14-
15-
1612
classFilter(_base.Filter):
1713
def__iter__(self):
1814
open_elements= []
@@ -21,73 +17,56 @@ def __iter__(self):
2117
iftypein ("StartTag","EmptyTag"):
2218
namespace=token["namespace"]
2319
name=token["name"]
24-
ifnamespaceisnotNoneandnotisinstance(namespace,text_type):
25-
raiseLintError("Tag namespace is not a string or None: %(name)r"% {"name":namespace})
26-
ifnamespace=="":
27-
raiseLintError("Empty tag namespace")
28-
ifnotisinstance(name,text_type):
29-
raiseLintError("Tag name is not a string: %(tag)r"% {"tag":name})
30-
ifnotname:
31-
raiseLintError("Empty tag name")
32-
iftype=="StartTag"and (notnamespaceornamespace==namespaces["html"])andnameinvoidElements:
33-
raiseLintError("Void element reported as StartTag token: %(tag)s"% {"tag":name})
34-
eliftype=="EmptyTag"and (notnamespaceornamespace==namespaces["html"])andnamenotinvoidElements:
35-
raiseLintError("Non-void element reported as EmptyTag token: %(tag)s"% {"tag":token["name"]})
20+
assertnamespaceisNoneorisinstance(namespace,text_type)
21+
assertnamespace!=""
22+
assertisinstance(name,text_type)
23+
assertname!=""
24+
assertisinstance(token["data"],dict)
25+
if (notnamespaceornamespace==namespaces["html"])andnameinvoidElements:
26+
asserttype=="EmptyTag"
27+
else:
28+
asserttype=="StartTag"
3629
iftype=="StartTag":
3730
open_elements.append((namespace,name))
38-
for (namespace,localname),valueintoken["data"].items():
39-
ifnamespaceisnotNoneandnotisinstance(namespace,text_type):
40-
raiseLintError("Attribute namespace is not a string or None: %(name)r"% {"name":namespace})
41-
ifnamespace=="":
42-
raiseLintError("Empty attribute namespace")
43-
ifnotisinstance(localname,text_type):
44-
raiseLintError("Attribute localname is not a string: %(name)r"% {"name":localname})
45-
ifnotlocalname:
46-
raiseLintError("Empty attribute localname")
47-
ifnotisinstance(value,text_type):
48-
raiseLintError("Attribute value is not a string: %(value)r"% {"value":value})
31+
for (namespace,name),valueintoken["data"].items():
32+
assertnamespaceisNoneorisinstance(namespace,text_type)
33+
assertnamespace!=""
34+
assertisinstance(name,text_type)
35+
assertname!=""
36+
assertisinstance(value,text_type)
4937

5038
eliftype=="EndTag":
5139
namespace=token["namespace"]
5240
name=token["name"]
53-
ifnamespaceisnotNoneandnotisinstance(namespace,text_type):
54-
raiseLintError("Tag namespace is not a string or None: %(name)r"% {"name":namespace})
55-
ifnamespace=="":
56-
raiseLintError("Empty tag namespace")
57-
ifnotisinstance(name,text_type):
58-
raiseLintError("Tag name is not a string: %(tag)r"% {"tag":name})
59-
ifnotname:
60-
raiseLintError("Empty tag name")
41+
assertnamespaceisNoneorisinstance(namespace,text_type)
42+
assertnamespace!=""
43+
assertisinstance(name,text_type)
44+
assertname!=""
6145
if (notnamespaceornamespace==namespaces["html"])andnameinvoidElements:
62-
raiseLintError("Void element reported as EndTag token: %(tag)s"% {"tag":name})
63-
start_name=open_elements.pop()
64-
ifstart_name!= (namespace,name):
65-
raiseLintError("EndTag (%(end)s) does not match StartTag (%(start)s)"% {"end":name,"start":start_name})
46+
assertFalse,"Void element reported as EndTag token: %(tag)s"% {"tag":name}
47+
else:
48+
start=open_elements.pop()
49+
assertstart== (namespace,name)
6650

6751
eliftype=="Comment":
6852
pass
6953

7054
eliftypein ("Characters","SpaceCharacters"):
7155
data=token["data"]
72-
ifnotisinstance(data,text_type):
73-
raiseLintError("Attribute name is not a string: %(name)r"% {"name":data})
74-
ifnotdata:
75-
raiseLintError("%(type)s token with empty data"% {"type":type})
56+
assertisinstance(data,text_type)
57+
assertdata!=""
7658
iftype=="SpaceCharacters":
77-
data=data.strip(spaceCharacters)
78-
ifdata:
79-
raiseLintError("Non-space character(s) found in SpaceCharacters token: %(token)r"% {"token":data})
59+
assertdata.strip(spaceCharacters)==""
8060

8161
eliftype=="Doctype":
8262
name=token["name"]
83-
ifnameisnotNoneandnotisinstance(name,text_type):
84-
raiseLintError("Tag name is not a string or None: %(tag)r"% {"tag":name})
63+
assertnameisNoneorisinstance(name,text_type)
8564
# XXX: what to do with token["data"] ?
8665

8766
eliftypein ("ParseError","SerializeError"):
8867
pass
8968

9069
else:
91-
raiseLintError("Unknown token type: %(type)s"% {"type":type})
70+
assertFalse,"Unknown token type: %(type)s"% {"type":type}
9271

9372
yieldtoken

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp