1+ from __future__import absolute_import
12from gettext import gettext
23_ = gettext
34
4- import _base
5+ from . import _base
56from html5lib .constants import cdataElements ,rcdataElements ,voidElements
67
78from html5lib .constants import spaceCharacters
@@ -12,39 +13,39 @@ class LintError(Exception): pass
1213class Filter (_base .Filter ):
1314def __iter__ (self ):
1415open_elements = []
15- contentModelFlag = "PCDATA"
16+ contentModelFlag = u "PCDATA"
1617for 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 )
2223if not isinstance (name ,unicode ):
2324raise LintError (_ (u"Tag name is not a string: %r" )% name )
2425if not name :
2526raise LintError (_ (u"Empty tag name" ))
26- if type == "StartTag" and name in voidElements :
27+ if type == u "StartTag"and name in voidElements :
2728raise 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" :
3132open_elements .append (name )
32- for name ,value in token ["data" ]:
33+ for name ,value in token [u "data" ]:
3334if 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 )
3536if not name :
3637raise LintError (_ (u"Empty attribute name" ))
3738if 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 )
3940if name in cdataElements :
40- contentModelFlag = "CDATA"
41+ contentModelFlag = u "CDATA"
4142elif 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"
4546
46- elif type == "EndTag" :
47- name = token ["name" ]
47+ elif type == u "EndTag" :
48+ name = token [u "name" ]
4849if not isinstance (name ,unicode ):
4950raise LintError (_ (u"Tag name is not a string: %r" )% name )
5051if not name :
@@ -54,35 +55,36 @@ def __iter__(self):
5455start_name = open_elements .pop ()
5556if start_name != name :
5657raise LintError (_ (u"EndTag (%s) does not match StartTag (%s)" )% (name ,start_name ))
57- contentModelFlag = "PCDATA"
58+ contentModelFlag = u "PCDATA"
5859
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" ))
6263
63- elif type in ("Characters" ,"SpaceCharacters" ):
64- data = token ["data" ]
64+ elif type in (u "Characters" ,u "SpaceCharacters" ):
65+ data = token [u "data" ]
6566if 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 )
6768if not data :
6869raise LintError (_ (u"%s token with empty data" )% type )
69- if type == "SpaceCharacters" :
70+ if type == u "SpaceCharacters" :
7071data = data .strip (spaceCharacters )
7172if data :
7273raise LintError (_ (u"Non-space character(s) found in SpaceCharacters token: " )% data )
7374
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 )
7879if not isinstance (name ,unicode ):
7980raise LintError (_ (u"Tag name is not a string: %r" )% name )
8081# XXX: what to do with token["data"] ?
8182
82- elif type in ("ParseError" ,"SerializeError" ):
83+ elif type in (u "ParseError" ,u "SerializeError" ):
8384pass
8485
8586else :
8687raise LintError (_ (u"Unknown token type: %s" )% type )
8788
8889yield token
90+ __iter__ .func_annotations = {}