parameters: (filename_or_stream, dir=None, stop_after=None, first_ids_file=None,
            debug=False, defines=None, tags_to_ignore=None, target_platform=None,
            predetermined_ids_file=None)
return_statement: return handler.root
docstring: Parses a GRD file into a tree of nodes (from grit.node).
  
    If filename_or_stream is a stream, 'dir' should point to the directory
    notionally containing the stream (this feature is only used in unit tests).
  
    If 'stop_after' is provided, the parsing will stop once the first node
    with this name has been fully parsed (including all its contents).
  
    If 'debug' is true, lots of information about the parsing events will be
    printed out during parsing of the file.
  
    If 'first_ids_file' is non-empty, it is used to override the setting for the
    first_ids_file attribute of the <grit> root node. Note that the first_ids_file
    parameter should be relative to the cwd, even though the first_ids_file
    attribute of the <grit> node is relative to the grd file.
  
    If 'target_platform' is set, this is used to determine the target
    platform of builds, instead of using |sys.platform|.
  
    Args:
      filename_or_stream: './bla.xml'
      dir: None (if filename_or_stream is a filename) or '.'
      stop_after: 'inputs'
      first_ids_file: 'GRIT_DIR/../gritsettings/resource_ids'
      debug: False
      defines: dictionary of defines, like {'chromeos': '1'}
      target_platform: None or the value that would be returned by sys.platform
          on your target platform.
      predetermined_ids_file: File path to a file containing a pre-determined
          mapping from resource names to resource ids which will be used to assign
          resource ids to those resources.
  
    Return:
      Subclass of grit.node.base.Node
  
    Throws:
      grit.exception.Parsing
docstring_summary: Parses a GRD file into a tree of nodes (from grit.node).
docstring_tokens: Parses a GRD file into a tree of nodes ( from grit . node ) .
function: def Parse(filename_or_stream, dir=None, stop_after=None, first_ids_file=None,
            debug=False, defines=None, tags_to_ignore=None, target_platform=None,
            predetermined_ids_file=None):
    '''Parses a GRD file into a tree of nodes (from grit.node).
  
    If filename_or_stream is a stream, 'dir' should point to the directory
    notionally containing the stream (this feature is only used in unit tests).
  
    If 'stop_after' is provided, the parsing will stop once the first node
    with this name has been fully parsed (including all its contents).
  
    If 'debug' is true, lots of information about the parsing events will be
    printed out during parsing of the file.
  
    If 'first_ids_file' is non-empty, it is used to override the setting for the
    first_ids_file attribute of the <grit> root node. Note that the first_ids_file
    parameter should be relative to the cwd, even though the first_ids_file
    attribute of the <grit> node is relative to the grd file.
  
    If 'target_platform' is set, this is used to determine the target
    platform of builds, instead of using |sys.platform|.
  
    Args:
      filename_or_stream: './bla.xml'
      dir: None (if filename_or_stream is a filename) or '.'
      stop_after: 'inputs'
      first_ids_file: 'GRIT_DIR/../gritsettings/resource_ids'
      debug: False
      defines: dictionary of defines, like {'chromeos': '1'}
      target_platform: None or the value that would be returned by sys.platform
          on your target platform.
      predetermined_ids_file: File path to a file containing a pre-determined
          mapping from resource names to resource ids which will be used to assign
          resource ids to those resources.
  
    Return:
      Subclass of grit.node.base.Node
  
    Throws:
      grit.exception.Parsing
    '''
  
    if isinstance(filename_or_stream, six.string_types):
      source = filename_or_stream
      if dir is None:
        dir = util.dirname(filename_or_stream)
    else:
      source = None
  
    handler = GrdContentHandler(stop_after=stop_after, debug=debug, dir=dir,
                                defines=defines, tags_to_ignore=tags_to_ignore,
                                target_platform=target_platform, source=source)
    try:
      xml.sax.parse(filename_or_stream, handler)
    except StopParsingException:
      assert stop_after
      pass
    except:
      if not debug:
        print("parse exception: run GRIT with the -x flag to debug .grd problems")
      raise
  
    if handler.root.name != 'grit':
      raise exception.MissingElement("root tag must be <grit>")
  
    if hasattr(handler.root, 'SetOwnDir'):
      # Fix up the base_dir so it is relative to the input file.
      assert dir is not None
      handler.root.SetOwnDir(dir)
  
    if isinstance(handler.root, misc.GritNode):
      handler.root.SetPredeterminedIdsFile(predetermined_ids_file)
      if first_ids_file:
        # Make the path to the first_ids_file relative to the grd file,
        # unless it begins with GRIT_DIR.
        GRIT_DIR_PREFIX = 'GRIT_DIR'
        if not (first_ids_file.startswith(GRIT_DIR_PREFIX)
            and first_ids_file[len(GRIT_DIR_PREFIX)] in ['/', '\\']):
          rel_dir = os.path.relpath(os.getcwd(), dir)
          first_ids_file = util.normpath(os.path.join(rel_dir, first_ids_file))
        handler.root.attrs['first_ids_file'] = first_ids_file
      # Assign first ids to the nodes that don't have them.
      handler.root.AssignFirstIds(filename_or_stream, defines)
  
    return handler.root
function_tokens: def Parse ( filename_or_stream , dir = None , stop_after = None , first_ids_file = None , debug = False , defines = None , tags_to_ignore = None , target_platform = None , predetermined_ids_file = None ) : if isinstance ( filename_or_stream , six . string_types ) : source = filename_or_stream if dir is None : dir = util . dirname ( filename_or_stream ) else : source = None handler = GrdContentHandler ( stop_after = stop_after , debug = debug , dir = dir , defines = defines , tags_to_ignore = tags_to_ignore , target_platform = target_platform , source = source ) try : xml . sax . parse ( filename_or_stream , handler ) except StopParsingException : assert stop_after pass except : if not debug : print ( "parse exception: run GRIT with the -x flag to debug .grd problems" ) raise if handler . root . name != 'grit' : raise exception . MissingElement ( "root tag must be <grit>" ) if hasattr ( handler . root , 'SetOwnDir' ) : # Fix up the base_dir so it is relative to the input file. assert dir is not None handler . root . SetOwnDir ( dir ) if isinstance ( handler . root , misc . GritNode ) : handler . root . SetPredeterminedIdsFile ( predetermined_ids_file ) if first_ids_file : # Make the path to the first_ids_file relative to the grd file, # unless it begins with GRIT_DIR. GRIT_DIR_PREFIX = 'GRIT_DIR' if not ( first_ids_file . startswith ( GRIT_DIR_PREFIX ) and first_ids_file [ len ( GRIT_DIR_PREFIX ) ] in [ '/' , '\\' ] ) : rel_dir = os . path . relpath ( os . getcwd ( ) , dir ) first_ids_file = util . normpath ( os . path . join ( rel_dir , first_ids_file ) ) handler . root . attrs [ 'first_ids_file' ] = first_ids_file # Assign first ids to the nodes that don't have them. handler . root . AssignFirstIds ( filename_or_stream , defines ) return handler . root