A powerful declarative symmetric parser/builder for binary data support cp950
Project description
Construct is a powerful declarative and symmetrical parser and builder for binary data.
Instead of writing imperative code to parse a piece of data, you declaratively define a data structure that describes your data. As this data structure is not code, you can use it in one direction to parse data into Pythonic objects, and in the other direction, to build objects into binary data.
The library provides both simple, atomic constructs (such as integers of various sizes), as well as composite ones which allow you form hierarchical and sequential structures of increasing complexity. Construct features bit and byte granularity, easy debugging and testing, an easy-to-extend subclass system, and lots of primitive constructs to make your work easier:
Fields: raw bytes or numerical types
Structs and Sequences: combine simpler constructs into more complex ones
Bitwise: splitting bytes into bit-grained fields
Adapters: change how data is represented
Arrays/Ranges: duplicate constructs
Meta-constructs: use the context (history) to compute the size of data
If/Switch: branch the computational path based on the context
On-demand (lazy) parsing: read and parse only what you require
Pointers: jump from here to there in the data stream
Tunneling: prefix data with a byte count or compress it
Example
A Struct is a collection of ordered, named fields:
>>> format = Struct( ... "signature" / Const(b"BMP"), ... "width" / Int8ub, ... "height" / Int8ub, ... "pixels" / Array(this.width * this.height, Byte), ... ) >>> format.build(dict(width=3,height=2,pixels=[7,8,9,11,12,13])) b'BMP\x03\x02\x07\x08\t\x0b\x0c\r' >>> format.parse(b'BMP\x03\x02\x07\x08\t\x0b\x0c\r') Container(signature=b'BMP')(width=3)(height=2)(pixels=[7, 8, 9, 11, 12, 13])
A Sequence is a collection of ordered fields, and differs from Array and GreedyRange in that those two are homogenous:
>>> format = Sequence(PascalString(Byte, "utf8"), GreedyRange(Byte)) >>> format.build([u"lalaland", [255,1,2]]) b'\nlalaland\xff\x01\x02' >>> format.parse(b"\x004361789432197") ['', [52, 51, 54, 49, 55, 56, 57, 52, 51, 50, 49, 57, 55]]
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 Distributions
Built Distributions
File details
Details for the file shio-2.10.1-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: shio-2.10.1-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ff52a766afd1f0716b8dd3e4dcdece7cc54a3e3d259e9f4ab4b276a90aba352 |
|
MD5 | f96a66e7d20c22f4b9b6ce9dd37924fe |
|
BLAKE2b-256 | 226a87b92df62ce0aaa8f0a2efbb7195e9460cbe1bb285638ed4109d52d6b53b |
File details
Details for the file shio-2.10.1-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: shio-2.10.1-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 925ddaf14793097ed36f00e467a23fe7702c2428c01f53df10d99eb78449d5db |
|
MD5 | f1ea4ab594687b6aadfa1bdf4e63bd14 |
|
BLAKE2b-256 | 9c94f1dcfa576a56ebf67cd0238bd1136dfa8154a537675eb51cb4aa22484de6 |
File details
Details for the file shio-2.10.1-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: shio-2.10.1-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 420740290f734852a58d851f0248a90087a7698f39ab89e3556256f4009c6ac2 |
|
MD5 | bd288dbd1451522e59e6197ec06226eb |
|
BLAKE2b-256 | 07c6ee9bfb162a7d6437950b2cfdcd6cf039d4aea5879df65154ed5ec5970c0e |
File details
Details for the file shio-2.10.1-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: shio-2.10.1-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e119a7685a16970ae026a7d55d05f99aff8979df6ffab32165b001cf4ec35ce7 |
|
MD5 | 6b7e754311ce9408157ef8f4637c4ac6 |
|
BLAKE2b-256 | 9e07b3e6d7325c1d1c0d101bd7193e158525c7608035ef5e9eed52d3eef1de19 |
File details
Details for the file shio-2.10.1-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: shio-2.10.1-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4075d8a4787c588d8f46846600f4e88f4d5fb0169f4cdb0cd3f85e4bb3eb2d7 |
|
MD5 | 1c26a41dfa2d09cccdb73a6cbf4dceb4 |
|
BLAKE2b-256 | 4444b01bdcae679e1b0f8fc3f59eee3e774b6e4f4bf2461a8491c1ca20f344ff |
File details
Details for the file shio-2.10.1-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: shio-2.10.1-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfdb2441bf23253cbf4ed6ac7f1439587441c74a497b420a992f038de398ad9d |
|
MD5 | 172fc932ac910fd525b0f5cf2ba8f076 |
|
BLAKE2b-256 | 7a3e60a74f62c547c170e43ff56fe9b8a69db5d753114df20553981c3f81634e |
File details
Details for the file shio-2.10.1-cp34-cp34m-manylinux1_x86_64.whl
.
File metadata
- Download URL: shio-2.10.1-cp34-cp34m-manylinux1_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.4m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d73f7feab5a96ae7428b3551b6120751fb146004b221cd880bcaeca8a7abc0d |
|
MD5 | 536ef4b4401e8138bdd6343a28c9a661 |
|
BLAKE2b-256 | 82caf037608a2718c7b304b989cf81daee519328623a71f012d544b39f270eb4 |
File details
Details for the file shio-2.10.1-cp27-cp27mu-manylinux1_x86_64.whl
.
File metadata
- Download URL: shio-2.10.1-cp27-cp27mu-manylinux1_x86_64.whl
- Upload date:
- Size: 4.6 MB
- Tags: CPython 2.7mu
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b518161558f71687ebdff07826bff0f1a923fb00a66cbfefcb659e4c78d11689 |
|
MD5 | b001a7dc5bd3ab5e7f79236966a651ef |
|
BLAKE2b-256 | 4a53d3166e3773f4de03b0499c797a41f48f9a80a48a5ce89b4d300eb5e86cd8 |
File details
Details for the file shio-2.10.1-cp27-cp27m-win_amd64.whl
.
File metadata
- Download URL: shio-2.10.1-cp27-cp27m-win_amd64.whl
- Upload date:
- Size: 996.0 kB
- Tags: CPython 2.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 076f21ebce67f895b36fe1665cc2f9250e52e4a7f3f38cf90fdc47c244aed222 |
|
MD5 | 15ab36de2f84ab77540e55f8dbba21fb |
|
BLAKE2b-256 | 06ee68a1c5d39426c4bfacde2d9bd092b5cf4ed5ef9f66dfba13136f83f432ce |
File details
Details for the file shio-2.10.1-cp27-cp27m-manylinux1_x86_64.whl
.
File metadata
- Download URL: shio-2.10.1-cp27-cp27m-manylinux1_x86_64.whl
- Upload date:
- Size: 4.6 MB
- Tags: CPython 2.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 427d541e8c42f04de0b6e59a9cc87aca1670e5435fa8ce0d8dce9dc0cd040961 |
|
MD5 | 5347bfc874c3ec6d643053594b82b02e |
|
BLAKE2b-256 | 05082e683b830880a7f2b3a6d6903895e7ec3d159302e0f4309ded0602fcc718 |