[Web-SIG] Defining a standard interface for common web tasks

Bill Janssen janssen at parc.com
Thu Oct 23 19:45:53 EDT 2003


I usually use a simple "response" object with a few standard methods:

class response:

    def open (self, content_type = "text/html"):
	"""Returns a file object open for write"""

    def redirect (self, url):
	"""Sends a redirect message to the specified URL"""

    def error (self, code, message):
        """Sends back error CODE (a valid HTTP code) with MESSAGE"""

    def reply (self, message):
        """Sends back reply string MESSAGE"""
	return self.error(200, message)

    def return_file (self, typ, path):
        """returns the file of MIME type TYP from PATH"""

    def add_cookie (self, name, value):
        """Add the cookie to the reply"""

But that's probably too simple.

Bill



More information about the Web-SIG mailing list