summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-05-11 18:42:10 (GMT)
committerGitHub <noreply@github.com>2022-05-11 18:42:10 (GMT)
commit65d2dfd5c29c25a4f620e928c5ac9b14cb44fafb (patch)
tree7ac06b4426bedb0fd5c1e344825699d9d7a84e4a /Lib
parentbfc88d3418af6f4ef16aa306f12dd2d36ef957ae (diff)
downloadcpython-65d2dfd5c29c25a4f620e928c5ac9b14cb44fafb.zip
cpython-65d2dfd5c29c25a4f620e928c5ac9b14cb44fafb.tar.gz
cpython-65d2dfd5c29c25a4f620e928c5ac9b14cb44fafb.tar.bz2
bpo-42627: Fix incorrect parsing of Windows registry proxy settings (GH-26307)
(cherry picked from commit b69297ea23c0ab9866ae8bd26a347a9b5df567a6) Co-authored-by: 狂男风 <CrazyBoyFeng@Live.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/urllib/request.py36
1 files changed, 20 insertions, 16 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 4e289fc..2e7d01f 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -2672,22 +2672,26 @@ elif os.name == 'nt':
# Returned as Unicode but problems if not converted to ASCII
proxyServer = str(winreg.QueryValueEx(internetSettings,
'ProxyServer')[0])
- if '=' in proxyServer:
- # Per-protocol settings
- for p in proxyServer.split(';'):
- protocol, address = p.split('=', 1)
- # See if address has a type:// prefix
- if not re.match('(?:[^/:]+)://', address):
- address = '%s://%s' % (protocol, address)
- proxies[protocol] = address
- else:
- # Use one setting for all protocols
- if proxyServer[:5] == 'http:':
- proxies['http'] = proxyServer
- else:
- proxies['http'] = 'http://%s' % proxyServer
- proxies['https'] = 'https://%s' % proxyServer
- proxies['ftp'] = 'ftp://%s' % proxyServer
+ if '=' not in proxyServer and ';' not in proxyServer:
+ # Use one setting for all protocols.
+ proxyServer = 'http={0};https={0};ftp={0}'.format(proxyServer)
+ for p in proxyServer.split(';'):
+ protocol, address = p.split('=', 1)
+ # See if address has a type:// prefix
+ if not re.match('(?:[^/:]+)://', address):
+ # Add type:// prefix to address without specifying type
+ if protocol in ('http', 'https', 'ftp'):
+ # The default proxy type of Windows is HTTP
+ address = 'http://' + address
+ elif protocol == 'socks':
+ address = 'socks://' + address
+ proxies[protocol] = address
+ # Use SOCKS proxy for HTTP(S) protocols
+ 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()
except (OSError, ValueError, TypeError):
# Either registry key not found etc, or the value in an