From 88ed1c8d08c70fd3e7943fc8383459545f726dcd Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 5 Jan 2021 12:18:04 +0100 Subject: [PATCH] Refs #27753 -- Removed django.utils.http urllib aliases per deprecation timeline. --- django/utils/http.py | 62 ++-------------------------------- docs/releases/4.0.txt | 3 +- tests/utils_tests/test_http.py | 26 ++------------ 3 files changed, 7 insertions(+), 84 deletions(-) diff --git a/django/utils/http.py b/django/utils/http.py index 810d7970ba..62c30d3394 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -7,14 +7,12 @@ import warnings from binascii import Error as BinasciiError from email.utils import formatdate from urllib.parse import ( - ParseResult, SplitResult, _coerce_args, _splitnetloc, _splitparams, quote, - quote_plus, scheme_chars, unquote, unquote_plus, - urlencode as original_urlencode, uses_params, + ParseResult, SplitResult, _coerce_args, _splitnetloc, _splitparams, + scheme_chars, unquote, urlencode as original_urlencode, uses_params, ) from django.utils.datastructures import MultiValueDict from django.utils.deprecation import RemovedInDjango40Warning -from django.utils.functional import keep_lazy_text from django.utils.regex_helper import _lazy_re_compile # based on RFC 7232, Appendix C @@ -42,62 +40,6 @@ RFC3986_GENDELIMS = ":/?#[]@" RFC3986_SUBDELIMS = "!$&'()*+,;=" -@keep_lazy_text -def urlquote(url, safe='/'): - """ - A legacy compatibility wrapper to Python's urllib.parse.quote() function. - (was used for unicode handling on Python 2) - """ - warnings.warn( - 'django.utils.http.urlquote() is deprecated in favor of ' - 'urllib.parse.quote().', - RemovedInDjango40Warning, stacklevel=2, - ) - return quote(url, safe) - - -@keep_lazy_text -def urlquote_plus(url, safe=''): - """ - A legacy compatibility wrapper to Python's urllib.parse.quote_plus() - function. (was used for unicode handling on Python 2) - """ - warnings.warn( - 'django.utils.http.urlquote_plus() is deprecated in favor of ' - 'urllib.parse.quote_plus(),', - RemovedInDjango40Warning, stacklevel=2, - ) - return quote_plus(url, safe) - - -@keep_lazy_text -def urlunquote(quoted_url): - """ - A legacy compatibility wrapper to Python's urllib.parse.unquote() function. - (was used for unicode handling on Python 2) - """ - warnings.warn( - 'django.utils.http.urlunquote() is deprecated in favor of ' - 'urllib.parse.unquote().', - RemovedInDjango40Warning, stacklevel=2, - ) - return unquote(quoted_url) - - -@keep_lazy_text -def urlunquote_plus(quoted_url): - """ - A legacy compatibility wrapper to Python's urllib.parse.unquote_plus() - function. (was used for unicode handling on Python 2) - """ - warnings.warn( - 'django.utils.http.urlunquote_plus() is deprecated in favor of ' - 'urllib.parse.unquote_plus().', - RemovedInDjango40Warning, stacklevel=2, - ) - return unquote_plus(quoted_url) - - def urlencode(query, doseq=False): """ A version of Python's urllib.parse.urlencode() function that can operate on diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt index cc8c698ba4..970a5ff126 100644 --- a/docs/releases/4.0.txt +++ b/docs/releases/4.0.txt @@ -246,7 +246,8 @@ in Django 4.0. See :ref:`deprecated-features-3.0` for details on these changes, including how to remove usage of these features. -* ... +* ``django.utils.http.urlquote()``, ``urlquote_plus()``, ``urlunquote()``, and + ``urlunquote_plus()`` are removed. See :ref:`deprecated-features-3.1` for details on these changes, including how to remove usage of these features. diff --git a/tests/utils_tests/test_http.py b/tests/utils_tests/test_http.py index 1966386e77..1a857dafa1 100644 --- a/tests/utils_tests/test_http.py +++ b/tests/utils_tests/test_http.py @@ -3,15 +3,14 @@ import unittest from datetime import datetime from unittest import mock -from django.test import SimpleTestCase, ignore_warnings +from django.test import SimpleTestCase from django.utils.datastructures import MultiValueDict from django.utils.deprecation import RemovedInDjango40Warning from django.utils.http import ( base36_to_int, escape_leading_slashes, http_date, int_to_base36, is_safe_url, is_same_domain, parse_etags, parse_http_date, parse_qsl, - quote_etag, url_has_allowed_host_and_scheme, urlencode, urlquote, - urlquote_plus, urlsafe_base64_decode, urlsafe_base64_encode, urlunquote, - urlunquote_plus, + quote_etag, url_has_allowed_host_and_scheme, urlencode, + urlsafe_base64_decode, urlsafe_base64_encode, ) @@ -252,25 +251,6 @@ class URLSafeBase64Tests(unittest.TestCase): self.assertEqual(bytestring, decoded) -@ignore_warnings(category=RemovedInDjango40Warning) -class URLQuoteTests(unittest.TestCase): - def test_quote(self): - self.assertEqual(urlquote('Paris & Orl\xe9ans'), 'Paris%20%26%20Orl%C3%A9ans') - self.assertEqual(urlquote('Paris & Orl\xe9ans', safe="&"), 'Paris%20&%20Orl%C3%A9ans') - - def test_unquote(self): - self.assertEqual(urlunquote('Paris%20%26%20Orl%C3%A9ans'), 'Paris & Orl\xe9ans') - self.assertEqual(urlunquote('Paris%20&%20Orl%C3%A9ans'), 'Paris & Orl\xe9ans') - - def test_quote_plus(self): - self.assertEqual(urlquote_plus('Paris & Orl\xe9ans'), 'Paris+%26+Orl%C3%A9ans') - self.assertEqual(urlquote_plus('Paris & Orl\xe9ans', safe="&"), 'Paris+&+Orl%C3%A9ans') - - def test_unquote_plus(self): - self.assertEqual(urlunquote_plus('Paris+%26+Orl%C3%A9ans'), 'Paris & Orl\xe9ans') - self.assertEqual(urlunquote_plus('Paris+&+Orl%C3%A9ans'), 'Paris & Orl\xe9ans') - - class IsSameDomainTests(unittest.TestCase): def test_good(self): for pair in (