[Python-checkins] python/dist/src/Modules zipimport.c,NONE,1.1 Setup.dist,1.34,1.35 getpath.c,1.44,1.45

jvr@users.sourceforge.net jvr@users.sourceforge.net
2002年12月30日 14:08:06 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv32400/Modules
Modified Files:
	Setup.dist getpath.c 
Added Files:
	zipimport.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.
--- NEW FILE: zipimport.c ---
#include "Python.h"
#include "structmember.h"
#include "osdefs.h"
#include "marshal.h"
#include "compile.h"
#include <time.h>
#define IS_SOURCE 0x0
#define IS_BYTECODE 0x1
#define IS_PACKAGE 0x2
struct st_zip_searchorder {
	char suffix[14];
	int type;
};
/* zip_searchorder defines how we search for a module in the Zip
 archive: we first search for a package __init__, then for
[...1148 lines suppressed...]
		return;
	Py_INCREF(ZipImportError);
	if (PyModule_AddObject(mod, "ZipImportError",
			 ZipImportError) < 0)
		return;
	Py_INCREF(&ZipImporter_Type);
	if (PyModule_AddObject(mod, "zipimporter",
			 (PyObject *)&ZipImporter_Type) < 0)
		return;
	
	zip_directory_cache = PyDict_New();
	if (zip_directory_cache == NULL)
		return;
	Py_INCREF(zip_directory_cache);
	if (PyModule_AddObject(mod, "_zip_directory_cache",
			 zip_directory_cache) < 0)
		return;
}
Index: Setup.dist
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/Setup.dist,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** Setup.dist	12 Dec 2002 17:37:50 -0000	1.34
--- Setup.dist	30 Dec 2002 22:08:03 -0000	1.35
***************
*** 114,117 ****
--- 114,121 ----
 _codecs _codecsmodule.c		# access to the builtin codecs and codec registry
 
+ # The zipimport module is always imported at startup. Having it as a
+ # builtin module avoids some bootstrapping problems and reduces overhead.
+ zipimport zipimport.c
+ 
 # The rest of the modules listed in this file are all commented out by
 # default. Usually they can be detected and built as dynamically
Index: getpath.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/getpath.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** getpath.c	23 Dec 2002 21:03:36 -0000	1.44
--- getpath.c	30 Dec 2002 22:08:03 -0000	1.45
***************
*** 366,369 ****
--- 366,370 ----
 char *prog = Py_GetProgramName();
 char argv0_path[MAXPATHLEN+1];
+ char zip_path[MAXPATHLEN+1];
 int pfound, efound; /* 1 if found; -1 if found build directory */
 char *buf;
***************
*** 484,487 ****
--- 485,500 ----
 reduce(prefix);
 
+ strncpy(zip_path, prefix, MAXPATHLEN);
+ if (pfound > 0) { /* Use the reduced prefix returned by Py_GetPrefix() */
+ reduce(zip_path);
+ reduce(zip_path);
+ }
+ else
+ strncpy(zip_path, PREFIX, MAXPATHLEN);
+ joinpath(zip_path, "lib/python00.zip");
+ bufsz = strlen(zip_path);	/* Replace "00" with version */
+ zip_path[bufsz - 6] = VERSION[0];
+ zip_path[bufsz - 5] = VERSION[2];
+ 
 if (!(efound = search_for_exec_prefix(argv0_path, home))) {
 if (!Py_FrozenFlag)
***************
*** 522,525 ****
--- 535,539 ----
 }
 
+ bufsz += strlen(zip_path) + 1;
 bufsz += strlen(exec_prefix) + 1;
 
***************
*** 541,544 ****
--- 555,562 ----
 else
 buf[0] = '0円';
+ 
+ /* Next is the default zip path */
+ strcat(buf, zip_path);
+ strcat(buf, delimiter);
 
 /* Next goes merge of compile-time $PYTHONPATH with

AltStyle によって変換されたページ (->オリジナル) /