remerkleable package

Submodules

remerkleable.basic module

exception remerkleable.basic.OperationNotSupported[source]

Bases: Exception

class remerkleable.basic.bit(value: int)[source]

Bases: boolean

class remerkleable.basic.boolean(value: int)[source]

Bases: int, BasicView

classmethod coerce_view(v)[source]
Return type:

TypeVar(BoolV, bound= boolean)

classmethod decode_bytes(bytez)[source]
Return type:

TypeVar(BoolV, bound= boolean)

encode_bytes()[source]
Return type:

bytes

classmethod from_obj(obj)[source]
Return type:

TypeVar(BoolV, bound= boolean)

to_obj()[source]
Return type:

Union[dict, list, tuple, str, int, bool, None]

classmethod type_byte_length()[source]
Return type:

int

classmethod type_repr()[source]
Return type:

str

class remerkleable.basic.byte(value: int)[source]

Bases: uint8

class remerkleable.basic.uint(value: int)[source]

Bases: int, BasicView

classmethod coerce_view(v)[source]
Return type:

TypeVar(T, bound= uint)

classmethod decode_bytes(bytez)[source]
Return type:

TypeVar(T, bound= uint)

encode_bytes()[source]
Return type:

bytes

classmethod from_obj(obj)[source]
Return type:

TypeVar(T, bound= uint)

to_obj()[source]
Return type:

Union[dict, list, tuple, str, int, bool, None]

classmethod type_repr()[source]
Return type:

str

class remerkleable.basic.uint128(value: int)[source]

Bases: uint

to_obj()[source]
Return type:

Union[dict, list, tuple, str, int, bool, None]

classmethod type_byte_length()[source]
Return type:

int

class remerkleable.basic.uint16(value: int)[source]

Bases: uint

classmethod type_byte_length()[source]
Return type:

int

class remerkleable.basic.uint256(value: int)[source]

Bases: uint

to_obj()[source]
Return type:

Union[dict, list, tuple, str, int, bool, None]

classmethod type_byte_length()[source]
Return type:

int

class remerkleable.basic.uint32(value: int)[source]

Bases: uint

classmethod type_byte_length()[source]
Return type:

int

class remerkleable.basic.uint64(value: int)[source]

Bases: uint

classmethod type_byte_length()[source]
Return type:

int

class remerkleable.basic.uint8(value: int)[source]

Bases: uint

classmethod type_byte_length()[source]
Return type:

int

remerkleable.bitfields module

class remerkleable.bitfields.Bitlist(*args, **kwargs)[source]

Bases: BitsView

append(v)[source]
classmethod contents_depth()[source]
Return type:

int

classmethod decode_bytes(bytez)[source]
Return type:

TypeVar(V, bound= View)

classmethod default_node()[source]
Return type:

Node

classmethod deserialize(stream, scope)[source]
Return type:

TypeVar(V, bound= View)

get(i)[source]
Return type:

boolean

classmethod is_fixed_byte_length()[source]
Return type:

bool

classmethod key_to_static_gindex(key)[source]
Return type:

NewType()(Gindex, int)

length()[source]
Return type:

int

classmethod limit()[source]
Return type:

int

classmethod max_byte_length()[source]
Return type:

int

classmethod min_byte_length()[source]
Return type:

int

classmethod navigate_type(key)[source]
Return type:

Type[View]

pop()[source]
serialize(stream)[source]
Return type:

int

set(i, v)[source]
Return type:

None

classmethod tree_depth()[source]
Return type:

int

classmethod type_repr()[source]
Return type:

str

value_byte_length()[source]
Return type:

int

class remerkleable.bitfields.BitsView(backing: Node | None = None, hook: Callable[[HV], None] | None = None, **kwargs)[source]

Bases: BackedView, Sequence

classmethod coerce_view(v)[source]
Return type:

TypeVar(V, bound= View)

classmethod decode_bytes(bytez)[source]
Return type:

TypeVar(V, bound= View)

encode_bytes()[source]
Return type:

bytes

