ASPN ActiveState Programmer Network
  ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups | Web Services
SEARCH

Reference
ActivePython 2.5
Python Documentation
Library Reference
18. Internet Protocols and Support
18.1 webbrowser -- Convenient Web-browser controller
18.2 cgi -- Common Gateway Interface support.
18.3 cgitb -- Traceback manager for CGI scripts
18.4 wsgiref -- WSGI Utilities and Reference Implementation
18.5 urllib -- Open arbitrary resources by URL
18.6 urllib2 -- extensible library for opening URLs
18.7 httplib -- HTTP protocol client
18.8 ftplib -- FTP protocol client
18.9 gopherlib -- Gopher protocol client
18.10 poplib -- POP3 protocol client
18.11 imaplib -- IMAP4 protocol client
18.12 nntplib -- NNTP protocol client
18.13 smtplib -- SMTP protocol client
18.14 smtpd -- SMTP Server
18.15 telnetlib -- Telnet client
18.16 uuid -- UUID objects according to RFC 4122
18.17 urlparse -- Parse URLs into components
18.18 SocketServer -- A framework for network servers
18.19 BaseHTTPServer -- Basic HTTP server
18.20 SimpleHTTPServer -- Simple HTTP request handler
18.21 CGIHTTPServer -- CGI-capable HTTP request handler
18.22 cookielib -- Cookie handling for HTTP clients
18.23 Cookie -- HTTP state management
18.24 xmlrpclib -- XML-RPC client access
18.25 SimpleXMLRPCServer -- Basic XML-RPC server
18.26 DocXMLRPCServer -- Self-documenting XML-RPC server

MyASPN >> Reference >> ActivePython 2.5 >> Python Documentation >> Library Reference >> 18. Internet Protocols and Support
ActivePython 2.5 documentation

18.21 CGIHTTPServer -- CGI-capable HTTP request handler

The CGIHTTPServer module defines a request-handler class, interface compatible with BaseHTTPServer.BaseHTTPRequestHandler and inherits behavior from SimpleHTTPServer.SimpleHTTPRequestHandler but can also run CGI scripts.

Note: This module can run CGI scripts on Unix and Windows systems; on Mac OS it will only be able to run Python scripts within the same process as itself.

Note: CGI scripts run by the CGIHTTPRequestHandler class cannot execute redirects (HTTP code 302), because code 200 (script output follows) is sent prior to execution of the CGI script. This pre-empts the status code.

The CGIHTTPServer module defines the following class:

class CGIHTTPRequestHandler( request, client_address, server)
This class is used to serve either files or output of CGI scripts from the current directory and below. Note that mapping HTTP hierarchic structure to local directory structure is exactly as in SimpleHTTPServer.SimpleHTTPRequestHandler.

The class will however, run the CGI script, instead of serving it as a file, if it guesses it to be a CGI script. Only directory-based CGI are used -- the other common server configuration is to treat special extensions as denoting CGI scripts.

The do_GET() and do_HEAD() functions are modified to run CGI scripts and serve the output, instead of serving files, if the request leads to somewhere below the cgi_directories path.

The CGIHTTPRequestHandler defines the following data member:

cgi_directories
This defaults to ['/cgi-bin', '/htbin'] and describes directories to treat as containing CGI scripts.

The CGIHTTPRequestHandler defines the following methods:

do_POST( )
This method serves the 'POST' request type, only allowed for CGI scripts. Error 501, "Can only POST to CGI scripts", is output when trying to POST to a non-CGI url.

Note that CGI scripts will be run with UID of user nobody, for security reasons. Problems with the CGI script will be translated to error 403.

For example usage, see the implementation of the test() function.

See Also:

Module BaseHTTPServer:
Base class implementation for Web server and request handler.
See About this document... for information on suggesting changes.

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState 2004 All rights reserved