1.1 --- a/examples/BaseHTTPRequestHandler/DemoApp.py Wed Sep 28 23:08:07 2005 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,100 +0,0 @@
1.4 -#!/usr/bin/env python
1.5 -
1.6 -"""
1.7 -A demonstration of WebStack. This is a quick and dirty combination of an
1.8 -adapter, employing lots of resources, and the index page resource.
1.9 -"""
1.10 -
1.11 -# Import the things which make the adapter code deploy the application.
1.12 -
1.13 -from WebStack.Adapters.BaseHTTPRequestHandler import deploy
1.14 -from WebStack.Resources.ResourceMap import MapResource
1.15 -from WebStack.Resources.LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator
1.16 -from WebStack.Resources.Login import LoginResource, LoginAuthenticator
1.17 -
1.18 -# Here are all the test resources.
1.19 -
1.20 -from Cookies import CookiesResource
1.21 -from Form import FormResource
1.22 -from Sessions import SessionsResource
1.23 -from Simple import SimpleResource
1.24 -from Unicode import UnicodeResource
1.25 -from VerySimple import VerySimpleResource
1.26 -from Calendar import CalendarResource
1.27 -
1.28 -# A very simple index page.
1.29 -
1.30 -from WebStack.Generic import ContentType
1.31 -
1.32 -class DemoResource:
1.33 - def respond(self, trans):
1.34 - trans.set_content_type(ContentType("text/html"))
1.35 - trans.get_response_stream().write("""
1.36 -<html>
1.37 - <head>
1.38 - <title>WebStack Examples</title>
1.39 - </head>
1.40 - <body>
1.41 - <h1>WebStack Examples</h1>
1.42 - <p>Here are some of the examples supplied with WebStack:</p>
1.43 - <ul>
1.44 - <li><a href="cookies">Cookie information</a></li>
1.45 - <li><a href="form">Form tests</a></li>
1.46 - <li><a href="sessions">Session information</a></li>
1.47 - <li><a href="simple">Simple test</a></li>
1.48 - <li><a href="simplewithlogin">Simple with login test</a></li>
1.49 - <li><a href="unicode">Unicode test</a></li>
1.50 - <li><a href="verysimple">Very simple test</a></li>
1.51 - <li><a href="webdav://localhost:8080/calendar/">Calendar store example</a> - <strong>requires a WebDAV-capable browser</strong><br />
1.52 - Copy calendar files into the directory, view them, delete them, and so on.</li>
1.53 - </ul>
1.54 - <p>You can run all of the examples independently - see the documentation in
1.55 - the <code>docs</code> directory, especially the subdirectories for each
1.56 - of the server environments or frameworks, for details of how this is
1.57 - done.</p>
1.58 - </body>
1.59 -</html>""")
1.60 - trans.set_response_code(200)
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 -
1.98 -# Special magic incantation.
1.99 -
1.100 -print "Serving..."
1.101 -deploy(resource, handle_errors=0)
1.102 -
1.103 -# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/examples/Common/DemoApp.py Thu Sep 29 14:15:26 2005 +0000
2.3 @@ -0,0 +1,96 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +"""
2.7 +A demonstration of WebStack.
2.8 +"""
2.9 +
2.10 +# Import the things which make the resource work.
2.11 +
2.12 +from WebStack.Resources.ResourceMap import MapResource
2.13 +from WebStack.Resources.LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator
2.14 +from WebStack.Resources.Login import LoginResource, LoginAuthenticator
2.15 +
2.16 +# Here are all the test resources.
2.17 +
2.18 +from Cookies import CookiesResource
2.19 +from Form import FormResource
2.20 +from Sessions import SessionsResource
2.21 +from Simple import SimpleResource
2.22 +from Unicode import UnicodeResource
2.23 +from VerySimple import VerySimpleResource
2.24 +from Calendar import CalendarResource
2.25 +
2.26 +# A very simple index page.
2.27 +
2.28 +from WebStack.Generic import ContentType
2.29 +
2.30 +class DemoResource:
2.31 + def respond(self, trans):
2.32 + trans.set_content_type(ContentType("text/html"))
2.33 + trans.get_response_stream().write("""
2.34 +<html>
2.35 + <head>
2.36 + <title>WebStack Examples</title>
2.37 + </head>
2.38 + <body>
2.39 + <h1>WebStack Examples</h1>
2.40 + <p>Here are some of the examples supplied with WebStack:</p>
2.41 + <ul>
2.42 + <li><a href="cookies">Cookie information</a></li>
2.43 + <li><a href="form">Form tests</a></li>
2.44 + <li><a href="sessions">Session information</a></li>
2.45 + <li><a href="simple">Simple test</a></li>
2.46 + <li><a href="simplewithlogin">Simple with login test</a></li>
2.47 + <li><a href="unicode">Unicode test</a></li>
2.48 + <li><a href="verysimple">Very simple test</a></li>
2.49 + <li><a href="webdav://localhost:8080/calendar/">Calendar store example</a> - <strong>requires a WebDAV-capable browser</strong><br />
2.50 + Copy calendar files into the directory, view them, delete them, and so on.</li>
2.51 + </ul>
2.52 + <p>You can run all of the examples independently - see the documentation in
2.53 + the <code>docs</code> directory, especially the subdirectories for each
2.54 + of the server environments or frameworks, for details of how this is
2.55 + done.</p>
2.56 + </body>
2.57 +</html>""")
2.58 + trans.set_response_code(200)
2.59 +
2.60 +def get_site():
2.61 +
2.62 + "Define the resource mapping."
2.63 +
2.64 + resource = MapResource({
2.65 + "cookies" : CookiesResource(),
2.66 + "form" : FormResource(),
2.67 + "sessions" : SessionsResource(),
2.68 + "simple" : SimpleResource(),
2.69 + "simplewithlogin" :
2.70 + LoginRedirectResource(
2.71 + login_url="http://localhost:8080/login",
2.72 + app_url="http://localhost:8080",
2.73 + resource=SimpleResource(),
2.74 + authenticator=LoginRedirectAuthenticator(secret_key="horses"),
2.75 + anonymous_parameter_name="anonymous",
2.76 + logout_parameter_name="logout"
2.77 + ),
2.78 + "login" :
2.79 + LoginResource(
2.80 + LoginAuthenticator(
2.81 + secret_key="horses",
2.82 + credentials=(
2.83 + ("badger", "abc"),
2.84 + ("vole", "xyz"),
2.85 + )
2.86 + )
2.87 + ),
2.88 + "unicode" : UnicodeResource(),
2.89 + "verysimple" : VerySimpleResource(),
2.90 + "calendar" : CalendarResource(),
2.91 + "" : DemoResource()
2.92 + })
2.93 +
2.94 + # Uncomment the line below to test arbitrary depth URLs/paths.
2.95 +
2.96 + #resource.mapping[None] = resource
2.97 + return resource
2.98 +
2.99 +# vim: tabstop=4 expandtab shiftwidth=4