From f73588eb425f611cb79c7a56133690328739bf6c Mon Sep 17 00:00:00 2001 From: Jens Alm Date: Sat, 2 Jul 2011 19:03:26 +0200 Subject: [PATCH 1/3] parsers.DEFAULT_PARSERS added to be consistent with renderers.DEFAULT_RENDERERS --- .gitignore | 1 + djangorestframework/parsers.py | 6 ++++++ djangorestframework/views.py | 4 +--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 4947943af..312b28df9 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ MANIFEST .coverage .tox .DS_Store +.idea/* \ No newline at end of file diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py index 5f19c521b..f4c8dcb40 100644 --- a/djangorestframework/parsers.py +++ b/djangorestframework/parsers.py @@ -167,3 +167,9 @@ class MultiPartParser(BaseParser): {'detail': 'multipart parse error - %s' % unicode(exc)}) return django_parser.parse() +DEFAULT_PARSERS = ( parsers.JSONParser, + parsers.FormParser, + parsers.MultiPartParser ) + +if YAMLParser: + DEFAULT_PARSERS += (YAMLParser,) diff --git a/djangorestframework/views.py b/djangorestframework/views.py index eea3b97ad..c25bb88f6 100644 --- a/djangorestframework/views.py +++ b/djangorestframework/views.py @@ -44,9 +44,7 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView): """ List of parsers the resource can parse the request with. """ - parsers = ( parsers.JSONParser, - parsers.FormParser, - parsers.MultiPartParser ) + parsers = parsers.DEFAULT_PARSERS """ List of all authenticating methods to attempt. From 20c7e605c987bbfec23fbd305e71168b21672bec Mon Sep 17 00:00:00 2001 From: Jens Alm Date: Sat, 2 Jul 2011 19:12:43 +0200 Subject: [PATCH 2/3] Sloppy copy-pasting... --- djangorestframework/parsers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py index f4c8dcb40..168d391ea 100644 --- a/djangorestframework/parsers.py +++ b/djangorestframework/parsers.py @@ -167,9 +167,9 @@ class MultiPartParser(BaseParser): {'detail': 'multipart parse error - %s' % unicode(exc)}) return django_parser.parse() -DEFAULT_PARSERS = ( parsers.JSONParser, - parsers.FormParser, - parsers.MultiPartParser ) +DEFAULT_PARSERS = ( JSONParser, + FormParser, + MultiPartParser ) if YAMLParser: DEFAULT_PARSERS += (YAMLParser,) From 3e0a978dd97a55a5db072584a2bba639ed790b82 Mon Sep 17 00:00:00 2001 From: Jens Alm Date: Sat, 2 Jul 2011 19:19:45 +0200 Subject: [PATCH 3/3] Fixed YAMLParser = None --- djangorestframework/parsers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py index 168d391ea..41f15aa3b 100644 --- a/djangorestframework/parsers.py +++ b/djangorestframework/parsers.py @@ -108,7 +108,8 @@ if yaml: except ValueError, exc: raise ErrorResponse(status.HTTP_400_BAD_REQUEST, {'detail': 'YAML parse error - %s' % unicode(exc)}) - +else: + YAMLParser = None class PlainTextParser(BaseParser): """