diff --git a/rest_framework/__init__.pxd b/rest_framework/__init__.pxd new file mode 100644 index 000000000..e69de29bb diff --git a/rest_framework/renderers.pxd b/rest_framework/renderers.pxd new file mode 100644 index 000000000..4a30472f9 --- /dev/null +++ b/rest_framework/renderers.pxd @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# coding: utf-8 + +cimport cython + +@cython.locals(media_type=unicode, format=unicode, charset=unicode, render_style=unicode) +cdef class BaseRenderer(object): + """ + All renderers should extend this class, setting the `media_type` + and `format` attributes, and override the `.render()` method. + """ + + @cython.locals(indent=int, separators=tuple) + cpdef object render(self, dict data, accepted_media_type=?, renderer_context=?) + +@cython.locals(compact=bool, ensure_ascii=bool, charset=unicode) +cdef class JSONRenderer(BaseRenderer): + @cython.locals(base_media_type=unicode, params=dict) + cpdef int get_indent(self, unicode accepted_media_type, dict renderer_context) + +@cython.locals(callback_parameter=unicode, default_callback=unicode) +cdef class JSONPRenderer(JSONRenderer): + cpdef unicode get_callback(self, dict renderer_context) diff --git a/setup.py b/setup.py index efe39d8d4..d26000f3c 100755 --- a/setup.py +++ b/setup.py @@ -1,12 +1,21 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from setuptools import setup -from setuptools.command.test import test as TestCommand +try: + from Cython.Build import cythonize +except ImportError: + ext_modules = None +else: + from setuptools import Extension + ext_modules = cythonize(Extension('speedups', ['rest_framework/renderers.py', + 'rest_framework/__init__.py'])) + import re import os import sys +from setuptools import setup + def get_version(package): """ @@ -43,7 +52,6 @@ def get_package_data(package): version = get_version('rest_framework') - if sys.argv[-1] == 'publish': if os.system("pip freeze | grep wheel"): print("wheel not installed.\nUse `pip install wheel`.\nExiting.") @@ -55,7 +63,6 @@ if sys.argv[-1] == 'publish': print(" git push --tags") sys.exit() - setup( name='djangorestframework', version=version, @@ -68,6 +75,7 @@ setup( package_data=get_package_data('rest_framework'), install_requires=[], zip_safe=False, + ext_modules=ext_modules, classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', @@ -82,7 +90,7 @@ setup( ) # (*) Please direct queries to the discussion group, rather than to me directly -# Doing so helps ensure your question is helpful to other users. -# Queries directly to my email are likely to receive a canned response. +# Doing so helps ensure your question is helpful to other users. +# Queries directly to my email are likely to receive a canned response. # # Many thanks for your understanding.