[Web-SIG] Sketching a WSGI 2-to-1 adapter with greenlets
Ian Bicking
ianb at colorstudy.com
Sat Sep 19 01:58:22 CEST 2009
On Fri, Sep 18, 2009 at 5:07 PM, P.J. Eby <pje at telecommunity.com> wrote:
> On his blog, Graham mentioned some skepticism about skipping WSGI 1.1 and
> going straight to 2.0, due to concern that people using write() would need
> to make major code changes to go to WSGI 2.0.
I'm not entirely clear why this is such a big deal. Here's how I'd
implement a WSGI 2 wrapper around a WSGI 1 app:
def wsgi1to2(app):
def new_app(environ):
written = []
status_headers = []
def start_response(status, headers, exc_info=None):
if exc_info is not None:
raise exc_info[0], exc_info[1], exc_info[2]
status_headers[:] = [status, headers]
return written.append
app_iter = app(environ, start_response)
if not status_headers:
app_iter = iter(app_iter)
written.append(app_iter.next())
assert status_headers
if written:
app_iter = itertools.chain(written, app_iter)
return status_headers[0], status_headers[1], app_iter
What's wrong with this simpler approach to the conversion?
--
Ian Bicking | http://blog.ianbicking.org | http://topplabs.org/civichacker
More information about the Web-SIG
mailing list