diff options
| author | Tom Christie | 2013-02-01 11:58:55 +0000 | 
|---|---|---|
| committer | Tom Christie | 2013-02-01 11:58:55 +0000 | 
| commit | d9c7b1c58523d63c8118d88f44ebfdf5f35e942a (patch) | |
| tree | 6efc5a04556b1800756034791ce8aed082f25d4d /rest_framework/parsers.py | |
| parent | 8021bb5d5089955b171173e60dcc0968e13d29ea (diff) | |
| parent | 0f0e76d8b1b7a7a28b4ce2c6d8f7ecc89e7219ff (diff) | |
| download | django-rest-framework-d9c7b1c58523d63c8118d88f44ebfdf5f35e942a.tar.bz2 | |
Merge branch 'p3k' of https://github.com/linovia/django-rest-framework into working
Conflicts:
	rest_framework/authentication.py
	rest_framework/relations.py
	rest_framework/serializers.py
	rest_framework/settings.py
	rest_framework/tests/authentication.py
	rest_framework/tests/genericrelations.py
	rest_framework/tests/generics.py
	rest_framework/tests/relations_hyperlink.py
	rest_framework/tests/relations_nested.py
	rest_framework/tests/relations_pk.py
	rest_framework/tests/serializer.py
Diffstat (limited to 'rest_framework/parsers.py')
| -rw-r--r-- | rest_framework/parsers.py | 23 | 
1 files changed, 13 insertions, 10 deletions
| diff --git a/rest_framework/parsers.py b/rest_framework/parsers.py index 149d6431..4a2b34a5 100644 --- a/rest_framework/parsers.py +++ b/rest_framework/parsers.py @@ -10,6 +10,7 @@ from django.http.multipartparser import MultiPartParser as DjangoMultiPartParser  from django.http.multipartparser import MultiPartParserError  from rest_framework.compat import yaml, ETParseError  from rest_framework.exceptions import ParseError +from rest_framework.compat import six  from xml.etree import ElementTree as ET  from xml.parsers.expat import ExpatError  import json @@ -55,9 +56,10 @@ class JSONParser(BaseParser):          `files` will always be `None`.          """          try: -            return json.load(stream) -        except ValueError, exc: -            raise ParseError('JSON parse error - %s' % unicode(exc)) +            data = stream.read().decode('iso-8859-1') +            return json.loads(data) +        except ValueError as exc: +            raise ParseError('JSON parse error - %s' % six.text_type(exc))  class YAMLParser(BaseParser): @@ -75,9 +77,10 @@ class YAMLParser(BaseParser):          `files` will always be `None`.          """          try: -            return yaml.safe_load(stream) -        except (ValueError, yaml.parser.ParserError), exc: -            raise ParseError('YAML parse error - %s' % unicode(exc)) +            data = stream.read().decode('iso-8859-1') +            return yaml.safe_load(data) +        except (ValueError, yaml.parser.ParserError) as exc: +            raise ParseError('YAML parse error - %s' % six.u(exc))  class FormParser(BaseParser): @@ -121,8 +124,8 @@ class MultiPartParser(BaseParser):              parser = DjangoMultiPartParser(meta, stream, upload_handlers)              data, files = parser.parse()              return DataAndFiles(data, files) -        except MultiPartParserError, exc: -            raise ParseError('Multipart form parse error - %s' % unicode(exc)) +        except MultiPartParserError as exc: +            raise ParseError('Multipart form parse error - %s' % six.u(exc))  class XMLParser(BaseParser): @@ -135,8 +138,8 @@ class XMLParser(BaseParser):      def parse(self, stream, media_type=None, parser_context=None):          try:              tree = ET.parse(stream) -        except (ExpatError, ETParseError, ValueError), exc: -            raise ParseError('XML parse error - %s' % unicode(exc)) +        except (ExpatError, ETParseError, ValueError) as exc: +            raise ParseError('XML parse error - %s' % six.u(exc))          data = self._xml_convert(tree.getroot())          return data | 
