aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/content.py
diff options
context:
space:
mode:
authorspiq2011-03-04 12:28:20 +0200
committerspiq2011-03-04 12:28:20 +0200
commit91b33659b562f26665cebc3c7d8aba6d57e9386c (patch)
tree254239bbc2b0c1ffab085e7ac4ae3184aedbe041 /djangorestframework/content.py
parent30fd23d7f5a2d468e39fa8b66bae508df88a4d0d (diff)
downloaddjango-rest-framework-91b33659b562f26665cebc3c7d8aba6d57e9386c.tar.bz2
fix for PUT files
Diffstat (limited to 'djangorestframework/content.py')
-rw-r--r--djangorestframework/content.py35
1 files changed, 32 insertions, 3 deletions
diff --git a/djangorestframework/content.py b/djangorestframework/content.py
index d612a2ee..abe2069e 100644
--- a/djangorestframework/content.py
+++ b/djangorestframework/content.py
@@ -24,6 +24,27 @@ class StandardContentMixin(ContentMixin):
return None
return (request.META.get('CONTENT_TYPE', None), request.raw_post_data)
+from django.core.files.base import File
+class SocketFile(File):
+ # Only forward access is allowed
+ def __init__(self, socket, size):
+ super(SocketFile, self).__init__(socket)
+ self._size = int(size)
+ self._pos = 0
+
+ def read(self, num_bytes=None):
+ if num_bytes is None:
+ num_bytes = self._size - self._pos
+ else:
+ num_bytes = min(num_bytes, self._size - self._pos)
+ self._pos += num_bytes
+ return self.file.read(num_bytes)
+
+ def tell(self):
+ return self._pos
+
+ def seek(self, position):
+ pass
class OverloadedContentMixin(ContentMixin):
"""HTTP request content behaviour that also allows arbitrary content to be tunneled in form data."""
@@ -39,7 +60,7 @@ class OverloadedContentMixin(ContentMixin):
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
@@ -51,5 +72,13 @@ class OverloadedContentMixin(ContentMixin):
content_type = request.POST.get(self.CONTENTTYPE_PARAM, None)
return (content_type, request.POST[self.CONTENT_PARAM])
-
- return (content_type, request.raw_post_data) \ No newline at end of file
+ elif request.method == 'PUT':
+ f = SocketFile(request.environ['wsgi.input'], request.META['CONTENT_LENGTH'])
+ returned = (content_type, f.read())
+ return returned
+ #try:
+ # f.close()
+ #except Exception as e:
+ # print 'exception', e
+ else:
+ return (content_type, request.raw_post_data)