|
|
@ -1354,37 +1354,48 @@ class Flask(_PackageBoundObject): |
|
|
|
string as body |
|
|
|
string as body |
|
|
|
:class:`unicode` a response object is created with the |
|
|
|
:class:`unicode` a response object is created with the |
|
|
|
string encoded to utf-8 as body |
|
|
|
string encoded to utf-8 as body |
|
|
|
:class:`tuple` the response object is created with the |
|
|
|
|
|
|
|
contents of the tuple as arguments |
|
|
|
|
|
|
|
a WSGI function the function is called as WSGI application |
|
|
|
a WSGI function the function is called as WSGI application |
|
|
|
and buffered as response object |
|
|
|
and buffered as response object |
|
|
|
|
|
|
|
:class:`tuple` A tuple in the form ``(response, status, |
|
|
|
|
|
|
|
headers)`` where `response` is any of the |
|
|
|
|
|
|
|
types defined here, `status` is a string |
|
|
|
|
|
|
|
or an integer and `headers` is a list of |
|
|
|
|
|
|
|
a dictionary with header values. |
|
|
|
======================= =========================================== |
|
|
|
======================= =========================================== |
|
|
|
|
|
|
|
|
|
|
|
:param rv: the return value from the view function |
|
|
|
:param rv: the return value from the view function |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. versionchanged:: 0.9 |
|
|
|
|
|
|
|
Previously a tuple was interpreted as the arguments for the |
|
|
|
|
|
|
|
response object. |
|
|
|
""" |
|
|
|
""" |
|
|
|
|
|
|
|
status = headers = None |
|
|
|
|
|
|
|
if isinstance(rv, tuple): |
|
|
|
|
|
|
|
rv, status, headers = rv + (None,) * (3 - len(rv)) |
|
|
|
|
|
|
|
|
|
|
|
if rv is None: |
|
|
|
if rv is None: |
|
|
|
raise ValueError('View function did not return a response') |
|
|
|
raise ValueError('View function did not return a response') |
|
|
|
if isinstance(rv, self.response_class): |
|
|
|
|
|
|
|
return rv |
|
|
|
if not isinstance(rv, self.response_class): |
|
|
|
|
|
|
|
# When we create a response object directly, we let the constructor |
|
|
|
|
|
|
|
# set the headers and status. We do this because there can be |
|
|
|
|
|
|
|
# some extra logic involved when creating these objects with |
|
|
|
|
|
|
|
# specific values (like defualt content type selection). |
|
|
|
if isinstance(rv, basestring): |
|
|
|
if isinstance(rv, basestring): |
|
|
|
return self.response_class(rv) |
|
|
|
rv = self.response_class(rv, headers=headers, status=status) |
|
|
|
if isinstance(rv, tuple): |
|
|
|
headers = status = None |
|
|
|
if len(rv) > 0 and isinstance(rv[0], self.response_class): |
|
|
|
else: |
|
|
|
original = rv[0] |
|
|
|
rv = self.response_class.force_type(rv, request.environ) |
|
|
|
new_response = self.response_class('', *rv[1:]) |
|
|
|
|
|
|
|
if len(rv) < 3: |
|
|
|
if status is not None: |
|
|
|
# The args for the response class are |
|
|
|
if isinstance(status, basestring): |
|
|
|
# response=None, status=None, headers=None, |
|
|
|
rv.status = status |
|
|
|
# mimetype=None, content_type=None, ... |
|
|
|
|
|
|
|
# so if there's at least 3 elements the rv |
|
|
|
|
|
|
|
# tuple contains header information so the |
|
|
|
|
|
|
|
# headers from rv[0] "win." |
|
|
|
|
|
|
|
new_response.headers = original.headers |
|
|
|
|
|
|
|
new_response.response = original.response |
|
|
|
|
|
|
|
return new_response |
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
return self.response_class(*rv) |
|
|
|
rv.status_code = status |
|
|
|
return self.response_class.force_type(rv, request.environ) |
|
|
|
if headers: |
|
|
|
|
|
|
|
rv.headers.extend(headers) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return rv |
|
|
|
|
|
|
|
|
|
|
|
def create_url_adapter(self, request): |
|
|
|
def create_url_adapter(self, request): |
|
|
|
"""Creates a URL adapter for the given request. The URL adapter |
|
|
|
"""Creates a URL adapter for the given request. The URL adapter |
|
|
|