MothPriest
Python module for creating intuitive file parsers.
Imagine you have a file with the following structure:
| Field | Size (Bytes) | Value |
|---|---|---|
| Magic | 6 | "STRING" |
| StringSize | 4 | uint32 (little endian) size String in bytes |
| String | StringSize | string data for this file |
MothPriest makes parsing and editing this file simple:
from io import BytesIO
from mothpriest.parsers import *
parser = BlockParser(
"root",
[
MagicParser("STRING", "Magic"),
IntegerParser("StringSize", size=4, little_endian=True, signed=False),
StringParser("String", size="StringSize") # Note the reference back to StringSize
]
)
data = b"STRING\x1A\x00\x00\x00Lorem ipsum dolor sit amet"
with BytesIO(data) as buffer:
parser(buffer)
assert parser['String'] == "Lorem ipsum dolor sit amet"
parser['String'] = "The quick brown fox jumps over the lazy dog"
# StringSize is now inconsistent with String, but there is no need to manually update
with BytesIO() as buffer:
parser.unparse(buffer)
buffer.seek(0)
output_data = buffer.read()
# Note how StringSize is updated automatically
assert output_data == b"STRING\x2B\x00\x00\x00The quick brown fox jumps over the lazy dog"
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mothpriest-1.1.0.tar.gz
(13.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 mothpriest-1.1.0.tar.gz.
File metadata
- Download URL: mothpriest-1.1.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffc0907a5add4a27b3c60c09cf5c6b384c06510b182c8ee91d4ce624a76d74e4
|
|
| MD5 |
8b680d8948698bbe4f1b3eac209ebebe
|
|
| BLAKE2b-256 |
e618e6c02d83f3d460d57b2f83bb21fc418505c27d3f0e67c8753cb939aa29da
|
File details
Details for the file mothpriest-1.1.0-py3-none-any.whl.
File metadata
- Download URL: mothpriest-1.1.0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa6394b0ff25d550622088f5b912f2e272c80860c5eea33a88bc9d8e8dbdf17a
|
|
| MD5 |
136d61bbd703602adb58feadf9e64eaf
|
|
| BLAKE2b-256 |
57bf679a669f7107413483c64557affede852e480c19becfcf08fec4ecb0e9b8
|