paulb@480 | 1 | #!/usr/bin/env python |
paulb@480 | 2 | |
paulb@480 | 3 | """ |
paulb@480 | 4 | A demonstration of WebStack. |
paulb@480 | 5 | """ |
paulb@480 | 6 | |
paulb@480 | 7 | # Import the things which make the resource work. |
paulb@480 | 8 | |
paulb@480 | 9 | from WebStack.Resources.ResourceMap import MapResource |
paulb@480 | 10 | |
paulb@480 | 11 | # Here are all the test resources. |
paulb@480 | 12 | |
paulb@480 | 13 | from Cookies import CookiesResource |
paulb@480 | 14 | from Form import FormResource |
paulb@480 | 15 | from Sessions import SessionsResource |
paulb@480 | 16 | from Simple import SimpleResource |
paul@765 | 17 | from SimpleWithLogin import get_site_map as SimpleWithLoginResource |
paul@765 | 18 | from SimpleWithOpenID import get_site_map as SimpleWithOpenIDResource |
paulb@480 | 19 | from Unicode import UnicodeResource |
paulb@480 | 20 | from VerySimple import VerySimpleResource |
paulb@480 | 21 | from Calendar import CalendarResource |
paulb@480 | 22 | |
paulb@480 | 23 | # A very simple index page. |
paulb@480 | 24 | |
paulb@480 | 25 | from WebStack.Generic import ContentType |
paulb@480 | 26 | |
paulb@480 | 27 | class DemoResource: |
paulb@480 | 28 | def respond(self, trans): |
paulb@480 | 29 | trans.set_content_type(ContentType("text/html")) |
paulb@480 | 30 | trans.get_response_stream().write(""" |
paulb@480 | 31 | <html> |
paulb@480 | 32 | <head> |
paulb@480 | 33 | <title>WebStack Examples</title> |
paulb@480 | 34 | </head> |
paulb@480 | 35 | <body> |
paulb@480 | 36 | <h1>WebStack Examples</h1> |
paulb@480 | 37 | <p>Here are some of the examples supplied with WebStack:</p> |
paulb@480 | 38 | <ul> |
paulb@480 | 39 | <li><a href="cookies">Cookie information</a></li> |
paulb@480 | 40 | <li><a href="form">Form tests</a></li> |
paulb@480 | 41 | <li><a href="sessions">Session information</a></li> |
paulb@480 | 42 | <li><a href="simple">Simple test</a></li> |
paulb@480 | 43 | <li><a href="simplewithlogin">Simple with login test</a></li> |
paul@765 | 44 | <li><a href="simplewithopenid">Simple with OpenID test</a></li> |
paulb@480 | 45 | <li><a href="unicode">Unicode test</a></li> |
paulb@480 | 46 | <li><a href="verysimple">Very simple test</a></li> |
paulb@480 | 47 | <li><a href="webdav://localhost:8080/calendar/">Calendar store example</a> - <strong>requires a WebDAV-capable browser</strong><br /> |
paulb@480 | 48 | Copy calendar files into the directory, view them, delete them, and so on.</li> |
paulb@480 | 49 | </ul> |
paulb@480 | 50 | <p>You can run all of the examples independently - see the documentation in |
paulb@480 | 51 | the <code>docs</code> directory, especially the subdirectories for each |
paulb@480 | 52 | of the server environments or frameworks, for details of how this is |
paulb@480 | 53 | done.</p> |
paulb@480 | 54 | </body> |
paulb@480 | 55 | </html>""") |
paulb@480 | 56 | trans.set_response_code(200) |
paulb@480 | 57 | |
paul@765 | 58 | def get_site(app_url, secret_key): |
paulb@480 | 59 | |
paulb@480 | 60 | "Define the resource mapping." |
paulb@480 | 61 | |
paulb@480 | 62 | resource = MapResource({ |
paulb@480 | 63 | "cookies" : CookiesResource(), |
paulb@480 | 64 | "form" : FormResource(), |
paulb@480 | 65 | "sessions" : SessionsResource(), |
paulb@480 | 66 | "simple" : SimpleResource(), |
paul@765 | 67 | "simplewithlogin" : SimpleWithLoginResource(app_url, app_url + "/simplewithlogin/login", secret_key), |
paul@765 | 68 | "simplewithopenid" : SimpleWithOpenIDResource(app_url, app_url + "/simplewithopenid/login", secret_key), |
paulb@480 | 69 | "unicode" : UnicodeResource(), |
paulb@480 | 70 | "verysimple" : VerySimpleResource(), |
paulb@480 | 71 | "calendar" : CalendarResource(), |
paulb@480 | 72 | "" : DemoResource() |
paulb@480 | 73 | }) |
paulb@480 | 74 | |
paulb@480 | 75 | # Uncomment the line below to test arbitrary depth URLs/paths. |
paulb@480 | 76 | |
paulb@480 | 77 | #resource.mapping[None] = resource |
paulb@480 | 78 | return resource |
paulb@480 | 79 | |
paulb@480 | 80 | # vim: tabstop=4 expandtab shiftwidth=4 |