Address RemovedInDjango40Warning (4)

In Django 3.0, django.utils.http.urlquote(), urlquote_plus(),
urlunquote(), and urlunquote_plus() are deprecated in favor of
the functions that they’re aliases for: urllib.parse.quote(),
quote_plus(), unquote(), and unquote_plus().

https: //docs.djangoproject.com/en/4.0/releases/3.0/
Change-Id: I37fcd917cbf87b4d3141cfbdd2675aa38f33f2a4
This commit is contained in:
Akihiro Motoki 2022-01-27 03:20:36 +09:00
parent d9266fd82c
commit e4444e6979
15 changed files with 63 additions and 60 deletions

View File

@ -20,6 +20,7 @@ import json
import logging
from operator import attrgetter
import sys
from urllib import parse
from django.conf import settings
from django.core import exceptions as core_exceptions
@ -32,7 +33,6 @@ from django.template.loader import render_to_string
from django import urls
from django.utils import encoding
from django.utils.html import escape
from django.utils import http
from django.utils.http import urlencode
from django.utils.safestring import mark_safe
from django.utils import termcolors
@ -1861,7 +1861,7 @@ class DataTable(object, metaclass=DataTableMetaclass):
The return value will be used as marker/limit-based paging in the API.
"""
return http.urlquote_plus(self.get_object_id(self.data[0])) \
return parse.quote_plus(self.get_object_id(self.data[0])) \
if self.data else ''
def get_marker(self):
@ -1869,7 +1869,7 @@ class DataTable(object, metaclass=DataTableMetaclass):
The return value will be used as marker/limit-based paging in the API.
"""
return http.urlquote_plus(self.get_object_id(self.data[-1])) \
return parse.quote_plus(self.get_object_id(self.data[-1])) \
if self.data else ''
def get_prev_pagination_string(self):

View File

@ -13,6 +13,7 @@
# limitations under the License.
"""API over the nova service."""
from collections import OrderedDict
from urllib import parse
from django.utils import http as utils_http
from django.utils.translation import gettext_lazy as _
@ -91,7 +92,7 @@ class Keypairs(generic.View):
request.DATA['name'],
request.DATA['key_type'])
return rest_utils.CreatedResponse(
'/api/nova/keypairs/%s' % utils_http.urlquote(new.name),
'/api/nova/keypairs/%s' % parse.quote(new.name),
new.to_dict()
)
@ -380,7 +381,7 @@ class Servers(generic.View):
new = api.nova.server_create(*args, **kw)
return rest_utils.CreatedResponse(
'/api/nova/servers/%s' % utils_http.urlquote(new.id),
'/api/nova/servers/%s' % parse.quote(new.id),
new.to_dict()
)
@ -445,7 +446,7 @@ class ServerGroups(generic.View):
"""
new_servergroup = api.nova.server_group_create(request, **request.DATA)
return rest_utils.CreatedResponse(
'/api/nova/servergroups/%s' % utils_http.urlquote(
'/api/nova/servergroups/%s' % parse.quote(
new_servergroup.id), new_servergroup.to_dict()
)

View File

@ -14,10 +14,10 @@
"""API for the swift service."""
import os
from urllib import parse
from django import forms
from django.http import StreamingHttpResponse
from django.utils.http import urlunquote
from django.views.decorators.csrf import csrf_exempt
from django.views import generic
@ -148,7 +148,7 @@ class Objects(generic.View):
"""
path = request.GET.get('path')
if path is not None:
path = urlunquote(path)
path = parse.unquote(path)
objects = api.swift.swift_get_objects(
request,

View File

@ -10,11 +10,12 @@
# License for the specific language governing permissions and limitations
# under the License.
from urllib import parse
from django.conf import settings
from django.test.utils import override_settings
from django.urls import reverse
from django.utils.http import urlencode
from django.utils.http import urlunquote
from openstack_dashboard import api
from openstack_dashboard.dashboards.admin.backups \
@ -40,7 +41,7 @@ class AdminVolumeBackupsViewTests(test.BaseAdminViewTests):
= self.cinder_volume_snapshots.list()
self.mock_tenant_list.return_value = [self.tenants.list(), False]
res = self.client.get(urlunquote(url))
res = self.client.get(parse.unquote(url))
self.assertEqual(res.status_code, 200)
self.assertTemplateUsed(res, 'horizon/common/_data_table_view.html')

View File

@ -15,6 +15,7 @@
import collections
from unittest import mock
from urllib import parse
from django.urls import reverse
@ -410,9 +411,8 @@ class NetworkSubnetTests(test.BaseAdminViewTests):
self.mock_subnet_list.return_value = [self.subnets.first()]
self.mock_tenant_quota_usages.return_value = quota_data
from django.utils.http import urlunquote
url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
args=[network.id]))
url = parse.unquote(reverse('horizon:admin:networks:subnets_tab',
args=[network.id]))
res = self.client.get(url)
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
subnets = res.context['subnets_table'].data

