Skip to content

Commit 02f2fd2

Browse files
authored
Add files via upload
1 parent 90b5d61 commit 02f2fd2

8 files changed

Lines changed: 360 additions & 120 deletions

PyWWW/pywwwget_chatgpt.py

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,7 +1565,7 @@ def parse_pycurl_verbose(fileobj_or_text):
15651565
'response': parse_response_block(resp_block) if resp_block else None,
15661566
}
15671567

1568-
def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, httpuseragent=None, httpreferer=None, httpcookie=geturls_cj, httpmethod="GET", returnstat=False):
1568+
def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, httpuseragent=None, httpreferer=None, httpcookie=geturls_cj, httpmethod="GET", postdata=None, returnstat=False):
15691569
if headers is None:
15701570
headers = {}
15711571
else:
@@ -1635,10 +1635,14 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
16351635
httpfile.write(chunk)
16361636
httpcodeout = r.status_code
16371637
httpcodereason = r.reason
1638-
if(r.raw.version == "10"):
1639-
httpversionout = "1.0"
1640-
else:
1641-
httpversionout = "1.1"
1638+
vertostr = {
1639+
10: "HTTP/1.0",
1640+
11: "HTTP/1.1"
1641+
}
1642+
try:
1643+
httpversionout = vertostr[r.raw.version]
1644+
except AttributeError:
1645+
httpversionout = "HTTP/1.1"
16421646
httpmethodout = httpmethod
16431647
httpurlout = r.url
16441648
httpheaderout = r.headers
@@ -1693,7 +1697,8 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
16931697
httpfile.write(r.content)
16941698
httpcodeout = r.status
16951699
httpcodereason = http_status_to_reason(r.status)
1696-
httpversionout = "1.1"
1700+
raw_version = r.extensions.get(b"http_version", b"HTTP/1.1")
1701+
httpversionout = raw_version.decode("ascii")
16971702
httpmethodout = httpmethod
16981703
httpurlout = str(rebuilt_url)
16991704
httpheaderout = r.headers
@@ -1719,7 +1724,14 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
17191724
shutil.copyfileobj(resp, httpfile)
17201725
httpcodeout = resp.code
17211726
httpcodereason = resp.msg
1722-
httpversionout = "1.1"
1727+
vertostr = {
1728+
10: "HTTP/1.0",
1729+
11: "HTTP/1.1"
1730+
}
1731+
try:
1732+
httpversionout = vertostr[br.version]
1733+
except AttributeError:
1734+
httpversionout = "HTTP/1.1"
17231735
httpmethodout = httpmethod
17241736
httpurlout = resp.geturl()
17251737
httpheaderout = resp.info()
@@ -1742,10 +1754,14 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
17421754
shutil.copyfileobj(resp, httpfile)
17431755
httpcodeout = resp.status
17441756
httpcodereason = resp.reason
1745-
if(resp.version == "10"):
1746-
httpversionout = "1.0"
1747-
else:
1748-
httpversionout = "1.1"
1757+
vertostr = {
1758+
10: "HTTP/1.0",
1759+
11: "HTTP/1.1"
1760+
}
1761+
try:
1762+
httpversionout = vertostr[resp.version]
1763+
except AttributeError:
1764+
httpversionout = "HTTP/1.1"
17491765
httpmethodout = httpmethod
17501766
httpurlout = resp.geturl()
17511767
httpheaderout = resp.info()
@@ -1821,7 +1837,6 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
18211837
pycurlhead = retrieved_headers.read()
18221838
if(sys.version[0] >= "3"):
18231839
pycurlhead = retrieved_headers.read().decode('UTF-8')
1824-
pyhttpverinfo = re.findall(r'^HTTP/([0-9.]+) (\d+)(?: ([A-Za-z\s]+))?$', pycurlhead.splitlines()[0].strip().rstrip('\r\n'))[0]
18251840
pycurlheadersout = make_http_headers_from_pycurl_to_dict(pycurlhead)
18261841
retrieved_body.seek(0, 0)
18271842
httpfile = retrieved_body
@@ -1832,9 +1847,20 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
18321847
return False
18331848
except ValueError:
18341849
return False
1850+
HTTP_VERSION_MAP = {
1851+
pycurl.CURL_HTTP_VERSION_1_0: "HTTP/1.0",
1852+
pycurl.CURL_HTTP_VERSION_1_1: "HTTP/1.1",
1853+
}
1854+
# Optional HTTP/3 (only if compiled in)
1855+
if hasattr(pycurl, "CURL_HTTP_VERSION_2"):
1856+
HTTP_VERSION_MAP[pycurl.CURL_HTTP_VERSION_2] = "HTTP/2.0"
1857+
# Optional HTTP/3 (only if compiled in)
1858+
if hasattr(pycurl, "CURL_HTTP_VERSION_3"):
1859+
HTTP_VERSION_MAP[pycurl.CURL_HTTP_VERSION_3] = "HTTP/3.0"
1860+
ver_enum = geturls_text.getinfo(pycurl.INFO_HTTP_VERSION)
18351861
httpcodeout = geturls_text.getinfo(geturls_text.HTTP_CODE)
18361862
httpcodereason = http_status_to_reason(geturls_text.getinfo(geturls_text.HTTP_CODE))
1837-
httpversionout = pyhttpverinfo[0]
1863+
httpversionout = HTTP_VERSION_MAP.get(ver_enum, "HTTP/1.1")
18381864
httpmethodout = httpmethod
18391865
httpurlout = geturls_text.getinfo(geturls_text.EFFECTIVE_URL)
18401866
httpheaderout = pycurlheadersout
@@ -1866,10 +1892,14 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
18661892
httpcodereason = resp.reason
18671893
except AttributeError:
18681894
httpcodereason = http_status_to_reason(geturls_text.getcode())
1895+
vertostr = {
1896+
10: "HTTP/1.0",
1897+
11: "HTTP/1.1"
1898+
}
18691899
try:
1870-
httpversionout = resp.version
1900+
httpversionout = vertostr[resp.version]
18711901
except AttributeError:
1872-
httpversionout = "1.1"
1902+
httpversionout = "HTTP/1.1"
18731903
try:
18741904
httpmethodout = resp.get_method()
18751905
except AttributeError:

