diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-08-03 18:46:30 +0200 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-08-03 18:51:28 +0200 |
| commit | d01eaf7104e96b2fcf373ddfbc80ef4568bd0387 (patch) | |
| tree | 6fd233f405c06ea97fc2a6289c1eb07e885d202e /django/utils/http.py | |
| parent | 129f1ac8484d63c2e61a44fb2a18dd17246c1c4d (diff) | |
[py3] Removed uses of sys.maxint under Python 3.
Also fixed #18706: improved exceptions raised by int_to_base36.
Diffstat (limited to 'django/utils/http.py')
| -rw-r--r-- | django/utils/http.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/django/utils/http.py b/django/utils/http.py index f3a3dce58c..272e73f190 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -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 |
