aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/parsers.py
diff options
context:
space:
mode:
authorTom Christie2011-05-12 12:55:13 +0100
committerTom Christie2011-05-12 12:55:13 +0100
commit15f9e7c56699d31043782045a9fe47c354f612cb (patch)
tree2c58441416a877d0afba22d85aea691190a17fa1 /djangorestframework/parsers.py
parent4d126796752cc3c79a24fd9caed49da6c525096f (diff)
downloaddjango-rest-framework-15f9e7c56699d31043782045a9fe47c354f612cb.tar.bz2
refactoring resource specfic stuff into ResourceMixin - validators now defunct
Diffstat (limited to 'djangorestframework/parsers.py')
-rw-r--r--djangorestframework/parsers.py19
1 files changed, 7 insertions, 12 deletions
diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py
index da700367..9e1b971b 100644
--- a/djangorestframework/parsers.py
+++ b/djangorestframework/parsers.py
@@ -41,7 +41,7 @@ class BaseParser(object):
"""
self.view = view
- def can_handle_request(self, media_type):
+ def can_handle_request(self, content_type):
"""
Returns `True` if this parser is able to deal with the given media type.
@@ -52,12 +52,12 @@ class BaseParser(object):
This may be overridden to provide for other behavior, but typically you'll
instead want to just set the ``media_type`` attribute on the class.
"""
- return media_type_matches(media_type, self.media_type)
+ return media_type_matches(content_type, self.media_type)
def parse(self, stream):
"""
Given a stream to read from, return the deserialized output.
- The return value may be of any type, but for many parsers it might typically be a dict-like object.
+ Should return a 2-tuple of (data, files).
"""
raise NotImplementedError("BaseParser.parse() Must be overridden to be implemented.")
@@ -67,7 +67,7 @@ class JSONParser(BaseParser):
def parse(self, stream):
try:
- return json.load(stream)
+ return (json.load(stream), None)
except ValueError, exc:
raise ErrorResponse(status.HTTP_400_BAD_REQUEST,
{'detail': 'JSON parse error - %s' % unicode(exc)})
@@ -107,7 +107,7 @@ class PlainTextParser(BaseParser):
media_type = 'text/plain'
def parse(self, stream):
- return stream.read()
+ return (stream.read(), None)
class FormParser(BaseParser, DataFlatener):
@@ -139,7 +139,7 @@ class FormParser(BaseParser, DataFlatener):
if key in self.RESERVED_FORM_PARAMS:
data.pop(key)
- return data
+ return (data, None)
def remove_empty_val(self, val_list):
""" """
@@ -152,11 +152,6 @@ class FormParser(BaseParser, DataFlatener):
val_list.pop(ind)
-class MultipartData(dict):
- def __init__(self, data, files):
- dict.__init__(self, data)
- self.FILES = files
-
class MultiPartParser(BaseParser, DataFlatener):
media_type = 'multipart/form-data'
RESERVED_FORM_PARAMS = ('csrfmiddlewaretoken',)
@@ -175,4 +170,4 @@ class MultiPartParser(BaseParser, DataFlatener):
if key in self.RESERVED_FORM_PARAMS:
data.pop(key)
- return MultipartData(data, files)
+ return (data, files)