Skip to content

Commit 2b92929

Browse files
authored
Add files via upload
1 parent 5e6c1c8 commit 2b92929

8 files changed

Lines changed: 328 additions & 32 deletions

PyWWW/pywwwget_chatgpt.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ def unquote(x): # very small fallback
383383
except Exception:
384384
pass
385385

386+
havehttpcore = False
387+
try:
388+
import httpcore
389+
havehttpcore = True
390+
except ImportError:
391+
pass
392+
386393
havemechanize = False
387394
try:
388395
import mechanize # noqa
@@ -1391,7 +1398,12 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
13911398

13921399
# HTTPX
13931400
elif usehttp == "httpx" and havehttpx:
1394-
with httpx.Client(follow_redirects=True, http1=True, http2=True, trust_env=True, timeout=60.0) as client:
1401+
try:
1402+
import h2
1403+
usehttp2 = True
1404+
except ImportError:
1405+
usehttp2 = False
1406+
with httpx.Client(follow_redirects=True, http1=True, http2=usehttp2, trust_env=True, timeout=60.0) as client:
13951407
auth = (username, password) if (username and password) else None
13961408
if(httpmethod == "GET"):
13971409
r = client.get(rebuilt_url, headers=headers, auth=auth, cookies=httpcookie)
@@ -1414,6 +1426,31 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
14141426
httpheaderout = r.headers
14151427
httpheadersentout = r.request.headers
14161428

