[Python-checkins] distutils2: Fix some try/except clauses in index.simple (now catchs socket timeouts too)
tarek.ziade
python-checkins at python.org
Sun Aug 8 11:50:46 CEST 2010
tarek.ziade pushed b7300dd2930a to distutils2:
http://hg.python.org/distutils2/rev/b7300dd2930a
changeset: 450:b7300dd2930a
user: Alexis Metaireau <ametaireau at gmail.com>
date: Wed Jul 21 09:58:08 2010 +0200
summary: Fix some try/except clauses in index.simple (now catchs socket timeouts too)
files: src/distutils2/index/simple.py
diff --git a/src/distutils2/index/simple.py b/src/distutils2/index/simple.py
--- a/src/distutils2/index/simple.py
+++ b/src/distutils2/index/simple.py
@@ -292,41 +292,32 @@
files support.
"""
+ scheme, netloc, path, params, query, frag = urlparse.urlparse(url)
+
+ # authentication stuff
+ if scheme in ('http', 'https'):
+ auth, host = urllib2.splituser(netloc)
+ else:
+ auth = None
+
+ # add index.html automatically for filesystem paths
+ if scheme == 'file':
+ if url.endswith('/'):
+ url += "index.html"
+
+ # add authorization headers if auth is provided
+ if auth:
+ auth = "Basic " + \
+ urllib2.unquote(auth).encode('base64').strip()
+ new_url = urlparse.urlunparse((
+ scheme, host, path, params, query, frag))
+ request = urllib2.Request(new_url)
+ request.add_header("Authorization", auth)
+ else:
+ request = urllib2.Request(url)
+ request.add_header('User-Agent', USER_AGENT)
try:
- scheme, netloc, path, params, query, frag = urlparse.urlparse(url)
-
- if scheme in ('http', 'https'):
- auth, host = urllib2.splituser(netloc)
- else:
- auth = None
-
- # add index.html automatically for filesystem paths
- if scheme == 'file':
- if url.endswith('/'):
- url += "index.html"
-
- if auth:
- auth = "Basic " + \
- urllib2.unquote(auth).encode('base64').strip()
- new_url = urlparse.urlunparse((
- scheme, host, path, params, query, frag))
- request = urllib2.Request(new_url)
- request.add_header("Authorization", auth)
- else:
- request = urllib2.Request(url)
- request.add_header('User-Agent', USER_AGENT)
fp = urllib2.urlopen(request)
-
- if auth:
- # Put authentication info back into request URL if same host,
- # so that links found on the page will work
- s2, h2, path2, param2, query2, frag2 = \
- urlparse.urlparse(fp.url)
- if s2 == scheme and h2 == host:
- fp.url = urlparse.urlunparse(
- (s2, netloc, path2, param2, query2, frag2))
-
- return fp
except (ValueError, httplib.InvalidURL), v:
msg = ' '.join([str(arg) for arg in v.args])
raise IndexError('%s %s' % (url, msg))
@@ -339,6 +330,19 @@
'The server might be down, %s' % (url, v.line))
except httplib.HTTPException, v:
raise DownloadError("Download error for %s: %s" % (url, v))
+ except socket.timeout:
+ raise DownloadError("The server timeouted")
+
+ if auth:
+ # Put authentication info back into request URL if same host,
+ # so that links found on the page will work
+ s2, h2, path2, param2, query2, frag2 = \
+ urlparse.urlparse(fp.url)
+ if s2 == scheme and h2 == host:
+ fp.url = urlparse.urlunparse(
+ (s2, netloc, path2, param2, query2, frag2))
+
+ return fp
def _decode_entity(self, match):
what = match.group(1)
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list