classmethod from_obj(obj)[source]
Return type:

TypeVar(V, bound= View)

get(i)[source]
Return type:

boolean

length()[source]
Return type:

int

navigate_view(key)[source]
Return type:

View

set(i, v)[source]
Return type:

None

to_obj()[source]
Return type:

Union[dict, list, tuple, str, int, bool, None]

classmethod tree_depth()[source]
Return type:

int

class remerkleable.bitfields.Bitvector(*args, **kwargs)[source]

Bases: BitsView, FixedByteLengthViewHelper

classmethod default_node()[source]
Return type:

Node

classmethod deserialize(stream, scope)[source]
Return type:

TypeVar(V, bound= View)

get(i)[source]
Return type:

boolean

classmethod key_to_static_gindex(key)[source]
Return type:

NewType()(Gindex, int)

length()[source]
Return type:

int

classmethod navigate_type(key)[source]
Return type:

Type[View]

serialize(stream)[source]
Return type:

int

set(i, v)[source]
Return type:

None

classmethod tree_depth()[source]
Return type:

int

classmethod type_byte_length()[source]
Return type:

int

classmethod type_repr()[source]
Return type:

str

classmethod vector_length()[source]
Return type:

int

remerkleable.byte_vector module

remerkleable.complex module

class remerkleable.complex.ComplexView(backing: Node | None = None, hook: Callable[[HV], None] | None = None, **kwargs)[source]

Bases: SubtreeView

classmethod decode_bytes(bytez)[source]
Return type:

TypeVar(V, bound= View)

encode_bytes()[source]
Return type:

bytes

class remerkleable.complex.Container(*args, backing: Node | None = None, hook: Callable[[HV], None] | None = None, append_nodes: List[Node] | None = None, **kwargs)[source]

Bases: _ContainerBase

classmethod coerce_view(v)[source]
Return type:

TypeVar(CV, bound= Container)

classmethod decode_bytes(bytez)[source]
Return type:

TypeVar(V, bound= View)

classmethod default_node()[source]
Return type:

Node

classmethod deserialize(stream, scope)[source]
Return type:

TypeVar(CV, bound= Container)

classmethod fields()[source]
Return type:

Dict[str, Type[View]]

classmethod from_obj(obj)[source]
Return type:

TypeVar(CV, bound= Container)

classmethod is_fixed_byte_length()[source]
Return type:

bool

classmethod is_packed()[source]
Return type:

bool

classmethod item_elem_cls(i)[source]
Return type:

Type[View]

classmethod key_to_static_gindex(key)[source]
Return type:

NewType()(Gindex, int)

classmethod max_byte_length()[source]
Return type:

int

classmethod min_byte_length()[source]
Return type:

int

classmethod navigate_type(key)[source]
Return type:

Type[View]

navigate_view(key)[source]
Return type:

View

serialize(stream)[source]
Return type:

int

to_obj()[source]
Return type:

Union[dict, list, tuple, str, int, bool, None]

classmethod tree_depth()[source]
Return type:

int

classmethod type_byte_length()[source]
Return type:

int

classmethod type_repr()[source]
Return type:

str

value_byte_length()[source]
Return type:

int

class remerkleable.complex.FieldOffset(key, typ, offset)[source]

Bases: tuple

key: str

Alias for field number 0

offset: int

Alias for field number 2

typ: Type[View]

Alias for field number 1

class remerkleable.complex.List(*args, backing: Node | None = None, hook: Callable[[HV], None] | None = None, **kwargs)[source]

Bases: MonoSubtreeView

append(v)[source]
classmethod contents_depth()[source]
Return type:

int

classmethod default_node()[source]
Return type:

Node

get(i)[source]
Return type:

View

classmethod is_fixed_byte_length()[source]
Return type:

bool

classmethod is_packed()[source]
Return type:

bool

classmethod is_valid_count(count)[source]
Return type:

bool

classmethod item_elem_cls(i)[source]
Return type:

Type[View]

classmethod key_to_static_gindex(key)[source]
Return type:

NewType()(Gindex, int)

length()[source]
Return type:

int

classmethod limit()[source]
Return type:

int

classmethod max_byte_length()[source]
Return type:

int

classmethod min_byte_length()[source]
Return type:

int

classmethod navigate_type(key)[source]
Return type:

Type[View]

pop()[source]
set(i, v)[source]
Return type:

None

to_obj()[source]
Return type:

Union[dict, list, tuple, str, int, bool, None]

classmethod tree_depth()[source]
Return type:

int

classmethod type_repr()[source]
Return type:

str

value_byte_length()[source]
Return type:

int

class remerkleable.complex.MonoSubtreeView(backing: Node | None = None, hook: Callable[[HV], None] | None = None, **kwargs)[source]

Bases: Sequence, ComplexView

classmethod coerce_view(v)[source]
Return type:

TypeVar(M, bound= MonoSubtreeView)

classmethod deserialize(stream, scope)[source]
Return type:

TypeVar(M, bound= MonoSubtreeView)

classmethod element_cls()[source]
Return type:

Type[View]

classmethod from_obj(obj)[source]
Return type:

TypeVar(M, bound= MonoSubtreeView)

classmethod is_valid_count(count)[source]
Return type:

bool

classmethod item_elem_cls(i)[source]
Return type:

Type[View]

classmethod key_to_static_gindex(key)[source]
Return type:

NewType()(Gindex, int)

length()[source]
Return type:

int

classmethod navigate_type(key)[source]
Return type:

Type[View]

navigate_view(key)[source]
Return type:

View

readonly_iter()[source]
serialize(stream)[source]
Return type:

int

classmethod to_chunk_length(elems_length)[source]
Return type:

int

classmethod views_into_chunks(views)[source]
Return type:

List[Node]

class remerkleable.complex.Vector(*args, backing: Node | None = None, hook: Callable[[HV], None] | None = None, **kwargs)[source]

Bases: MonoSubtreeView

classmethod default_node()[source]
Return type:

Node

get(i)[source]
Return type:

View

classmethod is_fixed_byte_length()[source]
Return type:

bool

classmethod is_valid_count(count)[source]
Return type:

bool

classmethod key_to_static_gindex(key)[source]
Return type:

NewType()(Gindex, int)

length()[source]
Return type:

int

classmethod max_byte_length()[source]
Return type:

int

classmethod min_byte_length()[source]
Return type:

int

classmethod navigate_type(key)[source]
Return type:

Type[View]

set(i, v)[source]
Return type:

None

to_obj()[source]
Return type:

Union[dict, list, tuple, str, int, bool, None]

classmethod type_repr()[source]
Return type:

str

value_byte_length()[source]
Return type:

int

classmethod vector_length()[source]
Return type:

int

remerkleable.complex.decode_offset(stream)[source]
Return type:

uint32

remerkleable.complex.encode_offset(stream, offset)[source]

remerkleable.core module

class remerkleable.core.BackedView(backing: Node | None = None, hook: Callable[[HV], None] | None = None, **kwargs)[source]

Bases: View

get_backing()[source]
Return type:

Node

set_backing(value)[source]
classmethod view_from_backing(node, hook=None)[source]
Return type:

TypeVar(BackedV, bound= BackedView)

class remerkleable.core.BasicView(*args, **kwargs)[source]

Bases: FixedByteLengthViewHelper, Protocol

backing_from_base(base, i)[source]
Return type:

Node

classmethod basic_view_from_backing(node, i)[source]
Return type:

TypeVar(BV, bound= BasicView)

copy()[source]
Return type:

TypeVar(V, bound= View)

classmethod default_node()[source]
Return type:

Node

get_backing()[source]
Return type:

Node

classmethod pack_views(views)[source]
Return type:

List[Node]

set_backing(value)[source]
classmethod view_from_backing(node, hook=None)[source]
Return type:

TypeVar(BV, bound= BasicView)

class remerkleable.core.FixedByteLengthViewHelper(*args, **kwargs)[source]

