| 246 | """A string attribute that represents a unique identifier of an element.""" |
| 247 | |
| 248 | def _assign(self, value): |
| 249 | if not isinstance(value, str): |
| 250 | raise ValueError('Expect a string value: got {}'.format(value)) |
| 251 | elif not value: |
| 252 | self.clear() |
| 253 | elif self._parent.spec.namespace == 'body' and value == 'world': |
| 254 | raise ValueError('A body cannot be named \'world\'. ' |
| 255 | 'The name \'world\' is used by MuJoCo to refer to the ' |
| 256 | '<worldbody>.') |
| 257 | elif constants.PREFIX_SEPARATOR in value: |
| 258 | raise ValueError( |
| 259 | 'An identifier cannot contain a {!r}, ' |
| 260 | 'as this is reserved for scoping purposes: got {!r}' |
| 261 | .format(constants.PREFIX_SEPARATOR, value)) |
| 262 | else: |
| 263 | old_value = self._value |
| 264 | if value != old_value: |
| 265 | self._parent.namescope.add( |
| 266 | self._parent.spec.namespace, value, self._parent) |
| 267 | if old_value: |
| 268 | self._parent.namescope.remove(self._parent.spec.namespace, old_value) |
| 269 | self._value = value |
| 270 | |
| 271 | def _before_clear(self): |
| 272 | if self._value: |