CMS 3D CMS Logo

Classes | Functions | Variables
XML2Python Namespace Reference

Classes

class  DataNode
 
class  TreeBuilder
 

Functions

def fixQuoteValue (match)
 
def xml2obj (kwargs)
 

Variables

 quoteRE
 
 regexList
 

Function Documentation

def XML2Python.fixQuoteValue (   match)
Changes all characters inside of the match

Definition at line 217 of file XML2Python.py.

Referenced by XML2Python.TreeBuilder._name_mangle().

217 def fixQuoteValue (match):
218  '''Changes all characters inside of the match'''
219  quote = match.group(2)
220  for regexTup in regexList:
221  quote = regexTup[0].sub( regexTup[1], quote )
222  return match.group(1) + quote + '"'
223 
224 
def fixQuoteValue(match)
Definition: XML2Python.py:217
def XML2Python.xml2obj (   kwargs)
Converts XML data into native Python object.  Takes either
file handle or string as input.  Does NOT fix illegal characters.

input source:  Exactly one of the three following is needed
filehandle     - input from file handle
contents       - input from string
filename       - input from filename

options:
filtering      - boolean value telling code whether or not to fileter
                 input selection to remove illegal XML characters
nameChangeDict - dictionaries of names to change in python object

Definition at line 225 of file XML2Python.py.

Referenced by XML2Python.TreeBuilder._name_mangle().

225 def xml2obj (**kwargs):
226  ''' Converts XML data into native Python object. Takes either
227  file handle or string as input. Does NOT fix illegal characters.
228 
229  input source: Exactly one of the three following is needed
230  filehandle - input from file handle
231  contents - input from string
232  filename - input from filename
233 
234  options:
235  filtering - boolean value telling code whether or not to fileter
236  input selection to remove illegal XML characters
237  nameChangeDict - dictionaries of names to change in python object'''
238 
239  # make sure we have exactly 1 input source
240  filehandle = kwargs.get ('filehandle')
241  contents = kwargs.get ('contents')
242  filename = kwargs.get ('filename')
243  if not filehandle and not contents and not filename:
244  raise RuntimeError("You must provide 'filehandle', 'contents', or 'filename'")
245  if filehandle and contents or \
246  filehandle and filename or \
247  contents and filename:
248  raise RuntimeError("You must provide only ONE of 'filehandle', 'contents', or 'filename'")
249 
250  # are we filtering?
251  filtering = kwargs.get ('filtering')
252  if filtering:
253  # if we are filtering, we need to read in the contents to modify them
254  if not contents:
255  if not filehandle:
256  try:
257  filehandle = open (filename, 'r')
258  except:
259  raise RuntimeError("Failed to open '%s'" % filename)
260  contents = ''
261  for line in filehandle:
262  contents += line
263  filehandle.close()
264  filehandle = filename = ''
265  contents = quoteRE.sub (fixQuoteValue, contents)
266 
267  ncDict = kwargs.get ('nameChangeDict', {})
268  builder = TreeBuilder (nameChangeDict = ncDict)
269  if contents:
270  xml.sax.parseString(contents, builder)
271  else:
272  if not filehandle:
273  try:
274  filehandle = open (filename, 'r')
275  except:
276  raise RuntimeError("Failed to open '%s'" % filename)
277  xml.sax.parse(filehandle, builder)
278  return builder.topLevel()
279 
def xml2obj(kwargs)
Definition: XML2Python.py:225

Variable Documentation

XML2Python.quoteRE

Definition at line 215 of file XML2Python.py.

XML2Python.regexList

Definition at line 208 of file XML2Python.py.