https://github.com/acatton/flatbencode
Fast, safe and non-recursive implementation of Bittorrent bencoding for Python 3
https://github.com/acatton/flatbencode
bencode bittorrent bittorrent-protocol deserialization flat python3 serialization torrent
Last synced: 11 months ago
JSON representation
Fast, safe and non-recursive implementation of Bittorrent bencoding for Python 3
- Host: GitHub
- URL: https://github.com/acatton/flatbencode
- Owner: acatton
- License: mit
- Created: 2016-06-12T12:59:31.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-08-16T19:27:25.000Z (over 3 years ago)
- Last Synced: 2025-04-13T16:09:59.758Z (11 months ago)
- Topics: bencode, bittorrent, bittorrent-protocol, deserialization, flat, python3, serialization, torrent
- Language: Python
- Size: 25.4 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
flatbencode
============
.. image:: https://travis-ci.org/acatton/flatbencode.svg?branch=master
:target: https://travis-ci.org/acatton/flatbencode
Fast, safe and thoroughly tested implementation of ``bencode`` in pure Python
3, without any C extension.
This is called ``flatbencode`` because the algorithm for decoding a ``bencode``
structure is non-recursive, thus preventing ``RuntimeException``.
Usage
-----
.. code:: python
>>> from flatbencode import encode, decode
>>> encode({b'foo': [b'bar', 1]})
b'd3:fool3:bari1eee'
>>> decode(b'ldei0e0:e')
[OrderedDict(), 0, b'']
Run tests
---------
.. code::
$ pip install pytest hypothesis
$ py.test -v
Changelog
---------
v0.3.0 (not released yet)
^^^^^^^^^^^^^^^^^^^^^^^^^
v0.2.1 (2016-10-22)
^^^^^^^^^^^^^^^^^^^
* Do not accept strings as dictionary keys [Antoine Catton]
v0.2.0 (2016-10-22)
^^^^^^^^^^^^^^^^^^^
* Raise an exception when there's still data left. [Tim Ruffing, #2]
* Use bytes as python dictionary keys (instead of strings) [Tim Ruffing, #2]
* Sort dictionary keys when serializing (follows the BEP-0003) [Antoine Catton]
v0.1.0 (2016-06-12)
^^^^^^^^^^^^^^^^^^^
* Initial release.
* Can decode bencoding into a python datastructure.
* Can encode a python datastructure into bencoding serialization format.