The PEAK Developers' Center   Diff for "AsyncWSGISketch" UserPreferences
 
HelpContents Search Diffs Info Edit Subscribe XML Print View
Ignore changes in the amount of whitespace

Differences between version dated 2011-01-08 16:38:56 and 2011-01-10 09:58:13 (spanning 2 versions)

Deletions are marked like this.
Additions are marked like this.

#!python
"""Some sketches of implementing a WSGI 2 async API, in both sync and async servers"""
 
def example_app(environ):
    yield '200 OK', [('Content-type','text/plain')], [b'hello world!']
 
 
def example_middleware(app):
 
    def wrapped(environ):
        # middleware can modify environ here
        status, headers, body = yield app(environ)
 
        # and modify or replace s, h, body here
        body = process(body) # ...only if you need to alter it
 
        yield status, headers, body
 
    def process(body_iter):
        # This function is only needed if the middleware wants to read
        # or modify the body in some way...
        while True:
            chunk = yield body_iter # fetch the next chunk from the body
            if chunk is None:
                break
            # process/modify chunk here, then yield it to the server
            yield chunk
 
    return wrapped
 
 
def WSGI2(app):
    """Decorator that synchronously emulates WSGI2 futures under WSGI 1"""
    def wsgi1_app(environ, start_response):

                    return rv
 
        # Coroutine is entirely finished when the stack is empty
        if exc_info:
            try:
                raise exc_info[1]
            finally:
                exc_info = ()
        return self.callback(value)
}}}

PythonPowered
ShowText of this page
EditText of this page
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, DeletePage, LikePages, LocalSiteMap, SpellCheck