From e34c33614d8e4f0208d96d71e9c0ac6571587555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergey=20M=E2=80=A4?= Date: Tue, 13 Dec 2016 02:23:49 +0700 Subject: [utils] Add convenience urljoin --- youtube_dl/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'youtube_dl/utils.py') diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 3d4951ad9..694e9a600 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1700,6 +1700,16 @@ def base_url(url): return re.match(r'https?://[^?#&]+/', url).group() +def urljoin(base, path): + if not isinstance(path, compat_str) or not path: + return None + if re.match(r'https?://', path): + return path + if not isinstance(base, compat_str) or not re.match(r'https?://', base): + return None + return compat_urlparse.urljoin(base, path) + + class HEADRequest(compat_urllib_request.Request): def get_method(self): return 'HEAD' -- cgit v1.2.3