summaryrefslogtreecommitdiffstats
path: root/Lib/urllib.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-02-13 01:39:16 (GMT)
committerGuido van Rossum <guido@python.org>1998-02-13 01:39:16 (GMT)
commit8a666e7c56192f42288a30a53adf5299fda29557 (patch)
treebc9b249f38a4d0a90e725f9d4076e4fa94edff58 /Lib/urllib.py
parente5bc49785c5aa6de9ca65754c1236e98e7c3a10f (diff)
downloadcpython-8a666e7c56192f42288a30a53adf5299fda29557.zip
cpython-8a666e7c56192f42288a30a53adf5299fda29557.tar.gz
cpython-8a666e7c56192f42288a30a53adf5299fda29557.tar.bz2
Fix a horrible race condition -- various routines were storing the
most recently opened URL in self.openedurl of the URLopener instance. This doesn't really work if multiple threads share the same opener instance! Fix: openedurl was actually simply the type prefix (e.g. "http:") followed by the rest of the URL; since the rest of the URL is available and the type is effectively determined by where you are in the code, I can reconstruct the full URL easily, e.g. "http:" + url.
Diffstat (limited to 'Lib/urllib.py')
-rw-r--r--Lib/urllib.py16
1 files changed, 7 insertions, 9 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py
index 5363f3c..79ee82b 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -27,7 +27,7 @@ import os
import sys
-__version__ = '1.9'
+__version__ = '1.10'
MAXFTPCACHE = 10 # Trim the ftp cache beyond this size
@@ -140,7 +140,6 @@ class URLopener:
return addinfourl(fp, headers, fullurl)
type, url = splittype(fullurl)
if not type: type = 'file'
- self.openedurl = '%s:%s' % (type, url)
if self.proxies.has_key(type):
proxy = self.proxies[type]
type, proxy = splittype(proxy)
@@ -173,7 +172,6 @@ class URLopener:
# or (tempfilename, headers) for a remote object
def retrieve(self, url, filename=None):
url = unwrap(url)
- self.openedurl = url
if self.tempcache and self.tempcache.has_key(url):
return self.tempcache[url]
type, url1 = splittype(url)
@@ -250,7 +248,7 @@ class URLopener:
errcode, errmsg, headers = h.getreply()
fp = h.getfile()
if errcode == 200:
- return addinfourl(fp, headers, self.openedurl)
+ return addinfourl(fp, headers, "http:" + url)
else:
return self.http_error(url,
fp, errcode, errmsg, headers)
@@ -287,7 +285,7 @@ class URLopener:
fp = gopherlib.send_query(selector, query, host)
else:
fp = gopherlib.send_selector(selector, host)
- return addinfourl(fp, noheaders(), self.openedurl)
+ return addinfourl(fp, noheaders(), "gopher:" + url)
# Use local file or FTP depending on form of URL
def open_file(self, url):
@@ -341,8 +339,8 @@ class URLopener:
try:
if not self.ftpcache.has_key(key):
self.ftpcache[key] = \
- ftpwrapper(user, passwd,
- host, port, dirs)
+ ftpwrapper(user, passwd,
+ host, port, dirs)
if not file: type = 'D'
else: type = 'I'
for attr in attrs:
@@ -352,7 +350,7 @@ class URLopener:
type = string.upper(value)
return addinfourl(
self.ftpcache[key].retrfile(file, type),
- noheaders(), self.openedurl)
+ noheaders(), "ftp:" + url)
except ftperrors(), msg:
raise IOError, ('ftp error', msg), sys.exc_info()[2]
@@ -366,7 +364,7 @@ class FancyURLopener(URLopener):
# Default error handling -- don't raise an exception
def http_error_default(self, url, fp, errcode, errmsg, headers):
- return addinfourl(fp, headers, self.openedurl)
+ return addinfourl(fp, headers, "http:" + url)
# Error 302 -- relocated (temporarily)
def http_error_302(self, url, fp, errcode, errmsg, headers):