22
33import struct
44from functools import cached_property
5- from typing import TYPE_CHECKING , Iterator , Optional , Union
5+ from typing import TYPE_CHECKING
66
77from dissect .esedb .c_esedb import PAGE_FLAG , TAG_FLAG , c_esedb
88
99if TYPE_CHECKING :
10+ from collections .abc import Iterator
11+
1012 from dissect .esedb .esedb import EseDB
1113
1214
@@ -81,10 +83,12 @@ def is_branch(self) -> bool:
8183 return not self .is_leaf
8284
8385 @cached_property
84- def key_prefix (self ) -> Optional [ bytes ] :
86+ def key_prefix (self ) -> bytes | None :
8587 if not self .is_root :
8688 return bytes (self .tag (0 ).data )
8789
90+ return None
91+
8892 def tag (self , num : int ) -> Tag :
8993 """Retrieve a tag by index.
9094
@@ -104,7 +108,7 @@ def tags(self) -> Iterator[Tag]:
104108 for i in range (1 , self .tag_count ):
105109 yield self .tag (i )
106110
107- def node (self , num : int ) -> Union [ BranchNode , LeafNode ] :
111+ def node (self , num : int ) -> BranchNode | LeafNode :
108112 """Retrieve a node by index.
109113
110114 Nodes are just tags, but indexed from the first tag.
@@ -123,7 +127,7 @@ def node(self, num: int) -> Union[BranchNode, LeafNode]:
123127
124128 return self ._node_cache [num ]
125129
126- def nodes (self ) -> Iterator [Union [ BranchNode , LeafNode ] ]:
130+ def nodes (self ) -> Iterator [BranchNode | LeafNode ]:
127131 """Yield all nodes."""
128132 for i in range (self .node_count ):
129133 yield self .node (i )
@@ -152,8 +156,7 @@ def iter_leaf_nodes(self) -> Iterator[LeafNode]:
152156 yield leaf
153157
154158 if self .is_root and leaf and leaf .tag .page .next_page :
155- for leaf in esedb .page (leaf .tag .page .next_page ).iter_leaf_nodes ():
156- yield leaf
159+ yield from esedb .page (leaf .tag .page .next_page ).iter_leaf_nodes ()
157160
158161 def __repr__ (self ) -> str :
159162 return f"<Page num={ self .num :d} >"
@@ -167,7 +170,7 @@ class Tag:
167170 num: The tag number to parse.
168171 """
169172
170- __slots__ = ("page " , "num " , "tag " , "offset" , "size " , "data " , "flags " )
173+ __slots__ = ("data " , "flags " , "num " , "offset" , "page " , "size " , "tag " )
171174
172175 def __init__ (self , page : Page , num : int ):
173176 self .page = page
@@ -210,7 +213,7 @@ class Node:
210213 tag: The :class:`Tag` to parse a node from.
211214 """
212215
213- __slots__ = ("tag " , "num " , "key " , "key_prefix " , "key_suffix " , "data " )
216+ __slots__ = ("data " , "key " , "key_prefix " , "key_suffix " , "num " , "tag " )
214217
215218 def __init__ (self , tag : Tag ):
216219 self .tag = tag
0 commit comments