@@ -17,37 +17,45 @@ def __iter__(self):
17
17
def error (self , msg ):
18
18
return {"type" : "SerializeError" , "data" : msg }
19
19
20
- def normalizeAttrs (self , attrs ):
21
- newattrs = {}
22
- if attrs :
23
- #TODO: treewalkers should always have attrs
24
- for (namespace ,name ),value in attrs .items ():
25
- assert namespace is None or isinstance (namespace , text_type ), type (namespace )
26
- assert isinstance (name , text_type )
27
- assert isinstance (value , text_type )
28
- newattrs [(namespace ,name )] = value
29
- return newattrs
30
-
31
20
def emptyTag (self , namespace , name , attrs , hasChildren = False ):
21
+ assert namespace is None or isinstance (namespace , text_type ), type (namespace )
22
+ assert isinstance (name , text_type ), type (name )
23
+ assert all ((namespace is None or isinstance (namespace , text_type )) and
24
+ isinstance (name , text_type ) and
25
+ isinstance (value , text_type )
26
+ for (namespace , name ), value in attrs .items ())
27
+
32
28
yield {"type" : "EmptyTag" , "name" : name ,
33
29
"namespace" :namespace ,
34
- "data" : self . normalizeAttrs ( attrs ) }
30
+ "data" : attrs }
35
31
if hasChildren :
36
32
yield self .error (_ ("Void element has children" ))
37
33
38
34
def startTag (self , namespace , name , attrs ):
35
+ assert namespace is None or isinstance (namespace , text_type ), type (namespace )
36
+ assert isinstance (name , text_type ), type (name )
37
+ assert all ((namespace is None or isinstance (namespace , text_type )) and
38
+ isinstance (name , text_type ) and
39
+ isinstance (value , text_type )
40
+ for (namespace , name ), value in attrs .items ())
41
+
39
42
return {"type" : "StartTag" ,
40
43
"name" : name ,
41
44
"namespace" :namespace ,
42
- "data" : self . normalizeAttrs ( attrs ) }
45
+ "data" : attrs }
43
46
44
47
def endTag (self , namespace , name ):
48
+ assert namespace is None or isinstance (namespace , text_type ), type (namespace )
49
+ assert isinstance (name , text_type ), type (namespace )
50
+
45
51
return {"type" : "EndTag" ,
46
52
"name" : name ,
47
53
"namespace" :namespace ,
48
54
"data" : {}}
49
55
50
56
def text (self , data ):
57
+ assert isinstance (data , text_type ), type (data )
58
+
51
59
data = data
52
60
middle = data .lstrip (spaceCharacters )
53
61
left = data [:len (data )- len (middle )]
@@ -62,16 +70,24 @@ def text(self, data):
62
70
yield {"type" : "SpaceCharacters" , "data" : right }
63
71
64
72
def comment (self , data ):
73
+ assert isinstance (data , text_type ), type (data )
74
+
65
75
return {"type" : "Comment" , "data" : data }
66
76
67
77
def doctype (self , name , publicId = None , systemId = None , correct = True ):
78
+ assert name is None or isinstance (name , text_type ), type (name )
79
+ assert publicId is None or isinstance (publicId , text_type ), type (publicId )
80
+ assert systemId is None or isinstance (systemId , text_type ), type (systemId )
81
+
68
82
return {"type" : "Doctype" ,
69
- "name" : name is not None and name or "" ,
83
+ "name" : name if name is not None else "" ,
70
84
"publicId" : publicId ,
71
85
"systemId" : systemId ,
72
86
"correct" : correct }
73
87
74
88
def entity (self , name ):
89
+ assert isinstance (name , text_type ), type (name )
90
+
75
91
return {"type" : "Entity" , "name" : name }
76
92
77
93
def unknown (self , nodeType ):
0 commit comments