
Phew, it works. The attached tgz file contains: zipper.patch: patches setup.py, Python/import.c, Python/importdl.h zipimport.c: zipimport module, move to Modules/ Do I need to mention it's a rough patch <wink>? import.c changes: - Allow arbitrary objects on sys.path. - If a path entry ends in ".zip", replace that entry with a zipimporter instance. (obviously, the zipimport module must be available for this to work.) - The search algo is: [handle builtin modules and frozen] for p on sys.path: if hasattr(p, "find_module"): handler = p.find_module(name) if handler is None: continue if isinstance(p, str): [do builtin import] zipimport.c implements: - The zipimporter object; explicit use example: sys.path.append(zipimport.zipimporter("myarchive.zip")) this is effectively equivalent to sys.path.append("myarchive.zip") - the zipimporter has two methods: find_module(subname) -> None or self load_module(fullname) -> module import.c todo/notes: - clean up, refactor, debug, document The patch adds two new static functions, find_module2() and load_module2(). Ideally these should _replace_ find_module and load_module, but since the signature of the new ones is different I decided to keep the originals (which are reimplemented to call the new ones) to keep the patch small for easier review. zipimport.c todo: - rework the zipimporter class as a subclass of str - doco - add a get_source(fullname) method (linecache.py could use that!) Have fun! Just

Just van Rossum wrote:
have you tested the following code with uncompressed PY files? buf[data_size] = 'Z'; /* saw this in zipfile.py */ data_size++; raw_data = PyString_FromStringAndSize(buf, data_size); PyMem_Free(buf); if (raw_data == NULL) return NULL; if (compress == 0) /* data is not compressed */ return raw_data; </F>

Just van Rossum wrote:
have you tested the following code with uncompressed PY files? buf[data_size] = 'Z'; /* saw this in zipfile.py */ data_size++; raw_data = PyString_FromStringAndSize(buf, data_size); PyMem_Free(buf); if (raw_data == NULL) return NULL; if (compress == 0) /* data is not compressed */ return raw_data; </F>
participants (2)
-
Fredrik Lundh
-
Just van Rossum