[Python-Dev] Zipping Zope3
Wiktor Sadowski
Wiktor Sadowski" <art@wiktorsadowski.com
Mon, 16 Dec 2002 18:37:49 +0100
This is a multi-part message in MIME format.
------=_NextPart_000_0052_01C2A532.3C12AD40
Content-Type: text/plain;
charset="windows-1250"
Content-Transfer-Encoding: quoted-printable
[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.
in an __init__.py:
if __file__:
............................
elif __importer__:
f=3D___importer__.open()#to speedup and to get direct access to =
the binary
#without ___importer__.open() should work as well =
=20
data1=3D___importer__.get_data("ModuleName\\index.html")
data2=3D___importer__.get_data("ModuleName\\help.html")
if data1:
..........
f.close()
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) !=3D 0)
........................................................
As for zipimport.c:
new methods:
open() for speedup :
........
char* fname=3DPyString_AsString(self->archive);
self->arcfile=3DPyFile_FromString(fname,"rb");
.......
return self->arcfile; #PyObject*arcfile new field(zipimporter struct)
..................................................................
get_data(data_path)#modified load_module=20
..................................................................
in load_module:
mod =3D PyImport_ExecCodeModuleEx2(fullname, code, modpath,self);
instead of=20
mod =3D PyImport_ExecCodeModuleEx(fullname, code, modpath);
Tested;)
Regards
Wiktor
http://www.wiktorsadowski.com
------=_NextPart_000_0052_01C2A532.3C12AD40
Content-Type: text/html;
charset="windows-1250"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1250">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>[Guido van Rossum]<BR>>The problem is that Zope3 needs *some* =
way of=20
storing data and config<BR>>files related to specific packages, and =
there=20
isn't really any other<BR>>convenient and conventional way except =
storing it=20
in a package<BR>>directory and using the package's __file__ to find =
it.</DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV>__importer__ , the zip specific alternative to __file__ could=20
be provided to solve the problem.</DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV>in an __init__.py:</DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV>if __file__:<BR> =
............................<BR>elif=20
__importer__:<BR> =
f=3D___importer__.open()#to=20
speedup and to get direct access to the binary</DIV>
<DIV> #without ___importer_=
_.open() =20
should work as=20
well &nb=
sp; &nbs=
p; <BR>&=
nbsp; =20
data1=3D___importer__.get_data("ModuleName\\index.html")<BR> &=
nbsp; =20
data2=3D___importer__.get_data("ModuleName\\help.html")<BR> &n=
bsp; =20
if data1:<BR> =20
..........<BR> f.close()</DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV>It would require some minor changes to Just's zipimport.c<BR>+ =
new =20
function in import.c<BR>PyImport_ExecCodeModuleEx2(char *name, PyObject =
*co,=20
char *pathname,PyObject *importer)<BR>where instead of setting =
__file__:<BR>if=20
(PyDict_SetItemString(d, "__importer__", importer) !=3D=20
0)<BR>........................................................</DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV>As for zipimport.c:<BR>new methods:<BR>open() for speedup=20
:<BR>........<BR> char*=20
fname=3DPyString_AsString(self->archive);<BR> self->arcfile=3D=
PyFile_FromString(fname,"rb");<BR> .......<BR> return=20
self->arcfile; #PyObject*arcfile new field(zipimporter=20
struct)<BR>..............................................................=
....<BR>get_data(data_path)#modified=20
load_module=20
<BR>..................................................................<BR=
>in=20
load_module:<BR>mod =3D PyImport_ExecCodeModuleEx2(fullname, code,=20
modpath,self);<BR>instead of <BR>mod =3D =
PyImport_ExecCodeModuleEx(fullname, code,=20
modpath);</DIV>
<DIV> </DIV>
<DIV>Tested;)</DIV>
<DIV> </DIV>
<DIV>Regards<BR>Wiktor<BR><A=20
href=3D"http://www.wiktorsadowski.com">http://www.wiktorsadowski.com</A><=
/DIV>
<DIV> </DIV>
<DIV><BR> </DIV></BODY></HTML>
------=_NextPart_000_0052_01C2A532.3C12AD40--