aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/content.py
diff options
context:
space:
mode:
authortom christie tom@tomchristie.com2011-04-02 16:32:37 +0100
committertom christie tom@tomchristie.com2011-04-02 16:32:37 +0100
commit4687db680cda52e9836743940e4cf7279b307294 (patch)
tree23b9b22eee3c08f6de09295b3c6630f5fb0730fa /djangorestframework/content.py
parent8845b281fe9aafbc9f9b2a283fafbde9787f4734 (diff)
downloaddjango-rest-framework-4687db680cda52e9836743940e4cf7279b307294.tar.bz2
Refactor to use self.CONTENT to access request body. Get file upload working
Diffstat (limited to 'djangorestframework/content.py')
-rw-r--r--djangorestframework/content.py57
1 files changed, 0 insertions, 57 deletions
diff --git a/djangorestframework/content.py b/djangorestframework/content.py
deleted file mode 100644
index cfdd33be..00000000
--- a/djangorestframework/content.py
+++ /dev/null
@@ -1,57 +0,0 @@
-"""Mixin classes that provide a determine_content(request) method to return the content type and content of a request.
-We use this more generic behaviour to allow for overloaded content in POST forms.
-"""
-
-class ContentMixin(object):
- """Base class for all ContentMixin classes, which simply defines the interface they provide."""
-
- def determine_content(self, request):
- """If the request contains content return a tuple of (content_type, content) otherwise return None.
- Note that content_type may be None if it is unset.
- Must be overridden to be implemented."""
- raise NotImplementedError()
-
-
-class StandardContentMixin(ContentMixin):
- """Standard HTTP request content behaviour.
- See RFC 2616 sec 4.3 - http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3"""
-
- def determine_content(self, request):
- """If the request contains content return a tuple of (content_type, content) otherwise return None.
- Note that content_type may be None if it is unset."""
-
- if not request.META.get('CONTENT_LENGTH', None) and not request.META.get('TRANSFER_ENCODING', None):
- return None
- return (request.META.get('CONTENT_TYPE', None), request.raw_post_data)
-
-
-class OverloadedContentMixin(ContentMixin):
- """HTTP request content behaviour that also allows arbitrary content to be tunneled in form data."""
-
- """The name to use for the content override field in the POST form.
- Set this to *None* to desactivate content overloading."""
- CONTENT_PARAM = '_content'
-
- """The name to use for the content-type override field in the POST form.
- Taken into account only if content overloading is activated."""
- CONTENTTYPE_PARAM = '_contenttype'
-
- def determine_content(self, request):
- """If the request contains content, returns a tuple of (content_type, content) otherwise returns None.
- Note that content_type may be None if it is unset."""
- if not request.META.get('CONTENT_LENGTH', None) and not request.META.get('TRANSFER_ENCODING', None):
- return None
- content_type = request.META.get('CONTENT_TYPE', None)
-
- if (request.method == 'POST' and self.CONTENT_PARAM and
- request.POST.get(self.CONTENT_PARAM, None) is not None):
-
- # Set content type if form contains a non-empty CONTENTTYPE_PARAM field
- content_type = None
- if self.CONTENTTYPE_PARAM and request.POST.get(self.CONTENTTYPE_PARAM, None):
- content_type = request.POST.get(self.CONTENTTYPE_PARAM, None)
- request.META['CONTENT_TYPE'] = content_type # TODO : VERY BAD, avoid modifying original request.
-
- return (content_type, request.POST[self.CONTENT_PARAM])
- else:
- return (content_type, request.raw_post_data)