1 #!/usr/bin/env python 2 3 """ 4 A demonstration of XSLTools. 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 example applications. 14 15 import Configurator 16 import Dictionary 17 from Dictionary.Dict import Dict 18 import Questionnaire 19 import PEP241 20 import VerySimple 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>XSLTools Examples</title> 33 </head> 34 <body> 35 <h1>XSLTools Examples</h1> 36 <p>Here are some of the examples supplied with XSLTools:</p> 37 <ul> 38 <li><a href="configurator">A Webshop-style system configurator</a></li> 39 <li><a href="dictionary">A simple word lookup interface</a></li> 40 <li><a href="questionnaire">A questionnaire generator</a></li> 41 <li><a href="pep241">A Python package repository user interface</a></li> 42 <li><a href="verysimple">A very simple example</a></li> 43 </ul> 44 <p>You can run all of the examples independently, too. See the 45 <code>examples</code> directory for the code.</p> 46 </body> 47 </html>""") 48 trans.set_response_code(200) 49 50 # Find out where our example document will be for the dictionary example. 51 52 import os 53 54 cwd = os.getcwd() 55 parts = os.path.split(cwd) 56 if parts[-1] == "tools": 57 parts = parts[:-1] 58 parts += ("docs", "LICENCE.txt") 59 doc = os.path.join(*parts) 60 dict = Dict(doc) 61 62 # Define the resource mapping. 63 64 resource = MapResource({ 65 "configurator" : Configurator.get_site(), 66 "dictionary" : Dictionary.get_site(dict), 67 "questionnaire" : Questionnaire.get_site(), 68 "pep241" : PEP241.get_site(), 69 "verysimple" : VerySimple.get_site(), 70 "" : DemoResource(), 71 }) 72 73 # Special magic incantation. 74 75 print "Serving..." 76 deploy(resource, handle_errors=0) 77 78 # vim: tabstop=4 expandtab shiftwidth=4