diff options
author | Guido van Rossum <guido@python.org> | 1997-09-08 16:07:11 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-09-08 16:07:11 (GMT) |
commit | 9905ef966939ff15de6514a4fb994ad0f030d7cf (patch) | |
tree | 606af222adef621d08d2690a048143c90ab8c9c2 /Python | |
parent | c8bf884248e58f0d61ac020c60be01b048c60b2b (diff) | |
download | cpython-9905ef966939ff15de6514a4fb994ad0f030d7cf.zip cpython-9905ef966939ff15de6514a4fb994ad0f030d7cf.tar.gz cpython-9905ef966939ff15de6514a4fb994ad0f030d7cf.tar.bz2 |
Added support for __all__, which should be a list of modules to be
imported when the user says "from package import *".
Diffstat (limited to 'Python')
-rw-r--r-- | Python/import.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/Python/import.c b/Python/import.c index 95e5aa9..3bf205f 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1000,7 +1000,7 @@ static PyObject *load_next Py_PROTO((PyObject *mod, PyObject *altmod, char **p_name, char *buf, int *p_buflen)); static int mark_miss Py_PROTO((char *name)); static int ensure_fromlist Py_PROTO((PyObject *mod, PyObject *fromlist, - char *buf, int buflen)); + char *buf, int buflen, int recursive)); static PyObject * import_submodule Py_PROTO((PyObject *mod, char *name, char *fullname)); @@ -1054,7 +1054,7 @@ PyImport_ImportModuleEx(name, globals, locals, fromlist) } Py_DECREF(head); - if (!ensure_fromlist(tail, fromlist, buf, buflen)) { + if (!ensure_fromlist(tail, fromlist, buf, buflen, 0)) { Py_DECREF(tail); return NULL; } @@ -1203,11 +1203,12 @@ mark_miss(name) } static int -ensure_fromlist(mod, fromlist, buf, buflen) +ensure_fromlist(mod, fromlist, buf, buflen, recursive) PyObject *mod; PyObject *fromlist; char *buf; int buflen; + int recursive; { int i; @@ -1231,7 +1232,19 @@ ensure_fromlist(mod, fromlist, buf, buflen) return 0; } if (PyString_AS_STRING(item)[0] == '*') { + PyObject *all; Py_DECREF(item); + /* See if the package defines __all__ */ + if (recursive) + continue; /* Avoid endless recursion */ + all = PyObject_GetAttrString(mod, "__all__"); + if (all == NULL) + PyErr_Clear(); + else { + if (!ensure_fromlist(mod, all, buf, buflen, 1)) + return 0; + Py_DECREF(all); + } continue; } hasit = PyObject_HasAttr(mod, item); |