(xml_root, escape_separators=False,
           model_dir='', resolve_references=True, assets=None)
Parses a complete MJCF model from an XML.

  Args:
    xml_root: An `etree.Element` object.
    escape_separators: (optional) A boolean, whether to replace '/' characters
      in element identifiers. If `False`, any '/' present in the XML causes
      a ValueError to be raised.
    model_dir: (optional) Path to the directory containing the model XML file.
      This is used to prefix the paths of all asset files.
    resolve_references: (optional) A boolean indicating whether the parser
      should attempt to resolve reference attributes to a corresponding element.
    assets: (optional) A dictionary of pre-loaded assets, of the form
      `{filename: bytestring}`. If present, PyMJCF will search for assets in
      this dictionary before attempting to load them from the filesystem.

  Returns:
    An `mjcf.RootElement`.

  Raises:
    ValueError: If `xml_root`'s tag is not 'mujoco.*'.
Parses a complete MJCF model from an XML.
Parses a complete MJCF model from an XML .
def _parse(xml_root, escape_separators=False,
           model_dir='', resolve_references=True, assets=None):
  """Parses a complete MJCF model from an XML.

  Args:
    xml_root: An `etree.Element` object.
    escape_separators: (optional) A boolean, whether to replace '/' characters
      in element identifiers. If `False`, any '/' present in the XML causes
      a ValueError to be raised.
    model_dir: (optional) Path to the directory containing the model XML file.
      This is used to prefix the paths of all asset files.
    resolve_references: (optional) A boolean indicating whether the parser
      should attempt to resolve reference attributes to a corresponding element.
    assets: (optional) A dictionary of pre-loaded assets, of the form
      `{filename: bytestring}`. If present, PyMJCF will search for assets in
      this dictionary before attempting to load them from the filesystem.

  Returns:
    An `mjcf.RootElement`.

  Raises:
    ValueError: If `xml_root`'s tag is not 'mujoco.*'.
  """

  assets = assets or {}

  if not xml_root.tag.startswith('mujoco'):
    raise ValueError('Root element of the XML should be <mujoco.*>: got <{}>'
                     .format(xml_root.tag))

  with debugging.freeze_current_stack_trace():
    # Recursively parse any included XML files.
    to_include = []
    for include_tag in xml_root.findall('include'):
      try:
        # First look for the path to the included XML file in the assets dict.
        path_or_xml_string = assets[include_tag.attrib['file']]
        parsing_func = from_xml_string
      except KeyError:
        # If it's not present in the assets dict then attempt to load the XML
        # from the filesystem.
        path_or_xml_string = os.path.join(model_dir, include_tag.attrib['file'])
        parsing_func = from_path
      included_mjcf = parsing_func(
          path_or_xml_string,
          escape_separators=escape_separators,
          resolve_references=resolve_references,
          assets=assets)
      to_include.append(included_mjcf)
      # We must remove <include/> tags before parsing the main XML file, since
      # these are a schema violation.
      xml_root.remove(include_tag)

    # Parse the main XML file.
    try:
      model = xml_root.attrib.pop('model')
    except KeyError:
      model = None
    mjcf_root = element.RootElement(
        model=model, model_dir=model_dir, assets=assets)
    _parse_children(xml_root, mjcf_root, escape_separators)

    # Merge in the included XML files.
    for included_mjcf in to_include:
      # The included MJCF might have been automatically assigned a model name
      # that conficts with that of `mjcf_root`, so we override it here.
      included_mjcf.model = mjcf_root.model
      mjcf_root.include_copy(included_mjcf)

    if resolve_references:
      mjcf_root.resolve_references()
    return mjcf_root
def _parse ( xml_root , escape_separators = False , model_dir = '' , resolve_references = True , assets = None ) : assets = assets or { } if not xml_root . tag . startswith ( 'mujoco' ) : raise ValueError ( 'Root element of the XML should be <mujoco.*>: got <{}>' . format ( xml_root . tag ) ) with debugging . freeze_current_stack_trace ( ) : # Recursively parse any included XML files. to_include = [ ] for include_tag in xml_root . findall ( 'include' ) : try : # First look for the path to the included XML file in the assets dict. path_or_xml_string = assets [ include_tag . attrib [ 'file' ] ] parsing_func = from_xml_string except KeyError : # If it's not present in the assets dict then attempt to load the XML # from the filesystem. path_or_xml_string = os . path . join ( model_dir , include_tag . attrib [ 'file' ] ) parsing_func = from_path included_mjcf = parsing_func ( path_or_xml_string , escape_separators = escape_separators , resolve_references = resolve_references , assets = assets ) to_include . append ( included_mjcf ) # We must remove <include/> tags before parsing the main XML file, since # these are a schema violation. xml_root . remove ( include_tag ) # Parse the main XML file. try : model = xml_root . attrib . pop ( 'model' ) except KeyError : model = None mjcf_root = element . RootElement ( model = model , model_dir = model_dir , assets = assets ) _parse_children ( xml_root , mjcf_root , escape_separators ) # Merge in the included XML files. for included_mjcf in to_include : # The included MJCF might have been automatically assigned a model name # that conficts with that of `mjcf_root`, so we override it here. included_mjcf . model = mjcf_root . model mjcf_root . include_copy ( included_mjcf ) if resolve_references : mjcf_root . resolve_references ( ) return mjcf_root