#NEWLINE# def store( self , response ) : #NEWLINE# #INDENT# '\n        Takes an HTTP response object and stores it in the cache according to\n        RFC 2616. Returns a boolean value indicating whether the response was\n        cached or not.\n\n        :param response: Requests :class:`Response <Response>` object to cache.\n        ' #NEWLINE# def date_header_or_default( header_name , default , response ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# date_header = response . headers [ header_name ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# value = default #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# value = parse_date_header ( date_header ) #NEWLINE# #UNINDENT# return value #NEWLINE# #UNINDENT# if ( response . status_code not in CACHEABLE_RCS ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# if ( response . request . method not in CACHEABLE_VERBS ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# url = response . url #NEWLINE# now = datetime . utcnow ( ) #NEWLINE# creation = date_header_or_default ( 'Date' , now , response ) #NEWLINE# cc = response . headers . get ( 'Cache-Control' , None ) #NEWLINE# if ( cc is not None ) : #NEWLINE# #INDENT# expiry = expires_from_cache_control ( cc , now ) #NEWLINE# if ( expiry is None ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# if ( date_header_or_default is None ) : #NEWLINE# #INDENT# expiry = date_header_or_default ( 'Expires' , None , response ) #NEWLINE# #UNINDENT# if ( ( expiry is not None ) and ( expiry <= creation ) ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# if ( ( expiry is None ) and ( response . request . method == 'GET' ) ) : #NEWLINE# #INDENT# if url_contains_query ( url ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# self . _cache [ url ] = { #NEWLINE# #INDENT# 'response' : response , #NEWLINE# 'creation' : creation , #NEWLINE# 'expiry' : expiry , #NEWLINE# #UNINDENT# } #NEWLINE# self . __reduce_cache_count ( ) #NEWLINE# return True