1 #!/usr/bin/env python 2 3 """ 4 A demonstration of WebStack. 5 """ 6 7 # Import the things which make the resource work. 8 9 from WebStack.Resources.ResourceMap import MapResource 10 from WebStack.Resources.LoginRedirect import LoginRedirectResource, LoginRedirectAuthenticator 11 from WebStack.Resources.Login import LoginResource, LoginAuthenticator 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="simplewithlogin">Simple with login test</a></li> 44 <li><a href="unicode">Unicode test</a></li> 45 <li><a href="verysimple">Very simple test</a></li> 46 <li><a href="webdav://localhost:8080/calendar/">Calendar store example</a> - <strong>requires a WebDAV-capable browser</strong><br /> 47 Copy calendar files into the directory, view them, delete them, and so on.</li> 48 </ul> 49 <p>You can run all of the examples independently - see the documentation in 50 the <code>docs</code> directory, especially the subdirectories for each 51 of the server environments or frameworks, for details of how this is 52 done.</p> 53 </body> 54 </html>""") 55 trans.set_response_code(200) 56 57 def get_site(): 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 return resource 95 96 # vim: tabstop=4 expandtab shiftwidth=4