From 4257e0618a799d502b24c1f80c5f47501e83e86e Mon Sep 17 00:00:00 2001 From: burivuh Date: Wed, 9 Oct 2019 18:07:22 +0300 Subject: [PATCH] review fixes --- snippets/pyaloha/__init__.py | 2 +- snippets/pyaloha/protocol.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/snippets/pyaloha/__init__.py b/snippets/pyaloha/__init__.py index 5cbf96b..dcaa354 100644 --- a/snippets/pyaloha/__init__.py +++ b/snippets/pyaloha/__init__.py @@ -1 +1 @@ -__version__="0.1.2" +__version__="0.1.3" diff --git a/snippets/pyaloha/protocol.py b/snippets/pyaloha/protocol.py index 1d5ad1f..0619083 100644 --- a/snippets/pyaloha/protocol.py +++ b/snippets/pyaloha/protocol.py @@ -156,10 +156,6 @@ def custom_loads(dct): class CustomEncoder(json.JSONEncoder): def default(self, obj): - if not isinstance(obj, str) and isinstance(obj, bytes): - # in python 2.7 str is bytes; don't decode it - return obj.decode() - if hasattr(obj, '__dumpdict__'): obj = obj.__dumpdict__() @@ -167,6 +163,10 @@ def default(self, obj): # process json unprocessable dict keys return decode_keys_for_json(obj) + 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)