python-urlopen 0.1.6__tar.gz → 0.1.6.2__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_urlopen-0.1.6 → python_urlopen-0.1.6.2}/PKG-INFO +2 -2
- {python_urlopen-0.1.6 → python_urlopen-0.1.6.2}/pyproject.toml +2 -2
- {python_urlopen-0.1.6 → python_urlopen-0.1.6.2}/urlopen/__init__.py +46 -35
- {python_urlopen-0.1.6 → python_urlopen-0.1.6.2}/LICENSE +0 -0
- {python_urlopen-0.1.6 → python_urlopen-0.1.6.2}/readme.md +0 -0
- {python_urlopen-0.1.6 → python_urlopen-0.1.6.2}/urlopen/__main__.py +0 -0
- {python_urlopen-0.1.6 → python_urlopen-0.1.6.2}/urlopen/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-urlopen
|
|
3
|
-
Version: 0.1.6
|
|
3
|
+
Version: 0.1.6.2
|
|
4
4
|
Summary: Python urlopen wrapper.
|
|
5
5
|
Home-page: https://github.com/ChenyangGao/python-modules/tree/main/python-urlopen
|
|
6
6
|
License: MIT
|
|
@@ -20,7 +20,7 @@ Classifier: Programming Language :: Python :: 3 :: Only
|
|
|
20
20
|
Classifier: Topic :: Software Development
|
|
21
21
|
Classifier: Topic :: Software Development :: Libraries
|
|
22
22
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
-
Requires-Dist: http_client_request (>=0.0.
|
|
23
|
+
Requires-Dist: http_client_request (>=0.0.7)
|
|
24
24
|
Requires-Dist: http_response (>=0.0.9)
|
|
25
25
|
Requires-Dist: python-argtools (>=0.0.2)
|
|
26
26
|
Requires-Dist: python-cookietools (>=0.1.3)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "python-urlopen"
|
|
3
|
-
version = "0.1.6"
|
|
3
|
+
version = "0.1.6.2"
|
|
4
4
|
description = "Python urlopen wrapper."
|
|
5
5
|
authors = ["ChenyangGao <wosiwujm@gmail.com>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -27,7 +27,7 @@ include = [
|
|
|
27
27
|
|
|
28
28
|
[tool.poetry.dependencies]
|
|
29
29
|
python = "^3.12"
|
|
30
|
-
http_client_request = ">=0.0.
|
|
30
|
+
http_client_request = ">=0.0.7"
|
|
31
31
|
http_response = ">=0.0.9"
|
|
32
32
|
python-argtools = ">=0.0.2"
|
|
33
33
|
python-cookietools = ">=0.1.3"
|
|
@@ -98,7 +98,10 @@ class KeepAliveBaseHTTPHandler(AbstractHTTPHandler):
|
|
|
98
98
|
if proxy_auth_hdr in headers:
|
|
99
99
|
tunnel_headers[proxy_auth_hdr] = headers[proxy_auth_hdr]
|
|
100
100
|
del headers[proxy_auth_hdr]
|
|
101
|
-
|
|
101
|
+
try:
|
|
102
|
+
h.set_tunnel(req._tunnel_host, headers=tunnel_headers)
|
|
103
|
+
except RuntimeError:
|
|
104
|
+
pass
|
|
102
105
|
else:
|
|
103
106
|
h._tunnel_host = None
|
|
104
107
|
h._tunnel_port = None
|
|
@@ -122,18 +125,15 @@ class KeepAliveBaseHTTPHandler(AbstractHTTPHandler):
|
|
|
122
125
|
|
|
123
126
|
|
|
124
127
|
class KeepAliveHTTPHandler(HTTPHandler, KeepAliveBaseHTTPHandler):
|
|
125
|
-
|
|
128
|
+
pool: ConnectionPool = CONNECTION_POOL
|
|
126
129
|
|
|
127
130
|
|
|
128
131
|
class KeepAliveHTTPSHandler(HTTPSHandler, KeepAliveBaseHTTPHandler):
|
|
129
|
-
|
|
132
|
+
pool: ConnectionPool = CONNECTION_POOL
|
|
130
133
|
|
|
131
134
|
|
|
132
|
-
_pool = CONNECTION_POOL
|
|
133
135
|
_http_handler = KeepAliveHTTPHandler()
|
|
134
|
-
_http_handler.pool = _pool
|
|
135
136
|
_https_handler = KeepAliveHTTPSHandler(context=_create_unverified_context())
|
|
136
|
-
_https_handler.pool = _pool
|
|
137
137
|
_cookies = CookieJar()
|
|
138
138
|
_opener: OpenerDirector = build_opener(
|
|
139
139
|
_http_handler,
|
|
@@ -163,6 +163,7 @@ def urlopen(
|
|
|
163
163
|
cookies: None | CookieJar | BaseCookie = None,
|
|
164
164
|
timeout: None | Undefined | float = undefined,
|
|
165
165
|
opener: None | OpenerDirector = _opener,
|
|
166
|
+
pool: None | ConnectionPool = None,
|
|
166
167
|
**_,
|
|
167
168
|
) -> HTTPResponse:
|
|
168
169
|
if isinstance(url, Request):
|
|
@@ -205,52 +206,62 @@ def urlopen(
|
|
|
205
206
|
cookies = getattr(opener, "cookies", None)
|
|
206
207
|
if cookies and "cookie" not in headers_:
|
|
207
208
|
headers_["cookie"] = cookies_to_str(cookies)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
add_handler = handlers.append
|
|
210
|
+
if opener is None:
|
|
211
|
+
http_handler = copy(_http_handler)
|
|
212
|
+
if context is None:
|
|
213
|
+
https_handler = copy(_https_handler)
|
|
211
214
|
else:
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
else:
|
|
219
|
-
handlers.append(copy(_https_handler))
|
|
215
|
+
https_handler = KeepAliveHTTPSHandler(context=context)
|
|
216
|
+
if pool is not None:
|
|
217
|
+
http_handler.pool = pool
|
|
218
|
+
https_handler.pool = pool
|
|
219
|
+
add_handler(http_handler)
|
|
220
|
+
add_handler(https_handler)
|
|
220
221
|
else:
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
222
|
+
for i, handler in enumerate(handlers):
|
|
223
|
+
if isinstance(handler, KeepAliveHTTPSHandler):
|
|
224
|
+
handler = handlers[i] = copy(handler)
|
|
225
|
+
if context is not None:
|
|
226
|
+
setattr(handler, "_context", context)
|
|
227
|
+
break
|
|
228
|
+
elif isinstance(handler, HTTPSHandler):
|
|
229
|
+
handler = handlers[i] = KeepAliveHTTPSHandler(
|
|
230
|
+
debuglevel=getattr(handler, "_debuglevel"),
|
|
231
|
+
context=getattr(handler, "_context") if context is None else context,
|
|
232
|
+
)
|
|
233
|
+
break
|
|
225
234
|
else:
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if opener is None:
|
|
233
|
-
handlers.append(copy(_http_handler))
|
|
234
|
-
else:
|
|
235
|
+
handler = copy(_https_handler)
|
|
236
|
+
if context is not None:
|
|
237
|
+
setattr(handler, "_context", context)
|
|
238
|
+
add_handler(handler)
|
|
239
|
+
if pool is not None:
|
|
240
|
+
handler.pool = pool
|
|
235
241
|
for i, handler in enumerate(handlers):
|
|
236
242
|
if isinstance(handler, KeepAliveHTTPHandler):
|
|
243
|
+
handler = handlers[i] = copy(handler)
|
|
237
244
|
break
|
|
238
245
|
elif isinstance(handler, HTTPHandler):
|
|
239
|
-
handlers[i] =
|
|
246
|
+
handler = handlers[i] = KeepAliveHTTPHandler(
|
|
247
|
+
debuglevel=getattr(handler, "_debuglevel"))
|
|
240
248
|
break
|
|
241
249
|
else:
|
|
242
|
-
|
|
250
|
+
handler = copy(_http_handler)
|
|
251
|
+
add_handler(handler)
|
|
252
|
+
if pool is not None:
|
|
253
|
+
handler.pool = pool
|
|
243
254
|
if cookies and (opener is None or all(
|
|
244
255
|
h.cookies is not cookies
|
|
245
256
|
for h in getattr(opener, "handlers") if isinstance(h, HTTPCookieProcessor)
|
|
246
257
|
)):
|
|
247
|
-
|
|
258
|
+
add_handler(HTTPCookieProcessor(cookies))
|
|
248
259
|
response_cookies = CookieJar()
|
|
249
260
|
if cookies is None:
|
|
250
261
|
cookies = response_cookies
|
|
251
|
-
|
|
262
|
+
add_handler(HTTPCookieProcessor(response_cookies))
|
|
252
263
|
if not follow_redirects:
|
|
253
|
-
|
|
264
|
+
add_handler(NoRedirectHandler())
|
|
254
265
|
opener = build_opener(*handlers)
|
|
255
266
|
setattr(opener, "cookies", cookies)
|
|
256
267
|
try:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|