Git Product home page Git Product logo

Comments (6)

sximba avatar sximba commented on June 27, 2024

@joachimmetz Yes, it seems like this is the intended behaviour. According to the bencode spec this is the correct behaviour. However, like you, I have come to rely on this library doing the conversion from bytes to strings. I was hoping the API would be changed to something like:

import bencode
with open('test_data/bencode_transmission', 'rb') as f: 
  x = bencode.bread(f, try_decode=True, encoding='utf-8')

This will allow people who want the previous behaviour to opt-in to it.

from bencode.py.

joachimmetz avatar joachimmetz commented on June 27, 2024

@sximba thx for the context, though for me file/data format specification and Python API are 2 separate things. I understand that the file/data format defines byte streams to store textual strings, and that it appears that over time UTF-8 seems to have become the standard encoding for this 1, 2.

However it is a bit surprising to me to, see the Python API change and seeing the Python 2 to 3 bytes to str changes, I'm left to wonder if this impactful API change is intentional or not. However this commit hints that this is intentional.

A request to the project maintainers to reflect this in https://github.com/fuzeman/bencode.py#usage

from bencode.py.

fuzeman avatar fuzeman commented on June 27, 2024

I'll add a flag to re-enable string decoding tomorrow (probably just an encoding option that defaults to None).

Should bytes be returned from decode_string if there is a decoding error (as it did in v2.1.0)? can we start throwing UnicodeDecodeError or do we need another flag to fallback to bytes if decoding fails?


Moving forward pinning to a major version would be a good idea to avoid unexpected changes to the API. No breaking changes will be released in minor or patch releases.

from bencode.py.

joachimmetz avatar joachimmetz commented on June 27, 2024

I'll add a flag to re-enable string decoding tomorrow (probably just an encoding option that defaults to None).

thx much appreciated

Moving forward pinning to a major version would be a good idea to avoid unexpected changes to the API.

Noworries, this only affected tests for us. That's why the tests are there in the first place to catch changes. For production purposes we "pin" to specific versions.

from bencode.py.

fuzeman avatar fuzeman commented on June 27, 2024

I've released v4.0.0 which now includes a bencode package that should be backwards-compatible with the API in v2.1.0.

The "Improved" API has been moved to bencodepy, this has also been updated to include a Bencode class that can be configured to enable string decoding with encoding='utf-8'.


Noworries, this only affected tests for us. That's why the tests are there in the first place to catch changes. For production purposes we "pin" to specific versions.

Great to hear. I was a bit concerned as requirements.txt in the referenced repository didn't have it pinned.

from bencode.py.

joachimmetz avatar joachimmetz commented on June 27, 2024

The "Improved" API has been moved to bencodepy, this has also been updated to include a Bencode class that can be configured to enable string decoding with encoding='utf-8'.

thx, much appreciated. I'll have a look shortly.

IMHO you can consider this issue closed

from bencode.py.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.