[Web-SIG] Entry points and import maps (was Re: Scarecrow deployment config
Phillip J. Eby
pje at telecommunity.com
Mon Jul 25 16:39:48 CEST 2005
At 03:02 AM 7/25/2005 -0400, Chris McDonough wrote:
>Actually, let me give this a shot.
>
>We package up an egg called helloworld.egg. It happens to contain
>something that can be used as a WSGI component. Let's say it's a WSGI
>application that always returns 'Hello World'. And let's say it also
>contains middleware that lowercases anything that passes through before
>it's returned.
>
>The implementations of these components could be as follows:
>
>class HelloWorld:
> def __init__(self, app, **kw):
> pass # nothing to configure
>
> def __call__(self, environ, start_response):
> start_response('200 OK', [])
> return ['Hello World']
I'm thinking that an application like this wouldn't take an 'app'
constuctor parameter, and if it takes no configuration parameters it
doesn't need **kw, but good so far.
>class Lowercaser:
> def __init__(self, app, **kw):
> self.app = app
> # nothing else to configure
>
> def __call__(self, environ, start_response):
> for chunk in self.app(environ, start_response):
> yield chunk.lower()
Again, no need for **kw if it doesn't take any configuration, but okay.
>An import map would ship inside of the egg-info dir:
>
>[wsgi.app_factories]
>helloworld = helloworld:HelloWorld
>lowercaser = helloworld:Lowercaser
I'm thinking it would be more like:
[wsgi.middleware]
lowercaser = helloworld:Lowercaser
[wsgi.apps]
helloworld = helloworld:HelloWorld
and you'd specify it in the setup script as something like this:
setup(
#...
entry_points = {
'wsgi.apps': ['helloworld = helloworld:HelloWorld']
'wsgi.middleware': ['lowercaser = helloworld:Lowercaser']
}
)
(And the CVS version of setuptools already supports this.)
>So we install the egg and this does nothing except allow it to be used
>from within Python.
>
>But when we create a "deployment descriptor" like so in a text editor:
>
>[helloworld from helloworld]
>
>[lowercaser from helloworld]
Opposite order, though; the lowercaser comes first because it's the
middleware; the application would always come last, because they're listed
in the order in which they receive data, just like a pipes-and-filters
command line.
>... and run some "starter" script that parses that as a pipeline,
... possibly using a #! line if you're using CGI or FastCGI with Apache or
some other non-Python webserver.
>creates the two instances, wires them together, and we get a running
>pipeline?
>
>Am I on track?
Definitely.
More information about the Web-SIG
mailing list