summaryrefslogtreecommitdiff
path: root/django/utils/http.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-07-20 15:36:52 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-07-22 09:29:55 +0200
commit0d914d08a0d7b5a1521f498a8047971fe6cd61e7 (patch)
treed0ab08b0b5b2041bd796c10a26a358ae60d0914a /django/utils/http.py
parentbdca5ea345c548a82a80d198906818c9ccbef896 (diff)
[py3] Updated urllib/urllib2/urlparse imports.
Lots of functions were moved. Use explicit imports in all cases to keey it easy to identify where the functions come from.
Diffstat (limited to 'django/utils/http.py')
-rw-r--r--django/utils/http.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/django/utils/http.py b/django/utils/http.py
index ec94d62903..f3a3dce58c 100644
--- a/django/utils/http.py
+++ b/django/utils/http.py
@@ -2,8 +2,14 @@ import calendar
import datetime
import re
import sys
-import urllib
-import urlparse
+try:
+ from urllib import parse as urllib_parse
+except ImportError: # Python 2
+ import urllib as urllib_parse
+ import urlparse
+ urllib_parse.urlparse = urlparse.urlparse
+
+
from email.utils import formatdate
from django.utils.datastructures import MultiValueDict
@@ -31,7 +37,7 @@ def urlquote(url, safe='/'):
can safely be used as part of an argument to a subsequent iri_to_uri() call
without double-quoting occurring.
"""
- return force_unicode(urllib.quote(smart_str(url), smart_str(safe)))
+ return force_unicode(urllib_parse.quote(smart_str(url), smart_str(safe)))
urlquote = allow_lazy(urlquote, six.text_type)
def urlquote_plus(url, safe=''):
@@ -41,7 +47,7 @@ def urlquote_plus(url, safe=''):
returned string can safely be used as part of an argument to a subsequent
iri_to_uri() call without double-quoting occurring.
"""
- return force_unicode(urllib.quote_plus(smart_str(url), smart_str(safe)))
+ return force_unicode(urllib_parse.quote_plus(smart_str(url), smart_str(safe)))
urlquote_plus = allow_lazy(urlquote_plus, six.text_type)
def urlunquote(quoted_url):
@@ -49,7 +55,7 @@ def urlunquote(quoted_url):
A wrapper for Python's urllib.unquote() function that can operate on
the result of django.utils.http.urlquote().
"""
- return force_unicode(urllib.unquote(smart_str(quoted_url)))
+ return force_unicode(urllib_parse.unquote(smart_str(quoted_url)))
urlunquote = allow_lazy(urlunquote, six.text_type)
def urlunquote_plus(quoted_url):
@@ -57,7 +63,7 @@ def urlunquote_plus(quoted_url):
A wrapper for Python's urllib.unquote_plus() function that can operate on
the result of django.utils.http.urlquote_plus().
"""
- return force_unicode(urllib.unquote_plus(smart_str(quoted_url)))
+ return force_unicode(urllib_parse.unquote_plus(smart_str(quoted_url)))
urlunquote_plus = allow_lazy(urlunquote_plus, six.text_type)
def urlencode(query, doseq=0):
@@ -70,7 +76,7 @@ def urlencode(query, doseq=0):
query = query.lists()
elif hasattr(query, 'items'):
query = query.items()
- return urllib.urlencode(
+ return urllib_parse.urlencode(
[(smart_str(k),
[smart_str(i) for i in v] if isinstance(v, (list,tuple)) else smart_str(v))
for k, v in query],
@@ -212,5 +218,5 @@ def same_origin(url1, url2):
"""
Checks if two URLs are 'same-origin'
"""
- p1, p2 = urlparse.urlparse(url1), urlparse.urlparse(url2)
+ p1, p2 = urllib_parse.urlparse(url1), urllib_parse.urlparse(url2)
return (p1.scheme, p1.hostname, p1.port) == (p2.scheme, p2.hostname, p2.port)