[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>&gt;The problem is that Zope3 needs *some* =
way of=20
storing data and config<BR>&gt;files related to specific packages, and =
there=20
isn't really any other<BR>&gt;convenient and conventional way except =
storing it=20
in a package<BR>&gt;directory and using the package's __file__ to find =
it.</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>__importer__ , the zip specific alternative to __file__ could=20
be&nbsp;provided to solve the problem.</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>in an __init__.py:</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>if __file__:<BR>&nbsp;&nbsp;&nbsp; =
............................<BR>elif=20
__importer__:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
f=3D___importer__.open()#to=20
speedup&nbsp;and to get direct access to the binary</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#without&nbsp;&nbsp;___importer_=
_.open()&nbsp;=20
should work as=20
well&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
data1=3D___importer__.get_data("ModuleName\\index.html")<BR>&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;=20
data2=3D___importer__.get_data("ModuleName\\help.html")<BR>&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;=20
if data1:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
..........<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f.close()</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>It would require some minor changes to Just's zipimport.c<BR>+ =
new&nbsp;=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>&nbsp;</DIV>
<DIV>As for zipimport.c:<BR>new methods:<BR>open() for speedup=20
:<BR>........<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char*=20
fname=3DPyString_AsString(self-&gt;archive);<BR>&nbsp;self-&gt;arcfile=3D=
PyFile_FromString(fname,"rb");<BR>&nbsp;.......<BR>&nbsp;return=20
self-&gt;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>&nbsp;</DIV>
<DIV>Tested;)</DIV>
<DIV>&nbsp;</DIV>
<DIV>Regards<BR>Wiktor<BR><A=20
href=3D"http://www.wiktorsadowski.com">http://www.wiktorsadowski.com</A><=
/DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0052_01C2A532.3C12AD40--