2011-01-24 02:08:16 +03:00
|
|
|
from django.core.handlers.wsgi import STATUS_CODE_TEXT
|
|
|
|
|
2011-02-19 13:47:26 +03:00
|
|
|
__all__ =['NoContent', 'Response', ]
|
2011-01-24 02:08:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 relflection I'm going to get rid of this and just not support serailized 'None' responses.
|
|
|
|
"""
|
2011-01-24 02:08:16 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Response(object):
|
2011-02-05 00:52:21 +03:00
|
|
|
def __init__(self, status=200, content=NoContent, headers={}):
|
2011-01-24 02:08:16 +03:00
|
|
|
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
|
2011-01-24 02:08:16 +03:00
|
|
|
self.headers = headers
|
|
|
|
|
|
|
|
@property
|
|
|
|
def status_text(self):
|
|
|
|
"""Return reason text corrosponding to our HTTP response status code.
|
|
|
|
Provided for convienience."""
|
|
|
|
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)
|