130 ''' Converts XML data into native Python object. Takes either 131 file handle or string as input. Does NOT fix illegal characters. 133 input source: Exactly one of the three following is needed 134 filehandle - input from file handle 135 contents - input from string 136 filename - input from filename 139 filtering - boolean value telling code whether or not to fileter 140 input selection to remove illegal XML characters 141 nameChangeDict - dictionaries of names to change in python object''' 144 filehandle = kwargs.get (
'filehandle')
145 contents = kwargs.get (
'contents')
146 filename = kwargs.get (
'filename')
147 if not filehandle
and not contents
and not filename:
148 raise RuntimeError(
"You must provide 'filehandle', 'contents', or 'filename'")
149 if filehandle
and contents
or \
150 filehandle
and filename
or \
151 contents
and filename:
152 raise RuntimeError(
"You must provide only ONE of 'filehandle', 'contents', or 'filename'")
155 filtering = kwargs.get (
'filtering')
161 filehandle = open (filename,
'r') except:
162 raise RuntimeError(
"Failed to open '%s'" % filename)
164 for line
in filehandle:
167 filehandle = filename =
'' 168 contents = quoteRE.sub (fixQuoteValue, contents)
170 ncDict = kwargs.get (
'nameChangeDict', {})
171 builder = TreeBuilder (nameChangeDict = ncDict)
173 xml.sax.parseString(contents, builder)
177 filehandle = open (filename,
'r') 179 raise RuntimeError(
"Failed to open '%s'" % filename)
180 xml.sax.parse(filehandle, builder)
181 return builder.topLevel()