Esempio n. 1
0
    def __init__(self, elementName, attributes, locator, config, parent):
        self.elementName = elementName
        self.config = config

        if locator is not None:
            self.locator = locator
        elif parent is not None:  # handy when we add nodes in preprocessing
            self.locator = parent.locator
        else:
            self.locator = NodeLocator(None)

        self.text = u''
        self.children = []
        self.attributes = attributes
        self.parent = parent
        self.metriclist = None
        self.nominalMetric = None
        if parent is not None:
            self.nodeIndex = len(parent.children)
            self.defaults = parent.defaults
            parent.children.append(self)
        else:
            self.defaults = globalDefaults.copy()
            self.defaults.update(config.defaults)
            self.nodeIndex = 0
Esempio n. 2
0
    def startElementNS(self, elementName, qName, attributes):
        if self.skip > 0:
            self.skip += 1
            return

        locator = NodeLocator(self.locator)
        (namespace, localName) = elementName
        if namespace and namespace != MathNS:
            if self.config.verbose:
                locator.message(
                    "Skipped element '%s' from an unknown namespace '%s'" %
                    (localName, namespace), "INFO")
            self.skip = 1
            return

        properties = {}
        for (attName, value) in attributes.items():
            (attNamespace, attLocalName) = attName
            if attNamespace and attNamespace != MathNS:
                if self.config.verbose:
                    locator.message(
                        "Ignored attribute '%s' from an unknown namespace '%s'"
                        % (attLocalName, attNamespace), "INFO")
                continue
            properties[attLocalName] = value

        self.currentNode = MathNode(localName, properties, locator,
                                    self.config, self.currentNode)