Actual implementation of a generic MJCF element object.
| 132 | |
| 133 | |
| 134 | class _ElementImpl(base.Element): |
| 135 | """Actual implementation of a generic MJCF element object.""" |
| 136 | __slots__ = ['__weakref__', '_spec', '_parent', '_attributes', '_children', |
| 137 | '_own_attributes', '_attachments', '_is_removed', '_init_stack', |
| 138 | '_is_worldbody', '_cached_namescope', '_cached_root', |
| 139 | '_cached_full_identifier', '_cached_revision', |
| 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. |
no outgoing calls
no test coverage detected
searching dependent graphs…