Pack python data onto a string.
Project description
pypacker
Encode / Decode arbitrary data into a string.
Op Codes (type codes):
Int Number i
Float Number f
Character c
String s
Binary b
List a (array) gets encoded as extended
Tuple t gets encoded as extended (x)
Dict d gets encoded as extended (x)
Extended x encoded as new packer string (recursive)
Usage:
arr_of_data = [datax, [ datay], { dataz : valz } ... etc]
formatstr = ""
pb = packbin()
newdata = pb.encode_data(formatstr, arr_of_data)
decdata = pb.decode_data(newdata)
?assert?(decdata == arr_of_data)
Empty format string will use the auto-detected types: (recommended)
newdata = pb.encode_data("", arr_of_data)
Preserves type and data. It is (mostly) 7/8 bit clean on
both python2 and python 3.
Note: python2 'bytes' type is a place holder - avoid encoding bytes on python 2
and decoding bytes on python 3; or at least be aware of the issues. This does
not effect the decoded data, but it does effect the cypher text.
The following comes into play when one encodes data with python 2 and
decodes it in python 3.
Python V2 and V3 str / bytes differences. In python 2 the 'bytes' type is
an alias to the str type. It accommodates the whole palette of numbers in
py2; thus we detect binary by looking at the str and seeing if non printable
characters are present. (the character < ' ' or > 'del')
This works well, however we consider it a work-around; so please be aware.
If you assure both encoder and decoder are the same python version, this
issue does not exist.
History:
Sat 18.Feb.2023 decode binary after done decomposing it
Mon 18.Dec.2023 moved to pypacker dir
Tue 19.Dec.2023 test for python2 python 3 -- note: bytes / v2 v3 differences
Thu 21.Dec.2023 cleanmup, docs, etc ...
Pytest results:
============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.0.0
rootdir: /home/peterglen/pgpygtk/pypacker/tests
collected 20 items
test_arr.py .. [ 10%]
test_bin.py .. [ 20%]
test_complex.py .. [ 30%]
test_dict.py . [ 35%]
test_float.py .. [ 45%]
test_int.py .. [ 55%]
test_packer.py ...... [ 85%]
test_str.py ... [100%]
============================== 20 passed in 0.09s ==============================
============================= test session starts ==============================
platform linux2 -- Python 2.7.18, pytest-4.6.11, py-1.11.0, pluggy-0.13.1
rootdir: /home/peterglen/pgpygtk/pypacker/tests
collected 20 items
test_arr.py .. [ 10%]
test_bin.py .. [ 20%]
test_complex.py .. [ 30%]
test_dict.py . [ 35%]
test_float.py .. [ 45%]
test_int.py .. [ 55%]
test_packer.py ...... [ 85%]
test_str.py ... [100%]
========================== 20 passed in 0.12 seconds ===========================
EOF
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
pyvpacker-1.0.tar.gz
(8.5 kB
view details)
Built Distribution
File details
Details for the file pyvpacker-1.0.tar.gz
.
File metadata
- Download URL: pyvpacker-1.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.28.2 rfc3986/1.5.0 tqdm/4.64.1 urllib3/1.26.5 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b990affc5923e6efbf729a8eb498a2877bcc6a4857e5ed2297a3e7f546872fc8 |
|
MD5 | 1a7036fc5802127b172efc3084a00541 |
|
BLAKE2b-256 | 4763dbdd35cbabd525e04e1b9d64d2319ee14959119df0e96ba666a98d9b5928 |
File details
Details for the file pyvpacker-1.0-py3-none-any.whl
.
File metadata
- Download URL: pyvpacker-1.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.28.2 rfc3986/1.5.0 tqdm/4.64.1 urllib3/1.26.5 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b61a093e16d0145455412cf1cc0e6ae10061c1dca537336705c3c1d24e0c9409 |
|
MD5 | 92c174ef9eeb441e4e26a0d7da82d29b |
|
BLAKE2b-256 | f107be396e1e1a529996697b1d05833318dd2b0db97ef818b8150059be2fa465 |