parameters: (string, filename)
return_statement: return s
docstring: Parse stack.xml string contents.
  
      :param string: stack.xml contents, ``str``
      :param filename: full file path for debugging, ``str``
      :returns: return parsed :class:`Stack`
docstring_summary: Parse stack.xml string contents.
docstring_tokens: Parse stack . xml string contents .
function: def parse_stack(string, filename):
      """
      Parse stack.xml string contents.
  
      :param string: stack.xml contents, ``str``
      :param filename: full file path for debugging, ``str``
      :returns: return parsed :class:`Stack`
      """
      # Create some classes to hold some members
      new_tuples = {}
      for key, members in LISTED_ATTRIBUTES.items():
          new_tuples[key] = collections.namedtuple(key, members)
  
      try:
          d = dom.parseString(string)
      except Exception as e:
          raise InvalidStack("[%s] invalid XML: %s"%(filename, e))
  
      s = Stack()
      p = _get_nodes_by_name(d, 'stack')
      if len(p) != 1:
          raise InvalidStack("stack.xml [%s] must have a single 'stack' element"%(filename))
      p = p[0]
      for attr in [ 'name', 'version', 'description',
                      'license', 'copyright', 'url', 'build_type', 'message_generator' ]:
          val = _check(attr)(p, filename)
          if val:
              setattr(s, attr, val)
  
      try:
          tag = _get_nodes_by_name(p, 'description')[0]
          s.description_brief = tag.getAttribute('brief') or ''
      except:
          # means that 'description' tag is missing
          pass
  
      s.authors = _build_listed_attributes(p, 'author', new_tuples['Author'])
      s.maintainers = _build_listed_attributes(p, 'maintainer', new_tuples['Maintainer'])
      s.depends = _build_listed_attributes(p, 'depends', new_tuples['Depend'])
      s.build_depends = _build_listed_attributes(p, 'build_depends', new_tuples['Depend'])
  
      try:
          tag = _get_nodes_by_name(p, 'review')[0]
          s.review_status = tag.getAttribute('status') or ''
      except:
          pass #stack.xml is missing optional 'review status' tag
  
      try:
          tag = _get_nodes_by_name(p, 'review')[0]
          s.review_notes = tag.getAttribute('notes') or ''
      except:
          pass #stack.xml is missing optional 'review notes' tag
  
      try:
          tag = _get_nodes_by_name(p, 'build_type')[0]
          s.build_type_file = tag.getAttribute('file') or ''
      except:
          pass #stack.xml is missing optional 'build_type file' tag
  
      # store unrecognized tags
      s.unknown_tags = [e.nodeName for e in p.childNodes if e.nodeType == e.ELEMENT_NODE and e.tagName not in VALID]
      if s.unknown_tags:
          raise InvalidStack("stack.xml [%s] must be cleaned up from %s"%(filename, str(s.unknown_tags)))
      return s
function_tokens: def parse_stack ( string , filename ) : # Create some classes to hold some members new_tuples = { } for key , members in LISTED_ATTRIBUTES . items ( ) : new_tuples [ key ] = collections . namedtuple ( key , members ) try : d = dom . parseString ( string ) except Exception as e : raise InvalidStack ( "[%s] invalid XML: %s" % ( filename , e ) ) s = Stack ( ) p = _get_nodes_by_name ( d , 'stack' ) if len ( p ) != 1 : raise InvalidStack ( "stack.xml [%s] must have a single 'stack' element" % ( filename ) ) p = p [ 0 ] for attr in [ 'name' , 'version' , 'description' , 'license' , 'copyright' , 'url' , 'build_type' , 'message_generator' ] : val = _check ( attr ) ( p , filename ) if val : setattr ( s , attr , val ) try : tag = _get_nodes_by_name ( p , 'description' ) [ 0 ] s . description_brief = tag . getAttribute ( 'brief' ) or '' except : # means that 'description' tag is missing pass s . authors = _build_listed_attributes ( p , 'author' , new_tuples [ 'Author' ] ) s . maintainers = _build_listed_attributes ( p , 'maintainer' , new_tuples [ 'Maintainer' ] ) s . depends = _build_listed_attributes ( p , 'depends' , new_tuples [ 'Depend' ] ) s . build_depends = _build_listed_attributes ( p , 'build_depends' , new_tuples [ 'Depend' ] ) try : tag = _get_nodes_by_name ( p , 'review' ) [ 0 ] s . review_status = tag . getAttribute ( 'status' ) or '' except : pass #stack.xml is missing optional 'review status' tag try : tag = _get_nodes_by_name ( p , 'review' ) [ 0 ] s . review_notes = tag . getAttribute ( 'notes' ) or '' except : pass #stack.xml is missing optional 'review notes' tag try : tag = _get_nodes_by_name ( p , 'build_type' ) [ 0 ] s . build_type_file = tag . getAttribute ( 'file' ) or '' except : pass #stack.xml is missing optional 'build_type file' tag # store unrecognized tags s . unknown_tags = [ e . nodeName for e in p . childNodes if e . nodeType == e . ELEMENT_NODE and e . tagName not in VALID ] if s . unknown_tags : raise InvalidStack ( "stack.xml [%s] must be cleaned up from %s" % ( filename , str ( s . unknown_tags ) ) ) return s