diff options
| author | Tom Christie | 2012-02-17 09:19:13 +0000 |
|---|---|---|
| committer | Tom Christie | 2012-02-17 09:19:13 +0000 |
| commit | fbf76c87affc88f04bb0d0acaecc6af6442ba921 (patch) | |
| tree | 5a75cbb061829694c4f714ae0e8413c584131739 /djangorestframework/parsers.py | |
| parent | 426493a78f3003fdba39053b6af23b93b312a777 (diff) | |
| parent | c04cb5145c4398cfac090ca7eef032296a04446f (diff) | |
| download | django-rest-framework-fbf76c87affc88f04bb0d0acaecc6af6442ba921.tar.bz2 | |
Merge git://github.com/sebpiq/django-rest-framework into develop
Diffstat (limited to 'djangorestframework/parsers.py')
| -rw-r--r-- | djangorestframework/parsers.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py index c8a014ae..d41e07e8 100644 --- a/djangorestframework/parsers.py +++ b/djangorestframework/parsers.py @@ -17,7 +17,7 @@ from django.http.multipartparser import MultiPartParserError from django.utils import simplejson as json from djangorestframework import status from djangorestframework.compat import yaml -from djangorestframework.response import ErrorResponse +from djangorestframework.response import ImmediateResponse from djangorestframework.utils.mediatypes import media_type_matches from xml.etree import ElementTree as ET import datetime @@ -43,7 +43,7 @@ class BaseParser(object): media_type = None - def __init__(self, view): + def __init__(self, view=None): """ Initialize the parser with the ``View`` instance as state, in case the parser needs to access any metadata on the :obj:`View` object. @@ -88,8 +88,9 @@ class JSONParser(BaseParser): try: return (json.load(stream), None) except ValueError, exc: - raise ErrorResponse(status.HTTP_400_BAD_REQUEST, - {'detail': 'JSON parse error - %s' % unicode(exc)}) + raise ImmediateResponse( + {'detail': 'JSON parse error - %s' % unicode(exc)}, + status=status.HTTP_400_BAD_REQUEST) if yaml: @@ -110,8 +111,9 @@ if yaml: try: return (yaml.safe_load(stream), None) except ValueError, exc: - raise ErrorResponse(status.HTTP_400_BAD_REQUEST, - {'detail': 'YAML parse error - %s' % unicode(exc)}) + raise ImmediateResponse( + {'detail': 'YAML parse error - %s' % unicode(exc)}, + status=status.HTTP_400_BAD_REQUEST) else: YAMLParser = None @@ -169,8 +171,9 @@ class MultiPartParser(BaseParser): try: django_parser = DjangoMultiPartParser(self.view.request.META, stream, upload_handlers) except MultiPartParserError, exc: - raise ErrorResponse(status.HTTP_400_BAD_REQUEST, - {'detail': 'multipart parse error - %s' % unicode(exc)}) + raise ImmediateResponse( + {'detail': 'multipart parse error - %s' % unicode(exc)}, + status=status.HTTP_400_BAD_REQUEST) return django_parser.parse() |
