1
1
from __future__ import absolute_import , division , unicode_literals
2
- from six import text_type
2
+ from six import text_type , string_types
3
3
4
4
import gettext
5
5
_ = gettext .gettext
@@ -19,43 +19,43 @@ def error(self, msg):
19
19
return {"type" : "SerializeError" , "data" : msg }
20
20
21
21
def emptyTag (self , namespace , name , attrs , hasChildren = False ):
22
- assert namespace is None or isinstance (namespace , text_type ), type (namespace )
23
- assert isinstance (name , text_type ), type (name )
24
- assert all ((namespace is None or isinstance (namespace , text_type )) and
25
- isinstance (name , text_type ) and
26
- isinstance (value , text_type )
22
+ assert namespace is None or isinstance (namespace , string_types ), type (namespace )
23
+ assert isinstance (name , string_types ), type (name )
24
+ assert all ((namespace is None or isinstance (namespace , string_types )) and
25
+ isinstance (name , string_types ) and
26
+ isinstance (value , string_types )
27
27
for (namespace , name ), value in attrs .items ())
28
28
29
- yield {"type" : "EmptyTag" , "name" : name ,
30
- "namespace" : namespace ,
29
+ yield {"type" : "EmptyTag" , "name" : text_type ( name ) ,
30
+ "namespace" : text_type ( namespace ) ,
31
31
"data" : attrs }
32
32
if hasChildren :
33
33
yield self .error (_ ("Void element has children" ))
34
34
35
35
def startTag (self , namespace , name , attrs ):
36
- assert namespace is None or isinstance (namespace , text_type ), type (namespace )
37
- assert isinstance (name , text_type ), type (name )
38
- assert all ((namespace is None or isinstance (namespace , text_type )) and
39
- isinstance (name , text_type ) and
40
- isinstance (value , text_type )
36
+ assert namespace is None or isinstance (namespace , string_types ), type (namespace )
37
+ assert isinstance (name , string_types ), type (name )
38
+ assert all ((namespace is None or isinstance (namespace , string_types )) and
39
+ isinstance (name , string_types ) and
40
+ isinstance (value , string_types )
41
41
for (namespace , name ), value in attrs .items ())
42
42
43
43
return {"type" : "StartTag" ,
44
- "name" : name ,
45
- "namespace" : namespace ,
44
+ "name" : text_type ( name ) ,
45
+ "namespace" : text_type ( namespace ) ,
46
46
"data" : attrs }
47
47
48
48
def endTag (self , namespace , name ):
49
- assert namespace is None or isinstance (namespace , text_type ), type (namespace )
50
- assert isinstance (name , text_type ), type (namespace )
49
+ assert namespace is None or isinstance (namespace , string_types ), type (namespace )
50
+ assert isinstance (name , string_types ), type (namespace )
51
51
52
52
return {"type" : "EndTag" ,
53
- "name" : name ,
54
- "namespace" : namespace ,
53
+ "name" : text_type ( name ) ,
54
+ "namespace" : text_type ( namespace ) ,
55
55
"data" : {}}
56
56
57
57
def text (self , data ):
58
- assert isinstance (data , text_type ), type (data )
58
+ assert isinstance (data , string_types ), type (data )
59
59
60
60
data = data
61
61
middle = data .lstrip (spaceCharacters )
@@ -71,14 +71,14 @@ def text(self, data):
71
71
yield {"type" : "SpaceCharacters" , "data" : right }
72
72
73
73
def comment (self , data ):
74
- assert isinstance (data , text_type ), type (data )
74
+ assert isinstance (data , string_types ), type (data )
75
75
76
76
return {"type" : "Comment" , "data" : data }
77
77
78
78
def doctype (self , name , publicId = None , systemId = None , correct = True ):
79
- assert name is None or isinstance (name , text_type ), type (name )
80
- assert publicId is None or isinstance (publicId , text_type ), type (publicId )
81
- assert systemId is None or isinstance (systemId , text_type ), type (systemId )
79
+ assert name is None or isinstance (name , string_types ), type (name )
80
+ assert publicId is None or isinstance (publicId , string_types ), type (publicId )
81
+ assert systemId is None or isinstance (systemId , string_types ), type (systemId )
82
82
83
83
return {"type" : "Doctype" ,
84
84
"name" : name if name is not None else "" ,
@@ -87,7 +87,7 @@ def doctype(self, name, publicId=None, systemId=None, correct=True):
87
87
"correct" : correct }
88
88
89
89
def entity (self , name ):
90
- assert isinstance (name , text_type ), type (name )
90
+ assert isinstance (name , string_types ), type (name )
91
91
92
92
return {"type" : "Entity" , "name" : name }
93
93
0 commit comments