MCPcopy Index your code
hub / github.com/Textualize/textual / load

Function load

src/textual/_binary_encode.py:169–325  ·  view source on GitHub ↗

Load an encoded data structure from bytes. Args: encoded: Encoded data in bytes. Raises: DecodeError: If an error was encountered decoding the string. Returns: Decoded data.

(encoded: bytes)

Source from the content-addressed store, hash-verified

167
168
169def load(encoded: bytes) -> object:
170 """Load an encoded data structure from bytes.
171
172 Args:
173 encoded: Encoded data in bytes.
174
175 Raises:
176 DecodeError: If an error was encountered decoding the string.
177
178 Returns:
179 Decoded data.
180 """
181 if not isinstance(encoded, bytes):
182 raise TypeError("must be bytes")
183 max_position = len(encoded)
184 position = 0
185
186 def get_byte() -> bytes:
187 """Get an encoded byte and advance position.
188
189 Raises:
190 DecodeError: If the end of the data was reached
191
192 Returns:
193 A bytes object with a single byte.
194 """
195 nonlocal position
196 if position >= max_position:
197 raise DecodeError("More data expected")
198 character = encoded[position : position + 1]
199 position += 1
200 return character
201
202 def peek_byte() -> bytes:
203 """Get the byte at the current position, but don't advance position.
204
205 Returns:
206 A bytes object with a single byte.
207 """
208 return encoded[position : position + 1]
209
210 def get_bytes(size: int) -> bytes:
211 """Get a number of bytes of encode data.
212
213 Args:
214 size: Number of bytes to retrieve.
215
216 Raises:
217 DecodeError: If there aren't enough bytes.
218
219 Returns:
220 A bytes object.
221 """
222 nonlocal position
223 bytes_data = encoded[position : position + size]
224 if len(bytes_data) != size:
225 raise DecodeError(b"Missing bytes in {bytes_data!r}")
226 position += size

Callers 3

test_round_tripFunction · 0.90
test_bad_encodingFunction · 0.90
test_load_wrong_typeFunction · 0.90

Calls 1

decodeFunction · 0.85

Tested by 3

test_round_tripFunction · 0.72
test_bad_encodingFunction · 0.72
test_load_wrong_typeFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…