Skip to main content

YABEncode - Yet Another Bencode module

Project description

An implementation of bencoding/bdecoding in Python 3, with somewhat descriptive Exceptions for decode errors.

Installing

To install from PyPI:

pip install yabencode

Usage:

import yabencode
# bencode supports dicts, lists, ints and strings (bytestrings)
yabencode.encode({'foo':'baz', 'list':['eggs', 'spam', 'bacon']})
# Input can be string, bytes or a file object
yabencode.decode(b'd3:foo3:baz4:listl4:eggs4:spam5:baconee')

try:
        # Malformed data, 'spam' is missing an 'a'
        yabencode.decode(b'd3:foo3:baz4:listl4:eggs4:spm5:baconee')
except yabencode.MalformedBencodeException as e:
        print(e)
        # Unexpected data type (b':') at position 31 (0x1F hex)

try:
        # Bencode does not support floats
        yabencode.encode({'float':3.14})
except yabencode.BencodeException as e:
        print(e)
        # Unsupported type <class 'float'>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

yabencode-0.1.0-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

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