mirror of https://github.com/python/cpython
bpo-42627: Fix incorrect parsing of Windows registry proxy settings (GH-26307)
(cherry picked from commit b69297ea23
)
Co-authored-by: 狂男风 <CrazyBoyFeng@Live.com>
This commit is contained in:
parent
a2c8180a9a
commit
5a33643dce
|
@ -2679,22 +2679,26 @@ elif os.name == 'nt':
|
||||||
# Returned as Unicode but problems if not converted to ASCII
|
# Returned as Unicode but problems if not converted to ASCII
|
||||||
proxyServer = str(winreg.QueryValueEx(internetSettings,
|
proxyServer = str(winreg.QueryValueEx(internetSettings,
|
||||||
'ProxyServer')[0])
|
'ProxyServer')[0])
|
||||||
if '=' in proxyServer:
|
if '=' not in proxyServer and ';' not in proxyServer:
|
||||||
# Per-protocol settings
|
# Use one setting for all protocols.
|
||||||
for p in proxyServer.split(';'):
|
proxyServer = 'http={0};https={0};ftp={0}'.format(proxyServer)
|
||||||
protocol, address = p.split('=', 1)
|
for p in proxyServer.split(';'):
|
||||||
# See if address has a type:// prefix
|
protocol, address = p.split('=', 1)
|
||||||
if not re.match('(?:[^/:]+)://', address):
|
# See if address has a type:// prefix
|
||||||
address = '%s://%s' % (protocol, address)
|
if not re.match('(?:[^/:]+)://', address):
|
||||||
proxies[protocol] = address
|
# Add type:// prefix to address without specifying type
|
||||||
else:
|
if protocol in ('http', 'https', 'ftp'):
|
||||||
# Use one setting for all protocols
|
# The default proxy type of Windows is HTTP
|
||||||
if proxyServer[:5] == 'http:':
|
address = 'http://' + address
|
||||||
proxies['http'] = proxyServer
|
elif protocol == 'socks':
|
||||||
else:
|
address = 'socks://' + address
|
||||||
proxies['http'] = 'http://%s' % proxyServer
|
proxies[protocol] = address
|
||||||
proxies['https'] = 'https://%s' % proxyServer
|
# Use SOCKS proxy for HTTP(S) protocols
|
||||||
proxies['ftp'] = 'ftp://%s' % proxyServer
|
if proxies.get('socks'):
|
||||||
|
# The default SOCKS proxy type of Windows is SOCKS4
|
||||||
|
address = re.sub(r'^socks://', 'socks4://', proxies['socks'])
|
||||||
|
proxies['http'] = proxies.get('http') or address
|
||||||
|
proxies['https'] = proxies.get('https') or address
|
||||||
internetSettings.Close()
|
internetSettings.Close()
|
||||||
except (OSError, ValueError, TypeError):
|
except (OSError, ValueError, TypeError):
|
||||||
# Either registry key not found etc, or the value in an
|
# Either registry key not found etc, or the value in an
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix incorrect parsing of Windows registry proxy settings
|
Loading…
Reference in New Issue