update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
import os.path
|
||||
import re
|
||||
import urllib
|
||||
from urllib.parse import urlparse, urlsplit
|
||||
|
||||
from httplib.exceptions import InvalidStatusLine, InvalidResponse, BadRequest, InvalidRequestLine
|
||||
@@ -255,6 +256,19 @@ def parse_uri(uri: str):
|
||||
return host, port, path
|
||||
|
||||
|
||||
def get_uri(url: str):
|
||||
"""
|
||||
Returns a valid URI of the specified URL.
|
||||
"""
|
||||
parsed = urlsplit(url)
|
||||
|
||||
result = f"http://{parsed.netloc}{parsed.path}"
|
||||
if parsed.query != '':
|
||||
result = f"{result}?{parsed.query}"
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def base_url(uri: str):
|
||||
parsed = urlsplit(uri)
|
||||
path = parsed.path.rsplit("/", 1)[0]
|
||||
@@ -265,3 +279,7 @@ def absolute_url(uri: str, rel_path: str):
|
||||
parsed = urlsplit(uri)
|
||||
path = os.path.normpath(os.path.join(parsed.path, rel_path))
|
||||
return f"{parsed.scheme}://{parsed.hostname}{path}"
|
||||
|
||||
|
||||
def urljoin(base, url):
|
||||
return urllib.parse.urljoin(base, url)
|
||||
|
Reference in New Issue
Block a user