django-rest-framework/djangorestframework/response.py

34 lines
1.2 KiB
Python
Raw Normal View History

from django.core.handlers.wsgi import STATUS_CODE_TEXT
2011-02-19 13:47:26 +03:00
__all__ =['NoContent', 'Response', ]
class NoContent(object):
"""Used to indicate no body in http response.
2011-02-19 13:47:26 +03:00
(We cannot just use None, as that is a valid, serializable response object.)
TODO: On reflection I'm going to get rid of this and just not support serialized 'None' responses.
2011-02-19 13:47:26 +03:00
"""
pass
class Response(object):
def __init__(self, status=200, content=NoContent, headers={}):
self.status = status
2011-02-19 13:47:26 +03:00
self.has_content_body = not content is NoContent # TODO: remove and just use content
self.raw_content = content # content prior to filtering - TODO: remove and just use content
self.cleaned_content = content # content after filtering TODO: remove and just use content
self.headers = headers
@property
def status_text(self):
"""Return reason text corresponding to our HTTP response status code.
Provided for convenience."""
return STATUS_CODE_TEXT.get(self.status, '')
class ResponseException(BaseException):
def __init__(self, status, content=NoContent, headers={}):
2011-01-27 22:24:58 +03:00
self.response = Response(status, content=content, headers=headers)