Skip to content

Commit

Permalink
Merge pull request #32 from vicpopov/avoid_decoding_in_2.7
Browse files Browse the repository at this point in the history
Do not decode already decoded str in python 2.7
  • Loading branch information
burivuh authored Aug 15, 2019
2 parents 8a1d9d4 + 2b63dcf commit cb293a0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion snippets/pyaloha/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ class CustomEncoder(json.JSONEncoder):
def default(self, obj):
if hasattr(obj, '__dumpdict__'):
return obj.__dumpdict__()
if isinstance(obj, bytes):
if not isinstance(obj, str) and isinstance(obj, bytes):
# in python 2.7 str is bytes; don't decode it
return obj.decode()
# Let the base class default method raise the TypeError
return super(CustomEncoder, self).default(obj)
Expand Down

0 comments on commit cb293a0

Please sign in to comment.