def require_params(method, *required_keys):
 def decorator(func):
  @wraps(func)
  def wrapper(self, *args, **kwargs):
   if (method == 'GET'):
    params = self.get_params
   elif (method == 'POST'):
    params = self.post_dict
   else:
    raise ValueError("Unsupported method '{method}'".format(method=method))
   missing = []
   for key in required_keys:
    if (params.get(key) is None):
     missing.append(key)
   if (len(missing) > 0):
    msg = 'Missing required key(s) {keys}'.format(keys=','.join(missing))
    self.send_response(400, content=msg, headers={'Content-type': 'text/plain'})
   else:
    return func(self, *args, **kwargs)
  return wrapper
 return decorator

def require_params ( method , * required_keys ) : def decorator ( func ) : @ wraps ( func ) def wrapper ( self , * args , ** kwargs ) : if ( method == 'GET' ) : params = self . get_params elif ( method == 'POST' ) : params = self . post_dict else : raise ValueError ( "Unsupported method '{method}'" . format ( method = method ) ) missing = [ ] for key in required_keys : if ( params . get ( key ) is None ) : missing . append ( key ) if ( len ( missing ) > 0 ) : msg = 'Missing required key(s) {keys}' . format ( keys = ',' . join ( missing ) ) self . send_response ( 400 , content = msg , headers = { 'Content-type' : 'text/plain' } ) else : return func ( self , * args , ** kwargs ) return wrapper return decorator
ensures that the request contains all required parameters .