[Zope3-dev] PEP 333 and Zope

Eckart Hertzler eckart at hertzler.de
Thu Nov 11 05:23:41 EST 2004


On Wednesday 10 November 2004 16:23, Phillip J. Eby is believed to have said:
> At 12:14 PM 11/10/04 +0100, Eckart Hertzler wrote:
> 
> >Ok, just now I checked in the application side.
> >I tried to incorporate Philips suggestions (hopefully correctyl) and
> >tried to streamline it a bit.
> 
> There's a bug in 'getHeaders()', it should use "line.split(':',1)", or else 
> it will break when a header value includes a colon.
> 
I fixed it.

> However, the startup is still incorrect, because it relies on 
> 'zope.app.server.main.run()', which is not going to be appropriate for use 
> inside say, Apache or Twisted.
> 
> There needs to be a way to have an object that automatically handles any 
> zope-specific startup, either through its module initialization, or by 
> having it check when it's called.
> 
> It seems to me that basically, one needs a module or script like:
> 
>       from zope.app.wsgi import PublisherApp
> 
>       # ...code to get a database from somewhere
> 
>       my_app = PublisherApp(database)
> 
> Then, this module could be used with any server.  The global 
> 'publisherApp', 'bootStrapSubscriber' and 'configure.zcml' should really 
> all go away.

I think this is what zope.app.server.main does, except that you don't get a reference to
the database from the setup method.
So, if setup would return the open database you could say

    from zope.app.server.main import setup, load_options
    from zope.app.wsgi import PublisherApp

    args = ["-C/path/to/zope.conf"]
    db = setup(load_options(args))

    my_app = PublisherApp(db)

    # do whatever

And if you want to start the ftp server or any other configured server you could always call run()

That way I could indeed throw away the zcml, bootStrapSubscriber and the global publisherApp.

Would that be a correct startup ?

> 
> If it's inappropriate for the module to hardcode a database-finding 
> mechanism, then an alternative is to add code to PublisherApp to let it 
> find its own configuration and database using a WSGI configuration 
> parameter, the first time it needs to.
> 
> For example, suppose we say that ZOPE3_CONFIG is an environment variable or 
> server configuration variable, then it could use this to load the startup 
> .zcml and determine the database.
> 
> 


More information about the Zope3-dev mailing list