def match_service(service1, service2): """ Compare two service URLs. Return ``True`` if the scheme, hostname, optional port and path match. """ s1, s2 = urlparse(service1), urlparse(service2) try: return (s1.scheme, s1.netloc, s1.path) == (s2.scheme, s2.netloc, s2.path) except ValueError: return False
def clean_service_url(url): """ Return only the scheme, hostname (with optional port) and path components of the parameter URL. """ parts = urlparse(url) return urlunparse((parts.scheme, parts.netloc, parts.path, '', '', ''))
def add_query_params(url, params): """ Inject additional query parameters into an existing URL. If parameters already exist with the same name, they will be overwritten. Parameters with empty values are ignored. Return the modified URL as a string. """ def encode(s): return force_bytes(s, settings.DEFAULT_CHARSET) params = dict([(encode(k), encode(v)) for k, v in params.items() if v]) parts = list(urlparse(url)) query = dict(parse_qsl(parts[4])) query.update(params) parts[4] = urlencode(query) return urlunparse(parts)
def is_scheme_https(url): """ Test the scheme of the parameter URL to see if it is HTTPS. If it is HTTPS return ``True``, otherwise return ``False``. """ return 'https' == urlparse(url).scheme