'Convert the return value from a view function to an instance of
:attr:`response_class`.
:param rv: the return value from the view function. The view function
must return a response. Returning ``None``, or the view ending
without returning, is not allowed. The following types are allowed
for ``view_rv``:
``str`` (``unicode`` in Python 2)
A response object is created with the string encoded to UTF-8
as the body.
``bytes`` (``str`` in Python 2)
A response object is created with the bytes as the body.
``tuple``
Either ``(body, status, headers)``, ``(body, status)``, or
``(body, headers)``, where ``body`` is any of the other types
allowed here, ``status`` is a string or an integer, and
``headers`` is a dictionary or a list of ``(key, value)``
tuples. If ``body`` is a :attr:`response_class` instance,
``status`` overwrites the exiting value and ``headers`` are
extended.
:attr:`response_class`
The object is returned unchanged.
other :class:`~werkzeug.wrappers.Response` class
The object is coerced to :attr:`response_class`.
:func:`callable`
The function is called as a WSGI application. The result is
used to create a response object.
.. versionchanged:: 0.9
Previously a tuple was interpreted as the arguments for the
response object.'

def make_response(self, rv):

    status = headers = None
    if isinstance(rv, (tuple, list)):
        len_rv = len(rv)
        if (len_rv == 3):
            (rv, status, headers) = rv
        elif (len_rv == 2):
            if isinstance(rv[1], (Headers, dict, tuple, list)):
                (rv, headers) = rv
            else:
                (rv, status) = rv
        else:
            raise TypeError('The    view    function    did    not    return    a    valid    response    tuple.    The    tuple    must    have    the    form    (body,    status,    headers),    (body,    status),    or    (body,    headers).')
    if (rv is None):
        raise TypeError('The    view    function    did    not    return    a    valid    response.    The    function    either    returned    None    or    ended    without    a    return    statement.')
    if (not isinstance(rv, self.response_class)):
        if isinstance(rv, (text_type, bytes, bytearray)):
            rv = self.response_class(rv, status=status, headers=headers)
            status = headers = None
        else:
            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,    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])
    if (status is not None):
        if isinstance(status, (text_type, bytes, bytearray)):
            rv.status = status
        else:
            rv.status_code = status
    if headers:
        rv.headers.extend(headers)
    return rv
