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.

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 

Referenced by XML2Python.TreeBuilder._name_mangle().

◆ 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.

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')
257  except:
258  raise RuntimeError("Failed to open '%s'" % filename)
259  contents = ''
260  for line in filehandle:
261  contents += line
262  filehandle.close()
263  filehandle = filename = ''
264  contents = quoteRE.sub (fixQuoteValue, contents)
265 
266  ncDict = kwargs.get ('nameChangeDict', {})
267  builder = TreeBuilder (nameChangeDict = ncDict)
268  if contents:
269  xml.sax.parseString(contents, builder)
270  else:
271  if not filehandle:
272  try:
273  filehandle = open (filename, 'r')
274  except:
275  raise RuntimeError("Failed to open '%s'" % filename)
276  xml.sax.parse(filehandle, builder)
277  return builder.topLevel()

Referenced by XML2Python.TreeBuilder._name_mangle().

Variable Documentation

◆ quoteRE

XML2Python.quoteRE

Definition at line 214 of file XML2Python.py.

◆ regexList

XML2Python.regexList

Definition at line 207 of file XML2Python.py.

python.XML2Python.fixQuoteValue
def fixQuoteValue(match)
Definition: XML2Python.py:121
python.XML2Python.xml2obj
def xml2obj(**kwargs)
Definition: XML2Python.py:129