Chad W. L. Whitacre
Zeta Design & Development
http://www.zetadev.com/software/httpy/
Email: chad@zetaweb.com
httpy is a Python module that smooths out WSGI's most glaring warts.
The request side of WSGI--the "commons" of the environ mapping--is quite nice. It honors the tradition of CGI, and it's just a mapping. Simple.
The response-side API is a little stiffer, because WSGI has to support edge
cases like serving large files, complex exception handling, and HTTP/1.1
features. This results in warts like start_response, and the requirement
that apps return an iterable. The intention in PEP
333 is that these warts be smoothed
over at other layers; this is such a layer.
httpy provides the following classes:
| app) |
| [code] [, body] [, headers]) |
Instances of httpy.Responder are middleware that speak plain WSGI on the
server side, but they also accept strings and Response objects from the
application side. When a Responder receives a Response object,
that becomes the WSGI endpoint. When a Responder receives a string, it
creates a Response object with the string as the body, and the
Content-Type: set to text/html. This implicit
Response then becomes the endpoint.
Instances of httpy.Response are also plain WSGI applications, with the following data attributes. Note that values are only validated in the constructor, so it is currently possible to return/raise a malformed Response by setting instance attributes post-instantiation.
When called, Response instances call start_response with
adaptations of code and headers, and return a one-item list
containing body.
Here is an example:
Python 2.5 (r25:52005, Sep 25 2006, 21:37:36)
[GCC 3.4.4 [FreeBSD] 20050518] on freebsd6
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import httpy
>>> app = lambda env, start: "Greetings, program!"
>>> app = httpy.Responder(app)
>>>
>>> from wsgiref.simple_server import make_server
>>> server = make_server('', 8080, app)
>>> server.serve_forever() # now hit http://localhost:8080/
>>>
192.168.1.100 - - [09/Nov/2006 23:52:45] "GET / HTTP/1.1" 200 19
Copyright (c) 2006, Chad Whitacre <chad@zetaweb.com>. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This document was generated using the LaTeX2HTML translator.
LaTeX2HTML is Copyright © 1993, 1994, 1995, 1996, 1997, Nikos Drakos, Computer Based Learning Unit, University of Leeds, and Copyright © 1997, 1998, Ross Moore, Mathematics Department, Macquarie University, Sydney.
The application of LaTeX2HTML to the Python documentation has been heavily tailored by Fred L. Drake, Jr. Original navigation icons were contributed by Christopher Petrilli.
httpy is Zeta software. It is copyright © 2006 by Chad Whitacre, and is offered free of charge, warranty, and restrictions.