Helper to build an HTTP response.

    Parameters:

    code
     :  An integer status code.
    body
     :  The response body. See `Response.__init__` for details.
    etag
     :  A value for the ETag header. Double quotes will be added unless the
        string starts and ends with a double quote.
    last_modified
     :  A value for the Last-Modified header as a datetime.datetime object
        or Unix timestamp.
    expires
     :  A value for the Expires header as number of seconds, datetime.timedelta
        or datetime.datetime object.
        Note: a value of type int or float is interpreted as a number of
        seconds in the future, *not* as Unix timestamp.
    **kw
     :  All other keyword arguments are interpreted as response headers.
        The names will be converted to header names by replacing
        underscores with hyphens and converting to title case
        (e.g. `x_powered_by` => `X-Powered-By`).

def response(code, body='', etag=None, last_modified=None, expires=None, **kw):
    """Helper to build an HTTP response.

    Parameters:

    code
     :  An integer status code.
    body
     :  The response body. See `Response.__init__` for details.
    etag
     :  A value for the ETag header. Double quotes will be added unless the
        string starts and ends with a double quote.
    last_modified
     :  A value for the Last-Modified header as a datetime.datetime object
        or Unix timestamp.
    expires
     :  A value for the Expires header as number of seconds, datetime.timedelta
        or datetime.datetime object.
        Note: a value of type int or float is interpreted as a number of
        seconds in the future, *not* as Unix timestamp.
    **kw
     :  All other keyword arguments are interpreted as response headers.
        The names will be converted to header names by replacing
        underscores with hyphens and converting to title case
        (e.g. `x_powered_by` => `X-Powered-By`).

    """
    if etag is not None:
        if not (etag[0] == '"' and etag[-1] == '"'):
            etag = '"%s"' % etag
        kw['etag'] = etag

    if last_modified is not None:
        kw['last_modified'] = datetime_to_httpdate(last_modified)

    if expires is not None:
        if isinstance(expires, datetime):
            kw['expires'] = datetime_to_httpdate(expires)
        else:
            kw['expires'] = timedelta_to_httpdate(expires)

    headers = [(k.replace('_', '-').title(), v) for k, v in sorted(kw.items())]
    return Response(code, headers, body)