@@ -31,11 +31,6 @@ def to_text(s, blank_if_none=True):
31
31
return text_type (s )
32
32
33
33
34
- def is_text_or_none (string ):
35
- """Wrapper around isinstance(string_types) or is None"""
36
- return string is None or isinstance (string , string_types )
37
-
38
-
39
34
class TreeWalker (object ):
40
35
def __init__ (self , tree ):
41
36
self .tree = tree
@@ -47,27 +42,13 @@ def error(self, msg):
47
42
return {"type" : "SerializeError" , "data" : msg }
48
43
49
44
def emptyTag (self , namespace , name , attrs , hasChildren = False ):
50
- assert namespace is None or isinstance (namespace , string_types ), type (namespace )
51
- assert isinstance (name , string_types ), type (name )
52
- assert all ((namespace is None or isinstance (namespace , string_types )) and
53
- isinstance (name , string_types ) and
54
- isinstance (value , string_types )
55
- for (namespace , name ), value in attrs .items ())
56
-
57
45
yield {"type" : "EmptyTag" , "name" : to_text (name , False ),
58
46
"namespace" : to_text (namespace ),
59
47
"data" : attrs }
60
48
if hasChildren :
61
49
yield self .error ("Void element has children" )
62
50
63
51
def startTag (self , namespace , name , attrs ):
64
- assert namespace is None or isinstance (namespace , string_types ), type (namespace )
65
- assert isinstance (name , string_types ), type (name )
66
- assert all ((namespace is None or isinstance (namespace , string_types )) and
67
- isinstance (name , string_types ) and
68
- isinstance (value , string_types )
69
- for (namespace , name ), value in attrs .items ())
70
-
71
52
return {"type" : "StartTag" ,
72
53
"name" : text_type (name ),
73
54
"namespace" : to_text (namespace ),
@@ -76,17 +57,12 @@ def startTag(self, namespace, name, attrs):
76
57
for (namespace , name ), value in attrs .items ())}
77
58
78
59
def endTag (self , namespace , name ):
79
- assert namespace is None or isinstance (namespace , string_types ), type (namespace )
80
- assert isinstance (name , string_types ), type (namespace )
81
-
82
60
return {"type" : "EndTag" ,
83
61
"name" : to_text (name , False ),
84
62
"namespace" : to_text (namespace ),
85
63
"data" : {}}
86
64
87
65
def text (self , data ):
88
- assert isinstance (data , string_types ), type (data )
89
-
90
66
data = to_text (data )
91
67
middle = data .lstrip (spaceCharacters )
92
68
left = data [:len (data ) - len (middle )]
@@ -101,24 +77,16 @@ def text(self, data):
101
77
yield {"type" : "SpaceCharacters" , "data" : right }
102
78
103
79
def comment (self , data ):
104
- assert isinstance (data , string_types ), type (data )
105
-
106
80
return {"type" : "Comment" , "data" : text_type (data )}
107
81
108
82
def doctype (self , name , publicId = None , systemId = None , correct = True ):
109
- assert is_text_or_none (name ), type (name )
110
- assert is_text_or_none (publicId ), type (publicId )
111
- assert is_text_or_none (systemId ), type (systemId )
112
-
113
83
return {"type" : "Doctype" ,
114
84
"name" : to_text (name ),
115
85
"publicId" : to_text (publicId ),
116
86
"systemId" : to_text (systemId ),
117
87
"correct" : to_text (correct )}
118
88
119
89
def entity (self , name ):
120
- assert isinstance (name , string_types ), type (name )
121
-
122
90
return {"type" : "Entity" , "name" : text_type (name )}
123
91
124
92
def unknown (self , nodeType ):
0 commit comments