summaryrefslogtreecommitdiff
path: root/django/utils/http.py
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2012-08-10 12:40:37 +0100
committerAndrew Godwin <andrew@aeracode.org>2012-08-10 12:40:37 +0100
commit184cf9ab798d5b25d855649ddb2ca580949778df (patch)
tree8512633ec04a6979b0953e32e73c9a43d09e5805 /django/utils/http.py
parentc4b2a3262cc79383d6562cfc7e9af20135c8e0bf (diff)
parent7275576235ae2e87f3de7b0facb3f9b0a2368f28 (diff)
Merge branch 'master' into schema-alteration
Diffstat (limited to 'django/utils/http.py')
-rw-r--r--django/utils/http.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/django/utils/http.py b/django/utils/http.py
index f3a3dce58c..22e81a33d7 100644
--- a/django/utils/http.py
+++ b/django/utils/http.py
@@ -13,7 +13,7 @@ except ImportError: # Python 2
from email.utils import formatdate
from django.utils.datastructures import MultiValueDict
-from django.utils.encoding import smart_str, force_unicode
+from django.utils.encoding import force_text, smart_str
from django.utils.functional import allow_lazy
from django.utils import six
@@ -37,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_parse.quote(smart_str(url), smart_str(safe)))
+ return force_text(urllib_parse.quote(smart_str(url), smart_str(safe)))
urlquote = allow_lazy(urlquote, six.text_type)
def urlquote_plus(url, safe=''):
@@ -47,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_parse.quote_plus(smart_str(url), smart_str(safe)))
+ return force_text(urllib_parse.quote_plus(smart_str(url), smart_str(safe)))
urlquote_plus = allow_lazy(urlquote_plus, six.text_type)
def urlunquote(quoted_url):
@@ -55,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_parse.unquote(smart_str(quoted_url)))
+ return force_text(urllib_parse.unquote(smart_str(quoted_url)))
urlunquote = allow_lazy(urlunquote, six.text_type)
def urlunquote_plus(quoted_url):
@@ -63,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_parse.unquote_plus(smart_str(quoted_url)))
+ return force_text(urllib_parse.unquote_plus(smart_str(quoted_url)))
urlunquote_plus = allow_lazy(urlunquote_plus, six.text_type)
def urlencode(query, doseq=0):
@@ -167,8 +167,9 @@ def base36_to_int(s):
if len(s) > 13:
raise ValueError("Base36 input too large")
value = int(s, 36)
- # ... then do a final check that the value will fit into an int.
- if value > sys.maxint:
+ # ... then do a final check that the value will fit into an int to avoid
+ # returning a long (#15067). The long type was removed in Python 3.
+ if not six.PY3 and value > sys.maxint:
raise ValueError("Base36 input too large")
return value
@@ -178,8 +179,13 @@ def int_to_base36(i):
"""
digits = "0123456789abcdefghijklmnopqrstuvwxyz"
factor = 0
- if not 0 <= i <= sys.maxint:
- raise ValueError("Base36 conversion input too large or incorrect type.")
+ if i < 0:
+ raise ValueError("Negative base36 conversion input.")
+ if not six.PY3:
+ if not isinstance(i, six.integer_types):
+ raise TypeError("Non-integer base36 conversion input.")
+ if i > sys.maxint:
+ raise ValueError("Base36 conversion input too large.")
# Find starting factor
while True:
factor += 1