trivial: use urllib.parse (#68784)

This commit is contained in:
Frédéric Péters 2022-09-06 18:48:37 +02:00
parent bc719b7b3d
commit 07241b226e
2 changed files with 8 additions and 6 deletions

View File

@ -14,19 +14,20 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import urllib.parse
from django.utils.http import urlencode
from django.utils.six.moves.urllib import parse as urlparse
def make_url(__url, **kwargs):
request = kwargs.pop('request', None)
parsed = urlparse.urlparse(__url)
query = urlparse.parse_qs(parsed.query)
parsed = urllib.parse.urlparse(__url)
query = urllib.parse.parse_qs(parsed.query)
for key, value in kwargs.items():
if value is not None:
query[key] = value
parsed = parsed[:4] + (urlencode(query),) + parsed[5:]
url = urlparse.urlunparse(parsed)
url = urllib.parse.urlunparse(parsed)
if request:
return request.build_absolute_uri(url)
return url

View File

@ -15,10 +15,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import urllib.parse
import pytest
from django.test import override_settings
from django.urls import reverse
from django.utils.six.moves.urllib import parse as urlparse
from webtest import Upload
try:
@ -34,7 +35,7 @@ pytestmark = pytest.mark.django_db
def test_unlogged(app):
assert urlparse.urlparse(app.get('/', status=302).location).path == '/login/'
assert urllib.parse.urlparse(app.get('/', status=302).location).path == '/login/'
def test_upload(app, john_doe):