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 11 # Here are all the test resources. 12 13 from Cookies import CookiesResource 14 from Form import FormResource 15 from Sessions import SessionsResource 16 from Simple import SimpleResource 17 from SimpleWithLogin import get_site_map as SimpleWithLoginResource 18 from SimpleWithOpenID import get_site_map as SimpleWithOpenIDResource 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="simplewithopenid">Simple with OpenID test</a></li> 45 <li><a href="unicode">Unicode test</a></li> 46 <li><a href="verysimple">Very simple test</a></li> 47 <li><a href="webdav://localhost:8080/calendar/">Calendar store example</a> - <strong>requires a WebDAV-capable browser</strong><br /> 48 Copy calendar files into the directory, view them, delete them, and so on.</li> 49 </ul> 50 <p>You can run all of the examples independently - see the documentation in 51 the <code>docs</code> directory, especially the subdirectories for each 52 of the server environments or frameworks, for details of how this is 53 done.</p> 54 </body> 55 </html>""") 56 trans.set_response_code(200) 57 58 def get_site(app_url, secret_key): 59 60 "Define the resource mapping." 61 62 resource = MapResource({ 63 "cookies" : CookiesResource(), 64 "form" : FormResource(), 65 "sessions" : SessionsResource(), 66 "simple" : SimpleResource(), 67 "simplewithlogin" : SimpleWithLoginResource(app_url, app_url + "/simplewithlogin/login", secret_key), 68 "simplewithopenid" : SimpleWithOpenIDResource(app_url, app_url + "/simplewithopenid/login", secret_key), 69 "unicode" : UnicodeResource(), 70 "verysimple" : VerySimpleResource(), 71 "calendar" : CalendarResource(), 72 "" : DemoResource() 73 }) 74 75 # Uncomment the line below to test arbitrary depth URLs/paths. 76 77 #resource.mapping[None] = resource 78 return resource 79 80 # vim: tabstop=4 expandtab shiftwidth=4