summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/library/exceptions.rst3
-rw-r--r--Doc/library/socket.rst3
-rw-r--r--Doc/whatsnew/2.6.rst3
-rw-r--r--Lib/test/test_urllib2net.py16
-rw-r--r--Lib/urllib2.py4
-rw-r--r--Modules/socketmodule.c3
6 files changed, 19 insertions, 13 deletions
diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst
index 9bc597e..c35d7d4 100644
--- a/Doc/library/exceptions.rst
+++ b/Doc/library/exceptions.rst
@@ -147,6 +147,9 @@ The following exceptions are the exceptions that are actually raised.
This class is derived from :exc:`EnvironmentError`. See the discussion above
for more information on exception instance attributes.
+ .. versionchanged:: 2.6
+ Changed :exc:`socket.error` to use this as a base class.
+
.. exception:: ImportError
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
index 758cfb1..7512e56 100644
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -85,6 +85,9 @@ The module :mod:`socket` exports the following constants and functions:
accompanying :exc:`os.error`. See the module :mod:`errno`, which contains names
for the error codes defined by the underlying operating system.
+ .. versionchanged:: 2.6
+ :exc:`socket.error` is now a child class of :exc:`IOError`.
+
.. exception:: herror
diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst
index dd537d3..154b103 100644
--- a/Doc/whatsnew/2.6.rst
+++ b/Doc/whatsnew/2.6.rst
@@ -282,7 +282,8 @@ Porting to Python 2.6
This section lists previously described changes that may require changes to your
code:
-* Everything is all in the details!
+* The :mod:`socket` module exception :exc:`socket.error` now inherits from
+ :exc:`IOError`.
.. % ======================================================================
diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py
index 02d69cf..fae7e4d 100644
--- a/Lib/test/test_urllib2net.py
+++ b/Lib/test/test_urllib2net.py
@@ -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():
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 58e0153..2aa90d7 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -1240,7 +1240,7 @@ class FTPHandler(BaseHandler):
import mimetypes
host = req.get_host()
if not host:
- raise IOError('ftp error', 'no host given')
+ raise URLError('ftp error', 'no host given')
host, port = splitport(host)
if port is None:
port = ftplib.FTP_PORT
@@ -1286,7 +1286,7 @@ class FTPHandler(BaseHandler):
headers = mimetools.Message(sf)
return addinfourl(fp, headers, req.get_full_url())
except ftplib.all_errors as msg:
- raise IOError('ftp error', msg).with_traceback(sys.exc_info()[2])
+ raise URLError('ftp error', msg).with_traceback(sys.exc_info()[2])
def connect_ftp(self, user, passwd, host, port, dirs, timeout):
fw = ftpwrapper(user, passwd, host, port, dirs, timeout)
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index b33798d..90a2f96 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -4035,7 +4035,8 @@ init_socket(void)
if (m == NULL)
return;
- socket_error = PyErr_NewException("socket.error", NULL, NULL);
+ socket_error = PyErr_NewException("socket.error",
+ PyExc_IOError, NULL);
if (socket_error == NULL)
return;
PySocketModuleAPI.error = socket_error;