Skip to main content

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


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.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

pyvpacker-1.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pyvpacker-1.1.tar.gz.

File metadata

  • Download URL: pyvpacker-1.1.tar.gz
  • Upload date:
  • Size: 8.6 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

Hashes for pyvpacker-1.1.tar.gz
Algorithm Hash digest
SHA256 da368d699b55de109b1d8e6af76bfcdc3f93549493153b5a405ecd4e2bd423fd
MD5 a4230f4c1e8de8073e58e90878237f9f
BLAKE2b-256 6294c15144b17b562ae3bee2c2b78c18f35bc6cb25c8e5e18b076cf7fa10a727

See more details on using hashes here.

File details

Details for the file pyvpacker-1.1-py3-none-any.whl.

File metadata

  • Download URL: pyvpacker-1.1-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

Hashes for pyvpacker-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2aad4946b6e5ff6fdfb93105eeacfca4d199bea794fe4f2b189d7b59175de115
MD5 0445271fe20806073e11b44e189bac4a
BLAKE2b-256 a1be431fbf0992f81de75b842d24403fc627f8adfdf05181899398d5f68c13f2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page