parameters: (response_headers, request_headers)
return_statement: return retval
docstring: Determine freshness from the Date, Expires and Cache-Control headers.
  
      We don't handle the following:
  
      1. Cache-Control: max-stale
      2. Age: headers are not used in the calculations.
  
      Not that this algorithm is simpler than you might think
      because we are operating as a private (non-shared) cache.
      This lets us ignore 's-maxage'. We can also ignore
      'proxy-invalidate' since we aren't a proxy.
      We will never return a stale document as
      fresh as a design decision, and thus the non-implementation
      of 'max-stale'. This also lets us safely ignore 'must-revalidate'
      since we operate as if every server has sent 'must-revalidate'.
      Since we are private we get to ignore both 'public' and
      'private' parameters. We also ignore 'no-transform' since
      we don't do any transformations.
      The 'no-store' parameter is handled at a higher level.
      So the only Cache-Control parameters we look at are:
  
      no-cache
      only-if-cached
      max-age
      min-fresh
docstring_summary: Determine freshness from the Date, Expires and Cache-Control headers.
docstring_tokens: Determine freshness from the Date Expires and Cache - Control headers .
function: def _entry_disposition(response_headers, request_headers):
      """Determine freshness from the Date, Expires and Cache-Control headers.
  
      We don't handle the following:
  
      1. Cache-Control: max-stale
      2. Age: headers are not used in the calculations.
  
      Not that this algorithm is simpler than you might think
      because we are operating as a private (non-shared) cache.
      This lets us ignore 's-maxage'. We can also ignore
      'proxy-invalidate' since we aren't a proxy.
      We will never return a stale document as
      fresh as a design decision, and thus the non-implementation
      of 'max-stale'. This also lets us safely ignore 'must-revalidate'
      since we operate as if every server has sent 'must-revalidate'.
      Since we are private we get to ignore both 'public' and
      'private' parameters. We also ignore 'no-transform' since
      we don't do any transformations.
      The 'no-store' parameter is handled at a higher level.
      So the only Cache-Control parameters we look at are:
  
      no-cache
      only-if-cached
      max-age
      min-fresh
      """
  
      retval = "STALE"
      cc = _parse_cache_control(request_headers)
      cc_response = _parse_cache_control(response_headers)
  
      if request_headers.has_key('pragma') and request_headers['pragma'].lower().find('no-cache') != -1:
          retval = "TRANSPARENT"
          if 'cache-control' not in request_headers:
              request_headers['cache-control'] = 'no-cache'
      elif cc.has_key('no-cache'):
          retval = "TRANSPARENT"
      elif cc_response.has_key('no-cache'):
          retval = "STALE"
      elif cc.has_key('only-if-cached'):
          retval = "FRESH"
      elif response_headers.has_key('date'):
          date = calendar.timegm(email.Utils.parsedate_tz(response_headers['date']))
          now = time.time()
          current_age = max(0, now - date)
          if cc_response.has_key('max-age'):
              try:
                  freshness_lifetime = int(cc_response['max-age'])
              except ValueError:
                  freshness_lifetime = 0
          elif response_headers.has_key('expires'):
              expires = email.Utils.parsedate_tz(response_headers['expires'])
              if None == expires:
                  freshness_lifetime = 0
              else:
                  freshness_lifetime = max(0, calendar.timegm(expires) - date)
          else:
              freshness_lifetime = 0
          if cc.has_key('max-age'):
              try:
                  freshness_lifetime = int(cc['max-age'])
              except ValueError:
                  freshness_lifetime = 0
          if cc.has_key('min-fresh'):
              try:
                  min_fresh = int(cc['min-fresh'])
              except ValueError:
                  min_fresh = 0
              current_age += min_fresh
          if freshness_lifetime > current_age:
              retval = "FRESH"
      return retval
function_tokens: def _entry_disposition ( response_headers , request_headers ) : retval = "STALE" cc = _parse_cache_control ( request_headers ) cc_response = _parse_cache_control ( response_headers ) if request_headers . has_key ( 'pragma' ) and request_headers [ 'pragma' ] . lower ( ) . find ( 'no-cache' ) != - 1 : retval = "TRANSPARENT" if 'cache-control' not in request_headers : request_headers [ 'cache-control' ] = 'no-cache' elif cc . has_key ( 'no-cache' ) : retval = "TRANSPARENT" elif cc_response . has_key ( 'no-cache' ) : retval = "STALE" elif cc . has_key ( 'only-if-cached' ) : retval = "FRESH" elif response_headers . has_key ( 'date' ) : date = calendar . timegm ( email . Utils . parsedate_tz ( response_headers [ 'date' ] ) ) now = time . time ( ) current_age = max ( 0 , now - date ) if cc_response . has_key ( 'max-age' ) : try : freshness_lifetime = int ( cc_response [ 'max-age' ] ) except ValueError : freshness_lifetime = 0 elif response_headers . has_key ( 'expires' ) : expires = email . Utils . parsedate_tz ( response_headers [ 'expires' ] ) if None == expires : freshness_lifetime = 0 else : freshness_lifetime = max ( 0 , calendar . timegm ( expires ) - date ) else : freshness_lifetime = 0 if cc . has_key ( 'max-age' ) : try : freshness_lifetime = int ( cc [ 'max-age' ] ) except ValueError : freshness_lifetime = 0 if cc . has_key ( 'min-fresh' ) : try : min_fresh = int ( cc [ 'min-fresh' ] ) except ValueError : min_fresh = 0 current_age += min_fresh if freshness_lifetime > current_age : retval = "FRESH" return retval