summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2002-04-04 20:41:34 (GMT)
committerFred Drake <fdrake@acm.org>2002-04-04 20:41:34 (GMT)
commitdf6eca7eb7b6ac1b00ba524f1d9565881a93b9ea (patch)
tree027d9f38e48bb904552997d3541866f41ab7b20a /Lib
parent5ca3a08cc0a110a50a6d66102d957c48fda6190c (diff)
downloadcpython-df6eca7eb7b6ac1b00ba524f1d9565881a93b9ea.zip
cpython-df6eca7eb7b6ac1b00ba524f1d9565881a93b9ea.tar.gz
cpython-df6eca7eb7b6ac1b00ba524f1d9565881a93b9ea.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/urllib.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py
index d028d7a..2d53c12 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -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 proxies is not None:
+ opener = FancyURLopener(proxies=proxies)
+ elif not _urlopener:
+ opener = FancyURLopener()
+ _urlopener = opener
+ else:
+ opener = _urlopener
if data is None:
- return _urlopener.open(url)
+ return opener.open(url)
else:
- return _urlopener.open(url, data)
+ return opener.open(url, data)
def urlretrieve(url, filename=None, reporthook=None, data=None):
global _urlopener
if not _urlopener: