def pre_event(f):
 @wraps(f)
 def decorated(*args, **kwargs):
  method = request.method
  if (method == 'HEAD'):
   method = 'GET'
  event_name = ('on_pre_' + method)
  resource = (args[0] if args else None)
  gh_params = ()
  rh_params = ()
  if (method in ('GET', 'PATCH', 'DELETE', 'PUT')):
   gh_params = (resource, request, kwargs)
   rh_params = (request, kwargs)
  elif (method in ('POST',)):
   gh_params = (resource, request)
   rh_params = (request,)
  getattr(app, event_name)(*gh_params)
  if resource:
   getattr(app, ((event_name + '_') + resource))(*rh_params)
  combined_args = kwargs
  if (len(args) > 1):
   combined_args.update(args[1].items())
  r = f(resource, **combined_args)
  return r
 return decorated

def pre_event ( f ) : @ wraps ( f ) def decorated ( * args , ** kwargs ) : method = request . method if ( method == 'HEAD' ) : method = 'GET' event_name = ( 'on_pre_' + method ) resource = ( args [ 0 ] if args else None ) gh_params = ( ) rh_params = ( ) if ( method in ( 'GET' , 'PATCH' , 'DELETE' , 'PUT' ) ) : gh_params = ( resource , request , kwargs ) rh_params = ( request , kwargs ) elif ( method in ( 'POST' , ) ) : gh_params = ( resource , request ) rh_params = ( request , ) getattr ( app , event_name ) ( * gh_params ) if resource : getattr ( app , ( ( event_name + '_' ) + resource ) ) ( * rh_params ) combined_args = kwargs if ( len ( args ) > 1 ) : combined_args . update ( args [ 1 ] . items ( ) ) r = f ( resource , ** combined_args ) return r return decorated
enable a hook pre http request .