Skip to content

Commit 817b0d5

Browse files
authored
Add files via upload
1 parent fe1fb13 commit 817b0d5

10 files changed

Lines changed: 182 additions & 4 deletions

PyWWW/pywwwget_bard.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ def unquote(x): return x
251251
except ImportError:
252252
pass
253253

254+
haveurllib3 = False
255+
try:
256+
import urllib3 # noqa
257+
haveurllib3 = True
258+
except Exception:
259+
pass
260+
254261
havehttpx = False
255262
try:
256263
import httpx
@@ -849,7 +856,17 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__):
849856
if username: br.add_password(rebuilt_url, username, password)
850857
resp = br.open(rebuilt_url)
851858
shutil.copyfileobj(resp, httpfile)
852-
859+
860+
elif usehttp == "urllib3" and haveurllib3:
861+
http = urllib3.PoolManager()
862+
if username and password:
863+
auth_headers = urllib3.make_headers(basic_auth="{}:{}".format(username, password))
864+
headers.update(auth_headers)
865+
# Request with preload_content=False to get a file-like object
866+
resp = http.request("GET", rebuilt_url, headers=headers, preload_content=False)
867+
shutil.copyfileobj(resp, httpfile)
868+
resp.release_conn()
869+
853870
else:
854871
req = Request(rebuilt_url, headers=headers)
855872
if username:

PyWWW/pywwwget_chatgpt.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ def unquote(x): # very small fallback
292292
except Exception:
293293
pass
294294

295+
haveurllib3 = False
296+
try:
297+
import urllib3 # noqa
298+
haveurllib3 = True
299+
except Exception:
300+
pass
301+
295302
havehttpx = False
296303
try:
297304
import httpx # noqa
@@ -1062,6 +1069,17 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__):
10621069
resp = br.open(rebuilt_url)
10631070
shutil.copyfileobj(resp, httpfile)
10641071

1072+
# URLLib3
1073+
elif usehttp == "urllib3" and haveurllib3:
1074+
http = urllib3.PoolManager()
1075+
if username and password:
1076+
auth_headers = urllib3.make_headers(basic_auth="{}:{}".format(username, password))
1077+
headers.update(auth_headers)
1078+
# Request with preload_content=False to get a file-like object
1079+
resp = http.request("GET", rebuilt_url, headers=headers, preload_content=False)
1080+
shutil.copyfileobj(resp, httpfile)
1081+
resp.release_conn()
1082+
10651083
# urllib fallback
10661084
else:
10671085
req = Request(rebuilt_url, headers=headers)

PyWWW/pywwwget_deepseek.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ def unquote(x): # very small fallback
270270
except ImportError:
271271
pass
272272

273+
haveurllib3 = False
274+
try:
275+
import urllib3 # noqa
276+
haveurllib3 = True
277+
except Exception:
278+
pass
279+
273280
havehttpx = False
274281
try:
275282
import httpx # noqa
@@ -1274,7 +1281,18 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__):
12741281

12751282
resp = br.open(rebuilt_url)
12761283
shutil.copyfileobj(resp, httpfile)
1277-
1284+
1285+
# URLLib3
1286+
elif usehttp == "urllib3" and haveurllib3:
1287+
http = urllib3.PoolManager()
1288+
if username and password:
1289+
auth_headers = urllib3.make_headers(basic_auth="{}:{}".format(username, password))
1290+
headers.update(auth_headers)
1291+
# Request with preload_content=False to get a file-like object
1292+
resp = http.request("GET", rebuilt_url, headers=headers, preload_content=False)
1293+
shutil.copyfileobj(resp, httpfile)
1294+
resp.release_conn()
1295+
12781296
# urllib fallback
12791297
else:
12801298
req = Request(rebuilt_url, headers=headers)

PyWWW/pywwwget_merged.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ def unquote(x): # very small fallback
295295
except Exception:
296296
pass
297297

