diff options
author | tarek <none@none> | 2009-08-26 08:42:44 +0200 |
---|---|---|
committer | tarek <none@none> | 2009-08-26 08:42:44 +0200 |
commit | 0ae5113b9bc5824a09b0e2c4e317084a4402cc0c (patch) | |
tree | ce06a09a47cb8327c9d9fe6ca0567ce079d9bc56 | |
parent | 6c31d16ce512c164e211aec0fa1d44437dfe5c61 (diff) | |
download | external_python_setuptools-0ae5113b9bc5824a09b0e2c4e317084a4402cc0c.tar.gz external_python_setuptools-0ae5113b9bc5824a09b0e2c4e317084a4402cc0c.tar.bz2 external_python_setuptools-0ae5113b9bc5824a09b0e2c4e317084a4402cc0c.zip |
fixed #16 and #18: BadStatusLine and ValueError in package_index.urlopen
--HG--
branch : distribute
extra : rebase_source : 6159cf23c0dc4effd40b525066266eefd292b96e
-rw-r--r-- | CHANGES.txt | 7 | ||||
-rwxr-xr-x | setuptools/package_index.py | 17 | ||||
-rw-r--r-- | setuptools/tests/test_packageindex.py | 33 |
3 files changed, 56 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 14920b3e..dd2bfe36 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -6,6 +6,13 @@ CHANGES 0.6.1 ----- +setuptools +========== + +* package_index.urlopen now catches BadStatusLine and malformed url errors. + This closes http://bitbucket.org/tarek/distribute/issue/16 and + http://bitbucket.org/tarek/distribute/issue/18. + bootstraping ============ diff --git a/setuptools/package_index.py b/setuptools/package_index.py index e601cc15..fef62942 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -1,5 +1,6 @@ """PyPI and direct package downloading""" import sys, os.path, re, urlparse, urllib2, shutil, random, socket, cStringIO +import httplib from pkg_resources import * from distutils import log from distutils.errors import DistutilsError @@ -577,13 +578,27 @@ class PackageIndex(Environment): return local_open(url) try: return open_with_auth(url) + except ValueError, v: + msg = ' '.join([str(arg) for arg in v.args]) + if warning: + self.warn(warning, msg) + else: + raise DistutilsError('%s %s' % (url, msg)) except urllib2.HTTPError, v: return v except urllib2.URLError, v: - if warning: self.warn(warning, v.reason) + if warning: + self.warn(warning, v.reason) else: raise DistutilsError("Download error for %s: %s" % (url, v.reason)) + except httplib.BadStatusLine, v: + if warning: + self.warn(warning, v.line) + else: + raise DistutilsError('%s returned a bad status line. ' + 'The server might be down, %s' % \ + (url, v.line)) def _download_url(self, scheme, url, tmpdir): # Determine download filename diff --git a/setuptools/tests/test_packageindex.py b/setuptools/tests/test_packageindex.py index 0231eda8..d7efe1bc 100644 --- a/setuptools/tests/test_packageindex.py +++ b/setuptools/tests/test_packageindex.py @@ -18,6 +18,39 @@ class TestPackageIndex(unittest.TestCase): else: self.assert_(isinstance(v,urllib2.HTTPError)) + # issue 16 + # easy_install inquant.contentmirror.plone breaks because of a typo + # in its home URL + index = setuptools.package_index.PackageIndex( + hosts=('www.example.com',) + ) + + url = 'url:%20https://svn.plone.org/svn/collective/inquant.contentmirror.plone/trunk' + try: + v = index.open_url(url) + except Exception, v: + self.assert_(url in str(v)) + else: + self.assert_(isinstance(v, urllib2.HTTPError)) + + def _urlopen(*args): + import httplib + raise httplib.BadStatusLine('line') + + old_urlopen = urllib2.urlopen + urllib2.urlopen = _urlopen + url = 'http://example.com' + try: + try: + v = index.open_url(url) + except Exception, v: + self.assert_('line' in str(v)) + else: + raise AssertionError('Should have raise here!') + finally: + urllib2.urlopen = old_urlopen + + def test_url_ok(self): index = setuptools.package_index.PackageIndex( hosts=('www.example.com',) |