merge this from trunk:

r58067 | gregory.p.smith | 2007-09-09 16:36:46 -0700 (Sun, 09 Sep 2007) | 22 lin
es

Change socket.error to inherit from IOError rather than being a stand
alone class.  This addresses the primary concern in

 http://bugs.python.org/issue1706815

python-dev discussion here:

 http://mail.python.org/pipermail/python-dev/2007-July/073749.html

I chose IOError rather than EnvironmentError as the base class since
socket objects are often used as transparent duck typed file objects
in code already prepared to deal with IOError exceptions.

also a minor fix:

 urllib2 - fix a couple places where IOError was raised rather than URLError.
           for better or worse, URLError already inherits from IOError so
           this won't break any existing code.

 test_urllib2net - replace bad ftp urls.
This commit is contained in:
Gregory P. Smith 2007-09-09 23:55:55 +00:00
parent c4119183a2
commit c111d9fbbd
6 changed files with 19 additions and 13 deletions

View file

@ -164,8 +164,9 @@ class OtherNetworkTests(unittest.TestCase):
def test_ftp(self):
urls = [
'ftp://www.python.org/pub/python/misc/sousa.au',
'ftp://www.python.org/pub/tmp/blat',
'ftp://ftp.kernel.org/pub/linux/kernel/README',
'ftp://ftp.kernel.org/pub/linux/kernel/non-existant-file',
#'ftp://ftp.kernel.org/pub/leenox/kernel/test',
'ftp://gatekeeper.research.compaq.com/pub/DEC/SRC'
'/research-reports/00README-Legal-Rules-Regs',
]
@ -179,10 +180,7 @@ class OtherNetworkTests(unittest.TestCase):
f.close()
urls = [
'file:'+sanepathname2url(os.path.abspath(TESTFN)),
# XXX bug, should raise URLError
#('file://nonsensename/etc/passwd', None, urllib2.URLError)
('file://nonsensename/etc/passwd', None, (EnvironmentError, socket.error))
('file:///nonsensename/etc/passwd', None, urllib2.URLError),
]
self._test_urls(urls, self._extra_handlers())
finally:
@ -242,11 +240,11 @@ class OtherNetworkTests(unittest.TestCase):
debug(url)
try:
f = urllib2.urlopen(url, req)
except (IOError, socket.error, OSError) as err:
except EnvironmentError as err:
debug(err)
if expected_err:
msg = ("Didn't get expected error(s) %s for %s %s, got %s" %
(expected_err, url, req, err))
msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" %
(expected_err, url, req, type(err), err))
self.assert_(isinstance(err, expected_err), msg)
else:
with test_support.transient_internet():