Comments (6)
@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.
@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.
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.
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.
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.
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)
- AttributeError: 'module' object has no attribute 'encode' HOT 2
- add license text HOT 2
- Decoding of example fails
- Encoder does not support base type - None HOT 2
- How to determine the bencode module version programmatically HOT 2
- LICENSE, which version? HOT 3
- bdecode fails on python3 with bytes objects HOT 2
- None of read, write, bread, bwrite exist HOT 1
- setuptools warnings
- License
- KeyError: <type 'unicode'> HOT 1
- Unnecessary data when saving to a file HOT 3
- Dict with bytes as keys? HOT 2
- encode_string has inconsistent return behavior HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bencode.py.