#NEWLINE# def serve_protected_file( request , path ) : #NEWLINE# #INDENT# '\n    Serve protected files to authenticated users with read permissions.\n    ' #NEWLINE# try : #NEWLINE# #INDENT# file_obj = File . objects . get ( file = path , is_public = False ) #NEWLINE# #UNINDENT# except File . DoesNotExist : #NEWLINE# #INDENT# raise Http404 ( 'File not found' ) #NEWLINE# #UNINDENT# if ( not file_obj . has_read_permission ( file_obj ) ) : #NEWLINE# #INDENT# if settings . DEBUG : #NEWLINE# #INDENT# raise PermissionDenied #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Http404 ( 'File not found' ) #NEWLINE# #UNINDENT# #UNINDENT# return server . serve ( request , file_obj = file_obj . file , save_as = False )