summaryrefslogtreecommitdiff
path: root/cherrypy/lib/jsontools.py
diff options
context:
space:
mode:
authorGustavo Picon <tabo@tabo.pe>2014-01-12 14:17:21 -0500
committerGustavo Picon <tabo@tabo.pe>2014-01-12 14:17:21 -0500
commitf3bf0e4c92b4ae812b42246ffc72b45c7209b94f (patch)
treef997c23aa6d04fc7db78e66ad5f58429b3be824e /cherrypy/lib/jsontools.py
parentfb84f7713d6ced0031dacb0e7e59d516cc681a4d (diff)
parentc26eb490862e664dc4ef4ea6e55c1dbd106146c4 (diff)
downloadcherrypy-git-f3bf0e4c92b4ae812b42246ffc72b45c7209b94f.tar.gz
Merge autopep8 branch
Diffstat (limited to 'cherrypy/lib/jsontools.py')
-rw-r--r--cherrypy/lib/jsontools.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/cherrypy/lib/jsontools.py b/cherrypy/lib/jsontools.py
index 3f8cf9dd..d3dfa5ad 100644
--- a/cherrypy/lib/jsontools.py
+++ b/cherrypy/lib/jsontools.py
@@ -2,6 +2,7 @@ import sys
import cherrypy
from cherrypy._cpcompat import basestring, ntou, json, json_encode, json_decode
+
def json_processor(entity):
"""Read application/json data into request.json."""
if not entity.headers.get(ntou("Content-Length"), ntou("")):
@@ -13,8 +14,9 @@ def json_processor(entity):
except ValueError:
raise cherrypy.HTTPError(400, 'Invalid JSON document')
+
def json_in(content_type=[ntou('application/json'), ntou('text/javascript')],
- force=True, debug=False, processor = json_processor):
+ force=True, debug=False, processor=json_processor):
"""Add a processor to parse JSON request entities:
The default processor places the parsed data into request.json.
@@ -57,10 +59,12 @@ def json_in(content_type=[ntou('application/json'), ntou('text/javascript')],
cherrypy.log('Adding body processor for %s' % ct, 'TOOLS.JSON_IN')
request.body.processors[ct] = processor
+
def json_handler(*args, **kwargs):
value = cherrypy.serving.request._json_inner_handler(*args, **kwargs)
return json_encode(value)
+
def json_out(content_type='application/json', debug=False, handler=json_handler):
"""Wrap request.handler to serialize its output to JSON. Sets Content-Type.
@@ -87,6 +91,6 @@ def json_out(content_type='application/json', debug=False, handler=json_handler)
request.handler = handler
if content_type is not None:
if debug:
- cherrypy.log('Setting Content-Type to %s' % content_type, 'TOOLS.JSON_OUT')
+ cherrypy.log('Setting Content-Type to %s' %
+ content_type, 'TOOLS.JSON_OUT')
cherrypy.serving.response.headers['Content-Type'] = content_type
-