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@362 | 21 | |
paulb@362 | 22 | # A very simple index page. |
paulb@362 | 23 | |
paulb@362 | 24 | from WebStack.Generic import ContentType |
paulb@362 | 25 | |
paulb@362 | 26 | class DemoResource: |
paulb@362 | 27 | def respond(self, trans): |
paulb@362 | 28 | trans.set_content_type(ContentType("text/html")) |
paulb@362 | 29 | trans.get_response_stream().write(""" |
paulb@362 | 30 | <html> |
paulb@362 | 31 | <head> |
paulb@362 | 32 | <title>WebStack Examples</title> |
paulb@362 | 33 | </head> |
paulb@362 | 34 | <body> |
paulb@362 | 35 | <h1>WebStack Examples</h1> |
paulb@362 | 36 | <p>Here are some of the examples supplied with WebStack:</p> |
paulb@362 | 37 | <ul> |
paulb@362 | 38 | <li><a href="cookies">Cookie information</a></li> |
paulb@362 | 39 | <li><a href="form">Form tests</a></li> |
paulb@362 | 40 | <li><a href="sessions">Session information</a></li> |
paulb@362 | 41 | <li><a href="simple">Simple test</a></li> |
paulb@362 | 42 | <li><a href="unicode">Unicode test</a></li> |
paulb@362 | 43 | <li><a href="verysimple">Very simple test</a></li> |
paulb@362 | 44 | </ul> |
paulb@362 | 45 | <p>You can run all of the examples independently - see the documentation in |
paulb@362 | 46 | the <code>docs</code> directory, especially the subdirectories for each |
paulb@362 | 47 | of the server environments or frameworks, for details of how this is |
paulb@362 | 48 | done.</p> |
paulb@362 | 49 | </body> |
paulb@362 | 50 | </html>""") |
paulb@362 | 51 | trans.set_response_code(200) |
paulb@362 | 52 | |
paulb@362 | 53 | # Define the resource mapping. |
paulb@362 | 54 | |
paulb@362 | 55 | resource = MapResource({ |
paulb@362 | 56 | "cookies" : CookiesResource(), |
paulb@362 | 57 | "form" : FormResource(), |
paulb@362 | 58 | "sessions" : SessionsResource(), |
paulb@362 | 59 | "simple" : SimpleResource(), |
paulb@362 | 60 | "unicode" : UnicodeResource(), |
paulb@362 | 61 | "verysimple" : VerySimpleResource(), |
paulb@362 | 62 | "" : DemoResource(), |
paulb@362 | 63 | }) |
paulb@362 | 64 | |
paulb@362 | 65 | # Special magic incantation. |
paulb@362 | 66 | |
paulb@362 | 67 | print "Serving..." |
paulb@362 | 68 | deploy(resource, handle_errors=0) |
paulb@362 | 69 | |
paulb@362 | 70 | # vim: tabstop=4 expandtab shiftwidth=4 |