CMS 3D CMS Logo

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

XML2Python::TreeBuilder Class Reference

List of all members.

Public Member Functions

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

Public Attributes

 current

Static Public Attributes

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

Private Member Functions

def _name_mangle
def _name_mangle

Private Attributes

 _ncDict
 _root
 _stack
 _text_parts

Detailed Description

Definition at line 159 of file XML2Python.py.


Constructor & Destructor Documentation

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

Definition at line 163 of file XML2Python.py.

00164                                  :
00165         self._stack = []
00166         self._text_parts = []
00167         self._ncDict = kwargs.get ('nameChangeDict', {})
00168         self._root = DataNode (nameChangeDict = self._ncDict)
00169         self.current = self._root

def 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 XML2Python::TreeBuilder::_name_mangle (   name) [private]

Definition at line 202 of file XML2Python.py.

00203                            :
00204         return TreeBuilder.non_id_char.sub('_', name)
00205 

def 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 XML2Python::TreeBuilder::characters (   self,
  content 
)

Definition at line 96 of file XML2Python.py.

00097                                   :
00098         self._text_parts.append(content)

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

Definition at line 190 of file XML2Python.py.

00191                                   :
00192         self._text_parts.append(content)

def 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 XML2Python::TreeBuilder::endElement (   self,
  name 
)

Definition at line 178 of file XML2Python.py.

00179                                :
00180         text = ''.join (self._text_parts).strip()
00181         if text:
00182             self.current._data = text
00183         if self.current.attributes():
00184             obj = self.current
00185         else:
00186             # a text only node is simply represented by the string
00187             obj = text or ''
00188         self.current, self._text_parts = self._stack.pop()
00189         self.current._add_xml_attr (TreeBuilder._name_mangle(name), obj)

def XML2Python::TreeBuilder::root (   self)

Definition at line 193 of file XML2Python.py.

00194                    :
00195         return self._root

def XML2Python::TreeBuilder::root (   self)

Definition at line 99 of file XML2Python.py.

00100                    :
00101         return self._root

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

Definition at line 170 of file XML2Python.py.

00171                                         :
00172         self._stack.append( (self.current, self._text_parts))
00173         self.current = DataNode (nameChangeDict = self._ncDict)
00174         self._text_parts = []
00175         # xml attributes --> python attributes
00176         for k, v in attrs.items():
00177             self.current._add_xml_attr (TreeBuilder._name_mangle(k), v)

def 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 XML2Python::TreeBuilder::topLevel (   self)
Returns top level object

Definition at line 196 of file XML2Python.py.

00197                        :
00198         '''Returns top level object'''
00199         return self._root.attributes().values()[0]
00200         

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

Definition at line 163 of file XML2Python.py.

Definition at line 163 of file XML2Python.py.

Definition at line 163 of file XML2Python.py.

Definition at line 163 of file XML2Python.py.

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

Definition at line 161 of file XML2Python.py.