MCPcopy Index your code
hub / github.com/RustPython/RustPython / getproxies_registry

Function getproxies_registry

Lib/urllib/request.py:2069–2116  ·  view source on GitHub ↗

Return a dictionary of scheme -> proxy server URL mappings. Win32 uses the registry to store proxies.

()

Source from the content-addressed store, hash-verified

2067
2068elif os.name == 'nt':
2069 def getproxies_registry():
2070 """Return a dictionary of scheme -> proxy server URL mappings.
2071
2072 Win32 uses the registry to store proxies.
2073
2074 """
2075 proxies = {}
2076 try:
2077 import winreg
2078 except ImportError:
2079 # Std module, so should be around - but you never know!
2080 return proxies
2081 try:
2082 internetSettings = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
2083 r'Software\Microsoft\Windows\CurrentVersion\Internet Settings')
2084 proxyEnable = winreg.QueryValueEx(internetSettings,
2085 'ProxyEnable')[0]
2086 if proxyEnable:
2087 # Returned as Unicode but problems if not converted to ASCII
2088 proxyServer = str(winreg.QueryValueEx(internetSettings,
2089 'ProxyServer')[0])
2090 if '=' not in proxyServer and ';' not in proxyServer:
2091 # Use one setting for all protocols.
2092 proxyServer = 'http={0};https={0};ftp={0}'.format(proxyServer)
2093 for p in proxyServer.split(';'):
2094 protocol, address = p.split('=', 1)
2095 # See if address has a type:// prefix
2096 if not re.match('(?:[^/:]+)://', address):
2097 # Add type:// prefix to address without specifying type
2098 if protocol in ('http', 'https', 'ftp'):
2099 # The default proxy type of Windows is HTTP
2100 address = 'http://' + address
2101 elif protocol == 'socks':
2102 address = 'socks://' + address
2103 proxies[protocol] = address
2104 # Use SOCKS proxy for HTTP(S) protocols
2105 if proxies.get('socks'):
2106 # The default SOCKS proxy type of Windows is SOCKS4
2107 address = re.sub(r'^socks://', 'socks4://', proxies['socks'])
2108 proxies['http'] = proxies.get('http') or address
2109 proxies['https'] = proxies.get('https') or address
2110 internetSettings.Close()
2111 except (OSError, ValueError, TypeError):
2112 # Either registry key not found etc, or the value in an
2113 # unexpected format.
2114 # proxies already set up to be empty so nothing to do
2115 pass
2116 return proxies
2117
2118 def getproxies():
2119 """Return a dictionary of scheme -> proxy server URL mappings.

Callers 1

getproxiesFunction · 0.85

Calls 7

strFunction · 0.85
formatMethod · 0.45
splitMethod · 0.45
matchMethod · 0.45
getMethod · 0.45
subMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected