add 'text.ensure_http_scheme()'

This commit is contained in:
Mike Fährmann
2020-05-19 21:25:07 +02:00
parent 4df2cadf60
commit 6294e2c540
5 changed files with 39 additions and 8 deletions

View File

@@ -60,6 +60,13 @@ def split_html(txt, sep=None):
return []
def ensure_http_scheme(url, scheme="https://"):
"""Prepend 'scheme' to 'url' if it doesn't have one"""
if url and not url.startswith(("https://", "http://")):
return scheme + url.lstrip("/:")
return url
def filename_from_url(url):
"""Extract the last part of an URL to use as a filename"""
try: