diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/Python/import.c b/Python/import.c index b97b3eb..1ea9297 100644 --- a/Python/import.c +++ b/Python/import.c @@ -109,7 +109,6 @@ static const struct filedescr _PyImport_StandardFiletab[] = { {0, 0} }; -static PyTypeObject NullImporterType; /* Forward reference */ /* Initialize things */ @@ -167,7 +166,7 @@ _PyImportHooks_Init(void) /* adding sys.path_hooks and sys.path_importer_cache, setting up zipimport */ - if (PyType_Ready(&NullImporterType) < 0) + if (PyType_Ready(&PyNullImporter_Type) < 0) goto error; if (Py_VerboseFlag) @@ -1088,7 +1087,7 @@ get_path_importer(PyObject *path_importer_cache, PyObject *path_hooks, } if (importer == NULL) { importer = PyObject_CallFunctionObjArgs( - (PyObject *)&NullImporterType, p, NULL + (PyObject *)&PyNullImporter_Type, p, NULL ); if (importer == NULL) { if (PyErr_ExceptionMatches(PyExc_ImportError)) { @@ -1106,6 +1105,20 @@ get_path_importer(PyObject *path_importer_cache, PyObject *path_hooks, return importer; } +PyAPI_FUNC(PyObject *) +PyImport_GetImporter(PyObject *path) { + PyObject *importer=NULL, *path_importer_cache=NULL, *path_hooks=NULL; + + if ((path_importer_cache = PySys_GetObject("path_importer_cache"))) { + if ((path_hooks = PySys_GetObject("path_hooks"))) { + importer = get_path_importer(path_importer_cache, + path_hooks, path); + } + } + Py_XINCREF(importer); /* get_path_importer returns a borrowed reference */ + return importer; +} + /* Search the path (default sys.path) for a module. Return the corresponding filedescr struct, and (via return arguments) the pathname and an open file. Return NULL if the module is not found. */ @@ -2981,7 +2994,7 @@ static PyMethodDef NullImporter_methods[] = { }; -static PyTypeObject NullImporterType = { +PyTypeObject PyNullImporter_Type = { PyVarObject_HEAD_INIT(NULL, 0) "imp.NullImporter", /*tp_name*/ sizeof(NullImporter), /*tp_basicsize*/ @@ -3028,7 +3041,7 @@ initimp(void) { PyObject *m, *d; - if (PyType_Ready(&NullImporterType) < 0) + if (PyType_Ready(&PyNullImporter_Type) < 0) goto failure; m = Py_InitModule4("imp", imp_methods, doc_imp, @@ -3050,8 +3063,8 @@ initimp(void) if (setint(d, "PY_CODERESOURCE", PY_CODERESOURCE) < 0) goto failure; if (setint(d, "IMP_HOOK", IMP_HOOK) < 0) goto failure; - Py_INCREF(&NullImporterType); - PyModule_AddObject(m, "NullImporter", (PyObject *)&NullImporterType); + Py_INCREF(&PyNullImporter_Type); + PyModule_AddObject(m, "NullImporter", (PyObject *)&PyNullImporter_Type); failure: ; } |