def on_valid(valid_content_type, on_invalid=json):
 invalid_kwargs = introspect.generate_accepted_kwargs(on_invalid, 'request', 'response')
 invalid_takes_response = introspect.takes_all_arguments(on_invalid, 'response')
 def wrapper(function):
  valid_kwargs = introspect.generate_accepted_kwargs(function, 'request', 'response')
  valid_takes_response = introspect.takes_all_arguments(function, 'response')
  @content_type(valid_content_type)
  @wraps(function)
  def output_content(content, response, **kwargs):
   if ((type(content) == dict) and ('errors' in content)):
    response.content_type = on_invalid.content_type
    if invalid_takes_response:
     kwargs['response'] = response
    return on_invalid(content, **invalid_kwargs(kwargs))
   if valid_takes_response:
    kwargs['response'] = response
   return function(content, **valid_kwargs(kwargs))
  return output_content
 return wrapper

def on_valid ( valid_content_type , on_invalid = json ) : invalid_kwargs = introspect . generate_accepted_kwargs ( on_invalid , 'request' , 'response' ) invalid_takes_response = introspect . takes_all_arguments ( on_invalid , 'response' ) def wrapper ( function ) : valid_kwargs = introspect . generate_accepted_kwargs ( function , 'request' , 'response' ) valid_takes_response = introspect . takes_all_arguments ( function , 'response' ) @ content_type ( valid_content_type ) @ wraps ( function ) def output_content ( content , response , ** kwargs ) : if ( ( type ( content ) == dict ) and ( 'errors' in content ) ) : response . content_type = on_invalid . content_type if invalid_takes_response : kwargs [ 'response' ] = response return on_invalid ( content , ** invalid_kwargs ( kwargs ) ) if valid_takes_response : kwargs [ 'response' ] = response return function ( content , ** valid_kwargs ( kwargs ) ) return output_content return wrapper
renders as the specified content type only if no errors are found in the provided data object .