Commit df6eca7e authored by Fred Drake's avatar Fred Drake

Support manual proxy configuration for simple urlopen() operations.

This change is similar to the supplied patch, but does not save the opener
when a proxy configuration is specified.
This closes SF patch #523415.
parent 5ca3a08c
...@@ -63,15 +63,20 @@ else: ...@@ -63,15 +63,20 @@ else:
# Shortcut for basic usage # Shortcut for basic usage
_urlopener = None _urlopener = None
def urlopen(url, data=None): def urlopen(url, data=None, proxies=None):
"""urlopen(url [, data]) -> open file-like object""" """urlopen(url [, data]) -> open file-like object"""
global _urlopener global _urlopener
if not _urlopener: if proxies is not None:
_urlopener = FancyURLopener() opener = FancyURLopener(proxies=proxies)
elif not _urlopener:
opener = FancyURLopener()
_urlopener = opener
else:
opener = _urlopener
if data is None: if data is None:
return _urlopener.open(url) return opener.open(url)
else: else:
return _urlopener.open(url, data) return opener.open(url, data)
def urlretrieve(url, filename=None, reporthook=None, data=None): def urlretrieve(url, filename=None, reporthook=None, data=None):
global _urlopener global _urlopener
if not _urlopener: if not _urlopener:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment