mrcrowbar.refs module¶
Definition classes for cross-references.
- class mrcrowbar.refs.Chain[source]¶
Bases:
Ref
Create a new Ref instance.
- path
The path to traverse from the context object to reach the target. Child lookups should be in property dot syntax (e.g. obj1.obj2.target). For Blocks that are constructed by other Blocks, you can use the _parent property to traverse up the stack.
- allow_write
Allow modification of the target with the set() method.
- class mrcrowbar.refs.ConstRef(path)[source]¶
Bases:
Ref
Create a new Ref instance.
- path
The path to traverse from the context object to reach the target. Child lookups should be in property dot syntax (e.g. obj1.obj2.target). For Blocks that are constructed by other Blocks, you can use the _parent property to traverse up the stack.
- class mrcrowbar.refs.EndOffset(path, neg=False, align=1)[source]¶
Bases:
Ref
Create a new EndOffset instance.
- path
The path to traverse from the context object to reach the target Field. Child lookups should be in property dot syntax (e.g. obj1.obj2.target). For Blocks that are constructed by other Blocks, you can use the _parent property to traverse up the stack.
- neg
Whether to return the end offset as a negative value. Useful for e.g. globally offsetting Stores which use an index relative to the very start of the file, even if the first chunk contains headers.
- align
Round up the result to the nearest multiple of this value.
- get(instance, **kwargs)[source]¶
Return an attribute from an object using the Ref path.
- instance
The object instance to traverse.
- property serialised¶
Tuple containing the contents of the object.
- class mrcrowbar.refs.Ref(path, allow_write=True)[source]¶
Bases:
object
Create a new Ref instance.
- path
The path to traverse from the context object to reach the target. Child lookups should be in property dot syntax (e.g. obj1.obj2.target). For Blocks that are constructed by other Blocks, you can use the _parent property to traverse up the stack.
- allow_write
Allow modification of the target with the set() method.
- cache(instance, name)[source]¶
Signal to the source to pre-load information.
Called by the parent Block constructor.
- get(instance, **kwargs)[source]¶
Return an attribute from an object using the Ref path.
- instance
The object instance to traverse.
- property repr¶
Plaintext summary of the object.
- property serialised¶
Tuple containing the contents of the object.
- mrcrowbar.refs.property_get(prop, instance, **kwargs)[source]¶
Wrapper for property reads which auto-dereferences Refs if required.
- prop
A Ref (which gets dereferenced and returned) or any other value (which gets returned).
- instance
The context object used to dereference the Ref.
- mrcrowbar.refs.property_set(prop, instance, value, **kwargs)[source]¶
Wrapper for property writes which auto-deferences Refs.
- prop
A Ref (which gets dereferenced and the target value set).
- instance
The context object used to dereference the Ref.
- value
The value to set the property to.
Throws AttributeError if prop is not a Ref.
- mrcrowbar.refs.view_property(prop)[source]¶
Wrapper for attributes of a View class which auto-dereferences Refs.
Equivalent to setting a property on the class with the getter wrapped with property_get(), and the setter wrapped with property_set().
- prop
A string containing the name of the class attribute to wrap.