Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bdecode fails on python3 with bytes objects #2

Closed
tritium21 opened this issue Jun 28, 2017 · 2 comments
Closed

bdecode fails on python3 with bytes objects #2

tritium21 opened this issue Jun 28, 2017 · 2 comments
Labels

Comments

@tritium21
Copy link

bencoded files can, and in their most common use case do, include raw binary data. The native string type in python 2 is just binary data (str). This means loading a torrent file, and decoding it with python 2 works just fine with bencode.py (as it uses uses the native string type exclusively internally).

In python 3, the native string type is a sequence of unicode code points, not bytes, and never the twain shall they meet. So while a unicode string (python 3 str) will encode and decode just fine with bencode.py, it cannot decode or encode a bytes structures. ...And you need to be able to do that to handle torrent files (which cannot be represented in unicode - there is raw binary in the file)

@lostnihilist
Copy link
Contributor

My fork seems to handle str versus bytes correctly for both encoding and decoding https://github.com/lostnihilist/bencode.py

@fuzeman
Copy link
Owner

fuzeman commented Dec 5, 2017

I've just merged @lostnihilist's improvements and made some adjustments to ensure Python 2 is still supported. (released in v2.0.0)

Let me know if there are still changes required, test cases will help as well.

@fuzeman fuzeman added the bug label Dec 5, 2017
@fuzeman fuzeman closed this as completed Dec 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants