aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/compat.py
diff options
context:
space:
mode:
Diffstat (limited to 'rest_framework/compat.py')
-rw-r--r--rest_framework/compat.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/rest_framework/compat.py b/rest_framework/compat.py
index 8c64d951..0d512342 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()