View File

@ -14,9 +14,9 @@
import collections
from unittest import mock
from urllib import parse
from django.urls import reverse
from django.utils.http import urlunquote
from horizon import forms
@ -119,8 +119,8 @@ class NetworkTests(test.BaseAdminViewTests):
'mac-learning': mac_learning,
'dhcp_agent_scheduler': True})
url = urlunquote(reverse('horizon:admin:networks:detail',
args=[network.id]))
url = parse.unquote(reverse('horizon:admin:networks:detail',
args=[network.id]))
res = self.client.get(url)
network = res.context['network']
@ -167,8 +167,8 @@ class NetworkTests(test.BaseAdminViewTests):
'dhcp_agent_scheduler': True})
self.mock_tenant_quota_usages.return_value = quota_data
url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
args=[network.id]))
url = parse.unquote(reverse('horizon:admin:networks:subnets_tab',
args=[network.id]))
res = self.client.get(url)
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
@ -211,7 +211,7 @@ class NetworkTests(test.BaseAdminViewTests):
url = reverse('horizon:admin:networks:ports_tab',
args=[network.id])
res = self.client.get(urlunquote(url))
res = self.client.get(parse.unquote(url))
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
ports = res.context['ports_table'].data
@ -256,7 +256,7 @@ class NetworkTests(test.BaseAdminViewTests):
self.mock_tenant_quota_usages.return_value = quota_data
url = reverse('horizon:admin:networks:agents_tab', args=[network.id])
res = self.client.get(urlunquote(url))
res = self.client.get(parse.unquote(url))
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
result_agents = res.context['agents_table'].data
@ -300,8 +300,8 @@ class NetworkTests(test.BaseAdminViewTests):
{'network-ip-availability': True,
'mac-learning': mac_learning})
url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
args=[network_id]))
url = parse.unquote(reverse('horizon:admin:networks:subnets_tab',
args=[network_id]))
res = self.client.get(url)
redir_url = INDEX_URL
@ -345,8 +345,8 @@ class NetworkTests(test.BaseAdminViewTests):
'network_availability_zone': True})
self.mock_tenant_quota_usages.return_value = quota_data
url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
args=[network.id]))
url = parse.unquote(reverse('horizon:admin:networks:subnets_tab',
args=[network.id]))
res = self.client.get(url)
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
@ -397,8 +397,8 @@ class NetworkTests(test.BaseAdminViewTests):
'dhcp_agent_scheduler': True})
self.mock_tenant_quota_usages.return_value = quota_data
url = urlunquote(reverse('horizon:admin:networks:subnets_tab',
args=[network.id]))
url = parse.unquote(reverse('horizon:admin:networks:subnets_tab',
args=[network.id]))
res = self.client.get(url)
self.assertTemplateUsed(res, 'horizon/common/_detail.html')

View File

