diff options
| author | Tom Christie | 2012-02-21 22:09:05 +0000 |
|---|---|---|
| committer | Tom Christie | 2012-02-21 22:09:05 +0000 |
| commit | 9277f438cb85e8205cfe0149142d2f2b4d11a31c (patch) | |
| tree | b9d48aff11c89d378f90db6ea06e6c01480dec39 /djangorestframework/parsers.py | |
| parent | ca9465f11e3310b7b1e18cd893e96b69963f68c9 (diff) | |
| download | django-rest-framework-9277f438cb85e8205cfe0149142d2f2b4d11a31c.tar.bz2 | |
Fix YAML parser bug
Diffstat (limited to 'djangorestframework/parsers.py')
| -rw-r--r-- | djangorestframework/parsers.py | 42 |
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 + |
