rendered paste body#!/usr/bin/env python2.5import Tkinterimport cherrypyfrom cherrypy._cpdispatch import Dispatcher,LateParamPageHandlerfrom cherrypy import exposeimport osclass NwsTcl: bootfile = './tcl-lib/bootstrap.tcl' def __init__(self): bootstrap = open(self.bootfile,'r+').read() tcl = Tkinter.Tcl() try: tcl.eval(bootstrap) except Exception,e: print "ERROR: failed to init NeoWebScript Tcl component" raise eclass NwsDispatcher(Dispatcher): def __call__(self, path_info): request = cherrypy.request if path_info != '//dummy.html': site_path = request.base.split(':')[1].lstrip('/') fs_root = '/www/%s'%site_path page_path = os.path.join(fs_root,path_info.lstrip('/')) if os.path.exists(page_path): print page_path request.handler = LateParamPageHandler(func, *vpath) else: request.handler = cherrypy.NotFound() else: func, vpath = self.find_handler(path_info) if func: # Decode any leftover %2F in the virtual_path atoms. vpath = [x.replace("%2F", "/") for x in vpath] request.handler = LateParamPageHandler(func, *vpath) else: request.handler = cherrypy.NotFound()def print_path(): print cherrypy.request.path_infocherrypy.tools.print_path = cherrypy.Tool('on_start_resource',print_path)class Vhost_Root: @expose @cherrypy.tools.print_path() def index(self): return "main vhost"root = Vhost_Root()root.test2 = Vhost_Root()root.test3 = Vhost_Root()def nws_dispatch(arg): print 'arg - %s'%argif __name__ == '__main__': tcl = NwsTcl() config = {'/': {'request.dispatch' : cherrypy.dispatch.VirtualHost( NwsDispatcher(), **{r'^/([.]+)$': '/', 'tools.staticdir.root': '/www/test', }), 'engine.autoreload_on' : True, 'tools.staticdir.on': True, 'tools.staticdir.index': 'index.html', 'tools.staticdir.dir': '/' } } cherrypy.quickstart(root,config=config)