@ -11,11 +11,11 @@
# under the License.
from unittest import mock
from urllib import parse
from django.conf import settings
from django.test.utils import override_settings
from django.urls import reverse
from django.utils.http import urlunquote
from openstack_dashboard.api import cinder
from openstack_dashboard.api import keystone
@ -38,7 +38,7 @@ class VolumeSnapshotsViewTests(test.BaseAdminViewTests):
self.mock_tenant_list.return_value = [self.tenants.list(), False]
url = reverse(INDEX_URL)
res = self.client.get(urlunquote(url))
res = self.client.get(parse.unquote(url))
self.assertEqual(res.status_code, 200)
self.assertTemplateUsed(res, 'horizon/common/_data_table_view.html')
@ -63,7 +63,7 @@ class VolumeSnapshotsViewTests(test.BaseAdminViewTests):
self.mock_volume_list.return_value = self.cinder_volumes.list()
self.mock_tenant_list.return_value = [self.tenants.list(), False]
res = self.client.get(urlunquote(url))
res = self.client.get(parse.unquote(url))
self.assertTemplateUsed(res, 'horizon/common/_data_table_view.html')
self.assertEqual(res.status_code, 200)

View File

@ -13,11 +13,11 @@
# under the License.
import copy
from urllib import parse
from django.conf import settings
from django.test.utils import override_settings
from django.urls import reverse
from django.utils.http import urlunquote
from openstack_dashboard import api
from openstack_dashboard.dashboards.project.volumes \
@ -92,7 +92,7 @@ class VolumeTests(test.BaseAdminViewTests):
self.mock_server_list.return_value = [self.servers.list(), False]
self.mock_tenant_list.return_value = [self.tenants.list(), False]
res = self.client.get(urlunquote(url))
res = self.client.get(parse.unquote(url))
self.mock_server_list.assert_called_once_with(
test.IsHttpRequest(), search_opts={'all_tenants': True})

View File

@ -10,11 +10,12 @@
# License for the specific language governing permissions and limitations
# under the License.
from urllib import parse
from django.conf import settings
from django.test.utils import override_settings
from django.urls import reverse
from django.utils.http import urlencode
from django.utils.http import urlunquote
from openstack_dashboard import api
from openstack_dashboard.dashboards.project.backups \
@ -39,7 +40,7 @@ class VolumeBackupsViewTests(test.TestCase):
self.mock_volume_snapshot_list.return_value \
= self.cinder_volume_snapshots.list()
res = self.client.get(urlunquote(url))
res = self.client.get(parse.unquote(url))
self.assertEqual(res.status_code, 200)
self.assertTemplateUsed(res, 'horizon/common/_data_table_view.html')

View File

@ -14,10 +14,10 @@
import collections
from unittest import mock
from urllib import parse
from django.urls import reverse
from django.utils.html import escape
from django.utils.http import urlunquote
from horizon.workflows import views
@ -200,8 +200,8 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
self._stub_is_extension_supported({'mac-learning': mac_learning,
'network_availability_zone': True})
url = urlunquote(reverse('horizon:project:networks:detail',
args=[network_id]))
url = parse.unquote(reverse('horizon:project:networks:detail',
args=[network_id]))
res = self.client.get(url)
network = res.context['network']
@ -234,8 +234,8 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
self._stub_is_extension_supported({'mac-learning': mac_learning,
'network_availability_zone': True})
url = urlunquote(reverse('horizon:project:networks:subnets_tab',
args=[network_id]))
url = parse.unquote(reverse('horizon:project:networks:subnets_tab',
args=[network_id]))
res = self.client.get(url)
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
@ -304,8 +304,8 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
self._stub_is_extension_supported({'mac-learning': mac_learning,
'network_availability_zone': True})
url = urlunquote(reverse('horizon:project:networks:subnets_tab',
args=[network_id]))
url = parse.unquote(reverse('horizon:project:networks:subnets_tab',
args=[network_id]))
res = self.client.get(url)
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
@ -345,8 +345,8 @@ class NetworkTests(test.TestCase, NetworkStubMixin):
self._stub_is_extension_supported({'mac-learning': mac_learning,
'network_availability_zone': True})
url = urlunquote(reverse('horizon:project:networks:subnets_tab',
args=[network_id]))
url = parse.unquote(reverse('horizon:project:networks:subnets_tab',
args=[network_id]))
res = self.client.get(url)
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
subnets = res.context['subnets_table'].data
@ -1248,8 +1248,8 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
'network_availability_zone': True})
self.mock_tenant_quota_usages.return_value = quota_data
url = urlunquote(reverse('horizon:project:networks:subnets_tab',
args=[network_id]))
url = parse.unquote(reverse('horizon:project:networks:subnets_tab',
args=[network_id]))
res = self.client.get(url)
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
@ -1320,8 +1320,8 @@ class NetworkViewTests(test.TestCase, NetworkStubMixin):
'network_availability_zone': True})
self.mock_tenant_quota_usages.return_value = quota_data
url = urlunquote(reverse('horizon:project:networks:ports_tab',
args=[network_id]))
url = parse.unquote(reverse('horizon:project:networks:ports_tab',
args=[network_id]))
res = self.client.get(url)
self.assertTemplateUsed(res, 'horizon/common/_detail.html')