PyWWW/pywwwget_deepseek.py

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ def parse_pycurl_verbose(fileobj_or_text):
17981798
'response': parse_response_block(resp_block) if resp_block else None,
17991799
}
18001800

1801-
def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, httpuseragent=None, httpreferer=None, httpcookie=geturls_cj, httpmethod="GET", returnstat=False):
1801+
def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, httpuseragent=None, httpreferer=None, httpcookie=geturls_cj, httpmethod="GET", postdata=None, returnstat=False):
18021802
if headers is None:
18031803
headers = {}
18041804
else:
@@ -1868,10 +1868,14 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
18681868
httpfile.write(chunk)
18691869
httpcodeout = r.status_code
18701870
httpcodereason = r.reason
1871-
if(r.raw.version == "10"):
1872-
httpversionout = "1.0"
1873-
else:
1874-
httpversionout = "1.1"
1871+
vertostr = {
1872+
10: "HTTP/1.0",
1873+
11: "HTTP/1.1"
1874+
}
1875+
try:
1876+
httpversionout = vertostr[r.raw.version]
1877+
except AttributeError:
1878+
httpversionout = "HTTP/1.1"
18751879
httpmethodout = httpmethod
18761880
httpurlout = r.url
18771881
httpheaderout = r.headers
@@ -1926,7 +1930,8 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
19261930
httpfile.write(r.content)
19271931
httpcodeout = r.status
19281932
httpcodereason = http_status_to_reason(r.status)
1929-
httpversionout = "1.1"
1933+
raw_version = r.extensions.get(b"http_version", b"HTTP/1.1")
1934+
httpversionout = raw_version.decode("ascii")
19301935
httpmethodout = httpmethod
19311936
httpurlout = str(rebuilt_url)
19321937
httpheaderout = r.headers
@@ -1952,7 +1957,14 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
19521957
shutil.copyfileobj(resp, httpfile)
19531958
httpcodeout = resp.code
19541959
httpcodereason = resp.msg
1955-
httpversionout = "1.1"
1960+
vertostr = {
1961+
10: "HTTP/1.0",
1962+
11: "HTTP/1.1"
1963+
}
1964+
try:
1965+
httpversionout = vertostr[br.version]
1966+
except AttributeError:
1967+
httpversionout = "HTTP/1.1"
19561968
httpmethodout = httpmethod
19571969
httpurlout = resp.geturl()
19581970
httpheaderout = resp.info()
@@ -1975,10 +1987,14 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
19751987
shutil.copyfileobj(resp, httpfile)
19761988
httpcodeout = resp.status
19771989
httpcodereason = resp.reason
1978-
if(resp.version == "10"):
1979-
httpversionout = "1.0"
1980-
else:
1981-
httpversionout = "1.1"
1990+
vertostr = {
1991+
10: "HTTP/1.0",
1992+
11: "HTTP/1.1"
1993+
}
1994+
try:
1995+
httpversionout = vertostr[resp.version]
1996+
except AttributeError:
1997+
httpversionout = "HTTP/1.1"
19821998
httpmethodout = httpmethod
19831999
httpurlout = resp.geturl()
19842000
httpheaderout = resp.info()
@@ -2054,7 +2070,6 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
20542070
pycurlhead = retrieved_headers.read()
20552071
if(sys.version[0] >= "3"):
20562072
pycurlhead = retrieved_headers.read().decode('UTF-8')
2057-
pyhttpverinfo = re.findall(r'^HTTP/([0-9.]+) (\d+)(?: ([A-Za-z\s]+))?$', pycurlhead.splitlines()[0].strip().rstrip('\r\n'))[0]
20582073
pycurlheadersout = make_http_headers_from_pycurl_to_dict(pycurlhead)
20592074
retrieved_body.seek(0, 0)
20602075
httpfile = retrieved_body
@@ -2065,9 +2080,20 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
20652080
return False
20662081
except ValueError:
20672082
return False
2083+
HTTP_VERSION_MAP = {
2084+
pycurl.CURL_HTTP_VERSION_1_0: "HTTP/1.0",
2085+
pycurl.CURL_HTTP_VERSION_1_1: "HTTP/1.1",
2086+
}
2087+
# Optional HTTP/3 (only if compiled in)
2088+
if hasattr(pycurl, "CURL_HTTP_VERSION_2"):
2089+
HTTP_VERSION_MAP[pycurl.CURL_HTTP_VERSION_2] = "HTTP/2.0"
2090+
# Optional HTTP/3 (only if compiled in)
2091+
if hasattr(pycurl, "CURL_HTTP_VERSION_3"):
2092+
HTTP_VERSION_MAP[pycurl.CURL_HTTP_VERSION_3] = "HTTP/3.0"
2093+
ver_enum = geturls_text.getinfo(pycurl.INFO_HTTP_VERSION)
20682094
httpcodeout = geturls_text.getinfo(geturls_text.HTTP_CODE)
20692095
httpcodereason = http_status_to_reason(geturls_text.getinfo(geturls_text.HTTP_CODE))
2070-
httpversionout = pyhttpverinfo[0]
2096+
httpversionout = HTTP_VERSION_MAP.get(ver_enum, "HTTP/1.1")
20712097
httpmethodout = httpmethod
20722098
httpurlout = geturls_text.getinfo(geturls_text.EFFECTIVE_URL)
20732099
httpheaderout = pycurlheadersout
@@ -2099,10 +2125,14 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
20992125
httpcodereason = resp.reason
21002126
except AttributeError:
21012127
httpcodereason = http_status_to_reason(geturls_text.getcode())
2128+
vertostr = {
2129+
10: "HTTP/1.0",
2130+
11: "HTTP/1.1"
2131+
}
21022132
try:
2103-
httpversionout = resp.version
2133+
httpversionout = vertostr[resp.version]
21042134
except AttributeError:
2105-
httpversionout = "1.1"
2135+
httpversionout = "HTTP/1.1"
21062136
try:
21072137
httpmethodout = resp.get_method()
21082138
except AttributeError:

