MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / _parse_element

Function _parse_element

dm_control/mjcf/schema.py:87–129  ·  view source on GitHub ↗

Parses an element in the schema.

(element_xml)

Source from the content-addressed store, hash-verified

85
86
87def _parse_element(element_xml):
88 """Parses an <element> element in the schema."""
89 name = element_xml.get('name')
90 if not name:
91 raise ValueError('Element must always have a name')
92 repeated = _str2bool(element_xml.get('repeated'))
93 on_demand = _str2bool(element_xml.get('on_demand'))
94
95 attributes = collections.OrderedDict()
96 attributes_xml = element_xml.find('attributes')
97 if attributes_xml is not None:
98 for attribute_xml in attributes_xml.findall('attribute'):
99 attributes[attribute_xml.get('name')] = _parse_attribute(attribute_xml)
100
101 identifier = None
102 namespace = None
103 for attribute_spec in attributes.values():
104 if attribute_spec.type == attribute.Identifier:
105 identifier = attribute_spec.name
106 namespace = element_xml.get('namespace') or name
107
108 children = collections.OrderedDict()
109 children_xml = element_xml.find('children')
110 if children_xml is not None:
111 for child_xml in children_xml.findall('element'):
112 children[child_xml.get('name')] = _parse_element(child_xml)
113
114 element_spec = ElementSpec(
115 name, repeated, on_demand, identifier, namespace, attributes, children)
116
117 recursive = _str2bool(element_xml.get('recursive'))
118 if recursive:
119 element_spec.children[name] = element_spec
120
121 common_keys = set(element_spec.attributes).intersection(element_spec.children)
122 if common_keys:
123 raise RuntimeError(
124 'Element \'{}\' contains the following attributes and children with '
125 'the same name: \'{}\'. This violates the design assumptions of '
126 'this library. Please file a bug report. Thank you.'
127 .format(name, sorted(common_keys)))
128
129 return element_spec
130
131
132def _parse_attribute(attribute_xml):

Callers 1

parse_schemaFunction · 0.85

Calls 5

_str2boolFunction · 0.85
_parse_attributeFunction · 0.85
valuesMethod · 0.80
getMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…