Bases: View, Protocol

classmethod deserialize(stream, scope)[source]
Return type:

TypeVar(V, bound= View)

classmethod is_fixed_byte_length()[source]
Return type:

bool

classmethod max_byte_length()[source]
Return type:

int

classmethod min_byte_length()[source]
Return type:

int

value_byte_length()[source]
Return type:

int

exception remerkleable.core.ObjParseException[source]

Bases: Exception

class remerkleable.core.Path(anchor, path=None)[source]

Bases: object

anchor: Type[View]
static from_raw_path(anchor, path)[source]
Return type:

Path

gindex(view=None)[source]
Return type:

NewType()(Gindex, int)

navigate_type()[source]
Return type:

Type[View]

navigate_view(v)[source]
Return type:

View

path: List[Tuple[Any, Type[View]]]
class remerkleable.core.View(*args, **kwargs)[source]

Bases: Protocol

classmethod coerce_view(v)[source]
Return type:

TypeVar(V, bound= View)

copy()[source]
Return type:

TypeVar(V, bound= View)

classmethod decode_bytes(bytez)[source]
Return type:

TypeVar(V, bound= View)

classmethod default(hook)[source]
Return type:

TypeVar(V, bound= View)

classmethod default_node()[source]
Return type:

Node

classmethod deserialize(stream, scope)[source]
Return type:

TypeVar(V, bound= View)

encode_bytes()[source]
Return type:

bytes

classmethod from_obj(obj)[source]
Return type:

TypeVar(V, bound= View)

get_backing()[source]
Return type:

Node

hash_tree_root()[source]
Return type:

NewType()(Root, bytes)

classmethod is_fixed_byte_length()[source]
Return type:

bool

key_to_dynamic_gindex(key)[source]
Return type:

NewType()(Gindex, int)

classmethod key_to_static_gindex(key)[source]
Return type:

NewType()(Gindex, int)

classmethod max_byte_length()[source]
Return type:

int

classmethod min_byte_length()[source]
Return type:

int

classmethod navigate_type(key)[source]
Return type:

Type[View]

navigate_view(key)[source]
Return type:

View

serialize(stream)[source]
Return type:

int

set_backing(value)[source]
to_obj()[source]
Return type:

Union[dict, list, tuple, str, int, bool, None]

classmethod type_byte_length()[source]
Return type:

int

classmethod type_repr()[source]
Return type:

str

value_byte_length()[source]
Return type:

int

classmethod view_from_backing(node, hook=None)[source]
Return type:

TypeVar(V, bound= View)

class remerkleable.core.ViewMeta(name, bases, namespace, **kwargs)[source]

Bases: _ProtocolMeta

remerkleable.core.bits_to_byte_int(byte)[source]
Return type:

int

remerkleable.core.byte_int_to_byte(b)[source]
Return type:

bytes

remerkleable.core.grouper(items, n, fillvalue=None)[source]

Collect data into fixed-length chunks or blocks grouper(‘ABCDEFG’, 3, ‘x’) –> ABC DEF Gxx

Return type:

Iterable[Tuple]

remerkleable.core.pack_bits_to_chunks(items)[source]
Return type:

List[Node]

remerkleable.core.pack_byte_ints_to_chunks(items)[source]
Return type:

List[Node]

remerkleable.core.pack_bytes_to_chunks(bytez)[source]
Return type:

List[Node]

remerkleable.core.pack_ints_to_chunks(items, items_per_chunk)[source]
Return type:

List[Node]

remerkleable.history module

remerkleable.history.get_target_history(history, target)[source]

Fetch an ordered, keyed, history of nodes at the given target. The sequential equal values are reduced into a single value, and keyed by the first occurrence. This is done efficiently by first comparing the top of the tree,

de-duplicating, and then recursively going deeper into the tree.

Parameters:
  • history (List[Tuple[TypeVar(K), Node]]) – An ordered keyed series of nodes, the root nodes to get the target from

  • target (NewType()(Gindex, int)) – The target node to look up, pointing to the values to return.

