diff options
author | Brett Cannon <bcannon@gmail.com> | 2009-03-15 02:20:16 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2009-03-15 02:20:16 (GMT) |
commit | 8d11013169efe085213842307859103f713beec5 (patch) | |
tree | e7b4cace8433ab483d8128524052fba93f442445 /Python/import.c | |
parent | 2b9fd47da776f75ddf5b488fcc73b8631ece8e2b (diff) | |
download | cpython-8d11013169efe085213842307859103f713beec5.zip cpython-8d11013169efe085213842307859103f713beec5.tar.gz cpython-8d11013169efe085213842307859103f713beec5.tar.bz2 |
Implement InspectLoader for FrozenImporter.
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Python/import.c b/Python/import.c index 6f2f4c7..9c70ed8 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1951,6 +1951,28 @@ get_frozen_object(char *name) return PyMarshal_ReadObjectFromString((char *)p->code, size); } +static PyObject * +is_frozen_package(char *name) +{ + struct _frozen *p = find_frozen(name); + int size; + + if (p == NULL) { + PyErr_Format(PyExc_ImportError, + "No such frozen object named %.200s", + name); + return NULL; + } + + size = p->size; + + if (size < 0) + Py_RETURN_TRUE; + else + Py_RETURN_FALSE; +} + + /* Initialize a frozen module. Return 1 for success, 0 if the module is not found, and -1 with an exception set if the initialization failed. @@ -2959,6 +2981,16 @@ imp_get_frozen_object(PyObject *self, PyObject *args) } static PyObject * +imp_is_frozen_package(PyObject *self, PyObject *args) +{ + char *name; + + if (!PyArg_ParseTuple(args, "s:is_frozen_package", &name)) + return NULL; + return is_frozen_package(name); +} + +static PyObject * imp_is_builtin(PyObject *self, PyObject *args) { char *name; @@ -3191,6 +3223,7 @@ static PyMethodDef imp_methods[] = { {"reload", imp_reload, METH_O, doc_reload}, /* The rest are obsolete */ {"get_frozen_object", imp_get_frozen_object, METH_VARARGS}, + {"is_frozen_package", imp_is_frozen_package, METH_VARARGS}, {"init_builtin", imp_init_builtin, METH_VARARGS}, {"init_frozen", imp_init_frozen, METH_VARARGS}, {"is_builtin", imp_is_builtin, METH_VARARGS}, |