summaryrefslogtreecommitdiff
path: root/cherrypy/_cpcompat.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2017-07-09 06:15:28 -0400
committerJason R. Coombs <jaraco@jaraco.com>2017-07-09 06:15:28 -0400
commite981b8112cca297c09bf16aeae20b7f9ab56014c (patch)
treed838c3fc632d546f31c8443a9cb7e241f50d0b04 /cherrypy/_cpcompat.py
parent219df2d8bc3e9536e3313bd72ec3dbfd59957067 (diff)
downloadcherrypy-git-e981b8112cca297c09bf16aeae20b7f9ab56014c.tar.gz
Move json_encode block out of finally
Diffstat (limited to 'cherrypy/_cpcompat.py')
-rw-r--r--cherrypy/_cpcompat.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/cherrypy/_cpcompat.py b/cherrypy/_cpcompat.py
index eac029d5..1b998607 100644
--- a/cherrypy/_cpcompat.py
+++ b/cherrypy/_cpcompat.py
@@ -152,15 +152,16 @@ except ImportError:
import json
json_decode = json.JSONDecoder().decode
_json_encode = json.JSONEncoder().iterencode
-finally:
- if json and six.PY3:
- # The two Python 3 implementations (simplejson/json)
- # outputs str. We need bytes.
- def json_encode(value):
- for chunk in _json_encode(value):
- yield chunk.encode('utf8')
- else:
- json_encode = _json_encode
+
+
+if six.PY3:
+ # Encode to bytes on Python 3
+ def json_encode(value):
+ for chunk in _json_encode(value):
+ yield chunk.encode('utf-8')
+else:
+ json_encode = _json_encode
+
text_or_bytes = six.text_type, six.binary_type