# HG changeset patch # User paulb # Date 1075677314 0 # Node ID e8d0e82964be1e044e189cc5beb85ab2a86eb6e7 # Parent 2c54be6c26ee71b37e08ab5f2db830cd6122a05e [project @ 2004-02-01 23:15:14 by paulb] Added a new example application. diff -r 2c54be6c26ee -r e8d0e82964be examples/Common/Calendar/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/Common/Calendar/__init__.py Sun Feb 01 23:15:14 2004 +0000 @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +"A calendar application." + +import WebStack.Generic + +class DirectoryResource: + + """ + A resource which handles incoming calendars and viewing requests. + An arbitrary set of rules can be applied to determine what is to be done + with a request, and in this case, the application appears as a directory of + calendars, yet also accepts incoming calendars. + """ + + def respond(self, trans): + + """ + Examine the incoming request, either saving a calendar or displaying + one. + """ + + # Get the last path component as the name of the calendar. + # NOTE: This could be improved to permit hierarchical naming. + + calendar_name = trans.get_path().split("/")[-1] + + # Determine the action to be taken. + + method = trans.get_request_method() + print method + + # NOTE: Some frameworks do not pass in the content type. + + content_type = trans.get_content_type() + + if method == "PUT": + input = trans.get_request_stream() + print "Name:", calendar_name + print "Content type:", content_type.content_type + print "--------" + print input.read() + print "--------" + else: + + # NOTE: Send the appropriate kind of response. + + trans.set_content_type(WebStack.Generic.ContentType("text/html")) + out = trans.get_response_stream() + out.write("

Calendar %s

" % calendar_name) + +# vim: tabstop=4 expandtab shiftwidth=4