arxiv_metadata/tools.py

30 lines
820 B
Python
Raw Normal View History

2015-12-24 20:34:34 +01:00
"""
Various utility functions.
"""
2015-12-25 00:56:45 +01:00
import bottle
2015-12-24 20:34:34 +01:00
import json
def pretty_json(data):
"""
Return pretty printed JSON-formatted string.
"""
return json.dumps(data,
sort_keys=True,
indent=4,
separators=(',', ': '))
2015-12-25 00:56:45 +01:00
class APIResponse(bottle.HTTPResponse):
"""
Extend bottle.HTTPResponse base class to add Content-Type header.
"""
def __init__(self, body='', status=None, headers=None, **more_headers):
if headers is None:
headers = {}
headers["Content-Type"] = "application/vnd.api+json"
super(APIResponse, self).__init__(body,
status,
headers,
**more_headers)