Beispiel #1
0
    def startElement(self, name, attrs):
        if self.ignore_depth or name in self.tags_to_ignore:
            if self.debug and self.ignore_depth == 0:
                print("Ignoring element %s and its children" % name)
            self.ignore_depth += 1
            return

        if self.debug:
            attr_list = ' '.join('%s="%s"' % kv for kv in attrs.items())
            print("Starting parsing of element %s with attributes %r" %
                  (name, attr_list or '(none)'))

        typeattr = attrs.get('type')
        node = mapping.ElementToClass(name, typeattr)()
        node.source = self.source

        if self.stack:
            self.stack[-1].AddChild(node)
            node.StartParsing(name, self.stack[-1])
        else:
            assert self.root is None
            self.root = node
            if isinstance(self.root, misc.GritNode):
                if self.target_platform:
                    self.root.SetTargetPlatform(self.target_platform)
            node.StartParsing(name, None)
            if self.defines:
                node.SetDefines(self.defines)
        self.stack.append(node)

        for attr, attrval in attrs.items():
            node.HandleAttribute(attr, attrval)
Beispiel #2
0
  def startElement(self, name, attrs):
    assert not self.root or len(self.stack) > 0

    if self.debug:
      attr_list = []
      for attr in attrs.getNames():
        attr_list.append('%s="%s"' % (attr, attrs.getValue(attr)))
      if len(attr_list) == 0: attr_list = ['(none)']
      attr_list = ' '.join(attr_list)
      print "Starting parsing of element %s with attributes %r" % (name, attr_list)

    typeattr = None
    if 'type' in attrs.getNames():
      typeattr = attrs.getValue('type')

    node = mapping.ElementToClass(name, typeattr)()

    if not self.root:
      self.root = node
      if self.defines:
        self.root.SetDefines(self.defines)

    if len(self.stack) > 0:
      self.stack[-1].AddChild(node)
      node.StartParsing(name, self.stack[-1])
    else:
      node.StartParsing(name, None)

    # Push
    self.stack.append(node)

    for attr in attrs.getNames():
      node.HandleAttribute(attr, attrs.getValue(attr))