298+
haveurllib3 = False
299+
try:
300+
import urllib3 # noqa
301+
haveurllib3 = True
302+
except Exception:
303+
pass
304+
298305
havehttpx = False
299306
try:
300307
import httpx # noqa
@@ -1069,6 +1076,17 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__):
10691076
resp = br.open(rebuilt_url)
10701077
shutil.copyfileobj(resp, httpfile)
10711078

1079+
# URLLib3
1080+
elif usehttp == "urllib3" and haveurllib3:
1081+
http = urllib3.PoolManager()
1082+
if username and password:
1083+
auth_headers = urllib3.make_headers(basic_auth="{}:{}".format(username, password))
1084+
headers.update(auth_headers)
1085+
# Request with preload_content=False to get a file-like object
1086+
resp = http.request("GET", rebuilt_url, headers=headers, preload_content=False)
1087+
shutil.copyfileobj(resp, httpfile)
1088+
resp.release_conn()
1089+
10721090
# urllib fallback
10731091
else:
10741092
req = Request(rebuilt_url, headers=headers)

PyWWW/pywwwget_nextver.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@ def unquote(x): # very small fallback
309309
except Exception:
310310
pass
311311

312+
haveurllib3 = False
313+
try:
314+
import urllib3 # noqa
315+
haveurllib3 = True
316+
except Exception:
317+
pass
318+
312319
havehttpx = False
313320
try:
314321
import httpx # noqa
@@ -1083,6 +1090,17 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__):
10831090
resp = br.open(rebuilt_url)
10841091
shutil.copyfileobj(resp, httpfile)
10851092

1093+
# URLLib3
1094+
elif usehttp == "urllib3" and haveurllib3:
1095+
http = urllib3.PoolManager()
1096+
if username and password:
1097+
auth_headers = urllib3.make_headers(basic_auth="{}:{}".format(username, password))
1098+
headers.update(auth_headers)
1099+
# Request with preload_content=False to get a file-like object
1100+
resp = http.request("GET", rebuilt_url, headers=headers, preload_content=False)
1101+
shutil.copyfileobj(resp, httpfile)
1102+
resp.release_conn()
1103+
10861104
# urllib fallback
10871105
else:
10881106
req = Request(rebuilt_url, headers=headers)

pywwwget_bard.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ def unquote(x): return x
251251
except ImportError:
252252
pass
253253

254+
haveurllib3 = False
255+
try:
256+
import urllib3 # noqa
257+
haveurllib3 = True
258+
except Exception:
259+
pass
260+
254261
havehttpx = False
255262
try:
256263
import httpx
@@ -849,7 +856,17 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__):
849856
if username: br.add_password(rebuilt_url, username, password)
850857
resp = br.open(rebuilt_url)
851858
shutil.copyfileobj(resp, httpfile)
852-
859+
860+
elif usehttp == "urllib3" and haveurllib3:
861+
http = urllib3.PoolManager()
862+
if username and password:
863+
auth_headers = urllib3.make_headers(basic_auth="{}:{}".format(username, password))
864+
headers.update(auth_headers)
865+
# Request with preload_content=False to get a file-like object
866+
resp = http.request("GET", rebuilt_url, headers=headers, preload_content=False)
867+
shutil.copyfileobj(resp, httpfile)
868+
resp.release_conn()
869+
853870
else:
854871
req = Request(rebuilt_url, headers=headers)
855872
if username:

pywwwget_chatgpt.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ def unquote(x): # very small fallback
292292
except Exception:
293293
pass
294294

295+
haveurllib3 = False
296+
try:
297+
import urllib3 # noqa
298+
haveurllib3 = True
299+
except Exception:
300+
pass
301+
295302
havehttpx = False
296303
try:
297304
import httpx # noqa
@@ -1062,6 +1069,17 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__):
10621069
resp = br.open(rebuilt_url)
10631070
shutil.copyfileobj(resp, httpfile)
10641071

