paulb@362 | 1 | #!/usr/bin/env python |
paulb@362 | 2 | |
paulb@362 | 3 | """ |
paulb@362 | 4 | A demonstration of WebStack. This is a quick and dirty combination of an |
paulb@362 | 5 | adapter, employing lots of resources, and the index page resource. |
paulb@362 | 6 | """ |
paulb@362 | 7 | |
paulb@362 | 8 | # Import the things which make the adapter code deploy the application. |
paulb@362 | 9 | |
paulb@362 | 10 | from WebStack.Adapters.BaseHTTPRequestHandler import deploy |
paulb@362 | 11 | from WebStack.Resources.ResourceMap import MapResource |
paulb@362 | 12 | |
paulb@362 | 13 | # Here are all the test resources. |
paulb@362 | 14 | |
paulb@362 | 15 | from Cookies import CookiesResource |
paulb@362 | 16 | from Form import FormResource |
paulb@362 | 17 | from Sessions import SessionsResource |
paulb@362 | 18 | from Simple import SimpleResource |
paulb@362 | 19 | from Unicode import UnicodeResource |
paulb@362 | 20 | from VerySimple import VerySimpleResource |
paulb@416 | 21 | from Calendar import CalendarResource |
paulb@362 | 22 | |
paulb@362 | 23 | # A very simple index page. |
paulb@362 | 24 | |
paulb@362 | 25 | from WebStack.Generic import ContentType |
paulb@362 | 26 | |
paulb@362 | 27 | class DemoResource: |
paulb@362 | 28 | def respond(self, trans): |
paulb@362 | 29 | trans.set_content_type(ContentType("text/html")) |
paulb@362 | 30 | trans.get_response_stream().write(""" |
paulb@362 | 31 | <html> |
paulb@362 | 32 | <head> |
paulb@362 | 33 | <title>WebStack Examples</title> |
paulb@362 | 34 | </head> |
paulb@362 | 35 | <body> |
paulb@362 | 36 | <h1>WebStack Examples</h1> |
paulb@362 | 37 | <p>Here are some of the examples supplied with WebStack:</p> |
paulb@362 | 38 | <ul> |
paulb@362 | 39 | <li><a href="cookies">Cookie information</a></li> |
paulb@362 | 40 | <li><a href="form">Form tests</a></li> |
paulb@362 | 41 | <li><a href="sessions">Session information</a></li> |
paulb@362 | 42 | <li><a href="simple">Simple test</a></li> |
paulb@362 | 43 | <li><a href="unicode">Unicode test</a></li> |
paulb@362 | 44 | <li><a href="verysimple">Very simple test</a></li> |
paulb@416 | 45 | <li><a href="webdav://localhost:8080/calendar/">Calendar store example</a> - <strong>requires a WebDAV-capable browser</strong><br /> |
paulb@416 | 46 | Copy calendar files into the directory, view them, delete them, and so on.</li> |
paulb@362 | 47 | </ul> |
paulb@362 | 48 | <p>You can run all of the examples independently - see the documentation in |
paulb@362 | 49 | the <code>docs</code> directory, especially the subdirectories for each |
paulb@362 | 50 | of the server environments or frameworks, for details of how this is |
paulb@362 | 51 | done.</p> |
paulb@362 | 52 | </body> |
paulb@362 | 53 | </html>""") |
paulb@362 | 54 | trans.set_response_code(200) |
paulb@362 | 55 | |
paulb@362 | 56 | # Define the resource mapping. |
paulb@362 | 57 | |
paulb@362 | 58 | resource = MapResource({ |
paulb@362 | 59 | "cookies" : CookiesResource(), |
paulb@362 | 60 | "form" : FormResource(), |
paulb@362 | 61 | "sessions" : SessionsResource(), |
paulb@362 | 62 | "simple" : SimpleResource(), |
paulb@362 | 63 | "unicode" : UnicodeResource(), |
paulb@362 | 64 | "verysimple" : VerySimpleResource(), |
paulb@416 | 65 | "calendar" : CalendarResource(), |
paulb@362 | 66 | "" : DemoResource(), |
paulb@362 | 67 | }) |
paulb@362 | 68 | |
paulb@362 | 69 | # Special magic incantation. |
paulb@362 | 70 | |
paulb@362 | 71 | print "Serving..." |
paulb@362 | 72 | deploy(resource, handle_errors=0) |
paulb@362 | 73 | |
paulb@362 | 74 | # vim: tabstop=4 expandtab shiftwidth=4 |