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