mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 03:23:59 +03:00
Move the urlparse lib compatibility to the compat file.
This commit is contained in:
parent
c95fa81cb2
commit
4b77b3c5ad
|
@ -30,6 +30,13 @@ except ImportError:
|
|||
from six import BytesIO
|
||||
|
||||
|
||||
# urlparse compat import (Required because it changed in python 3.x)
|
||||
try:
|
||||
from urllib import parse as urlparse
|
||||
except ImportError:
|
||||
import urlparse as urlparse
|
||||
|
||||
|
||||
# Try to import PIL in either of the two ways it can end up installed.
|
||||
try:
|
||||
from PIL import Image
|
||||
|
@ -109,7 +116,6 @@ else:
|
|||
import re
|
||||
import random
|
||||
import logging
|
||||
import urlparse
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import get_callable
|
||||
|
|
|
@ -12,7 +12,7 @@ except ImportError:
|
|||
from django.utils.encoding import smart_unicode as smart_text
|
||||
from rest_framework.fields import Field, WritableField
|
||||
from rest_framework.reverse import reverse
|
||||
from urlparse import urlparse
|
||||
from rest_framework.compat import urlparse
|
||||
|
||||
##### Relational fields #####
|
||||
|
||||
|
@ -360,7 +360,7 @@ class HyperlinkedRelatedField(RelatedField):
|
|||
|
||||
if value.startswith('http:') or value.startswith('https:'):
|
||||
# If needed convert absolute URLs to relative path
|
||||
value = urlparse(value).path
|
||||
value = urlparse.urlparse(value).path
|
||||
prefix = get_script_prefix()
|
||||
if value.startswith(prefix):
|
||||
value = '/' + value[len(prefix):]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
import six
|
||||
|
||||
from django import template
|
||||
|
@ -10,10 +10,7 @@ except ImportError:
|
|||
from django.utils.encoding import force_unicode as force_text
|
||||
from django.utils.html import escape
|
||||
from django.utils.safestring import SafeData, mark_safe
|
||||
try:
|
||||
from urllib.parse import urlsplit, urlunsplit
|
||||
except ImportError:
|
||||
from urlparse import urlsplit, urlunsplit
|
||||
from rest_framework.compat import urlparse
|
||||
import re
|
||||
import string
|
||||
|
||||
|
@ -108,11 +105,11 @@ def replace_query_param(url, key, val):
|
|||
Given a URL and a key/val pair, set or replace an item in the query
|
||||
parameters of the URL, and return the new URL.
|
||||
"""
|
||||
(scheme, netloc, path, query, fragment) = urlsplit(url)
|
||||
(scheme, netloc, path, query, fragment) = urlparse.urlsplit(url)
|
||||
query_dict = QueryDict(query).copy()
|
||||
query_dict[key] = val
|
||||
query = query_dict.urlencode()
|
||||
return urlunsplit((scheme, netloc, path, query, fragment))
|
||||
return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
|
||||
|
||||
|
||||
# Regex for adding classes to html snippets
|
||||
|
|
Loading…
Reference in New Issue
Block a user