All pastes #470956 Raw Edit

Cherrypy, second time around

public python v1 · immutable
·published 2007-05-04 16:59 UTC
rendered paste body
"""This is based on: Tutorial - Hello WorldGoals are to get vhost and /myfunc/arg1/arg2 to work."""# Import CherryPy global namespaceimport cherrypyclass MyRoot:    """ My Root. """    def index(self):        return "Hello world!"    index.exposed = Trueclass stats:    """ Stats dir providing 'static' png images. """    def index(self):        return """<html><head>        <title>Stats page</title></head><html><body><img src="router-bandwidth.png"><br /><img src="router-bandwidth-week.png"><br /><img src="bandwidth.png"><br /><img src="bandwidth-week.png"><br /><img src="cpu.png"><br /><img src="cpu-week.png"><br /></body></html>"""    index.exposed = Trueclass blog:    """ Sample for /blog/bla/blo, where bla and blo are args. """    def index(self,**keywords):	print keywords        return """"""    index.exposed = Trueclass VHost:        def __init__(self, sitename):            self.sitename = sitename        def index(self):            return "Welcome to %s" % self.sitename        index.exposed = Trueif __name__ == '__main__':    cherrypy.root = MyRoot()    cherrypy.root.stats = stats()    cherrypy.root.start = VHost("Server IP host")    cherrypy.root.blog = blog()    cherrypy.config.update({       'global': {'server.log_to_screen': True,          'server.environment': 'production',          'server.socket_port': 8033,          'server.socket_host': '192.168.1.2',          'virtual_host_filter.on': True,          'virtual_host_filter.stats.lan': '/start',          'virtual_host_filter.blog.lan': '/blog',          },       '/' : {'static_filter.on' : True,          'static_filter.root': '/path/to/www',          'static_filter.dir': '/',          },       '/start' : {'static_filter.on' : False,          'static_filter.dir': 'start',          },       '/stats' : {'static_filter.on' : True,          'static_filter.dir': 'stats',          },       '/blog' : {'static_filter.on' : False,          },    })    cherrypy.server.start()else:    print "Doh"