3.4 Couplers

The action in httpy is in the responders, but the couplers are the workhorses that put responders on the network. httpy includes three couplers out of the box. There are multiple Python webservers available, and a couple Python FastCGI libraries too. I've tried to pick the single most mature option in each category, and build the couplers on top of those. These decisions are purely pragmatic.

class CGI( responder)
Constructs a new CGI coupler object. This class is defined in the httpy.couplers.cgi module.

class FastCGI( responder)
Constructs a new FastCGI coupler object. This class is defined in the httpy.couplers.fastcgi module.

class StandAlone( responder[, argv])
Constructs a new StandAlone coupler object. argv is a sequence of arguments. If omitted or None, sys.argv is used. See the chapter on the httpy executable for the available options. This class is defined in the httpy.couplers.standalone module.

Each coupler takes a (possibly implicit) provider of the IResponder interface as its first argument, and each provides the following method:

go( )
For CGI instances, this responds to a single request. For FastCGI and StandAlone, this enters a blocking loop.

As an example, here is what a CGI script looks like with httpy:

#!/usr/local/bin/python
"""This is a CGI script.
"""
from httpy.couplers.cgi import CGI
import myresponder

coupled = CGI(myresponder)
coupled.go()

Those wishing to implement new couplers are invited to consult the source code, and to contact the author.

httpy is Zeta software. It is copyright © 2006 by Chad Whitacre, and is offered free of charge, warranty, and restrictions.