224 ''' Converts XML data into native Python object. Takes either 225 file handle or string as input. Does NOT fix illegal characters. 227 input source: Exactly one of the three following is needed 228 filehandle - input from file handle 229 contents - input from string 230 filename - input from filename 233 filtering - boolean value telling code whether or not to fileter 234 input selection to remove illegal XML characters 235 nameChangeDict - dictionaries of names to change in python object''' 238 filehandle = kwargs.get (
'filehandle')
239 contents = kwargs.get (
'contents')
240 filename = kwargs.get (
'filename')
241 if not filehandle
and not contents
and not filename:
242 raise RuntimeError(
"You must provide 'filehandle', 'contents', or 'filename'")
243 if filehandle
and contents
or \
244 filehandle
and filename
or \
245 contents
and filename:
246 raise RuntimeError(
"You must provide only ONE of 'filehandle', 'contents', or 'filename'")
249 filtering = kwargs.get (
'filtering')
255 filehandle = open (filename,
'r') 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()