1
1
from __future__ import absolute_import , division , unicode_literals
2
2
3
+ from gettext import gettext
4
+ _ = gettext
5
+
6
+ from six import text_type
7
+
3
8
from . import _base
4
9
from ..constants import cdataElements , rcdataElements , voidElements
5
10
@@ -21,7 +26,7 @@ def __iter__(self):
21
26
name = token ["name" ]
22
27
if contentModelFlag != "PCDATA" :
23
28
raise LintError ("StartTag not in PCDATA content model flag: %(tag)s" % {"tag" : name })
24
- if not isinstance (name , str ):
29
+ if not isinstance (name , text_type ):
25
30
raise LintError ("Tag name is not a string: %(tag)r" % {"tag" : name })
26
31
if not name :
27
32
raise LintError ("Empty tag name" )
@@ -31,12 +36,14 @@ def __iter__(self):
31
36
raise LintError ("Non-void element reported as EmptyTag token: %(tag)s" % {"tag" : token ["name" ]})
32
37
if type == "StartTag" :
33
38
open_elements .append (name )
34
- for name , value in token ["data" ]:
35
- if not isinstance (name , str ):
39
+ for (ns , name ), value in token ["data" ].items ():
40
+ if ns is not None and not isinstance (ns , text_type ):
41
+ raise LintError ("Attribute namespace is not None or a string: %(name)r" % {"name" : name })
42
+ if not isinstance (name , text_type ):
36
43
raise LintError ("Attribute name is not a string: %(name)r" % {"name" : name })
37
44
if not name :
38
45
raise LintError ("Empty attribute name" )
39
- if not isinstance (value , str ):
46
+ if not isinstance (value , text_type ):
40
47
raise LintError ("Attribute value is not a string: %(value)r" % {"value" : value })
41
48
if name in cdataElements :
42
49
contentModelFlag = "CDATA"
@@ -47,7 +54,7 @@ def __iter__(self):
47
54
48
55
elif type == "EndTag" :
49
56
name = token ["name" ]
50
- if not isinstance (name , str ):
57
+ if not isinstance (name , text_type ):
51
58
raise LintError ("Tag name is not a string: %(tag)r" % {"tag" : name })
52
59
if not name :
53
60
raise LintError ("Empty tag name" )
@@ -64,7 +71,7 @@ def __iter__(self):
64
71
65
72
elif type in ("Characters" , "SpaceCharacters" ):
66
73
data = token ["data" ]
67
- if not isinstance (data , str ):
74
+ if not isinstance (data , text_type ):
68
75
raise LintError ("Attribute name is not a string: %(name)r" % {"name" : data })
69
76
if not data :
70
77
raise LintError ("%(type)s token with empty data" % {"type" : type })
0 commit comments