Wiktor Sadowski wrote: > [Guido van Rossum] > >The problem is that Zope3 needs *some* way of storing data and config > >files related to specific packages, and there isn't really any other > >convenient and conventional way except storing it in a package > >directory and using the package's __file__ to find it. > > __importer__ , the zip specific alternative to __file__ could be > provided to solve the problem. Hm, I like this! > in an __init__.py: > > if __file__: > ............................ > elif __importer__: > f=___importer__.open()#to speedup and to get direct access to the binary > #without ___importer__.open() should work as well > data1=___importer__.get_data("ModuleName\\index.html") > data2=___importer__.get_data("ModuleName\\help.html") > if data1: > .......... > f.close() Or: try: __importer__ except NameError: <deal with __file__> else: x = __importer__.get_data(...) > It would require some minor changes to Just's zipimport.c > + new function in import.c > PyImport_ExecCodeModuleEx2(char *name, PyObject *co, char *pathname,PyObject *importer) > where instead of setting __file__: > if (PyDict_SetItemString(d, "__importer__", importer) != 0) > ......................................................... I'd say it should set __importer__ in *addition* to __file__. > As for zipimport.c: > new methods: > open() for speedup : > ......... > char* fname=PyString_AsString(self->archive); > self->arcfile=PyFile_FromString(fname,"rb"); > ....... > return self->arcfile; #PyObject*arcfile new field(zipimporter struct) > ................................................................... > get_data(data_path)#modified load_module > ................................................................... > in load_module: > mod = PyImport_ExecCodeModuleEx2(fullname, code, modpath,self); > instead of > mod = PyImport_ExecCodeModuleEx(fullname, code, modpath); > > Tested;) Ugh, you should really consider getting a decent diff tool :-/ How can *I* test if if I have no clue what exactly you've done? I can see that keeping the file object open could speed things up, but is it a polite & decent thing to do? Just
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4