]> granicus.if.org Git - python/commitdiff
Issue #10836: Fix exception raised when file not found in urlretrieve
authorSenthil Kumaran <senthil@uthcode.com>
Sun, 21 Oct 2012 20:30:02 +0000 (13:30 -0700)
committerSenthil Kumaran <senthil@uthcode.com>
Sun, 21 Oct 2012 20:30:02 +0000 (13:30 -0700)
Lib/test/test_urllib.py
Lib/urllib/request.py
Misc/NEWS

index 22ada56d0c8d15087535c78900c634f40e68eb31..5721296ffbd97738d319d716aa6b0fe81caf5e93 100644 (file)
@@ -268,6 +268,11 @@ Content-Type: text/html; charset=iso-8859-1
         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:
index 250d89efe05b07cd20b057bc9f494b6a3f5c6205..79a7b408d4f3f30af75dbe1684fe0ff2433abffb 100644 (file)
@@ -1664,7 +1664,7 @@ class URLopener:
                 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 @@ class URLopener:
         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]
index cffead00854e36239a974a1c0678bf7bfd298603..2f304c928743b1401b7dcc3cd7483216d2b69630 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -59,6 +59,9 @@ Core and Builtins
 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