mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
Issue #23696: Chain ZipImportError to the OSError
This commit is contained in:
parent
99953006df
commit
fbd6f9ed12
2 changed files with 9 additions and 2 deletions
|
|
@ -450,7 +450,10 @@ class BadFileZipImportTestCase(unittest.TestCase):
|
||||||
fd = os.open(TESTMOD, os.O_CREAT, 000)
|
fd = os.open(TESTMOD, os.O_CREAT, 000)
|
||||||
try:
|
try:
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
self.assertZipFailure(TESTMOD)
|
|
||||||
|
with self.assertRaises(zipimport.ZipImportError) as cm:
|
||||||
|
zipimport.zipimporter(TESTMOD)
|
||||||
|
self.assertIsInstance(cm.exception.__context__, PermissionError)
|
||||||
finally:
|
finally:
|
||||||
# If we leave "the read-only bit" set on Windows, nothing can
|
# If we leave "the read-only bit" set on Windows, nothing can
|
||||||
# delete TESTMOD, and later tests suffer bogus failures.
|
# delete TESTMOD, and later tests suffer bogus failures.
|
||||||
|
|
|
||||||
|
|
@ -875,8 +875,12 @@ read_directory(PyObject *archive)
|
||||||
|
|
||||||
fp = _Py_fopen_obj(archive, "rb");
|
fp = _Py_fopen_obj(archive, "rb");
|
||||||
if (fp == NULL) {
|
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_Format(ZipImportError, "can't open Zip file: %R", archive);
|
||||||
|
_PyErr_ChainExceptions(exc, val, tb);
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue