michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: # You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: import json michael@0: michael@0: def json_response(func): michael@0: """ Translates results of 'func' into a JSON response. """ michael@0: def wrap(*a, **kw): michael@0: (code, data) = func(*a, **kw) michael@0: json_data = json.dumps(data) michael@0: return (code, { 'Content-type': 'application/json', michael@0: 'Content-Length': len(json_data) }, json_data) michael@0: michael@0: return wrap