python-http_request 0.0.7__tar.gz → 0.0.7.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_http_request-0.0.7 → python_http_request-0.0.7.1}/PKG-INFO +1 -1
- {python_http_request-0.0.7 → python_http_request-0.0.7.1}/http_request/__init__.py +26 -12
- {python_http_request-0.0.7 → python_http_request-0.0.7.1}/pyproject.toml +1 -1
- {python_http_request-0.0.7 → python_http_request-0.0.7.1}/LICENSE +0 -0
- {python_http_request-0.0.7 → python_http_request-0.0.7.1}/http_request/py.typed +0 -0
- {python_http_request-0.0.7 → python_http_request-0.0.7.1}/readme.md +0 -0
|
@@ -26,7 +26,7 @@ from texttools import text_to_dict
|
|
|
26
26
|
|
|
27
27
|
AnyStr = TypeVar("AnyStr", bytes, str, covariant=True)
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
CRE_URL_SCHEME_match: Final = re_compile(r"(?i:[a-z][a-z0-9.+-]*)://").match
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
@runtime_checkable
|
|
@@ -34,27 +34,41 @@ class SupportsGeturl(Protocol[AnyStr]):
|
|
|
34
34
|
def geturl(self) -> AnyStr: ...
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
def url_origin(url: str,
|
|
38
|
-
if url.startswith("
|
|
37
|
+
def url_origin(url: str, /, default_port: int = 0) -> str:
|
|
38
|
+
if url.startswith("/"):
|
|
39
|
+
url = "http://localhost" + url
|
|
40
|
+
elif url.startswith("//"):
|
|
41
|
+
url = "http:" + url
|
|
42
|
+
elif url.startswith("://"):
|
|
39
43
|
url = "http" + url
|
|
40
|
-
elif
|
|
44
|
+
elif not CRE_URL_SCHEME_match(url):
|
|
41
45
|
url = "http://" + url
|
|
42
46
|
urlp = urlsplit(url)
|
|
43
|
-
scheme, netloc = urlp.scheme, urlp.netloc
|
|
44
|
-
if not
|
|
45
|
-
netloc = "
|
|
47
|
+
scheme, netloc = urlp.scheme or "http", urlp.netloc or "localhost"
|
|
48
|
+
if default_port and not urlp.port:
|
|
49
|
+
netloc = netloc.removesuffix(":") + f":{default_port}"
|
|
46
50
|
return f"{scheme}://{netloc}"
|
|
47
51
|
|
|
48
52
|
|
|
49
|
-
def complete_url(url: str,
|
|
50
|
-
if url.startswith("
|
|
53
|
+
def complete_url(url: str, /, default_port: int = 0) -> str:
|
|
54
|
+
if url.startswith("/"):
|
|
55
|
+
url = "http://localhost" + url
|
|
56
|
+
elif url.startswith("//"):
|
|
57
|
+
url = "http:" + url
|
|
58
|
+
elif url.startswith("://"):
|
|
51
59
|
url = "http" + url
|
|
52
|
-
elif
|
|
60
|
+
elif not CRE_URL_SCHEME_match(url):
|
|
53
61
|
url = "http://" + url
|
|
54
62
|
urlp = urlsplit(url)
|
|
55
63
|
repl = {"query": "", "fragment": ""}
|
|
56
|
-
if not urlp.
|
|
57
|
-
repl["
|
|
64
|
+
if not urlp.scheme:
|
|
65
|
+
repl["scheme"] = "http"
|
|
66
|
+
netloc = urlp.netloc
|
|
67
|
+
if not netloc:
|
|
68
|
+
netloc = "localhost"
|
|
69
|
+
if default_port and not urlp.port:
|
|
70
|
+
netloc = netloc.removesuffix(":") + f":{default_port}"
|
|
71
|
+
repl["netloc"] = netloc
|
|
58
72
|
return urlunsplit(urlp._replace(**repl)).rstrip("/")
|
|
59
73
|
|
|
60
74
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|