aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/parsers.py
diff options
context:
space:
mode:
Diffstat (limited to 'djangorestframework/parsers.py')
-rw-r--r--djangorestframework/parsers.py42
1 files changed, 21 insertions, 21 deletions
diff --git a/djangorestframework/parsers.py b/djangorestframework/parsers.py
index c8a014ae..099abe9a 100644
--- a/djangorestframework/parsers.py
+++ b/djangorestframework/parsers.py
@@ -92,28 +92,25 @@ class JSONParser(BaseParser):
{'detail': 'JSON parse error - %s' % unicode(exc)})
-if yaml:
- class YAMLParser(BaseParser):
- """
- Parses YAML-serialized data.
- """
+class YAMLParser(BaseParser):
+ """
+ Parses YAML-serialized data.
+ """
- media_type = 'application/yaml'
+ media_type = 'application/yaml'
- def parse(self, stream):
- """
- Returns a 2-tuple of `(data, files)`.
+ def parse(self, stream):
+ """
+ Returns a 2-tuple of `(data, files)`.
- `data` will be an object which is the parsed content of the response.
- `files` will always be `None`.
- """
- try:
- return (yaml.safe_load(stream), None)
- except ValueError, exc:
- raise ErrorResponse(status.HTTP_400_BAD_REQUEST,
- {'detail': 'YAML parse error - %s' % unicode(exc)})
-else:
- YAMLParser = None
+ `data` will be an object which is the parsed content of the response.
+ `files` will always be `None`.
+ """
+ try:
+ return (yaml.safe_load(stream), None)
+ except (ValueError, yaml.parser.ParserError), exc:
+ content = {'detail': 'YAML parse error - %s' % unicode(exc)}
+ raise ErrorResponse(status.HTTP_400_BAD_REQUEST, content)
class PlainTextParser(BaseParser):
@@ -248,5 +245,8 @@ DEFAULT_PARSERS = (
XMLParser
)
-if YAMLParser:
- DEFAULT_PARSERS += (YAMLParser,)
+if yaml:
+ DEFAULT_PARSERS += (YAMLParser, )
+else:
+ YAMLParser = None
+