1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/DemoApp.py Thu Sep 29 14:15:26 2005 +0000
1.3 @@ -0,0 +1,96 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +A demonstration of WebStack.
1.8 +"""
1.9 +
1.10 +# Import the things which make the resource work.
1.11 +
1.12 +from WebStack.Resources.ResourceMap import MapResource
1.13 +from WebStack.Resources.LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator
1.14 +from WebStack.Resources.Login import LoginResource, LoginAuthenticator
1.15 +
1.16 +# Here are all the test resources.
1.17 +
1.18 +from Cookies import CookiesResource
1.19 +from Form import FormResource
1.20 +from Sessions import SessionsResource
1.21 +from Simple import SimpleResource
1.22 +from Unicode import UnicodeResource
1.23 +from VerySimple import VerySimpleResource
1.24 +from Calendar import CalendarResource
1.25 +
1.26 +# A very simple index page.
1.27 +
1.28 +from WebStack.Generic import ContentType
1.29 +
1.30 +class DemoResource:
1.31 + def respond(self, trans):
1.32 + trans.set_content_type(ContentType("text/html"))
1.33 + trans.get_response_stream().write("""
1.34 +<html>
1.35 + <head>
1.36 + <title>WebStack Examples</title>
1.37 + </head>
1.38 + <body>
1.39 + <h1>WebStack Examples</h1>
1.40 + <p>Here are some of the examples supplied with WebStack:</p>
1.41 + <ul>
1.42 + <li><a href="cookies">Cookie information</a></li>
1.43 + <li><a href="form">Form tests</a></li>
1.44 + <li><a href="sessions">Session information</a></li>
1.45 + <li><a href="simple">Simple test</a></li>
1.46 + <li><a href="simplewithlogin">Simple with login test</a></li>
1.47 + <li><a href="unicode">Unicode test</a></li>
1.48 + <li><a href="verysimple">Very simple test</a></li>
1.49 + <li><a href="webdav://localhost:8080/calendar/">Calendar store example</a> - <strong>requires a WebDAV-capable browser</strong><br />
1.50 + Copy calendar files into the directory, view them, delete them, and so on.</li>
1.51 + </ul>
1.52 + <p>You can run all of the examples independently - see the documentation in
1.53 + the <code>docs</code> directory, especially the subdirectories for each
1.54 + of the server environments or frameworks, for details of how this is
1.55 + done.</p>
1.56 + </body>
1.57 +</html>""")
1.58 + trans.set_response_code(200)
1.59 +
1.60 +def get_site():
1.61 +
1.62 + "Define the resource mapping."
1.63 +
1.64 + resource = MapResource({
1.65 + "cookies" : CookiesResource(),
1.66 + "form" : FormResource(),
1.67 + "sessions" : SessionsResource(),
1.68 + "simple" : SimpleResource(),
1.69 + "simplewithlogin" :
1.70 + LoginRedirectResource(
1.71 + login_url="http://localhost:8080/login",
1.72 + app_url="http://localhost:8080",
1.73 + resource=SimpleResource(),
1.74 + authenticator=LoginRedirectAuthenticator(secret_key="horses"),
1.75 + anonymous_parameter_name="anonymous",
1.76 + logout_parameter_name="logout"
1.77 + ),
1.78 + "login" :
1.79 + LoginResource(
1.80 + LoginAuthenticator(
1.81 + secret_key="horses",
1.82 + credentials=(
1.83 + ("badger", "abc"),
1.84 + ("vole", "xyz"),
1.85 + )
1.86 + )
1.87 + ),
1.88 + "unicode" : UnicodeResource(),
1.89 + "verysimple" : VerySimpleResource(),
1.90 + "calendar" : CalendarResource(),
1.91 + "" : DemoResource()
1.92 + })
1.93 +
1.94 + # Uncomment the line below to test arbitrary depth URLs/paths.
1.95 +
1.96 + #resource.mapping[None] = resource
1.97 + return resource
1.98 +
1.99 +# vim: tabstop=4 expandtab shiftwidth=4