CMS 3D CMS Logo

Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes

python::XML2Python::TreeBuilder Class Reference

List of all members.

Public Member Functions

def __init__
def characters
def endElement
def root
def startElement
def topLevel

Public Attributes

 current

Static Public Attributes

tuple non_id_char = re.compile('[^_0-9a-zA-Z]')

Private Member Functions

def _name_mangle

Private Attributes

 _ncDict
 _root
 _stack
 _text_parts

Detailed Description

Definition at line 65 of file XML2Python.py.


Constructor & Destructor Documentation

def python::XML2Python::TreeBuilder::__init__ (   self,
  kwargs 
)

Definition at line 69 of file XML2Python.py.

00070                                  :
00071         self._stack = []
00072         self._text_parts = []
00073         self._ncDict = kwargs.get ('nameChangeDict', {})
00074         self._root = DataNode (nameChangeDict = self._ncDict)
00075         self.current = self._root


Member Function Documentation

def python::XML2Python::TreeBuilder::_name_mangle (   name) [private]

Definition at line 108 of file XML2Python.py.

00109                            :
00110         return TreeBuilder.non_id_char.sub('_', name)
00111 

def python::XML2Python::TreeBuilder::characters (   self,
  content 
)

Definition at line 96 of file XML2Python.py.

00097                                   :
00098         self._text_parts.append(content)

def python::XML2Python::TreeBuilder::endElement (   self,
  name 
)

Definition at line 84 of file XML2Python.py.

00085                                :
00086         text = ''.join (self._text_parts).strip()
00087         if text:
00088             self.current._data = text
00089         if self.current.attributes():
00090             obj = self.current
00091         else:
00092             # a text only node is simply represented by the string
00093             obj = text or ''
00094         self.current, self._text_parts = self._stack.pop()
00095         self.current._add_xml_attr (TreeBuilder._name_mangle(name), obj)

def python::XML2Python::TreeBuilder::root (   self)

Definition at line 99 of file XML2Python.py.

00100                    :
00101         return self._root

def python::XML2Python::TreeBuilder::startElement (   self,
  name,
  attrs 
)

Definition at line 76 of file XML2Python.py.

00077                                         :
00078         self._stack.append( (self.current, self._text_parts))
00079         self.current = DataNode (nameChangeDict = self._ncDict)
00080         self._text_parts = []
00081         # xml attributes --> python attributes
00082         for k, v in attrs.items():
00083             self.current._add_xml_attr (TreeBuilder._name_mangle(k), v)

def python::XML2Python::TreeBuilder::topLevel (   self)
Returns top level object

Definition at line 102 of file XML2Python.py.

00103                        :
00104         '''Returns top level object'''
00105         return self._root.attributes().values()[0]
00106         


Member Data Documentation

Definition at line 69 of file XML2Python.py.

Definition at line 69 of file XML2Python.py.

Definition at line 69 of file XML2Python.py.

Definition at line 69 of file XML2Python.py.

Definition at line 69 of file XML2Python.py.

tuple python::XML2Python::TreeBuilder::non_id_char = re.compile('[^_0-9a-zA-Z]') [static]

Definition at line 67 of file XML2Python.py.