@@ -139,83 +139,6 @@ def GenshiAdapter(tree):
139
139
"adapter" : GenshiAdapter ,
140
140
"walker" : treewalkers .getTreeWalker ("genshi" )}
141
141
142
-
143
- def concatenateCharacterTokens (tokens ):
144
- charactersToken = None
145
- for token in tokens :
146
- type = token ["type" ]
147
- if type in ("Characters" , "SpaceCharacters" ):
148
- if charactersToken is None :
149
- charactersToken = {"type" : "Characters" , "data" : token ["data" ]}
150
- else :
151
- charactersToken ["data" ] += token ["data" ]
152
- else :
153
- if charactersToken is not None :
154
- yield charactersToken
155
- charactersToken = None
156
- yield token
157
- if charactersToken is not None :
158
- yield charactersToken
159
-
160
-
161
- def convertTokens (tokens ):
162
- output = []
163
- indent = 0
164
- for token in concatenateCharacterTokens (tokens ):
165
- type = token ["type" ]
166
- if type in ("StartTag" , "EmptyTag" ):
167
- if (token ["namespace" ] and
168
- token ["namespace" ] != constants .namespaces ["html" ]):
169
- if token ["namespace" ] in constants .prefixes :
170
- name = constants .prefixes [token ["namespace" ]]
171
- else :
172
- name = token ["namespace" ]
173
- name += " " + token ["name" ]
174
- else :
175
- name = token ["name" ]
176
- output .append ("%s<%s>" % (" " * indent , name ))
177
- indent += 2
178
- attrs = token ["data" ]
179
- if attrs :
180
- # TODO: Remove this if statement, attrs should always exist
181
- for (namespace , name ), value in sorted (attrs .items ()):
182
- if namespace :
183
- if namespace in constants .prefixes :
184
- outputname = constants .prefixes [namespace ]
185
- else :
186
- outputname = namespace
187
- outputname += " " + name
188
- else :
189
- outputname = name
190
- output .append ("%s%s=\" %s\" " % (" " * indent , outputname , value ))
191
- if type == "EmptyTag" :
192
- indent -= 2
193
- elif type == "EndTag" :
194
- indent -= 2
195
- elif type == "Comment" :
196
- output .append ("%s<!-- %s -->" % (" " * indent , token ["data" ]))
197
- elif type == "Doctype" :
198
- if token ["name" ]:
199
- if token ["publicId" ]:
200
- output .append ("""%s<!DOCTYPE %s "%s" "%s">""" %
201
- (" " * indent , token ["name" ],
202
- token ["publicId" ],
203
- token ["systemId" ] and token ["systemId" ] or "" ))
204
- elif token ["systemId" ]:
205
- output .append ("""%s<!DOCTYPE %s "" "%s">""" %
206
- (" " * indent , token ["name" ],
207
- token ["systemId" ]))
208
- else :
209
- output .append ("%s<!DOCTYPE %s>" % (" " * indent ,
210
- token ["name" ]))
211
- else :
212
- output .append ("%s<!DOCTYPE >" % (" " * indent ,))
213
- elif type in ("Characters" , "SpaceCharacters" ):
214
- output .append ("%s\" %s\" " % (" " * indent , token ["data" ]))
215
- else :
216
- pass # TODO: what to do with errors?
217
- return "\n " .join (output )
218
-
219
142
import re
220
143
attrlist = re .compile (r"^(\s+)\w+=.*(\n\1\w+=.*)+" , re .M )
221
144
@@ -265,7 +188,7 @@ def runTreewalkerTest(innerHTML, input, expected, errors, treeClass):
265
188
266
189
document = treeClass .get ("adapter" , lambda x : x )(document )
267
190
try :
268
- output = convertTokens (treeClass ["walker" ](document ))
191
+ output = treewalkers . pprint (treeClass ["walker" ](document ))
269
192
output = attrlist .sub (sortattrs , output )
270
193
expected = attrlist .sub (sortattrs , convertExpected (expected ))
271
194
diff = "" .join (unified_diff ([line + "\n " for line in expected .splitlines ()],
@@ -323,7 +246,7 @@ def runTreewalkerEditTest(intext, expected, attrs_to_add, tree):
323
246
set_attribute_on_first_child (document , nom , val , treeName )
324
247
325
248
document = treeClass .get ("adapter" , lambda x : x )(document )
326
- output = convertTokens (treeClass ["walker" ](document ))
249
+ output = treewalkers . pprint (treeClass ["walker" ](document ))
327
250
output = attrlist .sub (sortattrs , output )
328
251
if not output in expected :
329
252
raise AssertionError ("TreewalkerEditTest: %s\n Expected:\n %s\n Received:\n %s" % (treeName , expected , output ))
0 commit comments