226 ''' Converts XML data into native Python object. Takes either
227 file handle or string as input. Does NOT fix illegal characters.
229 input source: Exactly one of the three following is needed
230 filehandle - input from file handle
231 contents - input from string
232 filename - input from filename
235 filtering - boolean value telling code whether or not to fileter
236 input selection to remove illegal XML characters
237 nameChangeDict - dictionaries of names to change in python object'''
240 filehandle = kwargs.get (
'filehandle')
241 contents = kwargs.get (
'contents')
242 filename = kwargs.get (
'filename')
243 if not filehandle
and not contents
and not filename:
244 raise RuntimeError(
"You must provide 'filehandle', 'contents', or 'filename'")
245 if filehandle
and contents
or \
246 filehandle
and filename
or \
247 contents
and filename:
248 raise RuntimeError(
"You must provide only ONE of 'filehandle', 'contents', or 'filename'")
251 filtering = kwargs.get (
'filtering')
257 filehandle = open (filename,
'r')
259 raise RuntimeError(
"Failed to open '%s'" % filename)
261 for line
in filehandle:
264 filehandle = filename =
''
265 contents = quoteRE.sub (fixQuoteValue, contents)
267 ncDict = kwargs.get (
'nameChangeDict', {})
268 builder = TreeBuilder (nameChangeDict = ncDict)
270 xml.sax.parseString(contents, builder)
274 filehandle = open (filename,
'r')
276 raise RuntimeError(
"Failed to open '%s'" % filename)
277 xml.sax.parse(filehandle, builder)
278 return builder.topLevel()