I packaged QWIP into a WSGI server for Quixote.  Proposed for inclusion as
quixote.servers.wsgi_server.py .  Use the QWIP object directly with any
WSGI server, or run the script standalone for the usual *_server.py
behavior using WSGI Utils' HTTP server.

#!/usr/bin/env python
"""
A WSGI wrapper for Quixote applications, and a standalone interface to WSGI
Utils' multi-threaded HTTP server.

To run the Quixote demos or your own application using wsgiutils' HTTP server:

    wsgi_server.py
    wsgi_server.py --factory=quixote.demo.altdemo.create_publisher
    wsgi_server.py --factory=quixote.demo.mini_demo.create_publisher
    wsgi_server.py --help              # Shows all options and defaults.

and point your browser to http://localhost:8080/ .  --factory names a function
that returns a Publisher object configured for the desired application.  You'll
get an ImportError if WSGI Utils is not installed; obtain it from
http://www.owlfish.com/software/wsgiutils/

To use your Quixote application with any WSGI server or middleware:

    from quixote.server.wsgi_server import QWIP
    wsgi_application = QWIP(create_publisher_function)

Authors: Mike Orr <[EMAIL PROTECTED]> and Titus Brown <[EMAIL PROTECTED]>.
Last updated 2005-04-29.
"""

from quixote.http_request import HTTPRequest

class QWIP:
    """I make a Quixote Publisher object look like a WSGI application."""
    request_class = HTTPRequest

    def __init__(self, create_publisher_fn):
        self.publisher = create_publisher_fn()
    
    def __call__(self, env, start_response):
        """I am called for each request."""
        if not env.has_key('REQUEST_URI'):
            env['REQUEST_URI'] = env['SCRIPT_NAME'] + env['PATH_INFO']
        input = env['wsgi.input']
        request = self.request_class(input, env)
        response = self.publisher.process_request(request)
        status = "%03d %s" % (response.status_code, response.reason_phrase)
        headers = response.generate_headers()
        start_response(status, headers)
        return response.generate_body_chunks()  # Iterable object.

def run(create_publisher, host='', port=80):
    """Runs a multi-threaded HTTP server publishing a Quixote application
       via WSGI/QWIP.  Depends on WSGI Utils from 
       http://www.owlfish.com/software/wsgiutils/
    """
    from wsgiutils.wsgiServer import WSGIServer
    app_map = {'': QWIP(create_publisher)}
    httpd = WSGIServer((host, port), app_map, serveFiles=False)
    httpd.serve_forever()

if __name__ == '__main__':
    from quixote.server.util import main
    main(run)
_______________________________________________
Quixote-users mailing list
[email protected]
http://mail.mems-exchange.org/mailman/listinfo/quixote-users

Reply via email to