quantum源码分析2

来源:互联网 发布:淘宝怎样批量上传宝贝 编辑:程序博客网 时间:2024/06/05 16:23
[code=python]
class Controller(object):
    """WSGI app that dispatched to methods.
     与Method对应的controller,上面说到,一个路由表会指定一个controller。


    WSGI app that reads routing information supplied by RoutesMiddleware
    and calls the requested action method upon itself.  All action methods
    must, in addition to their normal parameters, accept a 'req' argument
    which is the incoming wsgi.Request.  They raise a webob.exc exception,
    or return a dict which will be serialized by requested content type.
    """
    #装饰为一个WSGI应用
    @webob.dec.wsgify(RequestClass=Request)
    def __call__(self, req):
        """
        Call the method specified in req.environ by RoutesMiddleware.
        """
        arg_dict = req.environ['wsgiorg.routing_args'][1]
        action = arg_dict['action']
        method = getattr(self, action)
        del arg_dict['controller']
        del arg_dict['action']
        if 'format' in arg_dict:
            del arg_dict['format']
        arg_dict['request'] = req
        #执行方法,这里是一个抽象,子类继承后决定具体怎么执行  
        result = method(**arg_dict)  
[/code]