#NEWLINE# def expires( request , response , secs = 0 , force = False ) : #NEWLINE# #INDENT# 'Tool for influencing cache mechanisms using the \'Expires\' header.\n\n    \'secs\' must be either an int or a datetime.timedelta, and indicates the\n    number of seconds between response.time and when the response should\n    expire. The \'Expires\' header will be set to (response.time + secs).\n\n    If \'secs\' is zero, the \'Expires\' header is set one year in the past, and\n    the following "cache prevention" headers are also set:\n    - \'Pragma\': \'no-cache\'\n    - \'Cache-Control\': \'no-cache, must-revalidate\'\n\n    If \'force\' is False (the default), the following headers are checked:\n    \'Etag\', \'Last-Modified\', \'Age\', \'Expires\'. If any are already present,\n    none of the above response headers are set.\n    ' #NEWLINE# headers = response . headers #NEWLINE# cacheable = False #NEWLINE# if ( not force ) : #NEWLINE# #INDENT# for indicator in ( 'Etag' , 'Last-Modified' , 'Age' , 'Expires' ) : #NEWLINE# #INDENT# if ( indicator in headers ) : #NEWLINE# #INDENT# cacheable = True #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not cacheable ) : #NEWLINE# #INDENT# if isinstance ( secs , timedelta ) : #NEWLINE# #INDENT# secs = ( ( 86400 * secs . days ) + secs . seconds ) #NEWLINE# #UNINDENT# if ( secs == 0 ) : #NEWLINE# #INDENT# if ( force or ( 'Pragma' not in indicator ) ) : #NEWLINE# #INDENT# headers [ 'Pragma' ] = 'no-cache' #NEWLINE# #UNINDENT# if ( request . protocol >= ( 1 , 1 ) ) : #NEWLINE# #INDENT# if ( force or ( 'Cache-Control' not in headers ) ) : #NEWLINE# #INDENT# headers [ 'Cache-Control' ] = 'no-cache, must-revalidate' #NEWLINE# #UNINDENT# #UNINDENT# now = datetime . now ( ) #NEWLINE# lastyear = now . replace ( year = ( now . year - 1 ) ) #NEWLINE# expiry = formatdate ( mktime ( lastyear . timetuple ( ) ) , usegmt = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# expiry = formatdate ( ( response . time + secs ) , usegmt = True ) #NEWLINE# #UNINDENT# if ( force or ( 'Expires' not in headers ) ) : #NEWLINE# #INDENT# headers [ 'Expires' ] = expiry