Server IP : 85.214.239.14 / Your IP : 216.73.216.26 Web Server : Apache/2.4.65 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /srv/modoboa/env/lib64/python3.5/site-packages/rest_framework/utils/ |
Upload File : |
from urllib import parse from django.utils.encoding import force_str def replace_query_param(url, key, val): """ Given a URL and a key/val pair, set or replace an item in the query parameters of the URL, and return the new URL. """ (scheme, netloc, path, query, fragment) = parse.urlsplit(force_str(url)) query_dict = parse.parse_qs(query, keep_blank_values=True) query_dict[force_str(key)] = [force_str(val)] query = parse.urlencode(sorted(list(query_dict.items())), doseq=True) return parse.urlunsplit((scheme, netloc, path, query, fragment)) def remove_query_param(url, key): """ Given a URL and a key/val pair, remove an item in the query parameters of the URL, and return the new URL. """ (scheme, netloc, path, query, fragment) = parse.urlsplit(force_str(url)) query_dict = parse.parse_qs(query, keep_blank_values=True) query_dict.pop(key, None) query = parse.urlencode(sorted(list(query_dict.items())), doseq=True) return parse.urlunsplit((scheme, netloc, path, query, fragment))