python-urlopen 0.1.6__tar.gz → 0.1.6.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_urlopen-0.1.6 → python_urlopen-0.1.6.1}/PKG-INFO +1 -1
- {python_urlopen-0.1.6 → python_urlopen-0.1.6.1}/pyproject.toml +1 -1
- {python_urlopen-0.1.6 → python_urlopen-0.1.6.1}/urlopen/__init__.py +42 -34
- {python_urlopen-0.1.6 → python_urlopen-0.1.6.1}/LICENSE +0 -0
- {python_urlopen-0.1.6 → python_urlopen-0.1.6.1}/readme.md +0 -0
- {python_urlopen-0.1.6 → python_urlopen-0.1.6.1}/urlopen/__main__.py +0 -0
- {python_urlopen-0.1.6 → python_urlopen-0.1.6.1}/urlopen/py.typed +0 -0
|
@@ -122,18 +122,15 @@ class KeepAliveBaseHTTPHandler(AbstractHTTPHandler):
|
|
|
122
122
|
|
|
123
123
|
|
|
124
124
|
class KeepAliveHTTPHandler(HTTPHandler, KeepAliveBaseHTTPHandler):
|
|
125
|
-
|
|
125
|
+
pool: ConnectionPool = CONNECTION_POOL
|
|
126
126
|
|
|
127
127
|
|
|
128
128
|
class KeepAliveHTTPSHandler(HTTPSHandler, KeepAliveBaseHTTPHandler):
|
|
129
|
-
|
|
129
|
+
pool: ConnectionPool = CONNECTION_POOL
|
|
130
130
|
|
|
131
131
|
|
|
132
|
-
_pool = CONNECTION_POOL
|
|
133
132
|
_http_handler = KeepAliveHTTPHandler()
|
|
134
|
-
_http_handler.pool = _pool
|
|
135
133
|
_https_handler = KeepAliveHTTPSHandler(context=_create_unverified_context())
|
|
136
|
-
_https_handler.pool = _pool
|
|
137
134
|
_cookies = CookieJar()
|
|
138
135
|
_opener: OpenerDirector = build_opener(
|
|
139
136
|
_http_handler,
|
|
@@ -163,6 +160,7 @@ def urlopen(
|
|
|
163
160
|
cookies: None | CookieJar | BaseCookie = None,
|
|
164
161
|
timeout: None | Undefined | float = undefined,
|
|
165
162
|
opener: None | OpenerDirector = _opener,
|
|
163
|
+
pool: None | ConnectionPool = None,
|
|
166
164
|
**_,
|
|
167
165
|
) -> HTTPResponse:
|
|
168
166
|
if isinstance(url, Request):
|
|
@@ -205,52 +203,62 @@ def urlopen(
|
|
|
205
203
|
cookies = getattr(opener, "cookies", None)
|
|
206
204
|
if cookies and "cookie" not in headers_:
|
|
207
205
|
headers_["cookie"] = cookies_to_str(cookies)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
206
|
+
add_handler = handlers.append
|
|
207
|
+
if opener is None:
|
|
208
|
+
http_handler = copy(_http_handler)
|
|
209
|
+
if context is None:
|
|
210
|
+
https_handler = copy(_https_handler)
|
|
211
211
|
else:
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
else:
|
|
219
|
-
handlers.append(copy(_https_handler))
|
|
212
|
+
https_handler = KeepAliveHTTPSHandler(context=context)
|
|
213
|
+
if pool is not None:
|
|
214
|
+
http_handler.pool = pool
|
|
215
|
+
https_handler.pool = pool
|
|
216
|
+
add_handler(http_handler)
|
|
217
|
+
add_handler(https_handler)
|
|
220
218
|
else:
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
219
|
+
for i, handler in enumerate(handlers):
|
|
220
|
+
if isinstance(handler, KeepAliveHTTPSHandler):
|
|
221
|
+
handler = handlers[i] = copy(handler)
|
|
222
|
+
if context is not None:
|
|
223
|
+
setattr(handler, "_context", context)
|
|
224
|
+
break
|
|
225
|
+
elif isinstance(handler, HTTPSHandler):
|
|
226
|
+
handler = handlers[i] = KeepAliveHTTPSHandler(
|
|
227
|
+
debuglevel=getattr(handler, "_debuglevel"),
|
|
228
|
+
context=getattr(handler, "_context") if context is None else context,
|
|
229
|
+
)
|
|
230
|
+
break
|
|
225
231
|
else:
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if opener is None:
|
|
233
|
-
handlers.append(copy(_http_handler))
|
|
234
|
-
else:
|
|
232
|
+
handler = copy(_https_handler)
|
|
233
|
+
if context is not None:
|
|
234
|
+
setattr(handler, "_context", context)
|
|
235
|
+
add_handler(handler)
|
|
236
|
+
if pool is not None:
|
|
237
|
+
handler.pool = pool
|
|
235
238
|
for i, handler in enumerate(handlers):
|
|
236
239
|
if isinstance(handler, KeepAliveHTTPHandler):
|
|
240
|
+
handler = handlers[i] = copy(handler)
|
|
237
241
|
break
|
|
238
242
|
elif isinstance(handler, HTTPHandler):
|
|
239
|
-
handlers[i] =
|
|
243
|
+
handler = handlers[i] = KeepAliveHTTPHandler(
|
|
244
|
+
debuglevel=getattr(handler, "_debuglevel"))
|
|
240
245
|
break
|
|
241
246
|
else:
|
|
242
|
-
|
|
247
|
+
handler = copy(_http_handler)
|
|
248
|
+
add_handler(handler)
|
|
249
|
+
if pool is not None:
|
|
250
|
+
handler.pool = pool
|
|
243
251
|
if cookies and (opener is None or all(
|
|
244
252
|
h.cookies is not cookies
|
|
245
253
|
for h in getattr(opener, "handlers") if isinstance(h, HTTPCookieProcessor)
|
|
246
254
|
)):
|
|
247
|
-
|
|
255
|
+
add_handler(HTTPCookieProcessor(cookies))
|
|
248
256
|
response_cookies = CookieJar()
|
|
249
257
|
if cookies is None:
|
|
250
258
|
cookies = response_cookies
|
|
251
|
-
|
|
259
|
+
add_handler(HTTPCookieProcessor(response_cookies))
|
|
252
260
|
if not follow_redirects:
|
|
253
|
-
|
|
261
|
+
add_handler(NoRedirectHandler())
|
|
254
262
|
opener = build_opener(*handlers)
|
|
255
263
|
setattr(opener, "cookies", cookies)
|
|
256
264
|
try:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|