Issue #1247 resolved

Python 3.3.0 not work with simplejson in file _cpcompat.py

Eneldo Serrata
created an issue

in file _cpcompat.py line:272

force to use simplejson if can import, but if you use tools.json_out() you get exception

thanks Joel Rivera give me this patch to fix

--- /home/joe/repos/cherrypy/cherrypy/_cpcompat.py  2013-04-08 20:22:46.034643791 -0500
+++ lib/python3.3/site-packages/cherrypy/_cpcompat.py   2013-04-27 12:24:46.675519441 -0500
@@ -273,7 +273,13 @@
     # Prefer simplejson, which is usually more advanced than the builtin module.
     import simplejson as json
     json_decode = json.JSONDecoder().decode
-    json_encode = json.JSONEncoder().iterencode
+    _json_encode = json.JSONEncoder().iterencode
+    if py3k:
+        def json_encode(value):
+            for chunk in _json_encode(value):
+                yield chunk.encode('utf8')
+    else:
+        json_encode = _json_encode
 except ImportError:
     if py3k:
         # Python 3.0: json is part of the standard library,

Comments (1)

  1. Log in to comment