# make sure the body is an instance of the response class # 看这里就好了, ifnot isinstance(rv, self.response_class): if isinstance(rv, (text_type, bytes, bytearray)): # let the response class set the status and headers instead of # waiting to do it manually, so that the class can handle any # special logic rv = self.response_class(rv, status=status, headers=headers) status = headers = None elif isinstance(rv, dict): rv = jsonify(rv) elif isinstance(rv, BaseResponse) or callable(rv): # evaluate a WSGI callable, or coerce a different response # class to the correct type try: rv = self.response_class.force_type(rv, request.environ) except TypeError as e: new_error = TypeError( "{e}\nThe view function did not return a valid" " response. The return type must be a string, dict, tuple," " Response instance, or WSGI callable, but it was a" " {rv.__class__.__name__}.".format(e=e, rv=rv) ) reraise(TypeError, new_error, sys.exc_info()[2]) else: raise TypeError( "The view function did not return a valid" " response. The return type must be a string, dict, tuple," " Response instance, or WSGI callable, but it was a" " {rv.__class__.__name__}.".format(rv=rv) )
# prefer the status if it was provided if status isnotNone: if isinstance(status, (text_type, bytes, bytearray)): rv.status = status else: rv.status_code = status
# extend existing headers with provided headers if headers: rv.headers.extend(headers)
@property defmax_cookie_size(self): """Read-only view of the :data:`MAX_COOKIE_SIZE` config key. See :attr:`~werkzeug.wrappers.BaseResponse.max_cookie_size` in Werkzeug's docs. """ if current_app: return current_app.config["MAX_COOKIE_SIZE"]
# return Werkzeug's default when not in an app context return super(Response, self).max_cookie_size
又是mixin实现多继承
别忘了,我们的目的是看他的 __call__方法返回的是否是迭代对象
不用大海捞针去父类找,pycharm已经帮我们找好了,在左侧structure中找
1 2 3 4 5 6 7 8 9 10 11
def__call__(self, environ, start_response): """Process this response as WSGI application. :param environ: the WSGI environment. :param start_response: the response callable provided by the WSGI server. :return: an application iterator """ app_iter, status, headers = self.get_wsgi_response(environ) start_response(status, headers) return app_iter