1072+
# URLLib3
1073+
elif usehttp == "urllib3" and haveurllib3:
1074+
http = urllib3.PoolManager()
1075+
if username and password:
1076+
auth_headers = urllib3.make_headers(basic_auth="{}:{}".format(username, password))
1077+
headers.update(auth_headers)
1078+
# Request with preload_content=False to get a file-like object
1079+
resp = http.request("GET", rebuilt_url, headers=headers, preload_content=False)
1080+
shutil.copyfileobj(resp, httpfile)
1081+
resp.release_conn()
1082+
10651083
# urllib fallback
10661084
else:
10671085
req = Request(rebuilt_url, headers=headers)

pywwwget_deepseek.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ def unquote(x): # very small fallback
270270
except ImportError:
271271
pass
272272

273+
haveurllib3 = False
274+
try:
275+
import urllib3 # noqa
276+
haveurllib3 = True
277+
except Exception:
278+
pass
279+
273280
havehttpx = False
274281
try:
275282
import httpx # noqa
@@ -1274,7 +1281,18 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__):
12741281

12751282
resp = br.open(rebuilt_url)
12761283
shutil.copyfileobj(resp, httpfile)
1277-
1284+
1285+
# URLLib3
1286+
elif usehttp == "urllib3" and haveurllib3:
1287+
http = urllib3.PoolManager()
1288+
if username and password:
1289+
auth_headers = urllib3.make_headers(basic_auth="{}:{}".format(username, password))
1290+
headers.update(auth_headers)
1291+
# Request with preload_content=False to get a file-like object
1292+
resp = http.request("GET", rebuilt_url, headers=headers, preload_content=False)
1293+
shutil.copyfileobj(resp, httpfile)
1294+
resp.release_conn()
1295+
12781296
# urllib fallback
12791297
else:
12801298
req = Request(rebuilt_url, headers=headers)

pywwwget_merged.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ def unquote(x): # very small fallback
295295
except Exception:
296296
pass
297297

298+
haveurllib3 = False
299+
try:
300+
import urllib3 # noqa
301+
haveurllib3 = True
302+
except Exception:
303+
pass
304+
298305
havehttpx = False
299306
try:
300307
import httpx # noqa
@@ -1069,6 +1076,17 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__):
10691076
resp = br.open(rebuilt_url)
10701077
shutil.copyfileobj(resp, httpfile)
10711078

1079+
# URLLib3
1080+
elif usehttp == "urllib3" and haveurllib3:
1081+
http = urllib3.PoolManager()
1082+
if username and password:
1083+
auth_headers = urllib3.make_headers(basic_auth="{}:{}".format(username, password))
1084+
headers.update(auth_headers)
1085+
# Request with preload_content=False to get a file-like object
1086+
resp = http.request("GET", rebuilt_url, headers=headers, preload_content=False)
1087+
shutil.copyfileobj(resp, httpfile)
1088+
resp.release_conn()
1089+
10721090
# urllib fallback
10731091
else:
10741092
req = Request(rebuilt_url, headers=headers)

pywwwget_nextver.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,13 @@ def unquote(x): # very small fallback
309309
except Exception:
310310
pass
311311

312+
haveurllib3 = False
313+
try:
314+
import urllib3 # noqa
315+
haveurllib3 = True
316+
except Exception:
317+
pass
318+
312319
havehttpx = False
313320
try:
314321
import httpx # noqa
@@ -1083,6 +1090,17 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__):
10831090
resp = br.open(rebuilt_url)
10841091
shutil.copyfileobj(resp, httpfile)
10851092

1093+
# URLLib3
1094+
elif usehttp == "urllib3" and haveurllib3:
1095+
http = urllib3.PoolManager()
1096+
if username and password:
1097+
auth_headers = urllib3.make_headers(basic_auth="{}:{}".format(username, password))
1098+
headers.update(auth_headers)
1099+
# Request with preload_content=False to get a file-like object
1100+
resp = http.request("GET", rebuilt_url, headers=headers, preload_content=False)
1101+
shutil.copyfileobj(resp, httpfile)
1102+
resp.release_conn()
1103+
10861104
# urllib fallback
10871105
else:
10881106
req = Request(rebuilt_url, headers=headers)

0 commit comments

Comments
 (0)