test_virtualhost.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:watcher 作者: nosmokingbandit 项目源码 文件源码
def setup_server():
        class Root:

            @cherrypy.expose
            def index(self):
                return "Hello, world"

            @cherrypy.expose
            def dom4(self):
                return "Under construction"

            @cherrypy.expose
            def method(self, value):
                return "You sent %s" % value

        class VHost:

            def __init__(self, sitename):
                self.sitename = sitename

            @cherrypy.expose
            def index(self):
                return "Welcome to %s" % self.sitename

            @cherrypy.expose
            def vmethod(self, value):
                return "You sent %s" % value

            @cherrypy.expose
            def url(self):
                return cherrypy.url("nextpage")

            # Test static as a handler (section must NOT include vhost prefix)
            static = cherrypy.tools.staticdir.handler(
                section='/static', dir=curdir)

        root = Root()
        root.mydom2 = VHost("Domain 2")
        root.mydom3 = VHost("Domain 3")
        hostmap = {'www.mydom2.com': '/mydom2',
                   'www.mydom3.com': '/mydom3',
                   'www.mydom4.com': '/dom4',
                   }
        cherrypy.tree.mount(root, config={
            '/': {
                'request.dispatch': cherrypy.dispatch.VirtualHost(**hostmap)
            },
            # Test static in config (section must include vhost prefix)
            '/mydom2/static2': {
                'tools.staticdir.on': True,
                'tools.staticdir.root': curdir,
                'tools.staticdir.dir': 'static',
                'tools.staticdir.index': 'index.html',
            },
        })
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号