1 #!/usr/bin/env python 2 3 """ 4 A demonstration of WebStack. This is a quick and dirty combination of an 5 adapter, employing lots of resources, and the index page resource. 6 """ 7 8 # Import the things which make the adapter code deploy the application. 9 10 from WebStack.Adapters.BaseHTTPRequestHandler import deploy 11 from WebStack.Resources.ResourceMap import MapResource 12 13 # Here are all the test resources. 14 15 from Cookies import CookiesResource 16 from Form import FormResource 17 from Sessions import SessionsResource 18 from Simple import SimpleResource 19 from Unicode import UnicodeResource 20 from VerySimple import VerySimpleResource 21 22 # A very simple index page. 23 24 from WebStack.Generic import ContentType 25 26 class DemoResource: 27 def respond(self, trans): 28 trans.set_content_type(ContentType("text/html")) 29 trans.get_response_stream().write(""" 30 <html> 31 <head> 32 <title>WebStack Examples</title> 33 </head> 34 <body> 35 <h1>WebStack Examples</h1> 36 <p>Here are some of the examples supplied with WebStack:</p> 37 <ul> 38 <li><a href="cookies">Cookie information</a></li> 39 <li><a href="form">Form tests</a></li> 40 <li><a href="sessions">Session information</a></li> 41 <li><a href="simple">Simple test</a></li> 42 <li><a href="unicode">Unicode test</a></li> 43 <li><a href="verysimple">Very simple test</a></li> 44 </ul> 45 <p>You can run all of the examples independently - see the documentation in 46 the <code>docs</code> directory, especially the subdirectories for each 47 of the server environments or frameworks, for details of how this is 48 done.</p> 49 </body> 50 </html>""") 51 trans.set_response_code(200) 52 53 # Define the resource mapping. 54 55 resource = MapResource({ 56 "cookies" : CookiesResource(), 57 "form" : FormResource(), 58 "sessions" : SessionsResource(), 59 "simple" : SimpleResource(), 60 "unicode" : UnicodeResource(), 61 "verysimple" : VerySimpleResource(), 62 "" : DemoResource(), 63 }) 64 65 # Special magic incantation. 66 67 print "Serving..." 68 deploy(resource, handle_errors=0) 69 70 # vim: tabstop=4 expandtab shiftwidth=4