On Wed, Feb 28, 2007 at 11:47:15AM -0500, Giovannetti, Mark wrote:
> Hello,
> One of the problems that I've had learning zope 3 (and python
> at the same time) is that I did not understand how code 'got
> executed'.  This was a big stumbling block for someone coming
> from a non-object oriented background who was used to creating
> 'normal' websites--i.e. the html/cfm/whatever file is the 
> 'callable'.  This concept, to me, doesn't exist in zope3 as
> far as I can tell.
> Some questions, then, regarding how parts of code get executed 
> in zope3.  If anyone has the time to answer them, or confirm
> my understanding, it would be appreciated.  My descriptions 
> are likely oversimplified/incorrect.
> 1. At zope startup, each *-configure.zcml in etc/package-includes
> is read.  
> Q. The __init__.py file for each package is then executed, correct?
> A. Yes, since my testing indicates this is the case.  I had problems
> understanding this since the idiom is to just place a comment in 
> the __init__ file and it seemed rather useless to a new user.

The __init__.py file is executed when you import a package.  That
happens as a side effect when ZCML directives refer to classes and
functions in packages.  The purpose of a __init__.py is to define names
that could be imported, and not to run some initialization code.

In fact, this is how Python imports modules: it executes the .py file of
the module.  (It does this at most once during the program's execution,
unless you explicitly ask it to reload modules.  Zope 3 never asks.)

> 2. Each configure.zcml file in the package's root directory (the
> one pointed to by the *-configure.zcml in package-includes) is
> parsed.
> Q. Does each class referred to in a <class..> directive have
> the class' entire module loaded/executed or is the class just
> registered somewhere for future use?  
> A. ?

Yes, the module is imported.

> 3. Utilities and such in zcml.
> Q. Does each utility have its module executed to create the
> instance (utilities are instances, right?)
> A. I think so, but I'm not sure, see #2.

Yes, the module is imported.

> I hope someone can clear this up for me.  I never managed to
> find a good explanation of the flow of control for zope3 
> startup and initialization.  I have read both books already.

In brief, Zope 3 reads the configuration file (zope.conf), finds out the
name of the root zcml file (site.zcml, usually), then loads the ZCML
configuration (which involves parsing all the zcml files that include
each other, importing Python modules and accessing names defined in
those), executes the configuration (which involves modifying global
registries of adapters, utilities, security declarations etc), opens or
creates the ZODB database, and then starts listening on network ports.

Marius Gedminas
Any sufficiently advanced magic is indistinguishable from technology.

Attachment: signature.asc
Description: Digital signature

Zope3-users mailing list

Reply via email to