WebStack

examples/Common/Calendar/__init__.py

226:229a5f6310e1
2004-09-01 paulb [project @ 2004-09-01 22:52:13 by paulb] Changed content_type to media_type.
     1 #!/usr/bin/env python     2      3 "A calendar application."     4      5 import WebStack.Generic     6      7 class DirectoryResource:     8      9     """    10     A resource which handles incoming calendars and viewing requests.    11     An arbitrary set of rules can be applied to determine what is to be done    12     with a request, and in this case, the application appears as a directory of    13     calendars, yet also accepts incoming calendars.    14     """    15     16     def respond(self, trans):    17     18         """    19         Examine the incoming request, either saving a calendar or displaying    20         one.    21         """    22     23         # Get the last path component as the name of the calendar.    24         # NOTE: This could be improved to permit hierarchical naming.    25     26         calendar_name = trans.get_path_without_query().split("/")[-1]    27     28         # Determine the action to be taken.    29     30         method = trans.get_request_method()    31         print method    32     33         # NOTE: Some frameworks do not pass in the content type.    34     35         content_type = trans.get_content_type()    36     37         if method == "PUT":    38             input = trans.get_request_stream()    39             print "Name:", calendar_name    40             print "Content type:", content_type.media_type    41             print "--------"    42             print input.read()    43             print "--------"    44         else:    45     46             # NOTE: Send the appropriate kind of response.    47     48             trans.set_content_type(WebStack.Generic.ContentType("text/html"))    49             out = trans.get_response_stream()    50             out.write("<html><body><h1>Calendar %s</h1></body></html>" % calendar_name)    51     52 # vim: tabstop=4 expandtab shiftwidth=4