您的位置:首页 > 编程语言 > Python开发

quantum源码分析2

2013-08-12 14:32 141 查看
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)  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息