Created
March 11, 2010 16:03
-
-
Save judell/329274 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File "E:\Lib\urllib.py", line 1577, in getproxies_registry | |
# proxyEnable = _winreg.QueryValueEx(internetSettings, | |
# IOError: System.IO.IOException: The specified registry key does not exist. | |
elif os.name == 'nt': | |
def getproxies_registry(): | |
"""Return a dictionary of scheme -> proxy server URL mappings. | |
Win32 uses the registry to store proxies. | |
""" | |
proxies = {} | |
### begin azure patch | |
return proxies | |
### end azure patch | |
try: | |
import _winreg | |
except ImportError: | |
# Std module, so should be around - but you never know! | |
return proxies | |
try: | |
internetSettings = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, | |
r'Software\Microsoft\Windows\CurrentVersion\Internet Settings') | |
proxyEnable = _winreg.QueryValueEx(internetSettings, | |
'ProxyEnable')[0] | |
if proxyEnable: | |
# 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 | |
import re | |
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['ftp'] = 'ftp://%s' % proxyServer | |
internetSettings.Close() | |
except (WindowsError, ValueError, TypeError): | |
# Either registry key not found etc, or the value in an | |
# unexpected format. | |
# proxies already set up to be empty so nothing to do | |
pass | |
return proxies | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment