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.
This commit is contained in:
Fred Drake 2002-04-04 20:41:34 +00:00
parent 5ca3a08cc0
commit df6eca7eb7
1 changed files with 11 additions and 6 deletions

View File

@ -63,15 +63,20 @@ else:
# Shortcut for basic usage
_urlopener = None
def urlopen(url, data=None):
def urlopen(url, data=None, proxies=None):
"""urlopen(url [, data]) -> open file-like object"""
global _urlopener
if not _urlopener:
_urlopener = FancyURLopener()
if data is None:
return _urlopener.open(url)
if proxies is not None:
opener = FancyURLopener(proxies=proxies)
elif not _urlopener:
opener = FancyURLopener()
_urlopener = opener
else:
return _urlopener.open(url, data)
opener = _urlopener
if data is None:
return opener.open(url)
else:
return opener.open(url, data)
def urlretrieve(url, filename=None, reporthook=None, data=None):
global _urlopener
if not _urlopener: