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 from WebStack.Resources.LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator 13 from WebStack.Resources.Login import LoginResource, LoginAuthenticator 14 15 # Here are all the test resources. 16 17 from Cookies import CookiesResource 18 from Form import FormResource 19 from Sessions import SessionsResource 20 from Simple import SimpleResource 21 from Unicode import UnicodeResource 22 from VerySimple import VerySimpleResource 23 from Calendar import CalendarResource 24 25 # A very simple index page. 26 27 from WebStack.Generic import ContentType 28 29 class DemoResource: 30 def respond(self, trans): 31 trans.set_content_type(ContentType("text/html")) 32 trans.get_response_stream().write(""" 33 <html> 34 <head> 35 <title>WebStack Examples</title> 36 </head> 37 <body> 38 <h1>WebStack Examples</h1> 39 <p>Here are some of the examples supplied with WebStack:</p> 40 <ul> 41 <li><a href="cookies">Cookie information</a></li> 42 <li><a href="form">Form tests</a></li> 43 <li><a href="sessions">Session information</a></li> 44 <li><a href="simple">Simple test</a></li> 45 <li><a href="simplewithlogin">Simple with login test</a></li> 46 <li><a href="unicode">Unicode test</a></li> 47 <li><a href="verysimple">Very simple test</a></li> 48 <li><a href="webdav://localhost:8080/calendar/">Calendar store example</a> - <strong>requires a WebDAV-capable browser</strong><br /> 49 Copy calendar files into the directory, view them, delete them, and so on.</li> 50 </ul> 51 <p>You can run all of the examples independently - see the documentation in 52 the <code>docs</code> directory, especially the subdirectories for each 53 of the server environments or frameworks, for details of how this is 54 done.</p> 55 </body> 56 </html>""") 57 trans.set_response_code(200) 58 59 # Define the resource mapping. 60 61 resource = MapResource({ 62 "cookies" : CookiesResource(), 63 "form" : FormResource(), 64 "sessions" : SessionsResource(), 65 "simple" : SimpleResource(), 66 "simplewithlogin" : 67 LoginRedirectResource( 68 login_url="http://localhost:8080/login", 69 app_url="http://localhost:8080", 70 resource=SimpleResource(), 71 authenticator=LoginRedirectAuthenticator(secret_key="horses"), 72 anonymous_parameter_name="anonymous", 73 logout_parameter_name="logout" 74 ), 75 "login" : 76 LoginResource( 77 LoginAuthenticator( 78 secret_key="horses", 79 credentials=( 80 ("badger", "abc"), 81 ("vole", "xyz"), 82 ) 83 ) 84 ), 85 "unicode" : UnicodeResource(), 86 "verysimple" : VerySimpleResource(), 87 "calendar" : CalendarResource(), 88 "" : DemoResource() 89 }) 90 91 # Uncomment the line below to test arbitrary depth URLs/paths. 92 93 #resource.mapping[None] = resource 94 95 # Special magic incantation. 96 97 print "Serving..." 98 deploy(resource, handle_errors=0) 99 100 # vim: tabstop=4 expandtab shiftwidth=4