From f1719c7c3faeb4ae99a198f9564641945e93d91c Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Sat, 20 Oct 2018 01:14:44 +0100 Subject: [PATCH 1/2] compat: (py2) urlparse = urllib.parse (py3) We were mistakenly importing the 'urlparse' function from the Python 2 'urlparse' module, as opposed to the module itself. Correct this. Signed-off-by: Stephen Finucane Closes: #6261 --- rest_framework/compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 1d34828bdc..ea09ce9bcf 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -22,7 +22,7 @@ import urllib.parse as urlparse # noqa except ImportError: # Python 2.7 - from urlparse import urlparse # noqa + import urlparse # noqa try: from django.urls import ( # noqa From 3dce9146634395f4f7ab1261039defb06553a854 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Sat, 20 Oct 2018 23:54:04 +0100 Subject: [PATCH 2/2] compat: Remove 'compat.urlparse' We can just use Django's vendored six library, like we do everywhere else. Signed-off-by: Stephen Finucane --- rest_framework/compat.py | 7 ------- rest_framework/renderers.py | 3 ++- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index ea09ce9bcf..fffc179384 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -17,13 +17,6 @@ # Python 2.7 from collections import Mapping # noqa -try: - # Python 3 - import urllib.parse as urlparse # noqa -except ImportError: - # Python 2.7 - import urlparse # noqa - try: from django.urls import ( # noqa URLPattern, diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index 375c38a857..68d1413d1f 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -21,11 +21,12 @@ from django.urls import NoReverseMatch from django.utils import six from django.utils.html import mark_safe +from django.utils.six.moves.urllib import parse as urlparse from rest_framework import VERSION, exceptions, serializers, status from rest_framework.compat import ( INDENT_SEPARATORS, LONG_SEPARATORS, SHORT_SEPARATORS, coreapi, coreschema, - pygments_css, urlparse, yaml + pygments_css, yaml ) from rest_framework.exceptions import ParseError from rest_framework.request import is_form_media_type, override_method