Tools for building Sans IO libraries
Project description
sansio_tools
Useful tools for building Sans IO-based libraries.
BytesQueue
Example code:
from sansio_tools.queue import BytesQueue
q = BytesQueue()
q.append(b"012345")
print(bytes(q.peekleft(2))) # b"01"
print(bytes(q.popleft(3))) # b"012"
# put back bytes into the queue!
q.appendleft(b"012")
print(bytes(q.popleft(4))) # b"0123"
Parser and BytesParser
Example code:
from struct import Struct
from sansio_tools.parser import BinaryParser
# int8, uint32, uint64
my_struct = Struct("!bIQ")
def parser_generator(p: BinaryParser):
b = yield from p.read_bytes(6)
results.append(b)
b = yield from p.read_bytes(6)
results.append(b)
lst = yield from p.read_struct(my_struct)
results.append(lst)
n = yield from p.read_int(2, "little", False)
results.append(n)
n = yield from p.read_variable_length_int_7bit(
maximum_length=10,
byteorder="big",
continuation_bit_value=True,
require_canonical=True,
)
results.append(n)
results = []
p = BinaryParser(parser_generator)
p.feed(b"hell")
p.feed(b"o world!\xff")
# receive partial results as they become available!
assert results == [b"hello ", b"world!"]
assert not p.generator_exited
results.clear()
p.feed(b"\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x12\x34")
p.feed(b"\x81\x80\x80")
assert results == [(-1, 0xff << 24, 0xff << 56), 0x3412]
assert not p.generator_exited
results.clear()
p.feed(b"\x80\x05")
p.feed(b"") # signal eof
assert results == [(1 << (7 * 4)) + 5]
assert p.generator_exited
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sansio_tools-0.1.0.tar.gz
(10.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sansio_tools-0.1.0.tar.gz.
File metadata
- Download URL: sansio_tools-0.1.0.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2caa48186569d32b53d463c3b86705137c37c9e16cbb9bf6ae9e59eb7a15cdb1
|
|
| MD5 |
1724465e30fb7225bcd1ee512c71c040
|
|
| BLAKE2b-256 |
8c342a89d6a79b2776ec6c6b8d0147debc422a372d5e8ac258ce250d5f3dbc7c
|
File details
Details for the file sansio_tools-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sansio_tools-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6a06f7164737d7921891c5c22efbd85c1115223e1ce23dcabfa30e749a228dd
|
|
| MD5 |
7e0fbe182ea9cacb97ddbddc39df0a15
|
|
| BLAKE2b-256 |
b1c0ead20dfe8592fb6e5dc52180bf6776da68e3addd87cb038bf7f3de730746
|