From: Victor Stinner Date: Fri, 20 Mar 2015 09:52:25 +0000 (+0100) Subject: Issue #23696: Chain ZipImportError to the OSError X-Git-Tag: v3.5.0a3~117 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fbd6f9ed124c89753f6e3fd2cd84e4d9c474cc1f;p=python Issue #23696: Chain ZipImportError to the OSError --- diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py index 1e351c8c8a..5b8d77cae7 100644 --- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -450,7 +450,10 @@ class BadFileZipImportTestCase(unittest.TestCase): fd = os.open(TESTMOD, os.O_CREAT, 000) try: os.close(fd) - self.assertZipFailure(TESTMOD) + + with self.assertRaises(zipimport.ZipImportError) as cm: + zipimport.zipimporter(TESTMOD) + self.assertIsInstance(cm.exception.__context__, PermissionError) finally: # If we leave "the read-only bit" set on Windows, nothing can # delete TESTMOD, and later tests suffer bogus failures. diff --git a/Modules/zipimport.c b/Modules/zipimport.c index e83214c16c..38dc0c4290 100644 --- a/Modules/zipimport.c +++ b/Modules/zipimport.c @@ -875,8 +875,12 @@ read_directory(PyObject *archive) fp = _Py_fopen_obj(archive, "rb"); if (fp == NULL) { - if (PyErr_ExceptionMatches(PyExc_OSError)) + if (PyErr_ExceptionMatches(PyExc_OSError)) { + PyObject *exc, *val, *tb; + PyErr_Fetch(&exc, &val, &tb); PyErr_Format(ZipImportError, "can't open Zip file: %R", archive); + _PyErr_ChainExceptions(exc, val, tb); + } return NULL; }