mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-23 15:54:16 +03:00
Fix 2.6 compat
This commit is contained in:
parent
937ef00808
commit
7dc4bce4e2
|
@ -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()
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user