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

Public Member Functions

 __init__ (self)
 
 serialize (self, list[str] valueWriter)
 
None set_at_test_time (self, str key, Snapshot snapshot)
 
None remove_all_indices (self, list[int] indices)
 
"SnapshotFile" parse (cls, SnapshotValueReader value_reader)
 
"SnapshotFile" create_empty_with_unix_newlines (cls, bool unix_newlines)
 

Static Public Member Functions

 writeEntry (list[str] valueWriter, str key, Optional[str] facet, SnapshotValue value)
 

Public Attributes

 snapshots
 
 was_set_at_test_time
 
 HEADER_PREFIX
 

Static Public Attributes

str HEADER_PREFIX = "šŸ“· "
 
str END_OF_FILE = "[end of file]"
 

Detailed Description

Definition at line 11 of file SnapshotFile.py.

Constructor & Destructor Documentation

◆ __init__()

selfie_lib.SnapshotFile.SnapshotFile.__init__ (   self)

Definition at line 15 of file SnapshotFile.py.

15 def __init__(self):
16 self.unix_newlines: bool = True
17 self.metadata: Optional[tuple[str, str]] = None
18 self.snapshots: ArrayMap[str, Snapshot] = ArrayMap.empty()
19 self._lock: Lock = Lock()
20 self.was_set_at_test_time: bool = False
21

Member Function Documentation

◆ create_empty_with_unix_newlines()

"SnapshotFile" selfie_lib.SnapshotFile.SnapshotFile.create_empty_with_unix_newlines (   cls,
bool  unix_newlines 
)

Definition at line 105 of file SnapshotFile.py.

105 def create_empty_with_unix_newlines(cls, unix_newlines: bool) -> "SnapshotFile":
106 result = cls()
107 result.unix_newlines = unix_newlines
108 return result

◆ parse()

"SnapshotFile" selfie_lib.SnapshotFile.SnapshotFile.parse (   cls,
SnapshotValueReader  value_reader 
)

Definition at line 81 of file SnapshotFile.py.

81 def parse(cls, value_reader: SnapshotValueReader) -> "SnapshotFile":
82 result = cls()
83 result.unix_newlines = value_reader.unix_newlines
84 reader = SnapshotReader(value_reader)
85
86 peek_key = reader.peek_key()
87 if peek_key and peek_key.startswith(cls.HEADER_PREFIX):
88 metadata_name = peek_key[len(cls.HEADER_PREFIX) :]
89 metadata_value = value_reader.next_value().value_string()
90 result.metadata = (metadata_name, metadata_value)
91 reader.next_snapshot()
92
93 while True:
94 peek_key = reader.peek_key()
95 if peek_key is None or peek_key == cls.END_OF_FILE:
96 break
97 if peek_key.startswith(cls.HEADER_PREFIX):
98 continue
99 next_snapshot = reader.next_snapshot()
100 result.snapshots = result.snapshots.plus(peek_key, next_snapshot)
101
102 return result
103

◆ remove_all_indices()

None selfie_lib.SnapshotFile.SnapshotFile.remove_all_indices (   self,
list[int]  indices 
)

Definition at line 73 of file SnapshotFile.py.

73 def remove_all_indices(self, indices: list[int]) -> None:
74 with self._lock:
75 if not indices:
76 return
77 self.snapshots = self.snapshots.minus_sorted_indices(indices)
78 self.was_set_at_test_time = True
79

◆ serialize()

selfie_lib.SnapshotFile.SnapshotFile.serialize (   self,
list[str]  valueWriter 
)

Definition at line 22 of file SnapshotFile.py.

22 def serialize(self, valueWriter: list[str]):
23 if self.metadata is not None:
24 self.writeEntry(
25 valueWriter,
26 f"šŸ“· {self.metadata[0]}",
27 None,
28 SnapshotValue.of(self.metadata[1]),
29 )
30
31 for entry_key, entry_value in self.snapshots.items():
32 self.writeEntry(valueWriter, entry_key, None, entry_value.subject)
33 for facet_key, facet_value in entry_value.facets.items():
34 self.writeEntry(valueWriter, entry_key, facet_key, facet_value)
35
36 self.writeEntry(valueWriter, "", "end of file", SnapshotValue.of(""))
37

◆ set_at_test_time()

None selfie_lib.SnapshotFile.SnapshotFile.set_at_test_time (   self,
str  key,
Snapshot  snapshot 
)

Definition at line 68 of file SnapshotFile.py.

68 def set_at_test_time(self, key: str, snapshot: Snapshot) -> None:
69 with self._lock:
70 self.snapshots = self.snapshots.plus_or_noop_or_replace(key, snapshot)
71 self.was_set_at_test_time = True
72

◆ writeEntry()

selfie_lib.SnapshotFile.SnapshotFile.writeEntry ( list[str]  valueWriter,
str  key,
Optional[str]  facet,
SnapshotValue   value 
)
static

Definition at line 39 of file SnapshotFile.py.

41 ):
42 valueWriter.append("ā•”ā• ")
43 valueWriter.append(SnapshotValueReader.name_esc.escape(key))
44 if facet is not None:
45 valueWriter.append("[")
46 valueWriter.append(SnapshotValueReader.name_esc.escape(facet))
47 valueWriter.append("]")
48 valueWriter.append(" ā•ā•—")
49 if value.is_binary:
50 valueWriter.append(" base64 length ")
51 valueWriter.append(str(len(value.value_binary())))
52 valueWriter.append(" bytes")
53 valueWriter.append("\n")
54
55 if not key and facet == "end of file":
56 return
57
58 if value.is_binary:
59 escaped = base64.b64encode(value.value_binary()).decode("utf-8")
60 valueWriter.append(escaped.replace("\r", ""))
61 else:
62 escaped = SnapshotValueReader.body_esc.escape(value.value_string()).replace(
63 "\nā•”", "\n\ud801\udf41"
64 )
65 valueWriter.append(escaped)
66 valueWriter.append("\n")
67

Member Data Documentation

◆ END_OF_FILE

str selfie_lib.SnapshotFile.SnapshotFile.END_OF_FILE = "[end of file]"
static

Definition at line 13 of file SnapshotFile.py.

◆ HEADER_PREFIX [1/2]

str selfie_lib.SnapshotFile.SnapshotFile.HEADER_PREFIX = "šŸ“· "
static

Definition at line 12 of file SnapshotFile.py.

◆ HEADER_PREFIX [2/2]

selfie_lib.SnapshotFile.SnapshotFile.HEADER_PREFIX

Definition at line 87 of file SnapshotFile.py.

◆ snapshots

selfie_lib.SnapshotFile.SnapshotFile.snapshots

Definition at line 70 of file SnapshotFile.py.

◆ was_set_at_test_time

selfie_lib.SnapshotFile.SnapshotFile.was_set_at_test_time

Definition at line 71 of file SnapshotFile.py.


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