def condition(etag_func=None, last_modified_func=None):
 def decorator(func):
  @wraps(func)
  def inner(request, *args, **kwargs):
   def get_last_modified():
    if last_modified_func:
     dt = last_modified_func(request, *args, **kwargs)
     if dt:
      return timegm(dt.utctimetuple())
   res_etag = (etag_func(request, *args, **kwargs) if etag_func else None)
   res_etag = (quote_etag(res_etag) if (res_etag is not None) else None)
   res_last_modified = get_last_modified()
   response = get_conditional_response(request, etag=res_etag, last_modified=res_last_modified)
   if (response is None):
    response = func(request, *args, **kwargs)
   if (res_last_modified and (not response.has_header('Last-Modified'))):
    response['Last-Modified'] = http_date(res_last_modified)
   if (res_etag and (not response.has_header('ETag'))):
    response['ETag'] = res_etag
   return response
  return inner
 return decorator

def condition ( etag_func = None , last_modified_func = None ) : def decorator ( func ) : @ wraps ( func ) def inner ( request , * args , ** kwargs ) : def get_last_modified ( ) : if last_modified_func : dt = last_modified_func ( request , * args , ** kwargs ) if dt : return timegm ( dt . utctimetuple ( ) ) res_etag = ( etag_func ( request , * args , ** kwargs ) if etag_func else None ) res_etag = ( quote_etag ( res_etag ) if ( res_etag is not None ) else None ) res_last_modified = get_last_modified ( ) response = get_conditional_response ( request , etag = res_etag , last_modified = res_last_modified ) if ( response is None ) : response = func ( request , * args , ** kwargs ) if ( res_last_modified and ( not response . has_header ( 'Last-Modified' ) ) ) : response [ 'Last-Modified' ] = http_date ( res_last_modified ) if ( res_etag and ( not response . has_header ( 'ETag' ) ) ) : response [ 'ETag' ] = res_etag return response return inner return decorator
only apply rule if condition is true .