We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
It should be possible to specify a default_scheme similar to the already possible default_scheme.
default_scheme
E.g.
>>> url_normalize('/foo.png', default_scheme='https', default_domain='example.com') 'https://example.com/foo.png'
Currently that is not possible:
>>> url_normalize('/foo.png', default_scheme='https') '/foo.png'
The text was updated successfully, but these errors were encountered:
This could be done with the following
def provide_url_scheme(url, default_scheme=DEFAULT_SCHEME, default_host=None): has_scheme = ":" in url[:7] is_universal_scheme = url.startswith("//") is_stdout = url == "-" is_file_path = is_stdout or (url.startswith("/") and not is_universal_scheme) if default_host and is_file_path and not is_stdout: if is_universal_scheme: return default_scheme + ":" + default_host + url return default_scheme + "://" + default_host + url if not url or has_scheme or is_file_path: return url if is_universal_scheme: return default_scheme + ":" + url return default_scheme + "://" + url
All that has to be added to url_normalize(…) is:
url_normalize(…)
def url_normalize( - url, charset=DEFAULT_CHARSET, default_scheme=DEFAULT_SCHEME, sort_query_params=True + url, charset=DEFAULT_CHARSET, default_scheme=DEFAULT_SCHEME, default_host=None, sort_query_params=True ): if not url: return url - url = provide_url_scheme(url, default_scheme) + url = provide_url_scheme(url, default_scheme, default_host)
Which could look like this in the end:
>>> url_normalize('/blahbla/whatever.png', default_host='example.com') 'https://example.com/blahbla/whatever.png'
Sorry, something went wrong.
No branches or pull requests
It should be possible to specify a
default_scheme
similar to the already possibledefault_scheme
.E.g.
Currently that is not possible:
The text was updated successfully, but these errors were encountered: