zserio.walker module¶
The module implements generic walker through given zserio object tree.
- class zserio.walker.AndWalkFilter(walk_filters: List[WalkFilter])[source]¶
Bases:
WalkFilter
Walk filter which implements composition of particular filters.
The filters are called sequentially and logical and is applied on theirs results. Note that all filters are always called.
Constructor.
- Parameters:
walk_filters – List of filters to use in composition.
- after_array(array: List[Any], member_info: MemberInfo) bool [source]¶
Called after an array.
- Parameters:
array – Zserio array.
member_info – Array member info.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- after_compound(compound: Any, member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called after a compound object.
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- after_value(value: Any, member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called after a simple (or an unset compound or array - i.e. None) value.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- before_array(array: List[Any], member_info: MemberInfo) bool [source]¶
Called before an array.
Note that for None arrays (i.e. non-present optionals) the before_value with None is called instead!
- Parameters:
array – Zserio array.
member_info – Array member info.
- Returns:
True when the walking should continue to the array.
- before_compound(compound: Any, member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called before a compound object.
Note that for uninitialized compounds (i.e. None) the before_value method is called instead!
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- Returns:
True when the walking should continue into the compound object, False otherwise.
- before_value(value: Any, member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called before a simple (or an unset compound or array - i.e. None) value.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- Returns:
True when the walking should continue to the simple value, False otherwise.
- class zserio.walker.ArrayLengthWalkFilter(max_array_length: int)[source]¶
Bases:
WalkFilter
Walk filter which allows to walk only to the given maximum array length.
Constructor.
- Parameters:
max_array_length – Maximum array length to walk to.
- after_array(_array: List[Any], _member_info: MemberInfo) bool [source]¶
Called after an array.
- Parameters:
array – Zserio array.
member_info – Array member info.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- after_compound(_compound: Any, _member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called after a compound object.
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- after_value(_value: Any, _member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called after a simple (or an unset compound or array - i.e. None) value.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- before_array(_array: List[Any], _member_info: MemberInfo) bool [source]¶
Called before an array.
Note that for None arrays (i.e. non-present optionals) the before_value with None is called instead!
- Parameters:
array – Zserio array.
member_info – Array member info.
- Returns:
True when the walking should continue to the array.
- before_compound(_compound: Any, _member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called before a compound object.
Note that for uninitialized compounds (i.e. None) the before_value method is called instead!
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- Returns:
True when the walking should continue into the compound object, False otherwise.
- before_value(_value: Any, _member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called before a simple (or an unset compound or array - i.e. None) value.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- Returns:
True when the walking should continue to the simple value, False otherwise.
- class zserio.walker.DefaultWalkFilter[source]¶
Bases:
WalkFilter
Default walk filter which filters nothing.
- after_array(_array: List[Any], _member_info: MemberInfo) bool [source]¶
Called after an array.
- Parameters:
array – Zserio array.
member_info – Array member info.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- after_compound(_compound: Any, _member_info: MemberInfo, _element_index: int | None = None) bool [source]¶
Called after a compound object.
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- after_value(_value: Any, _member_info: MemberInfo, _element_index: int | None = None) bool [source]¶
Called after a simple (or an unset compound or array - i.e. None) value.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- before_array(_array: List[Any], _member_info: MemberInfo) bool [source]¶
Called before an array.
Note that for None arrays (i.e. non-present optionals) the before_value with None is called instead!
- Parameters:
array – Zserio array.
member_info – Array member info.
- Returns:
True when the walking should continue to the array.
- before_compound(_compound: Any, _member_info: MemberInfo, _element_index: int | None = None) bool [source]¶
Called before a compound object.
Note that for uninitialized compounds (i.e. None) the before_value method is called instead!
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- Returns:
True when the walking should continue into the compound object, False otherwise.
- before_value(_value: Any, _member_info: MemberInfo, _element_index: int | None = None) bool [source]¶
Called before a simple (or an unset compound or array - i.e. None) value.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- Returns:
True when the walking should continue to the simple value, False otherwise.
- class zserio.walker.DefaultWalkObserver[source]¶
Bases:
WalkObserver
Default walk observer which just does nothing.
- begin_array(_array: List[Any], member_info: MemberInfo) None [source]¶
Called at the beginning of an array.
Note that for None arrays (i.e. non-present optionals) the visit_value with None is called instead!
- Parameters:
array – Zserio array.
member_info – Array member info.
- begin_compound(_compound: Any, member_info: MemberInfo, element_index: int | None = None) None [source]¶
Called at the beginning of an compound field object.
Note that for None compounds (i.e. uninitialized or optionals) the visit_value method is called instead!
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- begin_root(_root: Any) None [source]¶
Called for the root compound zserio object which is to be walked-through.
- Parameters:
compound – Root compound zserio object.
- end_array(_array: List[Any], _member_info: MemberInfo) None [source]¶
Called at the end of an array.
- Parameters:
array – Zserio array.
member_info – Array member info.
- end_compound(_compound: Any, _member_info: MemberInfo, element_index: int | None = None) None [source]¶
Called at the end of just walked compound object.
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- end_root(_root: Any) None [source]¶
Called at the end of just walked root compound zserio object.
- Parameters:
compound – Root compound zserio object.
- visit_value(_value: Any, member_info: MemberInfo, element_index: int | None = None) None [source]¶
Called when a simple (or an unset compound or array - i.e. None) value is reached.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- class zserio.walker.DepthWalkFilter(max_depth: int)[source]¶
Bases:
WalkFilter
Walk filter which allows to walk only to the given maximum depth.
Constructor.
- Parameters:
max_depth – Maximum depth to walk to.
- after_array(_array: List[Any], _member_info: MemberInfo) bool [source]¶
Called after an array.
- Parameters:
array – Zserio array.
member_info – Array member info.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- after_compound(_compound: Any, _member_info: MemberInfo, _element_index: int | None = None) bool [source]¶
Called after a compound object.
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- after_value(_value: Any, _member_info: MemberInfo, _element_index: int | None = None) bool [source]¶
Called after a simple (or an unset compound or array - i.e. None) value.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- before_array(_array: List[Any], _member_info: MemberInfo) bool [source]¶
Called before an array.
Note that for None arrays (i.e. non-present optionals) the before_value with None is called instead!
- Parameters:
array – Zserio array.
member_info – Array member info.
- Returns:
True when the walking should continue to the array.
- before_compound(_compound: Any, _member_info: MemberInfo, _element_index: int | None = None) bool [source]¶
Called before a compound object.
Note that for uninitialized compounds (i.e. None) the before_value method is called instead!
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- Returns:
True when the walking should continue into the compound object, False otherwise.
- before_value(_value: Any, _member_info: MemberInfo, _element_index: int | None = None) bool [source]¶
Called before a simple (or an unset compound or array - i.e. None) value.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- Returns:
True when the walking should continue to the simple value, False otherwise.
- class zserio.walker.RegexWalkFilter(path_regex: str)[source]¶
Bases:
WalkFilter
Walk filter which allows to walk only paths matching the given regex.
The path is constructed from field names within the root object, thus the root object itself is not part of the path.
Array elements have the index appended to the path so that e.g. “compound.arrayField[0]” will match only the first element in the array “arrayField”.
Constructor.
- Parameters:
path_regex – Path regex to use for filtering.
- after_array(_array: List[Any], _member_info: MemberInfo) bool [source]¶
Called after an array.
- Parameters:
array – Zserio array.
member_info – Array member info.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- after_compound(_compound: Any, member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called after a compound object.
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- after_value(_value: Any, member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called after a simple (or an unset compound or array - i.e. None) value.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- before_array(array: List[Any], member_info: MemberInfo) bool [source]¶
Called before an array.
Note that for None arrays (i.e. non-present optionals) the before_value with None is called instead!
- Parameters:
array – Zserio array.
member_info – Array member info.
- Returns:
True when the walking should continue to the array.
- before_compound(compound: Any, member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called before a compound object.
Note that for uninitialized compounds (i.e. None) the before_value method is called instead!
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- Returns:
True when the walking should continue into the compound object, False otherwise.
- before_value(value: Any, member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called before a simple (or an unset compound or array - i.e. None) value.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- Returns:
True when the walking should continue to the simple value, False otherwise.
- class zserio.walker.WalkFilter[source]¶
Bases:
object
Interface for filters which can influence the walking.
- after_array(array: List[Any], member_info: MemberInfo) bool [source]¶
Called after an array.
- Parameters:
array – Zserio array.
member_info – Array member info.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- after_compound(compound: Any, member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called after a compound object.
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- after_value(value: Any, member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called after a simple (or an unset compound or array - i.e. None) value.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- Returns:
True when the walking should continue to a next sibling, False to return to the parent.
- before_array(array: List[Any], member_info: MemberInfo) bool [source]¶
Called before an array.
Note that for None arrays (i.e. non-present optionals) the before_value with None is called instead!
- Parameters:
array – Zserio array.
member_info – Array member info.
- Returns:
True when the walking should continue to the array.
- before_compound(compound: Any, member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called before a compound object.
Note that for uninitialized compounds (i.e. None) the before_value method is called instead!
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- Returns:
True when the walking should continue into the compound object, False otherwise.
- before_value(value: Any, member_info: MemberInfo, element_index: int | None = None) bool [source]¶
Called before a simple (or an unset compound or array - i.e. None) value.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- Returns:
True when the walking should continue to the simple value, False otherwise.
- class zserio.walker.WalkObserver[source]¶
Bases:
object
Interface for observers which are called by the walker.
- begin_array(array: List[Any], member_info: MemberInfo) None [source]¶
Called at the beginning of an array.
Note that for None arrays (i.e. non-present optionals) the visit_value with None is called instead!
- Parameters:
array – Zserio array.
member_info – Array member info.
- begin_compound(compound: Any, member_info: MemberInfo, element_index: int | None = None) None [source]¶
Called at the beginning of an compound field object.
Note that for None compounds (i.e. uninitialized or optionals) the visit_value method is called instead!
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- begin_root(compound: Any) None [source]¶
Called for the root compound zserio object which is to be walked-through.
- Parameters:
compound – Root compound zserio object.
- end_array(array: List[Any], member_info: MemberInfo) None [source]¶
Called at the end of an array.
- Parameters:
array – Zserio array.
member_info – Array member info.
- end_compound(compound: Any, member_info: MemberInfo, element_index: int | None = None) None [source]¶
Called at the end of just walked compound object.
- Parameters:
compound – Compound zserio object.
member_info – Compound member info.
element_index – Element index in array or None if the compound is not in array.
- end_root(compound: Any) None [source]¶
Called at the end of just walked root compound zserio object.
- Parameters:
compound – Root compound zserio object.
- visit_value(value: Any, member_info: MemberInfo, element_index: int | None = None) None [source]¶
Called when a simple (or an unset compound or array - i.e. None) value is reached.
- Parameters:
value – Simple value.
member_info – Member info.
element_index – Element index in array or None if the value is not in array.
- class zserio.walker.Walker(walk_observer: WalkObserver, walk_filter: WalkFilter | None = None)[source]¶
Bases:
object
Walker through zserio objects, based on generated type info (see -withTypeInfoCode).
Constructor.
- Parameters:
walk_observer – Observer to use during walking.
walk_filter – Walk filter to use.