Return type:

List[Tuple[TypeVar(K), Node]]

Returns:

the target values, keyed by the keys of the top nodes the target values first occurred in.

remerkleable.subtree module

class remerkleable.subtree.SubtreeView(backing: Node | None = None, hook: Callable[[HV], None] | None = None, **kwargs)[source]

Bases: BackedView

get(i)[source]
Return type:

View

classmethod is_packed()[source]
Return type:

bool

classmethod item_elem_cls(i)[source]
Return type:

Type[View]

set(i, v)[source]
Return type:

None

classmethod tree_depth()[source]
Return type:

int

remerkleable.test_impl module

remerkleable.test_typing module

remerkleable.tree module

exception remerkleable.tree.NavigationError[source]

Bases: RuntimeError

class remerkleable.tree.Node(*args, **kwargs)[source]

Bases: Protocol

get_left()[source]
Return type:

Node

get_right()[source]
Return type:

Node

getter(target)[source]
Return type:

Node

is_leaf()[source]
Return type:

bool

merkle_root()[source]
Return type:

NewType()(Root, bytes)

rebind_left(v)[source]
Return type:

Node

rebind_right(v)[source]
Return type:

Node

property root: Root
setter(target, expand=False)[source]
Return type:

Callable[[Node], Node]

summarize_into(target)[source]
Return type:

Callable[[], Node]

class remerkleable.tree.PairNode(left, right)[source]

Bases: RebindableNode, Node

An optimized, with lazily-computed root, a node that references two child nodes.

get_left()[source]
Return type:

Node

get_right()[source]
Return type:

Node

is_leaf()[source]
Return type:

bool

left: Node
merkle_root()[source]
Return type:

NewType()(Root, bytes)

right: Node
class remerkleable.tree.RebindableNode(*args, **kwargs)[source]

Bases: Node

combine(left, right)[source]
Return type:

Node

rebind_left(v)[source]
Return type:

Node

rebind_right(v)[source]
Return type:

Node

setter(target, expand=False)[source]
Return type:

Callable[[Node], Node]

class remerkleable.tree.RootNode(root)[source]

Bases: Node

An optimized root-holding node. To check if a Node functions as node without children, use node.is_leaf(), since there may be more classes implementing non-child node behavior.

getter(target)[source]
Return type:

Node

is_leaf()[source]
Return type:

bool

merkle_root()[source]
Return type:

NewType()(Root, bytes)

property root: Root
setter(target, expand=False)[source]
Return type:

Callable[[Node], Node]

remerkleable.tree.compose(inner, outer)[source]
Return type:

Callable[[Node], Node]

remerkleable.tree.concat_gindices(steps)[source]
Return type:

NewType()(Gindex, int)

remerkleable.tree.get_anchor_gindex(gindex)[source]
Return type:

NewType()(Gindex, int)

remerkleable.tree.get_depth(elem_count)[source]
Return type:

int

remerkleable.tree.get_diff(a, b)[source]

Iterate over the changes of b, not common with a. Left-to-right order. Returns (a,b) tuples that can’t be diffed deeper.

Return type:

Iterator[Tuple[Node, Node]]

remerkleable.tree.gindex_bit_iter(gindex)[source]
Return type:

Tuple[Iterator[bool], int]

remerkleable.tree.identity(v)[source]
Return type:

Node

remerkleable.tree.leaf_iter(node)[source]

Iterate ove the leaf nodes of the given node. Left-to-right order.

Return type:

Iterator[Node]

remerkleable.tree.subtree_fill_to_contents(nodes, depth)[source]
Return type:

Node

remerkleable.tree.subtree_fill_to_depth(bottom, depth)[source]
Return type:

Node

remerkleable.tree.subtree_fill_to_length(bottom, depth, length)[source]
Return type:

Node

remerkleable.tree.to_gindex(index, depth)[source]
Return type:

NewType()(Gindex, int)

remerkleable.tree.zero_node(depth)[source]
Return type:

RootNode

Module contents