yabencode


Nameyabencode JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/TheAMM/YABEncode
SummaryYABEncode - Yet Another Bencode module
upload_time2024-02-21 19:29:07
maintainer
docs_urlNone
authorAMM
requires_python>=3.3, <4
licenseMIT
keywords bencode bdecode torrent bencoding
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            YABEncode - Yet Another Bencode module
======================================

An implementation of bencoding/bdecoding in Python 3, with somewhat descriptive
Exceptions for decode errors.
Also includes a command-line tool for decoding and pretty-printing bencoded data!

Installing
------------------

To install from `PyPI <https://pypi.python.org/pypi/yabencode>`_:

.. code-block:: bash

    pip install yabencode

----

Usage:
######

In Python...

.. code-block:: python

    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'>

or with the command-line tool:

.. code-block:: bash

    $ yabencode -h
    usage: yabencode [-h] [-t KEY] [-r] FILE

    Bdecode a file/standard input and pretty-print the resulting data

    positional arguments:
      FILE                  Input file. Use - for stdin

    optional arguments:
      -h, --help            show this help message and exit
      -t KEY, --truncate KEY
                            Truncate values under given key. May be repeated for
                            multiple values
      -r, --raw             Raw keys - do not decode dictionary keys

    $ # The 'pieces'-bytestring is rather long, so let's truncate it
    $ yabencode -t pieces ubuntu-17.04-desktop-amd64.iso.torrent
    {'announce': b'http://torrent.ubuntu.com:6969/announce',
     'announce-list': [[b'http://torrent.ubuntu.com:6969/announce'],
                       [b'http://ipv6.torrent.ubuntu.com:6969/announce']],
     'comment': b'Ubuntu CD releases.ubuntu.com',
     'creation date': 1492077159,
     'info': {'length': 1609039872,
              'name': b'ubuntu-17.04-desktop-amd64.iso',
              'piece length': 524288,
              'pieces': '<truncated>'}}

    $ # Reading bytes from stdin (using -r to not decode the keys)
    $ curl -s 'http://torrent.ubuntu.com:6969/scrape?info_hash=%59%06%67%69%b9%ad%42%da%2e%50%86%11%c3%3d%7c%44%80%b3%85%7b' | yabencode -r -
    {b'files': {b'Y\x06gi\xb9\xadB\xda.P\x86\x11\xc3=|D\x80\xb3\x85{': {b'complete': 3473,
                                                                        b'downloaded': 33029,
                                                                        b'incomplete': 102,
                                                                        b'name': b'ubuntu-17.04-desktop-amd64.iso'}}}

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/TheAMM/YABEncode",
    "name": "yabencode",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.3, <4",
    "maintainer_email": "",
    "keywords": "bencode bdecode torrent bencoding",
    "author": "AMM",
    "author_email": "the.actual.amm@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/07/eb/b0fc95d4213859a87ad03cd4b7c3fa44c3a49a715cdd953a56c7438d7f92/yabencode-0.2.1.tar.gz",
    "platform": null,
    "description": "YABEncode - Yet Another Bencode module\n======================================\n\nAn implementation of bencoding/bdecoding in Python 3, with somewhat descriptive\nExceptions for decode errors.\nAlso includes a command-line tool for decoding and pretty-printing bencoded data!\n\nInstalling\n------------------\n\nTo install from `PyPI <https://pypi.python.org/pypi/yabencode>`_:\n\n.. code-block:: bash\n\n    pip install yabencode\n\n----\n\nUsage:\n######\n\nIn Python...\n\n.. code-block:: python\n\n    import yabencode\n    # bencode supports dicts, lists, ints and strings (bytestrings)\n    yabencode.encode({'foo':'baz', 'list':['eggs', 'spam', 'bacon']})\n    # Input can be string, bytes or a file object\n    yabencode.decode(b'd3:foo3:baz4:listl4:eggs4:spam5:baconee')\n\n    try:\n        # Malformed data, 'spam' is missing an 'a'\n        yabencode.decode(b'd3:foo3:baz4:listl4:eggs4:spm5:baconee')\n    except yabencode.MalformedBencodeException as e:\n        print(e)\n        # Unexpected data type (b':') at position 31 (0x1F hex)\n\n    try:\n        # Bencode does not support floats\n        yabencode.encode({'float':3.14})\n    except yabencode.BencodeException as e:\n        print(e)\n        # Unsupported type <class 'float'>\n\nor with the command-line tool:\n\n.. code-block:: bash\n\n    $ yabencode -h\n    usage: yabencode [-h] [-t KEY] [-r] FILE\n\n    Bdecode a file/standard input and pretty-print the resulting data\n\n    positional arguments:\n      FILE                  Input file. Use - for stdin\n\n    optional arguments:\n      -h, --help            show this help message and exit\n      -t KEY, --truncate KEY\n                            Truncate values under given key. May be repeated for\n                            multiple values\n      -r, --raw             Raw keys - do not decode dictionary keys\n\n    $ # The 'pieces'-bytestring is rather long, so let's truncate it\n    $ yabencode -t pieces ubuntu-17.04-desktop-amd64.iso.torrent\n    {'announce': b'http://torrent.ubuntu.com:6969/announce',\n     'announce-list': [[b'http://torrent.ubuntu.com:6969/announce'],\n                       [b'http://ipv6.torrent.ubuntu.com:6969/announce']],\n     'comment': b'Ubuntu CD releases.ubuntu.com',\n     'creation date': 1492077159,\n     'info': {'length': 1609039872,\n              'name': b'ubuntu-17.04-desktop-amd64.iso',\n              'piece length': 524288,\n              'pieces': '<truncated>'}}\n\n    $ # Reading bytes from stdin (using -r to not decode the keys)\n    $ curl -s 'http://torrent.ubuntu.com:6969/scrape?info_hash=%59%06%67%69%b9%ad%42%da%2e%50%86%11%c3%3d%7c%44%80%b3%85%7b' | yabencode -r -\n    {b'files': {b'Y\\x06gi\\xb9\\xadB\\xda.P\\x86\\x11\\xc3=|D\\x80\\xb3\\x85{': {b'complete': 3473,\n                                                                        b'downloaded': 33029,\n                                                                        b'incomplete': 102,\n                                                                        b'name': b'ubuntu-17.04-desktop-amd64.iso'}}}\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "YABEncode - Yet Another Bencode module",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/TheAMM/YABEncode"
    },
    "split_keywords": [
        "bencode",
        "bdecode",
        "torrent",
        "bencoding"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "672073f6f250f36aeb316b328fa2204a59d7d3440c3de8c07e72eeadfaa5a983",
                "md5": "5a55cb2c7cf941a26fca219a4d9c689c",
                "sha256": "b4183cb07551ead1ea139ca22b9fe7ccf2a71f0fe6eedbec0422a540db68928e"
            },
            "downloads": -1,
            "filename": "yabencode-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5a55cb2c7cf941a26fca219a4d9c689c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.3, <4",
            "size": 6862,
            "upload_time": "2024-02-21T19:29:05",
            "upload_time_iso_8601": "2024-02-21T19:29:05.420240Z",
            "url": "https://files.pythonhosted.org/packages/67/20/73f6f250f36aeb316b328fa2204a59d7d3440c3de8c07e72eeadfaa5a983/yabencode-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "07ebb0fc95d4213859a87ad03cd4b7c3fa44c3a49a715cdd953a56c7438d7f92",
                "md5": "6153732fe8b05e61e4c97fe319443bf9",
                "sha256": "09ff3171b97bb73d047d7191f91198f8d570f6c3726219ca2b0bb2c926fed04c"
            },
            "downloads": -1,
            "filename": "yabencode-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "6153732fe8b05e61e4c97fe319443bf9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.3, <4",
            "size": 6301,
            "upload_time": "2024-02-21T19:29:07",
            "upload_time_iso_8601": "2024-02-21T19:29:07.221956Z",
            "url": "https://files.pythonhosted.org/packages/07/eb/b0fc95d4213859a87ad03cd4b7c3fa44c3a49a715cdd953a56c7438d7f92/yabencode-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-21 19:29:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TheAMM",
    "github_project": "YABEncode",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "yabencode"
}
        
AMM
Elapsed time: 0.18229s