diff --git a/api/renderers.py b/api/renderers.py deleted file mode 100644 index 74cf2954e..000000000 --- a/api/renderers.py +++ /dev/null @@ -1,59 +0,0 @@ -import ujson -import six - -from rest_framework.renderers import JSONRenderer -from rest_framework.settings import api_settings -from rest_framework.utils import encoders - - -class JSONLDRenderer(JSONRenderer): - """ - Renderer which serializes to JSON. - """ - media_type = 'application/vnd.api+json' - format = 'json' - encoder_class = encoders.JSONEncoder - ensure_ascii = not api_settings.UNICODE_JSON - compact = api_settings.COMPACT_JSON - - # We don't set a charset because JSON is a binary encoding, - # that can be encoded as utf-8, utf-16 or utf-32. - # See: http://www.ietf.org/rfc/rfc4627.txt - # Also: http://lucumr.pocoo.org/2013/7/19/application-mimetypes-and-encodings/ - charset = None - - def render(self, data, accepted_media_type=None, renderer_context=None): - """ - Render `data` into JSON, returning a bytestring. - """ - if data is None: - return bytes() - - renderer_context = renderer_context or {} - indent = self.get_indent(accepted_media_type, renderer_context) or 4 - - # if indent is None: - # separators = SHORT_SEPARATORS if self.compact else LONG_SEPARATORS - # else: - # separators = INDENT_SEPARATORS - - ret = ujson.dumps( # UJSON is faster - data, - # , cls=self.encoder_class, - escape_forward_slashes=False, - indent=indent, ensure_ascii=self.ensure_ascii, - # separators=separators - ) - - # On python 2.x json.dumps() returns bytestrings if ensure_ascii=True, - # but if ensure_ascii=False, the return type is underspecified, - # and may (or may not) be unicode. - # On python 3.x json.dumps() returns unicode strings. - if isinstance(ret, six.text_type): - # We always fully escape \u2028 and \u2029 to ensure we output JSON - # that is a strict javascript subset. If bytes were returned - # by json.dumps() then we don't have these characters in any case. - # See: http://timelessrepo.com/json-isnt-a-javascript-subset - ret = ret.replace('\u2028', '\\u2028').replace('\u2029', '\\u2029') - return bytes(ret.encode('utf-8')) - return ret