Selfie
Loading...
Searching...
No Matches
selfie_lib.SnapshotReader.SnapshotReader Class Reference

Public Member Functions

None __init__ (self, SnapshotValueReader value_reader)
 
Optional[str] peek_key (self)
 
Snapshot next_snapshot (self)
 
None skip_snapshot (self)
 

Detailed Description

Definition at line 7 of file SnapshotReader.py.

Constructor & Destructor Documentation

◆ __init__()

None selfie_lib.SnapshotReader.SnapshotReader.__init__ (   self,
SnapshotValueReader  value_reader 
)

Definition at line 8 of file SnapshotReader.py.

8 def __init__(self, value_reader: SnapshotValueReader) -> None:
9 self.value_reader: SnapshotValueReader = value_reader
10

Member Function Documentation

◆ next_snapshot()

Snapshot selfie_lib.SnapshotReader.SnapshotReader.next_snapshot (   self)

Definition at line 17 of file SnapshotReader.py.

17 def next_snapshot(self) -> Snapshot:
18 root_name: Optional[str] = self.peek_key()
19 snapshot: Snapshot = Snapshot.of(self.value_reader.next_value())
20 while True:
21 next_key: Optional[str] = self.value_reader.peek_key()
22 if next_key is None or next_key == "[end of file]":
23 break
24 facet_idx: int = next_key.find("[")
25 if facet_idx == -1:
26 break
27 else:
28 facet_root, facet_name = (
29 next_key[:facet_idx],
30 next_key[facet_idx + 1 : -1],
31 )
32 if facet_root == root_name:
33 facet_value = self.value_reader.next_value()
34 snapshot = snapshot.plus_facet(facet_name, facet_value)
35 else:
36 break
37 return snapshot
38

◆ peek_key()

Optional[str] selfie_lib.SnapshotReader.SnapshotReader.peek_key (   self)

Definition at line 11 of file SnapshotReader.py.

11 def peek_key(self) -> Optional[str]:
12 next_key = self.value_reader.peek_key()
13 if next_key is None or next_key == "[end of file]":
14 return None
15 return next_key
16

◆ skip_snapshot()

None selfie_lib.SnapshotReader.SnapshotReader.skip_snapshot (   self)

Definition at line 39 of file SnapshotReader.py.

39 def skip_snapshot(self) -> None:
40 root_name: Optional[str] = self.peek_key()
41 if root_name is None:
42 raise ValueError("No snapshot to skip")
43 self.value_reader.skip_value()
44 while True:
45 next_key: Optional[str] = self.peek_key()
46 if next_key is None or not next_key.startswith(f"{root_name}["):
47 break
48 self.value_reader.skip_value()

The documentation for this class was generated from the following file: