python-http_request 0.0.9__tar.gz → 0.0.10__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-http_request
3
- Version: 0.0.9
3
+ Version: 0.0.10
4
4
  Summary: Python http response utils.
5
5
  Home-page: https://github.com/ChenyangGao/python-modules/tree/main/python-http_request
6
6
  License: MIT
@@ -2,7 +2,7 @@
2
2
  # encoding: utf-8
3
3
 
4
4
  __author__ = "ChenyangGao <https://chenyanggao.github.io>"
5
- __version__ = (0, 0, 9)
5
+ __version__ = (0, 0, 10)
6
6
  __all__ = [
7
7
  "SupportsGeturl", "url_origin", "complete_url", "ensure_ascii_url",
8
8
  "urlencode", "cookies_str_to_dict", "headers_str_to_dict_by_lines",
@@ -57,15 +57,17 @@ class SupportsGeturl[AnyStr: (bytes, str)](Protocol):
57
57
  def geturl(self) -> AnyStr: ...
58
58
 
59
59
 
60
- def url_origin(url: str, /, default_port: int = 0) -> str:
60
+ def url_origin(
61
+ url: str,
62
+ /,
63
+ default_port: int = 0,
64
+ ) -> str:
61
65
  if url.startswith("/"):
62
66
  url = "http://localhost" + url
63
67
  elif url.startswith("//"):
64
68
  url = "http:" + url
65
69
  elif url.startswith("://"):
66
70
  url = "http" + url
67
- elif not CRE_URL_SCHEME_match(url):
68
- url = "http://" + url
69
71
  urlp = urlparse(url)
70
72
  scheme, netloc = urlp.scheme or "http", urlp.netloc or "localhost"
71
73
  if default_port and not urlp.port:
@@ -73,17 +75,27 @@ def url_origin(url: str, /, default_port: int = 0) -> str:
73
75
  return f"{scheme}://{netloc}"
74
76
 
75
77
 
76
- def complete_url(url: str, /, default_port: int = 0) -> str:
78
+ def complete_url(
79
+ url: str,
80
+ /,
81
+ default_port: int = 0,
82
+ clean: bool = False,
83
+ ) -> str:
77
84
  if url.startswith("/"):
78
85
  url = "http://localhost" + url
79
86
  elif url.startswith("//"):
80
87
  url = "http:" + url
81
88
  elif url.startswith("://"):
82
89
  url = "http" + url
83
- elif not CRE_URL_SCHEME_match(url):
84
- url = "http://" + url
90
+ if not (clean or default_port):
91
+ if not CRE_URL_SCHEME_match(url):
92
+ url = "http://" + url
93
+ return url
85
94
  urlp = urlparse(url)
86
- repl = {"query": "", "fragment": ""}
95
+ if clean:
96
+ repl = {"params": "", "query": "", "fragment": ""}
97
+ else:
98
+ repl = {}
87
99
  if not urlp.scheme:
88
100
  repl["scheme"] = "http"
89
101
  netloc = urlp.netloc
@@ -91,7 +103,10 @@ def complete_url(url: str, /, default_port: int = 0) -> str:
91
103
  netloc = "localhost"
92
104
  if default_port and not urlp.port:
93
105
  netloc = netloc.removesuffix(":") + f":{default_port}"
94
- repl["netloc"] = netloc
106
+ if netloc != urlp.netloc:
107
+ repl["netloc"] = netloc
108
+ if not repl:
109
+ return url
95
110
  return urlunparse(urlp._replace(**repl)).rstrip("/")
96
111
 
97
112
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-http_request"
3
- version = "0.0.9"
3
+ version = "0.0.10"
4
4
  description = "Python http response utils."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"