diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 8c64d9510..0d512342b 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -426,3 +426,12 @@ try: from xml.etree import ParseError as ETParseError except ImportError: # python < 2.7 ETParseError = None + + +# XMLParser only takes an encoding arg from >= 2.7 +def ET_XMLParser(encoding=None): + from xml.etree import ElementTree as ET + try: + return ET.XMLParser(encoding=encoding) + except TypeError: + return ET.XMLParser() diff --git a/rest_framework/parsers.py b/rest_framework/parsers.py index 98d63fec1..06b022264 100644 --- a/rest_framework/parsers.py +++ b/rest_framework/parsers.py @@ -9,7 +9,7 @@ from django.conf import settings from django.http import QueryDict from django.http.multipartparser import MultiPartParser as DjangoMultiPartParser from django.http.multipartparser import MultiPartParserError -from rest_framework.compat import yaml, ETParseError +from rest_framework.compat import yaml, ETParseError, ET_XMLParser from rest_framework.exceptions import ParseError from rest_framework.compat import six from xml.etree import ElementTree as ET @@ -148,7 +148,7 @@ class XMLParser(BaseParser): def parse(self, stream, media_type=None, parser_context=None): parser_context = parser_context or {} encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET) - parser = ET.XMLParser(encoding=encoding) + parser = ET_XMLParser(encoding=encoding) try: tree = ET.parse(stream, parser=parser) except (ExpatError, ETParseError, ValueError) as exc: diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index b635d20d3..d9125e211 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -165,6 +165,11 @@ class BaseSerializer(Field): # Remove anything in 'exclude' if self.opts.exclude: + # Note: To be deprecated in line with Django's ModelForm change. + # https://code.djangoproject.com/ticket/19733 + warnings.warn('`exclude` option on serializers is due to be deprecated. ' + 'Use the `fields` option instead.', + PendingDeprecationWarning, stacklevel=2) for key in self.opts.exclude: ret.pop(key, None)