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 the bytes back into the queue!
q.appendleft(b"012")
print(bytes(q.popleft(4))) # b"0123"
BinaryParser
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(None) # signal eof
assert results == [(1 << (7 * 4)) + 5]
assert p.generator_exited
Metadata
Release files for sansio-tools 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sansio_tools-1.0.1.tar.gz | 14.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sansio_tools-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.6 kB
Release files / sansio_tools-1.0.1.tar.gz
| Download URL | sansio_tools-1.0.1.tar.gz |
|---|---|
| Size | 14.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14e2c6451c4eb1564e811858a00772894b0e4ddf05dc3e67b1c5d7f4788f9e6b
|
|
BLAKE2b-256 checksum How to use checksums |
6990d887a983b31ba3ec4d7497462401e6a1fb30dac4c04faea9b9876f066689
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / sansio_tools-1.0.1-py3-none-any.whl
| Download URL | sansio_tools-1.0.1-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8397a26c7af052a1c855b53e5bd98c7e2a2072a027f71e967c36871b3174f3e9
|
|
BLAKE2b-256 checksum How to use checksums |
9a71c4dc656ce86c409a55106166f9b5fe7f78321fae924e141fff34c84cf638
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|