diff options
| author | Tom Christie | 2011-06-02 12:58:10 +0100 |
|---|---|---|
| committer | Tom Christie | 2011-06-02 12:58:10 +0100 |
| commit | b50492853f537a2473bb0a9eea86c8b0ed6b8824 (patch) | |
| tree | d289d39aacf187a8a0696a4c1c863aabe1472c3a /djangorestframework/response.py | |
| parent | 7ee9adbe5c03c29cd4a894dd476548f7fe73b5e4 (diff) | |
| parent | fc1640de75511006e89f033c9270ec91a9f1e4d4 (diff) | |
| download | django-rest-framework-b50492853f537a2473bb0a9eea86c8b0ed6b8824.tar.bz2 | |
pull in -dev as 0.2.0
Diffstat (limited to 'djangorestframework/response.py')
| -rw-r--r-- | djangorestframework/response.py | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/djangorestframework/response.py b/djangorestframework/response.py index fb2e14a2..d68ececf 100644 --- a/djangorestframework/response.py +++ b/djangorestframework/response.py @@ -1,33 +1,43 @@ -from django.core.handlers.wsgi import STATUS_CODE_TEXT +""" +The :mod:`response` module provides Response classes you can use in your +views to return a certain HTTP response. Typically a response is *rendered* +into a HTTP response depending on what renderers are set on your view and +als depending on the accept header of the request. +""" -__all__ =['NoContent', 'Response', ] +from django.core.handlers.wsgi import STATUS_CODE_TEXT +__all__ = ('Response', 'ErrorResponse') +# TODO: remove raw_content/cleaned_content and just use content? -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. +class Response(object): + """ + An HttpResponse that may include content that hasn't yet been serialized. """ - pass - -class Response(object): - def __init__(self, status=200, content=NoContent, headers={}): + def __init__(self, status=200, content=None, 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.media_type = None + self.has_content_body = content is not None + self.raw_content = content # content prior to filtering + self.cleaned_content = content # content after filtering self.headers = headers @property def status_text(self): - """Return reason text corrosponding to our HTTP response status code. - Provided for convienience.""" + """ + 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={}): +class ErrorResponse(BaseException): + """ + An exception representing an Response that should be returned immediately. + Any content should be serialized as-is, without being filtered. + """ + + def __init__(self, status, content=None, headers={}): self.response = Response(status, content=content, headers=headers) |
