[PATCH 0 of 4] Make hgweb more WSGI-compliant (hail the iterables!)

Dirkjan Ochtman dirkjan at ochtman.nl
Sun Jun 29 08:24:39 CDT 2008


These patches provide an attempt at making hgweb more WSGI-compatible.

According to the spec [1], the write() callable returned by start_response()
"should not be used by new applications or frameworks if it can be avoided".

In order to achieve this, I changed streamclone.stream_out() to yield chunks
instead of writing to a file-like object that's passed in (to make it possible
for hgweb.protocol.stream_out() to yield the chunks, as well) and I fixed the
templater to yield strings only (instead of yielding generators, Nones and
some integers). Both of these seem reasonable changes in their own right:
the streamclone API seems a bit simpler to me (although callers now have to
flush on their own, but that seems like a burden the caller should bear,
anyway). I think it's reasonable to expect a templater to yield only strings,
obviating the need for using stringify() all over the place.

There's at least one problem left with this: the WSGI spec section on
Buffering and Streaming mentions that small chunks should not be yielded
separately, because the server is required to flush each of these as they
come in. Therefore, at least the templater bits should probably be joined
back together before being passed up to the server. For the protocol bits,
it seems better to keep the larger chunks used in changegroup{,subset}() and
stream_out() separate as they come in. Any ideas on this?

I think this would be a good step towards making hgweb a better WSGI citizen.

Cheers,

Dirkjan

[1] http://www.python.org/dev/peps/pep-0333/



More information about the Mercurial-devel mailing list