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

Public Member Functions

 __init__ (self, LineReader line_reader)
 
Optional[str] peek_key (self)
 
SnapshotValue next_value (self)
 
None skip_value (self)
 
"SnapshotValueReader" of (cls, str content)
 
"SnapshotValueReader" of_binary (cls, bytes content)
 

Public Attributes

 line_reader
 
 unix_newlines
 
 KEY_FIRST_CHAR
 
 line
 

Static Public Attributes

str KEY_FIRST_CHAR = "╔"
 
str KEY_START = "╔═ "
 
str KEY_END = " ═╗"
 
str FLAG_BASE64 = " ═╗ base64"
 
 name_esc = PerCharacterEscaper.specified_escape("\\\\[(])\nn\tt╔┌╗┐═─")
 
 body_esc = PerCharacterEscaper.self_escape("\ud801\udf43\ud801\udf41")
 

Detailed Description

Definition at line 10 of file SnapshotValueReader.py.

Constructor & Destructor Documentation

◆ __init__()

selfie_lib.SnapshotValueReader.SnapshotValueReader.__init__ (   self,
LineReader  line_reader 
)

Definition at line 18 of file SnapshotValueReader.py.

18 def __init__(self, line_reader: LineReader):
19 self.line_reader = line_reader
20 self.line: Optional[str] = None
21 self.unix_newlines = self.line_reader.unix_newlines()
22

Member Function Documentation

◆ next_value()

SnapshotValue selfie_lib.SnapshotValueReader.SnapshotValueReader.next_value (   self)

Definition at line 26 of file SnapshotValueReader.py.

26 def next_value(self) -> SnapshotValue:
27 # Validate key
28 self.__next_key()
29 nextLineCheckForBase64: Optional[str] = self.__next_line()
30 if nextLineCheckForBase64 is None:
31 raise ParseException(self.line_reader, "Expected to validate key")
32 is_base64: bool = self.FLAG_BASE64 in nextLineCheckForBase64
33 self.__reset_line()
34
35 # Read value
36 buffer: list[str] = []
37
38 def consumer(line: str) -> None:
39 # Check for special condition and append to buffer accordingly
40 if len(line) >= 2 and ord(line[0]) == 0xD801 and ord(line[1]) == 0xDF41:
41 buffer.append(self.KEY_FIRST_CHAR)
42 buffer.append(line[2:])
43 else:
44 buffer.append(line)
45 buffer.append("\n")
46
47 self.__scan_value(consumer)
48
49 raw_string: str = "" if buffer.__len__() == 0 else ("".join(buffer))[:-1]
50
51 # Decode or unescape value
52 if is_base64:
53 decoded_bytes: bytes = base64.b64decode(raw_string)
54 return SnapshotValue.of(decoded_bytes)
55 else:
56 return SnapshotValue.of(self.body_esc.unescape(raw_string))
57

◆ of()

"SnapshotValueReader" selfie_lib.SnapshotValueReader.SnapshotValueReader.of (   cls,
str  content 
)

Definition at line 104 of file SnapshotValueReader.py.

104 def of(cls, content: str) -> "SnapshotValueReader":
105 return cls(LineReader.for_string(content))
106

◆ of_binary()

"SnapshotValueReader" selfie_lib.SnapshotValueReader.SnapshotValueReader.of_binary (   cls,
bytes  content 
)

Definition at line 108 of file SnapshotValueReader.py.

108 def of_binary(cls, content: bytes) -> "SnapshotValueReader":
109 return cls(LineReader.for_binary(content))

◆ peek_key()

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

Definition at line 23 of file SnapshotValueReader.py.

23 def peek_key(self) -> Optional[str]:
24 return self.__next_key()
25

◆ skip_value()

None selfie_lib.SnapshotValueReader.SnapshotValueReader.skip_value (   self)

Definition at line 58 of file SnapshotValueReader.py.

58 def skip_value(self) -> None:
59 self.__next_key()
60 self.__reset_line()
61 self.__scan_value(lambda _: None)
62

Member Data Documentation

◆ body_esc

selfie_lib.SnapshotValueReader.SnapshotValueReader.body_esc = PerCharacterEscaper.self_escape("\ud801\udf43\ud801\udf41")
static

Definition at line 16 of file SnapshotValueReader.py.

◆ FLAG_BASE64

str selfie_lib.SnapshotValueReader.SnapshotValueReader.FLAG_BASE64 = " ═╗ base64"
static

Definition at line 14 of file SnapshotValueReader.py.

◆ KEY_END

str selfie_lib.SnapshotValueReader.SnapshotValueReader.KEY_END = " ═╗"
static

Definition at line 13 of file SnapshotValueReader.py.

◆ KEY_FIRST_CHAR [1/2]

str selfie_lib.SnapshotValueReader.SnapshotValueReader.KEY_FIRST_CHAR = "╔"
static

Definition at line 11 of file SnapshotValueReader.py.

◆ KEY_FIRST_CHAR [2/2]

selfie_lib.SnapshotValueReader.SnapshotValueReader.KEY_FIRST_CHAR

Definition at line 41 of file SnapshotValueReader.py.

◆ KEY_START

str selfie_lib.SnapshotValueReader.SnapshotValueReader.KEY_START = "╔═ "
static

Definition at line 12 of file SnapshotValueReader.py.

◆ line

selfie_lib.SnapshotValueReader.SnapshotValueReader.line

Definition at line 97 of file SnapshotValueReader.py.

◆ line_reader

selfie_lib.SnapshotValueReader.SnapshotValueReader.line_reader

Definition at line 19 of file SnapshotValueReader.py.

◆ name_esc

selfie_lib.SnapshotValueReader.SnapshotValueReader.name_esc = PerCharacterEscaper.specified_escape("\\\\[(])\nn\tt╔┌╗┐═─")
static

Definition at line 15 of file SnapshotValueReader.py.

◆ unix_newlines

selfie_lib.SnapshotValueReader.SnapshotValueReader.unix_newlines

Definition at line 21 of file SnapshotValueReader.py.


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