blob: fb2e14a284ba1d24a736a4da44f04d5fec7fbf7d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
from django.core.handlers.wsgi import STATUS_CODE_TEXT
__all__ =['NoContent', 'Response', ]
class NoContent(object):
"""Used to indicate no body in http response.
(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.
"""
pass
class Response(object):
def __init__(self, status=200, content=NoContent, headers={}):
self.status = status
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 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={}):
self.response = Response(status, content=content, headers=headers)
|