#NEWLINE# 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 ) : #NEWLINE# #INDENT# resp = response_type ( '' ) #NEWLINE# if ( cache_timeout and cached_modify_time ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# mtime = get_file_mtime ( path ) #NEWLINE# #UNINDENT# except ( ValueError , IOError , OSError ) : #NEWLINE# #INDENT# raise Forbidden ( is_breaking = False ) #NEWLINE# #UNINDENT# resp . cache_control . public = True #NEWLINE# if ( mtime <= cached_modify_time ) : #NEWLINE# #INDENT# resp . status_code = 304 #NEWLINE# resp . cache_control . max_age = cache_timeout #NEWLINE# return resp #NEWLINE# #UNINDENT# #UNINDENT# if ( not isfile ( path ) ) : #NEWLINE# #INDENT# raise NotFound ( is_breaking = False ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# file_obj = open ( path , 'rb' ) #NEWLINE# mtime = get_file_mtime ( path ) #NEWLINE# fsize = os . path . getsize ( path ) #NEWLINE# #UNINDENT# except ( ValueError , IOError , OSError ) : #NEWLINE# #INDENT# raise Forbidden ( is_breaking = False ) #NEWLINE# #UNINDENT# if ( not mimetype ) : #NEWLINE# #INDENT# ( mimetype , encoding ) = mimetypes . guess_type ( path ) #NEWLINE# #UNINDENT# if ( not mimetype ) : #NEWLINE# #INDENT# peeked = peek_file ( file_obj , 1024 ) #NEWLINE# is_binary = is_binary_string ( peeked ) #NEWLINE# if ( peeked and is_binary ) : #NEWLINE# #INDENT# mimetype = default_binary_mime #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# mimetype = default_text_mime #NEWLINE# #UNINDENT# #UNINDENT# resp . response = file_wrapper ( file_obj ) #NEWLINE# resp . content_type = mimetype #NEWLINE# resp . content_length = fsize #NEWLINE# resp . last_modified = mtime #NEWLINE# resp . cache_control . max_age = cache_timeout #NEWLINE# return resp