python-urlopen 0.0.7.2__tar.gz → 0.0.8__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-urlopen
3
- Version: 0.0.7.2
3
+ Version: 0.0.8
4
4
  Summary: Python urlopen wrapper.
5
5
  Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-urlopen
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-urlopen"
3
- version = "0.0.7.2"
3
+ version = "0.0.8"
4
4
  description = "Python urlopen wrapper."
5
5
  authors = ["ChenyangGao <wosiwujm@gmail.com>"]
6
6
  license = "MIT"
@@ -2,7 +2,7 @@
2
2
  # coding: utf-8
3
3
 
4
4
  __author__ = "ChenyangGao <https://chenyanggao.github.io>"
5
- __version__ = (0, 0, 7)
5
+ __version__ = (0, 0, 8)
6
6
  __all__ = ["urlopen", "request", "download"]
7
7
 
8
8
  import errno
@@ -21,6 +21,7 @@ from shutil import COPY_BUFSIZE # type: ignore
21
21
  from socket import getdefaulttimeout, setdefaulttimeout
22
22
  from ssl import SSLContext, _create_unverified_context
23
23
  from string import punctuation
24
+ from types import EllipsisType
24
25
  from typing import cast, Any, Literal
25
26
  from urllib.error import HTTPError
26
27
  from urllib.parse import quote, urlencode, urlsplit
@@ -66,13 +67,20 @@ def decompress_deflate(data: bytes, compresslevel: int = 9) -> bytes:
66
67
  return deflated
67
68
 
68
69
 
70
+ def get_charset(content_type: str, default="utf-8") -> str:
71
+ match = CRE_search_charset(content_type)
72
+ if match is None:
73
+ return "utf-8"
74
+ return match["charset"]
75
+
76
+
69
77
  def ensure_ascii_url(url: str, /) -> str:
70
78
  if url.isascii():
71
79
  return url
72
80
  return quote(url, safe=punctuation)
73
81
 
74
82
 
75
- def decompress_response(resp: HTTPResponse) -> bytes:
83
+ def decompress_response(resp: HTTPResponse, /) -> bytes:
76
84
  data = resp.read()
77
85
  content_encoding = resp.headers.get("Content-Encoding")
78
86
  match content_encoding:
@@ -172,17 +180,10 @@ def urlopen(
172
180
  return opener.open(req, timeout=timeout)
173
181
 
174
182
 
175
- def get_charset(content_type: str, default="utf-8") -> str:
176
- match = CRE_search_charset(content_type)
177
- if match is None:
178
- return "utf-8"
179
- return match["charset"]
180
-
181
-
182
183
  def request(
183
184
  url: str | Request,
184
185
  method: str = "GET",
185
- parse: Literal[None, ...] | bool | Callable = None,
186
+ parse: None | EllipsisType | bool | Callable = None,
186
187
  raise_for_status: bool = True,
187
188
  timeout: None | float = 60,
188
189
  **request_kwargs,
File without changes