<s> from __future__ import absolute_import , unicode_literals <EOL> import os <EOL> import re <EOL> import stat <EOL> from wsgiref . util import FileWrapper <EOL> from django . http import HttpResponseNotModified , StreamingHttpResponse <EOL> from django . utils . http import http_date <EOL> try : <EOL> from email . utils import parsedate_tz , mktime_tz <EOL> except ImportError : <EOL> from email . Utils import parsedate_tz , mktime_tz <EOL> def sendfile ( request , filename , ** kwargs ) : <EOL> statobj = os . stat ( filename ) <EOL> if not was_modified_since ( request . META . get ( '<STR_LIT>' ) , <EOL> statobj [ stat . ST_MTIME ] , statobj [ stat . ST_SIZE ] ) : <EOL> return HttpResponseNotModified ( ) <EOL> response = StreamingHttpResponse ( FileWrapper ( open ( filename , '<STR_LIT:rb>' ) ) ) <EOL> response [ "<STR_LIT>" ] = http_date ( statobj [ stat . ST_MTIME ] ) <EOL> return response <EOL> def was_modified_since ( header = None , mtime = <NUM_LIT:0> , size = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if header is None : <EOL> raise ValueError <EOL> matches = re . match ( r"<STR_LIT>" , header , <EOL> re . IGNORECASE ) <EOL> header_date = parsedate_tz ( matches . group ( <NUM_LIT:1> ) ) <EOL> if header_date is None : <EOL> raise ValueError <EOL> header_mtime = mktime_tz ( header_date ) <EOL> header_len = matches . group ( <NUM_LIT:3> ) <EOL> if header_len and int ( header_len ) != size : <EOL> raise ValueError <EOL> if mtime > header_mtime : <EOL> raise ValueError <EOL> except ( AttributeError , ValueError , OverflowError ) : <EOL> return True <EOL> return False </s>
