(self, spec, parent, attributes=None)
| 140 | '_last_attribute_error'] |
| 141 | |
| 142 | def __init__(self, spec, parent, attributes=None): |
| 143 | attributes = attributes or {} |
| 144 | |
| 145 | # For certain `asset` elements the `name` attribute can be omitted, in which |
| 146 | # case the name will be the filename without the leading path and extension. |
| 147 | # See http://www.mujoco.org/book/XMLreference.html#asset. |
| 148 | if ('name' not in attributes |
| 149 | and 'file' in attributes |
| 150 | and spec.name in _DEFAULT_NAME_FROM_FILENAME): |
| 151 | _, filename = os.path.split(attributes['file']) |
| 152 | basename, _ = os.path.splitext(filename) |
| 153 | attributes['name'] = basename |
| 154 | |
| 155 | self._spec = spec |
| 156 | self._parent = parent |
| 157 | self._attributes = collections.OrderedDict() |
| 158 | self._own_attributes = None |
| 159 | self._children = [] |
| 160 | self._attachments = collections.OrderedDict() |
| 161 | self._is_removed = False |
| 162 | self._is_worldbody = (self.tag == 'worldbody') |
| 163 | |
| 164 | if self._parent: |
| 165 | self._cached_namescope = self._parent.namescope |
| 166 | self._cached_root = self._parent.root |
| 167 | self._cached_full_identifier = '' |
| 168 | self._cached_revision = -1 |
| 169 | |
| 170 | self._last_attribute_error = None |
| 171 | |
| 172 | if debugging.debug_mode(): |
| 173 | self._init_stack = debugging.get_current_stack_trace() |
| 174 | |
| 175 | with debugging.freeze_current_stack_trace(): |
| 176 | for child_spec in self._spec.children.values(): |
| 177 | if not (child_spec.repeated or child_spec.on_demand): |
| 178 | self._children.append(_make_element(spec=child_spec, parent=self)) |
| 179 | |
| 180 | if constants.DCLASS in attributes: |
| 181 | attributes[constants.CLASS] = attributes[constants.DCLASS] |
| 182 | del attributes[constants.DCLASS] |
| 183 | |
| 184 | for attribute_name in attributes.keys(): |
| 185 | self._check_valid_attribute(attribute_name) |
| 186 | |
| 187 | for attribute_spec in self._spec.attributes.values(): |
| 188 | value = None |
| 189 | # Some Reference attributes refer to a namespace that is specified |
| 190 | # via another attribute. We therefore have to set things up for |
| 191 | # the additional indirection. |
| 192 | if attribute_spec.type is attribute_types.Reference: |
| 193 | reference_namespace = ( |
| 194 | attribute_spec.other_kwargs['reference_namespace']) |
| 195 | if reference_namespace.startswith( |
| 196 | constants.INDIRECT_REFERENCE_NAMESPACE_PREFIX): |
| 197 | attribute_spec = copy.deepcopy(attribute_spec) |
| 198 | namespace_attrib_name = reference_namespace[ |
| 199 | len(constants.INDIRECT_REFERENCE_NAMESPACE_PREFIX):] |
nothing calls this directly
no test coverage detected