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')
163 raise RuntimeError(
"Failed to open '%s'" % filename)
165 for line
in filehandle:
168 filehandle = filename =
''
169 contents = quoteRE.sub (fixQuoteValue, contents)
171 ncDict = kwargs.get (
'nameChangeDict', {})
172 builder = TreeBuilder (nameChangeDict = ncDict)
174 xml.sax.parseString(contents, builder)
178 filehandle = open (filename,
'r')
180 raise RuntimeError(
"Failed to open '%s'" % filename)
181 xml.sax.parse(filehandle, builder)
182 return builder.topLevel()