PyWWW/pywwwget_merged.py

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ def parse_pycurl_verbose(fileobj_or_text):
16001600
'response': parse_response_block(resp_block) if resp_block else None,
16011601
}
16021602

1603-
def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, httpuseragent=None, httpreferer=None, httpcookie=geturls_cj, httpmethod="GET", returnstat=False):
1603+
def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, httpuseragent=None, httpreferer=None, httpcookie=geturls_cj, httpmethod="GET", postdata=None, returnstat=False):
16041604
if headers is None:
16051605
headers = {}
16061606
else:
@@ -1670,10 +1670,14 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
16701670
httpfile.write(chunk)
16711671
httpcodeout = r.status_code
16721672
httpcodereason = r.reason
1673-
if(r.raw.version == "10"):
1674-
httpversionout = "1.0"
1675-
else:
1676-
httpversionout = "1.1"
1673+
vertostr = {
1674+
10: "HTTP/1.0",
1675+
11: "HTTP/1.1"
1676+
}
1677+
try:
1678+
httpversionout = vertostr[r.raw.version]
1679+
except AttributeError:
1680+
httpversionout = "HTTP/1.1"
16771681
httpmethodout = httpmethod
16781682
httpurlout = r.url
16791683
httpheaderout = r.headers
@@ -1728,7 +1732,8 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
17281732
httpfile.write(r.content)
17291733
httpcodeout = r.status
17301734
httpcodereason = http_status_to_reason(r.status)
1731-
httpversionout = "1.1"
1735+
raw_version = r.extensions.get(b"http_version", b"HTTP/1.1")
1736+
httpversionout = raw_version.decode("ascii")
17321737
httpmethodout = httpmethod
17331738
httpurlout = str(rebuilt_url)
17341739
httpheaderout = r.headers
@@ -1754,7 +1759,14 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
17541759
shutil.copyfileobj(resp, httpfile)
17551760
httpcodeout = resp.code
17561761
httpcodereason = resp.msg
1757-
httpversionout = "1.1"
1762+
vertostr = {
1763+
10: "HTTP/1.0",
1764+
11: "HTTP/1.1"
1765+
}
1766+
try:
1767+
httpversionout = vertostr[br.version]
1768+
except AttributeError:
1769+
httpversionout = "HTTP/1.1"
17581770
httpmethodout = httpmethod
17591771
httpurlout = resp.geturl()
17601772
httpheaderout = resp.info()
@@ -1777,10 +1789,14 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
17771789
shutil.copyfileobj(resp, httpfile)
17781790
httpcodeout = resp.status
17791791
httpcodereason = resp.reason
1780-
if(resp.version == "10"):
1781-
httpversionout = "1.0"
1782-
else:
1783-
httpversionout = "1.1"
1792+
vertostr = {
1793+
10: "HTTP/1.0",
1794+
11: "HTTP/1.1"
1795+
}
1796+
try:
1797+
httpversionout = vertostr[resp.version]
1798+
except AttributeError:
1799+
httpversionout = "HTTP/1.1"
17841800
httpmethodout = httpmethod
17851801
httpurlout = resp.geturl()
17861802
httpheaderout = resp.info()
@@ -1856,7 +1872,6 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
18561872
pycurlhead = retrieved_headers.read()
18571873
if(sys.version[0] >= "3"):
18581874
pycurlhead = retrieved_headers.read().decode('UTF-8')
1859-
pyhttpverinfo = re.findall(r'^HTTP/([0-9.]+) (\d+)(?: ([A-Za-z\s]+))?$', pycurlhead.splitlines()[0].strip().rstrip('\r\n'))[0]
18601875
pycurlheadersout = make_http_headers_from_pycurl_to_dict(pycurlhead)
18611876
retrieved_body.seek(0, 0)
18621877
httpfile = retrieved_body
@@ -1867,9 +1882,20 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
18671882
return False
18681883
except ValueError:
18691884
return False
1885+
HTTP_VERSION_MAP = {
1886+
pycurl.CURL_HTTP_VERSION_1_0: "HTTP/1.0",
1887+
pycurl.CURL_HTTP_VERSION_1_1: "HTTP/1.1",
1888+
}
1889+
# Optional HTTP/3 (only if compiled in)
1890+
if hasattr(pycurl, "CURL_HTTP_VERSION_2"):
1891+
HTTP_VERSION_MAP[pycurl.CURL_HTTP_VERSION_2] = "HTTP/2.0"
1892+
# Optional HTTP/3 (only if compiled in)
1893+
if hasattr(pycurl, "CURL_HTTP_VERSION_3"):
1894+
HTTP_VERSION_MAP[pycurl.CURL_HTTP_VERSION_3] = "HTTP/3.0"
1895+
ver_enum = geturls_text.getinfo(pycurl.INFO_HTTP_VERSION)
18701896
httpcodeout = geturls_text.getinfo(geturls_text.HTTP_CODE)
18711897
httpcodereason = http_status_to_reason(geturls_text.getinfo(geturls_text.HTTP_CODE))
1872-
httpversionout = pyhttpverinfo[0]
1898+
httpversionout = HTTP_VERSION_MAP.get(ver_enum, "HTTP/1.1")
18731899
httpmethodout = httpmethod
18741900
httpurlout = geturls_text.getinfo(geturls_text.EFFECTIVE_URL)
18751901
httpheaderout = pycurlheadersout
@@ -1901,10 +1927,14 @@ def download_file_from_http_file(url, headers=None, usehttp=__use_http_lib__, ht
19011927
httpcodereason = resp.reason
19021928
except AttributeError:
19031929
httpcodereason = http_status_to_reason(geturls_text.getcode())
1930+
vertostr = {
1931+
10: "HTTP/1.0",
1932+
11: "HTTP/1.1"
1933+
}
19041934
try:
1905-
httpversionout = resp.version
1935+
httpversionout = vertostr[resp.version]
19061936
except AttributeError:
1907-
httpversionout = "1.1"
1937+
httpversionout = "HTTP/1.1"
19081938
try:
19091939
httpmethodout = resp.get_method()
19101940
except AttributeError:

0 commit comments

Comments
 (0)