def static_file(filename, root,<EOL>mimetype='<STR_LIT>',<EOL>download=False,<EOL>charset='<STR_LIT>'):
root = os.path.abspath(root) + os.sep<EOL>filename = os.path.abspath(os.path.join(root, filename.strip('<STR_LIT>')))<EOL>headers = dict()<EOL>if not filename.startswith(root):<EOL><INDENT>return HTTPError(<NUM_LIT>, "<STR_LIT>")<EOL><DEDENT>if not os.path.exists(filename) or not os.path.isfile(filename):<EOL><INDENT>return HTTPError(<NUM_LIT>, "<STR_LIT>")<EOL><DEDENT>if not os.access(filename, os.R_OK):<EOL><INDENT>return HTTPError(<NUM_LIT>, "<STR_LIT>")<EOL><DEDENT>if mimetype == '<STR_LIT>':<EOL><INDENT>if download and download != True:<EOL><INDENT>mimetype, encoding = mimetypes.guess_type(download)<EOL><DEDENT>else:<EOL><INDENT>mimetype, encoding = mimetypes.guess_type(filename)<EOL><DEDENT>if encoding: headers['<STR_LIT>'] = encoding<EOL><DEDENT>if mimetype:<EOL><INDENT>if mimetype[:<NUM_LIT:5>] == '<STR_LIT>' and charset and '<STR_LIT>' not in mimetype:<EOL><INDENT>mimetype += '<STR_LIT>' % charset<EOL><DEDENT>headers['<STR_LIT:Content-Type>'] = mimetype<EOL><DEDENT>if download:<EOL><INDENT>download = os.path.basename(filename if download == True else download)<EOL>headers['<STR_LIT>'] = '<STR_LIT>' % download<EOL><DEDENT>stats = os.stat(filename)<EOL>headers['<STR_LIT>'] = clen = stats.st_size<EOL>lm = time.strftime("<STR_LIT>", time.gmtime(stats.st_mtime))<EOL>headers['<STR_LIT>'] = lm<EOL>ims = request.environ.get('<STR_LIT>')<EOL>if ims:<EOL><INDENT>ims = parse_date(ims.split("<STR_LIT:;>")[<NUM_LIT:0>].strip())<EOL><DEDENT>if ims is not None and ims >= int(stats.st_mtime):<EOL><INDENT>headers['<STR_LIT>'] = time.strftime("<STR_LIT>",<EOL>time.gmtime())<EOL>return HTTPResponse(status=<NUM_LIT>, **headers)<EOL><DEDENT>body = '<STR_LIT>' if request.method == '<STR_LIT>' else open(filename, '<STR_LIT:rb>')<EOL>headers["<STR_LIT>"] = "<STR_LIT>"<EOL>ranges = request.environ.get('<STR_LIT>')<EOL>if '<STR_LIT>' in request.environ:<EOL><INDENT>ranges = list(parse_range_header(request.environ['<STR_LIT>'], clen))<EOL>if not ranges:<EOL><INDENT>return HTTPError(<NUM_LIT>, "<STR_LIT>")<EOL><DEDENT>offset, end = ranges[<NUM_LIT:0>]<EOL>headers["<STR_LIT>"] = "<STR_LIT>" % (offset, end - <NUM_LIT:1>, clen)<EOL>headers["<STR_LIT>"] = str(end - offset)<EOL>if body: body = _file_iter_range(body, offset, end - offset)<EOL>return HTTPResponse(body, status=<NUM_LIT>, **headers)<EOL><DEDENT>return HTTPResponse(body, **headers)<EOL>
Open a file in a safe way and return :exc:`HTTPResponse` with status
        code 200, 305, 403 or 404. The ``Content-Type``, ``Content-Encoding``,
        ``Content-Length`` and ``Last-Modified`` headers are set if possible.
        Special support for ``If-Modified-Since``, ``Range`` and ``HEAD``
        requests.

        :param filename: Name or path of the file to send.
        :param root: Root path for file lookups. Should be an absolute directory
            path.
        :param mimetype: Defines the content-type header (default: guess from
            file extension)
        :param download: If True, ask the browser to open a `Save as...` dialog
            instead of opening the file with the associated program. You can
            specify a custom filename as a string. If not specified, the
            original filename is used (default: False).
        :param charset: The charset to use for files with a ``text/*``
            mime-type. (default: UTF-8)