def build_file_response(path,
                        cache_timeout=None,
                        cached_modify_time=None,
                        mimetype=None,
                        default_text_mime=DEFAULT_TEXT_MIME,
                        default_binary_mime=DEFAULT_BINARY_MIME,
                        file_wrapper=FileWrapper,
                        response_type=Response):
    resp = response_type('')
    if cache_timeout and cached_modify_time:
        try:
            mtime = get_file_mtime(path)
        except (ValueError, IOError, OSError):  # TODO: winnow this down
            raise Forbidden(is_breaking=False)
        resp.cache_control.public = True
        if mtime <= cached_modify_time:
            resp.status_code = 304
            resp.cache_control.max_age = cache_timeout
            return resp

    if not isfile(path):
        raise NotFound(is_breaking=False)
    try:
        file_obj = open(path, 'rb')
        mtime = get_file_mtime(path)
        fsize = os.path.getsize(path)
    except (ValueError, IOError, __HOLE__):
        raise Forbidden(is_breaking=False)
    if not mimetype:
        mimetype, encoding = mimetypes.guess_type(path)
    if not mimetype:
        peeked = peek_file(file_obj, 1024)
        is_binary = is_binary_string(peeked)
        if peeked and is_binary:
            mimetype = default_binary_mime
        else:
            mimetype = default_text_mime
    resp.response = file_wrapper(file_obj)
    resp.content_type = mimetype
    resp.content_length = fsize
    resp.last_modified = mtime
    resp.cache_control.max_age = cache_timeout
    return resp
dataset/ETHPy150Open mahmoud/clastic/clastic/static.py/build_file_response