kosqx / better-bencode

Fast, standard compliant Bencode serialization
Other
20 stars 5 forks source link

ENH: support bytearray and unicode (#3) #4

Open westurner opened 7 years ago

westurner commented 7 years ago
notpushkin commented 7 years ago

Fails on Python 3, NameError: name 'unicode' is not defined :(

westurner commented 7 years ago

Whoops. I think that should only be for Python 2 because in Python 3 all str are unicode.

On Wednesday, November 16, 2016, Alexander Pushkov notifications@github.com wrote:

Fails on Python 3, NameError: name 'unicode' is not defined :(

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kosqx/better-bencode/pull/4#issuecomment-260935205, or mute the thread https://github.com/notifications/unsubscribe-auth/AADGy77ug9XCD5PdA461pQNqM3AtSJzmks5q-vfTgaJpZM4Kwxlh .

notpushkin commented 7 years ago

The error actually happens in the elif t is unicode line. We can safely substitute unicode for str (in py3k) here (as unicode_to_bytes accepts str in python 3), so I suggest this simple fix: https://github.com/Songbee/better-bencode/commit/0bb114b9875fac1a6829e0a7bd8ffb933c66c525

westurner commented 7 years ago

Good call @iamale

westurner commented 7 years ago
westurner commented 7 years ago

... TIL "All character string values are UTF-8 encoded." https://wiki.theory.org/BitTorrentSpecification#Metainfo_File_Structure

notpushkin commented 7 years ago

Also I think it would be nice to decode unicode strings to unicode/str as well (although it might be a bit trickier).