[Python-checkins] cpython: Issue #10836: Fix exception raised when file not found in urlretrieve
senthil.kumaran
python-checkins at python.org
Sun Oct 21 22:30:11 CEST 2012
http://hg.python.org/cpython/rev/daef5526d2ac
changeset: 79883:daef5526d2ac
user: Senthil Kumaran <senthil at uthcode.com>
date: Sun Oct 21 13:30:02 2012 -0700
summary:
Issue #10836: Fix exception raised when file not found in urlretrieve
files:
Lib/test/test_urllib.py | 5 +++++
Lib/urllib/request.py | 4 ++--
Misc/NEWS | 3 +++
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -268,6 +268,11 @@
finally:
self.unfakehttp()
+ def test_missing_localfile(self):
+ # Test for #10836
+ with self.assertRaises(urllib.error.URLError):
+ urlopen('file://localhost/a/file/which/doesnot/exists.py')
+
def test_userpass_inurl(self):
self.fakehttp(b"HTTP/1.0 200 OK\r\n\r\nHello!")
try:
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1664,7 +1664,7 @@
return getattr(self, name)(url)
else:
return getattr(self, name)(url, data)
- except HTTPError:
+ except (HTTPError, URLError):
raise
except socket.error as msg:
raise IOError('socket error', msg).with_traceback(sys.exc_info()[2])
@@ -1891,7 +1891,7 @@
try:
stats = os.stat(localname)
except OSError as e:
- raise URLError(e.errno, e.strerror, e.filename)
+ raise URLError(e.strerror, e.filename)
size = stats.st_size
modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
mtype = mimetypes.guess_type(url)[0]
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -59,6 +59,9 @@
Library
-------
+- Issue #10836: Fix exception raised when file not found in urlretrieve
+ Initial patch by Ezio Melotti.
+
- Issue #14398: Fix size truncation and overflow bugs in the bz2 module.
- Issue #12692: Fix resource leak in urllib.request when talking to an HTTP
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list