#!/usr/bin/python # # Copyright (c) 2007-2008 by Fred Morris Consult, Seattle WA USA # # Author: Fred Morris # Date: 25-Jan-2008 # # Licensed under the Perl Artistic License: "under the same terms # as Perl itself". """Nesting Example Usage: Called as a CGI Script Demonstrates build a web page from three separate web pages by insertion into tagged locations. The two inner handlers are automagically inserted into the outer handler's template. ASYNCHRONOUS IS NOT ALWAYS BETTER -- A NOTE ON STYLE: In the as-shipped case all three templates are coming off of the same server. In a system which has any load on it at all, there is very little chance that firing off three simultaneous requests is going to produce any appreciable speedup for static pages but it is guaranteed to increase consumption of system resources. I'm doing it here for demonstration purposes, but I personally wouldn't do it in this particular case. Parameters: None Version: 1.1 Modification History: FWM 20-Feb-2008 ...; Fetch all templates asynchronously. """ import sys from snakestation.handlers import Nester, Inner class Inner1 (Inner): TEMPLATE_NAME = 'Inner' ASYNCHRONOUS_TEMPLATE = True SPLITTER = '%%inner%%' # Uncomment these and see what happens. #INSERTION_MODE = 'Regex' #INSERTION_LOCATION = 'Before' class Inner2 (Inner): TEMPLATE_NAME = 'Inner2' ASYNCHRONOUS_TEMPLATE = True SPLITTER = '%%inner2%%' # Uncomment these and see what happens. #INSERTION_MODE = 'Regex' #INSERTION_LOCATION = 'After' class Outer (Nester): """A toplevel handler containing nested handlers.""" TEMPLATE_NAME = 'Outer' ASYNCHRONOUS_TEMPLATE = True INNER_HANDLERS = (Inner1,Inner2) def __init__(self,**args): """Send HTML""" Nester.__init__(self,**args) self.response.send_html() return def main(): handler = Outer() handler.template_map = { 'Outer' : 'http://flame.m3047.net/snakestation/outer.html', 'Inner' : 'http://flame.m3047.net/snakestation/inner.html', 'Inner2': 'http://flame.m3047.net/snakestation/inner-2.html', } handler.main() if __name__ == '__main__': main()