1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/Calendar/__init__.py Sun Feb 01 23:15:14 2004 +0000
1.3 @@ -0,0 +1,52 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"A calendar application."
1.7 +
1.8 +import WebStack.Generic
1.9 +
1.10 +class DirectoryResource:
1.11 +
1.12 + """
1.13 + A resource which handles incoming calendars and viewing requests.
1.14 + An arbitrary set of rules can be applied to determine what is to be done
1.15 + with a request, and in this case, the application appears as a directory of
1.16 + calendars, yet also accepts incoming calendars.
1.17 + """
1.18 +
1.19 + def respond(self, trans):
1.20 +
1.21 + """
1.22 + Examine the incoming request, either saving a calendar or displaying
1.23 + one.
1.24 + """
1.25 +
1.26 + # Get the last path component as the name of the calendar.
1.27 + # NOTE: This could be improved to permit hierarchical naming.
1.28 +
1.29 + calendar_name = trans.get_path().split("/")[-1]
1.30 +
1.31 + # Determine the action to be taken.
1.32 +
1.33 + method = trans.get_request_method()
1.34 + print method
1.35 +
1.36 + # NOTE: Some frameworks do not pass in the content type.
1.37 +
1.38 + content_type = trans.get_content_type()
1.39 +
1.40 + if method == "PUT":
1.41 + input = trans.get_request_stream()
1.42 + print "Name:", calendar_name
1.43 + print "Content type:", content_type.content_type
1.44 + print "--------"
1.45 + print input.read()
1.46 + print "--------"
1.47 + else:
1.48 +
1.49 + # NOTE: Send the appropriate kind of response.
1.50 +
1.51 + trans.set_content_type(WebStack.Generic.ContentType("text/html"))
1.52 + out = trans.get_response_stream()
1.53 + out.write("<html><body><h1>Calendar %s</h1></body></html>" % calendar_name)
1.54 +
1.55 +# vim: tabstop=4 expandtab shiftwidth=4