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') except:
257 raise RuntimeError(
"Failed to open '%s'" % filename)
259 for line
in filehandle:
262 filehandle = filename =
'' 263 contents = quoteRE.sub (fixQuoteValue, contents)
265 ncDict = kwargs.get (
'nameChangeDict', {})
266 builder = TreeBuilder (nameChangeDict = ncDict)
268 xml.sax.parseString(contents, builder)
272 filehandle = open (filename,
'r') 274 raise RuntimeError(
"Failed to open '%s'" % filename)
275 xml.sax.parse(filehandle, builder)
276 return builder.topLevel()