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 | from WebStack.Resources.LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator |
paulb@480 | 11 | from WebStack.Resources.Login import LoginResource, LoginAuthenticator |
paulb@480 | 12 | |
paulb@480 | 13 | # Here are all the test resources. |
paulb@480 | 14 | |
paulb@480 | 15 | from Cookies import CookiesResource |
paulb@480 | 16 | from Form import FormResource |
paulb@480 | 17 | from Sessions import SessionsResource |
paulb@480 | 18 | from Simple import SimpleResource |
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> |
paulb@480 | 44 | <li><a href="unicode">Unicode test</a></li> |
paulb@480 | 45 | <li><a href="verysimple">Very simple test</a></li> |
paulb@480 | 46 | <li><a href="webdav://localhost:8080/calendar/">Calendar store example</a> - <strong>requires a WebDAV-capable browser</strong><br /> |
paulb@480 | 47 | Copy calendar files into the directory, view them, delete them, and so on.</li> |
paulb@480 | 48 | </ul> |
paulb@480 | 49 | <p>You can run all of the examples independently - see the documentation in |
paulb@480 | 50 | the <code>docs</code> directory, especially the subdirectories for each |
paulb@480 | 51 | of the server environments or frameworks, for details of how this is |
paulb@480 | 52 | done.</p> |
paulb@480 | 53 | </body> |
paulb@480 | 54 | </html>""") |
paulb@480 | 55 | trans.set_response_code(200) |
paulb@480 | 56 | |
paulb@480 | 57 | def get_site(): |
paulb@480 | 58 | |
paulb@480 | 59 | "Define the resource mapping." |
paulb@480 | 60 | |
paulb@480 | 61 | resource = MapResource({ |
paulb@480 | 62 | "cookies" : CookiesResource(), |
paulb@480 | 63 | "form" : FormResource(), |
paulb@480 | 64 | "sessions" : SessionsResource(), |
paulb@480 | 65 | "simple" : SimpleResource(), |
paulb@480 | 66 | "simplewithlogin" : |
paulb@480 | 67 | LoginRedirectResource( |
paulb@480 | 68 | login_url="http://localhost:8080/login", |
paulb@480 | 69 | app_url="http://localhost:8080", |
paulb@480 | 70 | resource=SimpleResource(), |
paulb@480 | 71 | authenticator=LoginRedirectAuthenticator(secret_key="horses"), |
paulb@480 | 72 | anonymous_parameter_name="anonymous", |
paulb@480 | 73 | logout_parameter_name="logout" |
paulb@480 | 74 | ), |
paulb@480 | 75 | "login" : |
paulb@480 | 76 | LoginResource( |
paulb@480 | 77 | LoginAuthenticator( |
paulb@480 | 78 | secret_key="horses", |
paulb@480 | 79 | credentials=( |
paulb@480 | 80 | ("badger", "abc"), |
paulb@480 | 81 | ("vole", "xyz"), |
paulb@480 | 82 | ) |
paulb@480 | 83 | ) |
paulb@480 | 84 | ), |
paulb@480 | 85 | "unicode" : UnicodeResource(), |
paulb@480 | 86 | "verysimple" : VerySimpleResource(), |
paulb@480 | 87 | "calendar" : CalendarResource(), |
paulb@480 | 88 | "" : DemoResource() |
paulb@480 | 89 | }) |
paulb@480 | 90 | |
paulb@480 | 91 | # Uncomment the line below to test arbitrary depth URLs/paths. |
paulb@480 | 92 | |
paulb@480 | 93 | #resource.mapping[None] = resource |
paulb@480 | 94 | return resource |
paulb@480 | 95 | |
paulb@480 | 96 | # vim: tabstop=4 expandtab shiftwidth=4 |