[Python-checkins] python/dist/src/PC config.c,1.36,1.37 getpathp.c,1.28,1.29
jvr@users.sourceforge.net
jvr@users.sourceforge.net
2002年12月30日 14:08:06 -0800
Update of /cvsroot/python/python/dist/src/PC
In directory sc8-pr-cvs1:/tmp/cvs-serv32400/PC
Modified Files:
config.c getpathp.c
Log Message:
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.
Index: config.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/PC/config.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** config.c 29 Dec 2002 23:46:40 -0000 1.36
--- config.c 30 Dec 2002 22:08:04 -0000 1.37
***************
*** 44,47 ****
--- 44,48 ----
extern void init_hotshot(void);
extern void initxxsubtype(void);
+ extern void initzipimport(void);
extern void init_random(void);
***************
*** 99,102 ****
--- 100,104 ----
{"xxsubtype", initxxsubtype},
+ {"zipimport", initzipimport},
/* XXX tim: what's the purpose of ADDMODULE MARKER? */
Index: getpathp.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/PC/getpathp.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** getpathp.c 22 Jul 2002 13:28:21 -0000 1.28
--- getpathp.c 30 Dec 2002 22:08:04 -0000 1.29
***************
*** 82,85 ****
--- 82,86 ----
static char prefix[MAXPATHLEN+1];
static char progpath[MAXPATHLEN+1];
+ static char dllpath[MAXPATHLEN+1];
static char *module_search_path = NULL;
***************
*** 351,354 ****
--- 352,356 ----
#ifdef MS_WINDOWS
+ extern HANDLE PyWin_DLLhModule;
#ifdef UNICODE
WCHAR wprogpath[MAXPATHLEN+1];
***************
*** 358,361 ****
--- 360,371 ----
*/
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,
***************
*** 367,370 ****
--- 377,383 ----
#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;
***************
*** 428,431 ****
--- 441,446 ----
char *machinepath = NULL;
char *userpath = NULL;
+ char zip_path[MAXPATHLEN+1];
+ size_t len;
#endif
***************
*** 448,451 ****
--- 463,481 ----
#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);
***************
*** 459,470 ****
/* 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 "."
of each component replaced with pythonhome, if set;
! (4) the directory containing the executable (argv0_path).
! The length calculation calculates #3 first.
Extra rules:
! - If PYTHONHOME is set (in any way) item (2) is ignored.
! - If registry values are used, (3) and (4) are ignored.
*/
--- 489,501 ----
/* We need to construct a path from the following parts.
(1) the PYTHONPATH environment variable, if set;
! (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;
! (5) the directory containing the executable (argv0_path).
! The length calculation calculates #4 first.
Extra rules:
! - If PYTHONHOME is set (in any way) item (3) is ignored.
! - If registry values are used, (4) and (5) are ignored.
*/
***************
*** 488,491 ****
--- 519,523 ----
if (machinepath)
bufsz += strlen(machinepath) + 1;
+ bufsz += strlen(zip_path) + 1;
#endif
if (envpath != NULL)
***************
*** 519,522 ****
--- 551,559 ----
}
#ifdef MS_WINDOWS
+ if (zip_path[0]) {
+ strcpy(buf, zip_path);
+ buf = strchr(buf, '0円');
+ *buf++ = DELIM;
+ }
if (userpath) {
strcpy(buf, userpath);