Ejemplo n.º 1
0
 def EndParsing(self):
   children = self.children
   self.if_then_else = False
   if any(isinstance(node, (ThenNode, ElseNode)) for node in children):
     if (len(children) != 2 or not isinstance(children[0], ThenNode) or
                               not isinstance(children[1], ElseNode)):
       raise exception.UnexpectedChild(
           '<if> element must be <if><then>...</then><else>...</else></if>')
     self.if_then_else = True
Ejemplo n.º 2
0
 def AddChild(self, child):
   '''Adds a child to the list of children of this node, if it is a valid
   child for the node.'''
   assert isinstance(child, Node)
   if (not self._IsValidChild(child) or
       self._ContentType() == self._CONTENT_TYPE_CDATA):
     explanation = 'invalid child %s for parent %s' % (str(child), self.name)
     raise exception.UnexpectedChild(explanation)
   self.children.append(child)
   self.mixed_content.append(child)
Ejemplo n.º 3
0
 def AddChild(self, child):
     '''Adds a child to the list of children of this node, if it is a valid
 child for the node.'''
     assert isinstance(child, Node)
     if (not self._IsValidChild(child)
             or self._ContentType() == self._CONTENT_TYPE_CDATA):
         if child.parent:
             explanation = 'child %s of parent %s' % (child.name,
                                                      child.parent.name)
         else:
             explanation = 'node %s with no parent' % child.name
         raise exception.UnexpectedChild(explanation)
     self.children.append(child)
     self.mixed_content.append(child)