1
+ from __future__ import absolute_import
1
2
from gettext import gettext
2
3
_ = gettext
3
4
4
- import _base
5
+ from . import _base
5
6
from html5lib .constants import cdataElements , rcdataElements , voidElements
6
7
7
8
from html5lib .constants import spaceCharacters
@@ -12,39 +13,39 @@ class LintError(Exception): pass
12
13
class Filter (_base .Filter ):
13
14
def __iter__ (self ):
14
15
open_elements = []
15
- contentModelFlag = "PCDATA"
16
+ contentModelFlag = u "PCDATA"
16
17
for token in _base .Filter .__iter__ (self ):
17
- type = token ["type" ]
18
- if type in ("StartTag" , "EmptyTag" ):
19
- name = token ["name" ]
20
- if contentModelFlag != "PCDATA" :
21
- raise LintError (_ ("StartTag not in PCDATA content model flag: %s" ) % name )
18
+ type = token [u "type" ]
19
+ if type in (u "StartTag" , u "EmptyTag" ):
20
+ name = token [u "name" ]
21
+ if contentModelFlag != u "PCDATA" :
22
+ raise LintError (_ (u "StartTag not in PCDATA content model flag: %s" ) % name )
22
23
if not isinstance (name , unicode ):
23
24
raise LintError (_ (u"Tag name is not a string: %r" ) % name )
24
25
if not name :
25
26
raise LintError (_ (u"Empty tag name" ))
26
- if type == "StartTag" and name in voidElements :
27
+ if type == u "StartTag" and name in voidElements :
27
28
raise LintError (_ (u"Void element reported as StartTag token: %s" ) % name )
28
- elif type == "EmptyTag" and name not in voidElements :
29
- raise LintError (_ (u"Non-void element reported as EmptyTag token: %s" ) % token ["name" ])
30
- if type == "StartTag" :
29
+ elif type == u "EmptyTag" and name not in voidElements :
30
+ raise LintError (_ (u"Non-void element reported as EmptyTag token: %s" ) % token [u "name" ])
31
+ if type == u "StartTag" :
31
32
open_elements .append (name )
32
- for name , value in token ["data" ]:
33
+ for name , value in token [u "data" ]:
33
34
if not isinstance (name , unicode ):
34
- raise LintError (_ ("Attribute name is not a string: %r" ) % name )
35
+ raise LintError (_ (u "Attribute name is not a string: %r" ) % name )
35
36
if not name :
36
37
raise LintError (_ (u"Empty attribute name" ))
37
38
if not isinstance (value , unicode ):
38
- raise LintError (_ ("Attribute value is not a string: %r" ) % value )
39
+ raise LintError (_ (u "Attribute value is not a string: %r" ) % value )
39
40
if name in cdataElements :
40
- contentModelFlag = "CDATA"
41
+ contentModelFlag = u "CDATA"
41
42
elif name in rcdataElements :
42
- contentModelFlag = "RCDATA"
43
- elif name == "plaintext" :
44
- contentModelFlag = "PLAINTEXT"
43
+ contentModelFlag = u "RCDATA"
44
+ elif name == u "plaintext" :
45
+ contentModelFlag = u "PLAINTEXT"
45
46
46
- elif type == "EndTag" :
47
- name = token ["name" ]
47
+ elif type == u "EndTag" :
48
+ name = token [u "name" ]
48
49
if not isinstance (name , unicode ):
49
50
raise LintError (_ (u"Tag name is not a string: %r" ) % name )
50
51
if not name :
@@ -54,35 +55,36 @@ def __iter__(self):
54
55
start_name = open_elements .pop ()
55
56
if start_name != name :
56
57
raise LintError (_ (u"EndTag (%s) does not match StartTag (%s)" ) % (name , start_name ))
57
- contentModelFlag = "PCDATA"
58
+ contentModelFlag = u "PCDATA"
58
59
59
- elif type == "Comment" :
60
- if contentModelFlag != "PCDATA" :
61
- raise LintError (_ ("Comment not in PCDATA content model flag" ))
60
+ elif type == u "Comment" :
61
+ if contentModelFlag != u "PCDATA" :
62
+ raise LintError (_ (u "Comment not in PCDATA content model flag" ))
62
63
63
- elif type in ("Characters" , "SpaceCharacters" ):
64
- data = token ["data" ]
64
+ elif type in (u "Characters" , u "SpaceCharacters" ):
65
+ data = token [u "data" ]
65
66
if not isinstance (data , unicode ):
66
- raise LintError (_ ("Attribute name is not a string: %r" ) % data )
67
+ raise LintError (_ (u "Attribute name is not a string: %r" ) % data )
67
68
if not data :
68
69
raise LintError (_ (u"%s token with empty data" ) % type )
69
- if type == "SpaceCharacters" :
70
+ if type == u "SpaceCharacters" :
70
71
data = data .strip (spaceCharacters )
71
72
if data :
72
73
raise LintError (_ (u"Non-space character(s) found in SpaceCharacters token: " ) % data )
73
74
74
- elif type == "Doctype" :
75
- name = token ["name" ]
76
- if contentModelFlag != "PCDATA" :
77
- raise LintError (_ ("Doctype not in PCDATA content model flag: %s" ) % name )
75
+ elif type == u "Doctype" :
76
+ name = token [u "name" ]
77
+ if contentModelFlag != u "PCDATA" :
78
+ raise LintError (_ (u "Doctype not in PCDATA content model flag: %s" ) % name )
78
79
if not isinstance (name , unicode ):
79
80
raise LintError (_ (u"Tag name is not a string: %r" ) % name )
80
81
# XXX: what to do with token["data"] ?
81
82
82
- elif type in ("ParseError" , "SerializeError" ):
83
+ elif type in (u "ParseError" , u "SerializeError" ):
83
84
pass
84
85
85
86
else :
86
87
raise LintError (_ (u"Unknown token type: %s" ) % type )
87
88
88
89
yield token
90
+ __iter__ .func_annotations = {}
0 commit comments