Kaydet (Commit) aee0bad0 authored tarafından Guido van Rossum's avatar Guido van Rossum

First part of package support.

This doesn't yet support "import a.b.c" or "from a.b.c import x", but
it does recognize directories.  When importing a directory, it
initializes __path__ to a list containing the directory name, and
loads the __init__ module if found.

The (internal) find_module() and load_module() functions are
restructured so that they both also handle built-in and frozen modules
and Mac resources (and directories of course).  The imp module's
find_module() and (new) load_module() also have this functionality.
Moreover, imp unconditionally defines constants for all module types,
and has two more new functions: find_module_in_package() and
find_module_in_directory().

There's also a new API function, PyImport_ImportModuleEx(), which
takes all four __import__ arguments (name, globals, locals, fromlist).
The last three may be NULL.  This is currently the same as
PyImport_ImportModule() but in the future it will be able to do
relative dotted-path imports.

Other changes:

- bltinmodule.c: in __import__, call PyImport_ImportModuleEx().

- ceval.c: always pass the fromlist to __import__, even if it is a C
function, so PyImport_ImportModuleEx() is useful.

- getmtime.c: the function has a second argument, the FILE*, on which
it applies fstat().  According to Sjoerd this is much faster.  The
first (pathname) argument is ignored, but remains for backward
compatibility (so the Mac version still works without changes).

By cleverly combining the new imp functionality, the full support for
dotted names in Python (mini.py, not checked in) is now about 7K,
lavishly commented (vs. 14K for ni plus 11K for ihooks, also lavishly
commented).

Good night!
üst 026de199
......@@ -65,7 +65,7 @@ builtin___import__(self, args)
if (!PyArg_ParseTuple(args, "s|OOO:__import__",
&name, &globals, &locals, &fromlist))
return NULL;
return PyImport_ImportModule(name);
return PyImport_ImportModuleEx(name, globals, locals, fromlist);
}
......
......@@ -1408,16 +1408,10 @@ eval_code2(co, globals, locals,
"__import__ not found");
break;
}
if (PyCFunction_Check(x)) {
u = Py_None;
Py_INCREF(u);
}
else {
u = find_from_args(f, INSTR_OFFSET());
if (u == NULL) {
x = u;
break;
}
u = find_from_args(f, INSTR_OFFSET());
if (u == NULL) {
x = u;
break;
}
w = Py_BuildValue("(OOOO)",
w,
......
......@@ -35,15 +35,17 @@ PERFORMANCE OF THIS SOFTWARE.
#include "config.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
long
PyOS_GetLastModificationTime(path)
PyOS_GetLastModificationTime(path, fp)
char *path;
FILE *fp;
{
struct stat st;
if (stat(path, &st) != 0)
if (fstat(fileno(fp), &st) != 0)
return -1;
else
return st.st_mtime;
......
This diff is collapsed.
......@@ -30,11 +30,16 @@ PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/* Definitions for dynamic loading of extension modules */
#ifdef macintosh
enum filetype {SEARCH_ERROR, PY_SOURCE, PY_COMPILED, C_EXTENSION, PY_RESOURCE};
#else
enum filetype {SEARCH_ERROR, PY_SOURCE, PY_COMPILED, C_EXTENSION};
#endif
enum filetype {
SEARCH_ERROR,
PY_SOURCE,
PY_COMPILED,
C_EXTENSION,
PY_RESOURCE, /* Mac only */
PKG_DIRECTORY,
C_BUILTIN,
PY_FROZEN
};
extern struct filedescr {
char *suffix;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment