tools/metrics/common/models.py
def Unmarshall(self, node):
    """Extracts the content of the node to an object.

    Args:
      node: The XML node to extract data from.

    Returns:
      An object extracted from the node.

    Raises:
      ValueError: The node is missing required children.
    """
    obj = {}
    obj[COMMENT_KEY] = GetCommentsForNode(node)

    for attr, attr_type, attr_re in self.attributes:
      if node.hasAttribute(attr):
        obj[attr] = attr_type(node.getAttribute(attr))
      if attr_re is not None:
        attr_val = obj.get(attr, '')
        if not re.match(attr_re, attr_val):
          raise ValueError('%s "%s" does not match regex "%s"' %
                           (attr, attr_val, attr_re))

    # We need to iterate through all the children and get their nodeValue,
    # to account for the cases where other children node precedes the text
    # attribute.
    obj[self.text_attribute] = ''
    child = node.firstChild
    while child:
      obj[self.text_attribute] += (child.nodeValue.strip()
                                   if child.nodeValue else '')
      child = child.nextSibling

    # This prevents setting a None key with empty string value
    if obj[self.text_attribute] == '':
      del obj[self.text_attribute]

    for child in self.children:
      nodes = GetChildrenByTag(node, child.node_type.tag)
      if child.multiple:
        obj[child.attr] = [
            child.node_type.Unmarshall(n) for n in nodes]
      elif nodes:
        obj[child.attr] = child.node_type.Unmarshall(nodes[0])

    unexpected = GetUnexpectedChildren(
        node, set([child.node_type.tag for child in self.children]))
    if unexpected:
      raise ValueError("Unexpected children: %s in <%s> node" %
                       (','.join(unexpected), self.tag))

    return obj
Extracts the content of the node to an object.

    Args:
      node: The XML node to extract data from.

    Returns:
      An object extracted from the node.

    Raises:
      ValueError: The node is missing required children.
    
Extracts the content of the node to an object.
Extracts the content of the node to an object .
def Unmarshall(self, node):
    obj = {}
    obj[COMMENT_KEY] = GetCommentsForNode(node)
    for attr, attr_type, attr_re in self.attributes:
      if node.hasAttribute(attr):
        obj[attr] = attr_type(node.getAttribute(attr))
      if attr_re is not None:
        attr_val = obj.get(attr, '')
        if not re.match(attr_re, attr_val):
          raise ValueError('%s "%s" does not match regex "%s"' %
                           (attr, attr_val, attr_re))
    obj[self.text_attribute] = ''
    child = node.firstChild
    while child:
      obj[self.text_attribute] += (child.nodeValue.strip()
                                   if child.nodeValue else '')
      child = child.nextSibling
    if obj[self.text_attribute] == '':
      del obj[self.text_attribute]
    for child in self.children:
      nodes = GetChildrenByTag(node, child.node_type.tag)
      if child.multiple:
        obj[child.attr] = [
            child.node_type.Unmarshall(n) for n in nodes]
      elif nodes:
        obj[child.attr] = child.node_type.Unmarshall(nodes[0])
    unexpected = GetUnexpectedChildren(
        node, set([child.node_type.tag for child in self.children]))
    if unexpected:
      raise ValueError("Unexpected children: %s in <%s> node" %
                       (','.join(unexpected), self.tag))
    return obj
def Unmarshall ( self , node ) : obj = { } obj [ COMMENT_KEY ] = GetCommentsForNode ( node ) for attr , attr_type , attr_re in self . attributes : if node . hasAttribute ( attr ) : obj [ attr ] = attr_type ( node . getAttribute ( attr ) ) if attr_re is not None : attr_val = obj . get ( attr , '' ) if not re . match ( attr_re , attr_val ) : raise ValueError ( '%s "%s" does not match regex "%s"' % ( attr , attr_val , attr_re ) ) obj [ self . text_attribute ] = '' child = node . firstChild while child : obj [ self . text_attribute ] += ( child . nodeValue . strip ( ) if child . nodeValue else '' ) child = child . nextSibling if obj [ self . text_attribute ] == '' : del obj [ self . text_attribute ] for child in self . children : nodes = GetChildrenByTag ( node , child . node_type . tag ) if child . multiple : obj [ child . attr ] = [ child . node_type . Unmarshall ( n ) for n in nodes ] elif nodes : obj [ child . attr ] = child . node_type . Unmarshall ( nodes [ 0 ] ) unexpected = GetUnexpectedChildren ( node , set ( [ child . node_type . tag for child in self . children ] ) ) if unexpected : raise ValueError ( "Unexpected children: %s in <%s> node" % ( ',' . join ( unexpected ) , self . tag ) ) return obj
Extracts the content of the node to an object.
Extracts the content of the node to an object .
"""Extracts the content of the node to an object.

    Args:
      node: The XML node to extract data from.

    Returns:
      An object extracted from the node.

    Raises:
      ValueError: The node is missing required children.
    """ # We need to iterate through all the children and get their nodeValue, # to account for the cases where other children node precedes the text # attribute. # This prevents setting a None key with empty string value
An object extracted from the node.
An object extracted from the node .
The node is missing required children.
The node is missing required children .
ValueError
self
node
The XML node to extract data from.
The XML node to extract data from .