diff options
author | Just van Rossum <just@letterror.com> | 2002-12-30 22:08:05 (GMT) |
---|---|---|
committer | Just van Rossum <just@letterror.com> | 2002-12-30 22:08:05 (GMT) |
commit | 52e14d640be3a7fa2c17f5a2a6bc9626d622aa40 (patch) | |
tree | 417c361ba0bae8b22b262570769933ccdd5ad5e0 /PC | |
parent | 60087fb45092d9c199cea162e58d9193c7c1558c (diff) | |
download | cpython-52e14d640be3a7fa2c17f5a2a6bc9626d622aa40.zip cpython-52e14d640be3a7fa2c17f5a2a6bc9626d622aa40.tar.gz cpython-52e14d640be3a7fa2c17f5a2a6bc9626d622aa40.tar.bz2 |
PEP 302 + zipimport:
- new import hooks in import.c, exposed in the sys module
- new module called 'zipimport'
- various changes to allow bootstrapping from zip files
I hope I didn't break the Windows build (or anything else for that
matter), but then again, it's been sitting on sf long enough...
Regarding the latest discussions on python-dev: zipimport sets
pkg.__path__ as specified in PEP 273, and likewise, sys.path item such as
/path/to/Archive.zip/subdir/ are supported again.
Diffstat (limited to 'PC')
-rw-r--r-- | PC/config.c | 2 | ||||
-rw-r--r-- | PC/getpathp.c | 49 |
2 files changed, 45 insertions, 6 deletions
diff --git a/PC/config.c b/PC/config.c index af023bf..b20831d 100644 --- a/PC/config.c +++ b/PC/config.c @@ -43,6 +43,7 @@ extern void initxreadlines(void); extern void init_weakref(void); extern void init_hotshot(void); extern void initxxsubtype(void); +extern void initzipimport(void); extern void init_random(void); /* XXX tim: what's the purpose of ADDMODULE MARKER? */ @@ -98,6 +99,7 @@ struct _inittab _PyImport_Inittab[] = { {"_random", init_random}, {"xxsubtype", initxxsubtype}, + {"zipimport", initzipimport}, /* XXX tim: what's the purpose of ADDMODULE MARKER? */ /* -- ADDMODULE MARKER 2 -- */ diff --git a/PC/getpathp.c b/PC/getpathp.c index a38224a..4930ad8 100644 --- a/PC/getpathp.c +++ b/PC/getpathp.c @@ -81,6 +81,7 @@ static char prefix[MAXPATHLEN+1]; static char progpath[MAXPATHLEN+1]; +static char dllpath[MAXPATHLEN+1]; static char *module_search_path = NULL; @@ -350,6 +351,7 @@ get_progpath(void) char *prog = Py_GetProgramName(); #ifdef MS_WINDOWS + extern HANDLE PyWin_DLLhModule; #ifdef UNICODE WCHAR wprogpath[MAXPATHLEN+1]; /* Windows documents that GetModuleFileName() will "truncate", @@ -357,6 +359,14 @@ get_progpath(void) PLUS Windows itself defines MAX_PATH as the same, but anyway... */ wprogpath[MAXPATHLEN]=_T('\0'); + if (PyWin_DLLhModule && + GetModuleFileName(PyWin_DLLhModule, wprogpath, MAXPATHLEN)) { + WideCharToMultiByte(CP_ACP, 0, + wprogpath, -1, + dllpath, MAXPATHLEN+1, + NULL, NULL); + } + wprogpath[MAXPATHLEN]=_T('\0')'; if (GetModuleFileName(NULL, wprogpath, MAXPATHLEN)) { WideCharToMultiByte(CP_ACP, 0, wprogpath, -1, @@ -366,6 +376,9 @@ get_progpath(void) } #else /* static init of progpath ensures final char remains \0 */ + if (PyWin_DLLhModule) + if (!GetModuleFileName(PyWin_DLLhModule, dllpath, MAXPATHLEN)) + dllpath[0] = 0; if (GetModuleFileName(NULL, progpath, MAXPATHLEN)) return; #endif @@ -427,6 +440,8 @@ calculate_path(void) int skiphome, skipdefault; char *machinepath = NULL; char *userpath = NULL; + char zip_path[MAXPATHLEN+1]; + size_t len; #endif get_progpath(); @@ -447,6 +462,21 @@ calculate_path(void) #ifdef MS_WINDOWS + /* Calculate zip archive path */ + if (dllpath[0]) /* use name of python DLL */ + strncpy(zip_path, dllpath, MAXPATHLEN); + else /* use name of executable program */ + strncpy(zip_path, progpath, MAXPATHLEN); + len = strlen(zip_path); + if (len > 4) { + zip_path[len-3] = 'z'; /* change ending to "zip" */ + zip_path[len-2] = 'i'; + zip_path[len-1] = 'p'; + } + else { + zip_path[0] = 0; + } + skiphome = pythonhome==NULL ? 0 : 1; machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, skiphome); userpath = getpythonregpath(HKEY_CURRENT_USER, skiphome); @@ -458,14 +488,15 @@ calculate_path(void) /* We need to construct a path from the following parts. (1) the PYTHONPATH environment variable, if set; - (2) for Win32, the machinepath and userpath, if set; - (3) the PYTHONPATH config macro, with the leading "." + (2) for Win32, the zip archive file path; + (3) for Win32, the machinepath and userpath, if set; + (4) the PYTHONPATH config macro, with the leading "." of each component replaced with pythonhome, if set; - (4) the directory containing the executable (argv0_path). - The length calculation calculates #3 first. + (5) the directory containing the executable (argv0_path). + The length calculation calculates #4 first. Extra rules: - - If PYTHONHOME is set (in any way) item (2) is ignored. - - If registry values are used, (3) and (4) are ignored. + - If PYTHONHOME is set (in any way) item (3) is ignored. + - If registry values are used, (4) and (5) are ignored. */ /* Calculate size of return buffer */ @@ -487,6 +518,7 @@ calculate_path(void) bufsz += strlen(userpath) + 1; if (machinepath) bufsz += strlen(machinepath) + 1; + bufsz += strlen(zip_path) + 1; #endif if (envpath != NULL) bufsz += strlen(envpath) + 1; @@ -518,6 +550,11 @@ calculate_path(void) *buf++ = DELIM; } #ifdef MS_WINDOWS + if (zip_path[0]) { + strcpy(buf, zip_path); + buf = strchr(buf, '\0'); + *buf++ = DELIM; + } if (userpath) { strcpy(buf, userpath); buf = strchr(buf, '\0'); |