Package pyffi :: Module object_models :: Module xml :: Class XmlSaxHandler
[hide private]
[frames] | no frames]

Class XmlSaxHandler

source code

xml.sax.handler.ContentHandler --+
                                 |
                                XmlSaxHandler

This class contains all functions for parsing the xml and converting the xml structure into Python classes.
Instance Methods [hide private]
 
__init__(self, cls, name, bases, dct)
Set up the xml parser.
source code
 
pushTag(self, tag)
Push tag C{tag} on the stack and make it the current tag.
source code
 
popTag(self)
Pop the current tag from the stack and return it.
source code
 
startElement(self, name, attrs)
Called when parser starts parsing an element called C{name}.
source code
 
endElement(self, name)
Called at the end of each xml tag.
source code
 
endDocument(self)
Called when the xml is completely parsed.
source code
 
characters(self, chars)
Add the string C{chars} to the docstring.
source code

Inherited from xml.sax.handler.ContentHandler: endElementNS, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startElementNS, startPrefixMapping

Class Variables [hide private]
  tag_file = 1
  tag_version = 2
  tag_basic = 3
  tag_alias = 4
  tag_enum = 5
  tag_option = 6
  tag_bit_struct = 7
  tag_struct = 8
  tag_attribute = 9
  tag_bits = 10
  tags = {'add': 9, 'alias': 4, 'basic': 3, 'bits': 10, 'bitstru...
  tags_niftools = {'bitflags': 7, 'compound': 8, 'niftoolsxml': ...
Method Details [hide private]

__init__(self, cls, name, bases, dct)
(Constructor)

source code 

Set up the xml parser.

Upon instantiation this function does the following:
  • Creates a dictionary C{cls.versions} which maps each supported version strings onto a version integer.
  • Creates a dictionary C{cls.games} which maps each supported game onto a list of versions.
  • Makes an alias C{self.cls} for C{cls}.
  • Initializes a stack C{self.stack} of xml tags.
  • Initializes the current tag.
Overrides: xml.sax.handler.ContentHandler.__init__

pushTag(self, tag)

source code 
Push tag C{tag} on the stack and make it the current tag.
Parameters:
  • tag - The tag to put on the stack.

popTag(self)

source code 
Pop the current tag from the stack and return it. Also update the current tag.
Returns:
The tag popped from the stack.

startElement(self, name, attrs)

source code 

Called when parser starts parsing an element called C{name}.

This function sets up all variables for creating the class in the C{self.endElement} function. For struct elements, it will set up C{self.class_name}, C{self.class_bases}, and C{self.class_dict} which will be used to create the class by invokation of C{type} in C{self.endElement}. For basic, enum, and bitstruct elements, it will set up C{self.basic_class} to link to the proper class implemented by C{self.cls}. The code also performs sanity checks on the attributes.

For xml add tags, the function will add an entry to the C{self.class_dict["_attrs"]} list. Note that this list is used by the struct metaclass: the class attributes are created exactly from this list.

Parameters:
  • name - The name of the xml element.
  • attrs - A dictionary of attributes of the element.
Overrides: xml.sax.handler.ContentHandler.startElement

endElement(self, name)

source code 

Called at the end of each xml tag.

Creates classes.

Overrides: xml.sax.handler.ContentHandler.endElement

endDocument(self)

source code 

Called when the xml is completely parsed.

Searches and adds class customized functions. For version tags, adds version to version and game lists.

Overrides: xml.sax.handler.ContentHandler.endDocument

characters(self, chars)

source code 
Add the string C{chars} to the docstring. For version tags, updates the game version list.
Overrides: xml.sax.handler.ContentHandler.characters

Class Variable Details [hide private]

tags

Value:
{'add': 9,
 'alias': 4,
 'basic': 3,
 'bits': 10,
 'bitstruct': 7,
 'enum': 5,
 'fileformat': 1,
 'option': 6,
...

tags_niftools

Value:
{'bitflags': 7, 'compound': 8, 'niftoolsxml': 1, 'niobject': 8}