with self.assertWarns(DeprecationWarning):
zipimport.zipimporter(memoryview(os.fsencode(filename)))
+ @support.cpython_only
+ def testUninitializedZipimporter(self):
+ # The interpreter shouldn't crash in case of calling methods of an
+ # uninitialized zipimport.zipimporter object.
+ zi = zipimport.zipimporter.__new__(zipimport.zipimporter)
+ self.assertRaises(ValueError, zi.find_module, 'foo')
+ self.assertRaises(ValueError, zi.find_loader, 'foo')
+ self.assertRaises(ValueError, zi.load_module, 'foo')
+ self.assertRaises(ValueError, zi.get_filename, 'foo')
+ self.assertRaises(ValueError, zi.is_package, 'foo')
+ self.assertRaises(ValueError, zi.get_data, 'foo')
+ self.assertRaises(ValueError, zi.get_code, 'foo')
+ self.assertRaises(ValueError, zi.get_source, 'foo')
+
@support.requires_zlib
class CompressedZipImportTestCase(UncompressedZipImportTestCase):
PyObject *path, *fullpath, *item;
struct st_zip_searchorder *zso;
+ if (self->prefix == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "zipimporter.__init__() wasn't called");
+ return MI_ERROR;
+ }
+
subname = get_subname(fullname);
if (subname == NULL)
return MI_ERROR;
PyObject *toc_entry;
Py_ssize_t path_start, path_len, len;
+ if (self->archive == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "zipimporter.__init__() wasn't called");
+ return NULL;
+ }
+
#ifdef ALTSEP
path = _PyObject_CallMethodId((PyObject *)&PyUnicode_Type, &PyId_replace,
"OCC", path, ALTSEP, SEP);
PyObject *path, *fullpath = NULL;
struct st_zip_searchorder *zso;
+ if (self->prefix == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "zipimporter.__init__() wasn't called");
+ return NULL;
+ }
+
subname = get_subname(fullname);
if (subname == NULL)
return NULL;