webob

作者: lmem | 来源:发表于2017-04-13 11:45 被阅读66次
    # -*- coding: utf-8 -*-
    from wsgiref.simple_server import make_server
    
    import routes.middleware
    import webob.dec
    import webob.exc
    from oslo_config import cfg
    from oslo_context import context
    from oslo_log import log as logging
    
    DOMAIN = 'demo'
    CONF = cfg.CONF
    LOG = logging.getLogger(__name__)
    logging.register_options(CONF)
    logging.setup(CONF, DOMAIN)
    class Controller:
        @webob.dec.wsgify
        def __call__(self, req):
            return webob.Response("Hello World!")
    
    
    class Router(object):
        def __init__(self):
            self._mapper = routes.Mapper()
            self._mapper.connect('/spch',
                                 controller=Controller(),
                                 action='index',
                                 conditions={'method': ['GET']})
    
            self._router = routes.middleware.RoutesMiddleware(self._dispatch, self._mapper)
    
        @webob.dec.wsgify
        def __call__(self, req):
            return self._router
    
        @staticmethod
        @webob.dec.wsgify
        def _dispatch(req):
            match = req.environ['wsgiorg.routing_args'][1]
            LOG.info("Listing backups for instance '%s'" % "fdfdfd")
            if not match:
                return webob.exc.HTTPNotFound()
            #根据连接,找到对应的控制器
            app = match['controller']
            return app
    
    
    app = Router()
    httpd = make_server('localhost', 8282, app)
    httpd.serve_forever()
    

    相关文章

      网友评论

          本文标题: webob

          本文链接:https://www.haomeiwen.com/subject/mblbattx.html