Commit 0ae5113b authored by tarek's avatar tarek

fixed #16 and #18: BadStatusLine and ValueError in package_index.urlopen

--HG--
branch : distribute
extra : rebase_source : 6159cf23c0dc4effd40b525066266eefd292b96e
parent 6c31d16c
......@@ -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
============
......
"""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
......
......@@ -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',)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment