Snakelets and WSGI

Robert Brewer fumanchu at
Wed Oct 13 06:58:10 CEST 2004

> Pardon my ignorance, but would it be feasible for a server such
> as Snakelets to implement both the WSGI API, *and* the existing
> 'native' API?


> If I want this, and I understand WSGI correctly, this would
> require something that the WSGI spec calls "WSGI-Middleware".
> Right?

Probably not. Let's define terms a bit. Alan thought you might want to
split your framework into two parts, a "server" and an "application";
those are the terms WSGI uses. The server (your standalone CGI server)
would have to provide a WSGI interface. I'm thinking it would include
most of what's in your snakeserver.server module. By contrast, most of
the webapp module would go into the "application" half. The server would
request an iterable, and your PageProcessor(s) would supply them. You
could then queue YPages as normal and return the output to the
webapp.do_GET call, which would then return iter([output]), something

    def do_GET(self, handler, passtroughRequest, passtroughResponse):
        pageprocessor =
self.getPageProcessor(self._getPath(handler.path), handler)
        if pageprocessor:
            output = pageprocessor.do_GET(passtroughRequest,
            return iter([output])
        elif self.checkAuthorizationPatterns(passtroughRequest,
passtroughResponse, None, handler):
            # we received a GET request for a URL that is allowed, but
that we don't handle.
            raise NotHandled()

Snakelets are more problematic, because WSGI heavily prefers a "server
pull" model over write() calls. You'd probably have to deprecate
Snakelets as written (or wrap write() so it queues their output as
well), replacing them eventually with a model that yields values rather
than calling write().

Middleware would be for things like statistics, content rewriting, and
such, which existing servers (and apps) provide, but which are not
server-specific. Most commonly, that's going to be services which apply
directly to the HTTP stream, not to either your server or your app
framework. Looking quickly over Snakelets I don't see many candidates
for middleware.

Robert Brewer
Amor Ministries
fumanchu at

More information about the Python-list mailing list