[utils] Add convenience urljoin

This commit is contained in:
Sergey M․ 2016-12-13 02:23:49 +07:00
parent abf3494ac7
commit e34c33614d
No known key found for this signature in database
GPG key ID: 2C393E0F18A9236D
2 changed files with 24 additions and 0 deletions

View file

@ -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'