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

◆ fixQuoteValue()

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

Definition at line 216 of file XML2Python.py.

Referenced by XML2Python.TreeBuilder._name_mangle().

216 def fixQuoteValue (match):
217  '''Changes all characters inside of the match'''
218  quote = match.group(2)
219  for regexTup in regexList:
220  quote = regexTup[0].sub( regexTup[1], quote )
221  return match.group(1) + quote + '"'
222 
223 
def fixQuoteValue(match)
Definition: XML2Python.py:121

◆ xml2obj()

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 224 of file XML2Python.py.

Referenced by XML2Python.TreeBuilder._name_mangle().

224 def xml2obj (**kwargs):
225  ''' Converts XML data into native Python object. Takes either
226  file handle or string as input. Does NOT fix illegal characters.
227 
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
232 
233  options:
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'''
237 
238  # make sure we have exactly 1 input source
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'")
248 
249  # are we filtering?
250  filtering = kwargs.get ('filtering')
251  if filtering:
252  # if we are filtering, we need to read in the contents to modify them
253  if not contents:
254  if not filehandle:
255  try:
256  filehandle = open (filename, 'r') except:
257  raise RuntimeError("Failed to open '%s'" % filename)
258  contents = ''
259  for line in filehandle:
260  contents += line
261  filehandle.close()
262  filehandle = filename = ''
263  contents = quoteRE.sub (fixQuoteValue, contents)
264 
265  ncDict = kwargs.get ('nameChangeDict', {})
266  builder = TreeBuilder (nameChangeDict = ncDict)
267  if contents:
268  xml.sax.parseString(contents, builder)
269  else:
270  if not filehandle:
271  try:
272  filehandle = open (filename, 'r')
273  except:
274  raise RuntimeError("Failed to open '%s'" % filename)
275  xml.sax.parse(filehandle, builder)
276  return builder.topLevel()
277 
def xml2obj(kwargs)
Definition: XML2Python.py:129

Variable Documentation

◆ quoteRE

XML2Python.quoteRE

Definition at line 214 of file XML2Python.py.

◆ regexList

XML2Python.regexList

Definition at line 207 of file XML2Python.py.