View File

@ -17,11 +17,11 @@
# under the License.
from unittest import mock
from urllib import parse
from django.conf import settings
from django.test.utils import override_settings
from django.urls import reverse
from django.utils.http import urlunquote
from openstack_dashboard import api
from openstack_dashboard.dashboards.project.snapshots \
@ -49,7 +49,7 @@ class VolumeSnapshotsViewTests(test.TestCase):
self.mock_group_snapshot_list.return_value = \
self.cinder_volume_snapshots_with_groups.list()
res = self.client.get(urlunquote(url))
res = self.client.get(parse.unquote(url))
self.assertEqual(res.status_code, 200)
self.assertTemplateUsed(res, 'horizon/common/_data_table_view.html')

View File

@ -11,17 +11,17 @@
# under the License.
from unittest import mock
from urllib import parse
from django.urls import reverse
from django.utils.http import urlunquote
from openstack_dashboard.api import cinder
from openstack_dashboard.test import helpers as test
INDEX_URL = reverse('horizon:project:volume_groups:index')
VOLUME_GROUPS_SNAP_INDEX_URL = urlunquote(reverse(
'horizon:project:vg_snapshots:index'))
VOLUME_GROUPS_SNAP_INDEX_URL = parse.unquote(
reverse('horizon:project:vg_snapshots:index'))
class VolumeGroupTests(test.TestCase):

View File

@ -14,13 +14,13 @@
import copy
from unittest import mock
from urllib import parse
from django.conf import settings
from django.forms import widgets
from django.template.defaultfilters import slugify
from django.test.utils import override_settings
from django.urls import reverse
from django.utils.http import urlunquote
from openstack_dashboard import api
from openstack_dashboard.api import cinder
@ -122,7 +122,7 @@ class VolumeIndexViewTests(test.ResetImageAPIVersionMixin, test.TestCase):
self.mock_tenant_absolute_limits.return_value = \
self.cinder_limits['absolute']
res = self.client.get(urlunquote(url))
res = self.client.get(parse.unquote(url))
self.assertEqual(2, self.mock_volume_backup_supported.call_count)
self.mock_volume_list_paged.assert_called_once_with(

View File

@ -22,6 +22,7 @@ import logging
import os
import traceback
from unittest import mock
from urllib import parse
from django.conf import settings
from django.contrib.messages.storage import cookie as cookie_storage
@ -31,7 +32,6 @@ from django.test.client import RequestFactory
from django.test import tag
from django.test import testcases
from django import urls
from django.utils import http
from openstack_auth import user
from openstack_auth import utils
@ -289,8 +289,8 @@ class TestCase(horizon_helpers.TestCase):
loc = response['location']
else:
loc = ''
loc = http.urlunquote(loc)
expected_url = http.urlunquote(expected_url)
loc = parse.unquote(loc)
expected_url = parse.unquote(expected_url)
self.assertEqual(loc, expected_url)
self.assertEqual(response.status_code, 302)

View File

@ -11,9 +11,10 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_utils import timeutils
from django.utils import http as utils_http
from urllib import parse
from oslo_utils import timeutils
from openstack_dashboard.api import swift
from openstack_dashboard.test.test_data import utils
@ -45,8 +46,7 @@ def data(TEST):
"is_public": True,
"public_url":
"http://public.swift.example.com:8080/" +
"v1/project_id/%s" % utils_http.urlquote(
container_2_name)}
"v1/project_id/%s" % parse.quote(container_2_name)}
container_2 = swift.Container(container_dict_2)
container_dict_3 = {"name": "container,three%\u6346",
"container_object_count": 2,