Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/modules/bpy_types.py
| Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | def path_resolve(self, path, coerce=True): | ||||
| # to simplify exception handling for the caller. | # to simplify exception handling for the caller. | ||||
| value = getattr(self, attr, _sentinel) | value = getattr(self, attr, _sentinel) | ||||
| if value is _sentinel: | if value is _sentinel: | ||||
| raise ValueError("Path could not be resolved: %r" % attr) | raise ValueError("Path could not be resolved: %r" % attr) | ||||
| if value is None: | if value is None: | ||||
| return value | return value | ||||
| # If the attribute is a list property, apply subscripting. | |||||
| if isinstance(value, list) and path_rest.startswith("["): | |||||
| index_str, div, index_tail = path_rest[1:].partition("]") | |||||
| if not div: | |||||
| raise ValueError("Path index is not terminated: %s%s" % (attr, path_rest)) | |||||
| try: | |||||
| index = int(index_str) | |||||
| except ValueError: | |||||
| raise ValueError("Path index is invalid: %s[%s]" % (attr, index_str)) | |||||
| if 0 <= index < len(value): | |||||
| path_rest = index_tail | |||||
| value = value[index] | |||||
| else: | |||||
| raise IndexError("Path index out of range: %s[%s]" % (attr, index_str)) | |||||
| # Resolve the rest of the path if necessary. | # Resolve the rest of the path if necessary. | ||||
| if path_rest: | if path_rest: | ||||
| path_resolve_fn = getattr(value, "path_resolve", None) | path_resolve_fn = getattr(value, "path_resolve", None) | ||||
| if path_resolve_fn is None: | if path_resolve_fn is None: | ||||
| raise ValueError("Path %s resolves to a non RNA value" % attr) | raise ValueError("Path %s resolves to a non RNA value" % attr) | ||||
| return path_resolve_fn(path_rest, coerce) | return path_resolve_fn(path_rest, coerce) | ||||
| return value | return value | ||||
| ▲ Show 20 Lines • Show All 1,087 Lines • Show Last 20 Lines | |||||