1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/BaseHTTPRequestHandler/DemoApp.py Sat Apr 30 21:23:30 2005 +0000
1.3 @@ -0,0 +1,70 @@
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 +
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 +
1.25 +# A very simple index page.
1.26 +
1.27 +from WebStack.Generic import ContentType
1.28 +
1.29 +class DemoResource:
1.30 + def respond(self, trans):
1.31 + trans.set_content_type(ContentType("text/html"))
1.32 + trans.get_response_stream().write("""
1.33 +<html>
1.34 + <head>
1.35 + <title>WebStack Examples</title>
1.36 + </head>
1.37 + <body>
1.38 + <h1>WebStack Examples</h1>
1.39 + <p>Here are some of the examples supplied with WebStack:</p>
1.40 + <ul>
1.41 + <li><a href="cookies">Cookie information</a></li>
1.42 + <li><a href="form">Form tests</a></li>
1.43 + <li><a href="sessions">Session information</a></li>
1.44 + <li><a href="simple">Simple test</a></li>
1.45 + <li><a href="unicode">Unicode test</a></li>
1.46 + <li><a href="verysimple">Very simple test</a></li>
1.47 + </ul>
1.48 + <p>You can run all of the examples independently - see the documentation in
1.49 + the <code>docs</code> directory, especially the subdirectories for each
1.50 + of the server environments or frameworks, for details of how this is
1.51 + done.</p>
1.52 + </body>
1.53 +</html>""")
1.54 + trans.set_response_code(200)
1.55 +
1.56 +# Define the resource mapping.
1.57 +
1.58 +resource = MapResource({
1.59 + "cookies" : CookiesResource(),
1.60 + "form" : FormResource(),
1.61 + "sessions" : SessionsResource(),
1.62 + "simple" : SimpleResource(),
1.63 + "unicode" : UnicodeResource(),
1.64 + "verysimple" : VerySimpleResource(),
1.65 + "" : DemoResource(),
1.66 + })
1.67 +
1.68 +# Special magic incantation.
1.69 +
1.70 +print "Serving..."
1.71 +deploy(resource, handle_errors=0)
1.72 +
1.73 +# vim: tabstop=4 expandtab shiftwidth=4