1429+
1430+
# HTTPCore
1431+
elif usehttp == "httpcore" and havehttpcore:
1432+
try:
1433+
import h2
1434+
usehttp2 = True
1435+
except ImportError:
1436+
usehttp2 = False
1437+
with httpcore.ConnectionPool(http1=True, http2=usehttp2) as client:
1438+
auth = (username, password) if (username and password) else None
1439+
if(httpmethod == "GET"):
1440+
r = client.request("GET", rebuilt_url, headers=headers)
1441+
if(httpmethod == "POST"):
1442+
r = client.request("POST", rebuilt_url, data=postdata, headers=headers)
1443+
else:
1444+
r = client.request("GET", rebuilt_url, headers=headers)
1445+
httpfile.write(r.content)
1446+
httpcodeout = r.status
1447+
httpcodereason = http_status_to_reason(r.status)
1448+
httpversionout = "1.1"
1449+
httpmethodout = httpmethod
1450+
httpurlout = str(httpurl)
1451+
httpheaderout = r.headers
1452+
httpheadersentout = headers
1453+
14171454
# Mechanize
14181455
elif usehttp == "mechanize" and havemechanize:
14191456
br = mechanize.Browser()
@@ -1479,7 +1516,7 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
14791516
usehttpver = geturls_text.CURL_HTTP_VERSION_2_0
14801517
else:
14811518
usehttpver = geturls_text.CURL_HTTP_VERSION_1_1
1482-
geturls_text.setopt(geturls_text.URL, url)
1519+
geturls_text.setopt(geturls_text.URL, rebuilt_url)
14831520
geturls_text.setopt(geturls_text.HTTP_VERSION,
14841521
geturls_text.CURL_HTTP_VERSION_1_1)
14851522
geturls_text.setopt(
@@ -1498,7 +1535,7 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
14981535
usehttpver = geturls_text.CURL_HTTP_VERSION_2_0
14991536
else:
15001537
usehttpver = geturls_text.CURL_HTTP_VERSION_1_1
1501-
geturls_text.setopt(geturls_text.URL, url)
1538+
geturls_text.setopt(geturls_text.URL, rebuilt_url)
15021539
geturls_text.setopt(geturls_text.HTTP_VERSION,
15031540
geturls_text.CURL_HTTP_VERSION_1_1)
15041541
geturls_text.setopt(
@@ -1519,7 +1556,7 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
15191556
usehttpver = geturls_text.CURL_HTTP_VERSION_2_0
15201557
else:
15211558
usehttpver = geturls_text.CURL_HTTP_VERSION_1_1
1522-
geturls_text.setopt(geturls_text.URL, url)
1559+
geturls_text.setopt(geturls_text.URL, rebuilt_url)
15231560
geturls_text.setopt(geturls_text.HTTP_VERSION,
15241561
geturls_text.CURL_HTTP_VERSION_1_1)
15251562
geturls_text.setopt(

PyWWW/pywwwget_deepseek.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ def unquote(x): # very small fallback
360360
except ImportError:
361361
pass
362362

363+
havehttpcore = False
364+
try:
365+
import httpcore
366+
havehttpcore = True
367+
except ImportError:
368+
pass
369+
363370
havemechanize = False
364371
try:
365372
import mechanize # noqa
@@ -1624,7 +1631,12 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
16241631

16251632
# HTTPX
16261633
elif usehttp == "httpx" and havehttpx:
1627-
with httpx.Client(follow_redirects=True, http1=True, http2=True, trust_env=True, timeout=60.0) as client:
1634+
try:
1635+
import h2
1636+
usehttp2 = True
1637+
except ImportError:
1638+
usehttp2 = False
1639+
with httpx.Client(follow_redirects=True, http1=True, http2=usehttp2, trust_env=True, timeout=60.0) as client:
16281640
auth = (username, password) if (username and password) else None
16291641
if(httpmethod == "GET"):
16301642
r = client.get(rebuilt_url, headers=headers, auth=auth, cookies=httpcookie)
@@ -1647,6 +1659,31 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
16471659
httpheaderout = r.headers
16481660
httpheadersentout = r.request.headers
16491661

1662+
1663+
# HTTPCore
1664+
elif usehttp == "httpcore" and havehttpcore:
1665+
try:
1666+
import h2
1667+
usehttp2 = True
1668+
except ImportError:
1669+
usehttp2 = False
1670+
with httpcore.ConnectionPool(http1=True, http2=usehttp2) as client:
1671+
auth = (username, password) if (username and password) else None
1672+
if(httpmethod == "GET"):
1673+
r = client.request("GET", rebuilt_url, headers=headers)
1674+
if(httpmethod == "POST"):
1675+
r = client.request("POST", rebuilt_url, data=postdata, headers=headers)
1676+
else:
1677+
r = client.request("GET", rebuilt_url, headers=headers)
1678+
httpfile.write(r.content)
1679+
httpcodeout = r.status
1680+
httpcodereason = http_status_to_reason(r.status)
1681+
httpversionout = "1.1"
1682+
httpmethodout = httpmethod
1683+
httpurlout = str(httpurl)
1684+
httpheaderout = r.headers
1685+
httpheadersentout = headers
1686+
16501687
# Mechanize
16511688
elif usehttp == "mechanize" and havemechanize:
16521689
br = mechanize.Browser()
@@ -1712,7 +1749,7 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
17121749
usehttpver = geturls_text.CURL_HTTP_VERSION_2_0
17131750
else:
17141751
usehttpver = geturls_text.CURL_HTTP_VERSION_1_1
1715-
geturls_text.setopt(geturls_text.URL, url)
1752+
geturls_text.setopt(geturls_text.URL, rebuilt_url)
17161753
geturls_text.setopt(geturls_text.HTTP_VERSION,
17171754
geturls_text.CURL_HTTP_VERSION_1_1)
17181755
geturls_text.setopt(
@@ -1731,7 +1768,7 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
17311768
usehttpver = geturls_text.CURL_HTTP_VERSION_2_0
17321769
else:
17331770
usehttpver = geturls_text.CURL_HTTP_VERSION_1_1
1734-
geturls_text.setopt(geturls_text.URL, url)
1771+
geturls_text.setopt(geturls_text.URL, rebuilt_url)
17351772
geturls_text.setopt(geturls_text.HTTP_VERSION,
17361773
geturls_text.CURL_HTTP_VERSION_1_1)
17371774
geturls_text.setopt(
@@ -1752,7 +1789,7 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
17521789
usehttpver = geturls_text.CURL_HTTP_VERSION_2_0
17531790
else:
17541791
usehttpver = geturls_text.CURL_HTTP_VERSION_1_1
1755-
geturls_text.setopt(geturls_text.URL, url)
1792+
geturls_text.setopt(geturls_text.URL, rebuilt_url)
17561793
geturls_text.setopt(geturls_text.HTTP_VERSION,
17571794
geturls_text.CURL_HTTP_VERSION_1_1)
17581795
geturls_text.setopt(

PyWWW/pywwwget_merged.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,13 @@ def unquote(x): # very small fallback
387387
except Exception:
388388
pass
389389

390+
havehttpcore = False
391+
try:
392+
import httpcore
393+
havehttpcore = True
394+
except ImportError:
395+
pass
396+
390397
havemechanize = False
391398
try:
392399
import mechanize # noqa
@@ -1426,7 +1433,12 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
14261433

14271434
# HTTPX
14281435
elif usehttp == "httpx" and havehttpx:
1429-
with httpx.Client(follow_redirects=True, http1=True, http2=True, trust_env=True, timeout=60.0) as client:
1436+
try:
1437+
import h2
1438+
usehttp2 = True
1439+
except ImportError:
1440+
usehttp2 = False
1441+
with httpx.Client(follow_redirects=True, http1=True, http2=usehttp2, trust_env=True, timeout=60.0) as client:
14301442
auth = (username, password) if (username and password) else None
14311443
if(httpmethod == "GET"):
14321444
r = client.get(rebuilt_url, headers=headers, auth=auth, cookies=httpcookie)
@@ -1449,6 +1461,31 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
14491461
httpheaderout = r.headers
14501462
httpheadersentout = r.request.headers
14511463

1464+
1465+
# HTTPCore
1466+
elif usehttp == "httpcore" and havehttpcore:
1467+
try:
1468+
import h2
1469+
usehttp2 = True
1470+
except ImportError:
1471+
usehttp2 = False
1472+
with httpcore.ConnectionPool(http1=True, http2=usehttp2) as client:
1473+
auth = (username, password) if (username and password) else None
1474+
if(httpmethod == "GET"):
1475+
r = client.request("GET", rebuilt_url, headers=headers)
1476+
if(httpmethod == "POST"):
1477+
r = client.request("POST", rebuilt_url, data=postdata, headers=headers)
1478+
else:
1479+
r = client.request("GET", rebuilt_url, headers=headers)
1480+
httpfile.write(r.content)
1481+
httpcodeout = r.status
1482+
httpcodereason = http_status_to_reason(r.status)
1483+
httpversionout = "1.1"
1484+
httpmethodout = httpmethod
1485+
httpurlout = str(httpurl)
1486+
httpheaderout = r.headers
1487+
httpheadersentout = headers
1488+
14521489
# Mechanize
14531490
elif usehttp == "mechanize" and havemechanize:
14541491
br = mechanize.Browser()
@@ -1514,7 +1551,7 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
15141551
usehttpver = geturls_text.CURL_HTTP_VERSION_2_0
15151552
else:
15161553
usehttpver = geturls_text.CURL_HTTP_VERSION_1_1
1517-
geturls_text.setopt(geturls_text.URL, url)
1554+
geturls_text.setopt(geturls_text.URL, rebuilt_url)
15181555
geturls_text.setopt(geturls_text.HTTP_VERSION,
15191556
geturls_text.CURL_HTTP_VERSION_1_1)
15201557
geturls_text.setopt(
@@ -1533,7 +1570,7 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
15331570
usehttpver = geturls_text.CURL_HTTP_VERSION_2_0
15341571
else:
15351572
usehttpver = geturls_text.CURL_HTTP_VERSION_1_1
1536-
geturls_text.setopt(geturls_text.URL, url)
1573+
geturls_text.setopt(geturls_text.URL, rebuilt_url)
15371574
geturls_text.setopt(geturls_text.HTTP_VERSION,
15381575
geturls_text.CURL_HTTP_VERSION_1_1)
15391576
geturls_text.setopt(
@@ -1554,7 +1591,7 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
15541591
usehttpver = geturls_text.CURL_HTTP_VERSION_2_0
15551592
else:
15561593
usehttpver = geturls_text.CURL_HTTP_VERSION_1_1
1557-
geturls_text.setopt(geturls_text.URL, url)
1594+
geturls_text.setopt(geturls_text.URL, rebuilt_url)
15581595
geturls_text.setopt(geturls_text.HTTP_VERSION,
15591596
geturls_text.CURL_HTTP_VERSION_1_1)
15601597
geturls_text.setopt(

PyWWW/pywwwget_nextver.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,13 @@ def unquote(x): # very small fallback
395395
except Exception:
396396
pass
397397

398+
havehttpcore = False
399+
try:
400+
import httpcore
401+
havehttpcore = True
402+
except ImportError:
403+
pass
404+
398405
havemechanize = False
399406
try:
400407
import mechanize # noqa
@@ -1407,7 +1414,12 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
14071414

14081415
# HTTPX
14091416
elif usehttp == "httpx" and havehttpx:
1410-
with httpx.Client(follow_redirects=True, http1=True, http2=True, trust_env=True, timeout=60.0) as client:
1417+
try:
1418+
import h2
1419+
usehttp2 = True
1420+
except ImportError:
1421+
usehttp2 = False
1422+
with httpx.Client(follow_redirects=True, http1=True, http2=usehttp2, trust_env=True, timeout=60.0) as client:
14111423
auth = (username, password) if (username and password) else None
14121424
if(httpmethod == "GET"):
14131425
r = client.get(rebuilt_url, headers=headers, auth=auth, cookies=httpcookie)
@@ -1430,6 +1442,31 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
14301442
httpheaderout = r.headers
14311443
httpheadersentout = r.request.headers
14321444

1445+
1446+
# HTTPCore
1447+
elif usehttp == "httpcore" and havehttpcore:
1448+
try:
1449+
import h2
1450+
usehttp2 = True
1451+
except ImportError:
1452+
usehttp2 = False
1453+
with httpcore.ConnectionPool(http1=True, http2=usehttp2) as client:
1454+
auth = (username, password) if (username and password) else None
1455+
if(httpmethod == "GET"):
1456+
r = client.request("GET", rebuilt_url, headers=headers)
1457+
if(httpmethod == "POST"):
1458+
r = client.request("POST", rebuilt_url, data=postdata, headers=headers)
1459+
else:
1460+
r = client.request("GET", rebuilt_url, headers=headers)
1461+
httpfile.write(r.content)
1462+
httpcodeout = r.status
1463+
httpcodereason = http_status_to_reason(r.status)
1464+
httpversionout = "1.1"
1465+
httpmethodout = httpmethod
1466+
httpurlout = str(rebuilt_url)
1467+
httpheaderout = r.headers
1468+
httpheadersentout = headers
1469+
14331470
# Mechanize
14341471
elif usehttp == "mechanize" and havemechanize:
14351472
br = mechanize.Browser()
@@ -1495,7 +1532,7 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
14951532
usehttpver = geturls_text.CURL_HTTP_VERSION_2_0
14961533
else:
14971534
usehttpver = geturls_text.CURL_HTTP_VERSION_1_1
1498-
geturls_text.setopt(geturls_text.URL, url)
1535+
geturls_text.setopt(geturls_text.URL, rebuilt_url)
14991536
geturls_text.setopt(geturls_text.HTTP_VERSION,
15001537
geturls_text.CURL_HTTP_VERSION_1_1)
15011538
geturls_text.setopt(
@@ -1514,7 +1551,7 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
15141551
usehttpver = geturls_text.CURL_HTTP_VERSION_2_0
15151552
else:
15161553
usehttpver = geturls_text.CURL_HTTP_VERSION_1_1
1517-
geturls_text.setopt(geturls_text.URL, url)
1554+
geturls_text.setopt(geturls_text.URL, rebuilt_url)
15181555
geturls_text.setopt(geturls_text.HTTP_VERSION,
15191556
geturls_text.CURL_HTTP_VERSION_1_1)
15201557
geturls_text.setopt(
@@ -1535,7 +1572,7 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
15351572
usehttpver = geturls_text.CURL_HTTP_VERSION_2_0
15361573
else:
15371574
usehttpver = geturls_text.CURL_HTTP_VERSION_1_1
1538-
geturls_text.setopt(geturls_text.URL, url)
1575+
geturls_text.setopt(geturls_text.URL, rebuilt_url)
15391576
geturls_text.setopt(geturls_text.HTTP_VERSION,
15401577
geturls_text.CURL_HTTP_VERSION_1_1)
15411578
geturls_text.setopt(

0 commit comments

Comments
 (0)