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 from Calendar import CalendarResource 22 23 # A very simple index page. 24 25 from WebStack.Generic import ContentType 26 27 class DemoResource: 28 def respond(self, trans): 29 trans.set_content_type(ContentType("text/html")) 30 trans.get_response_stream().write(""" 31 <html> 32 <head> 33 <title>WebStack Examples</title> 34 </head> 35 <body> 36 <h1>WebStack Examples</h1> 37 <p>Here are some of the examples supplied with WebStack:</p> 38 <ul> 39 <li><a href="cookies">Cookie information</a></li> 40 <li><a href="form">Form tests</a></li> 41 <li><a href="sessions">Session information</a></li> 42 <li><a href="simple">Simple test</a></li> 43 <li><a href="unicode">Unicode test</a></li> 44 <li><a href="verysimple">Very simple test</a></li> 45 <li><a href="webdav://localhost:8080/calendar/">Calendar store example</a> - <strong>requires a WebDAV-capable browser</strong><br /> 46 Copy calendar files into the directory, view them, delete them, and so on.</li> 47 </ul> 48 <p>You can run all of the examples independently - see the documentation in 49 the <code>docs</code> directory, especially the subdirectories for each 50 of the server environments or frameworks, for details of how this is 51 done.</p> 52 </body> 53 </html>""") 54 trans.set_response_code(200) 55 56 # Get various special arguments. 57 58 import sys 59 60 if len(sys.argv) > 1: 61 fsencoding = sys.argv[1] 62 else: 63 fsencoding = None 64 65 # Define the resource mapping. 66 67 resource = MapResource({ 68 "cookies" : CookiesResource(), 69 "form" : FormResource(), 70 "sessions" : SessionsResource(), 71 "simple" : SimpleResource(), 72 "unicode" : UnicodeResource(), 73 "verysimple" : VerySimpleResource(), 74 "calendar" : CalendarResource(fsencoding), 75 "" : DemoResource() 76 }) 77 78 resource.mapping[None] = resource 79 80 # Special magic incantation. 81 82 print "Serving..." 83 deploy(resource, handle_errors=0) 84 85 # vim: tabstop=4 expandtab shiftwidth=4