def EventHandler(source_restriction=False, auth_required=True, allow_client_access=False):
 def Decorator(f):
  'Initialised Decorator.'
  @functools.wraps(f)
  def Decorated(self, msg):
   'A decorator that assists in enforcing EventListener restrictions.'
   if (auth_required and (msg.auth_state != msg.AuthorizationState.AUTHENTICATED)):
    raise RuntimeError(('Message from %s not authenticated.' % msg.source))
   if ((not allow_client_access) and msg.source and rdf_client.ClientURN.Validate(msg.source)):
    raise RuntimeError('Event does not support clients.')
   if source_restriction:
    source_check_method = getattr(self, 'CheckSource')
    if (not source_check_method):
     raise RuntimeError('CheckSource method not found.')
    if (not source_check_method(msg.source)):
     raise RuntimeError('Message source invalid.')
   stats.STATS.IncrementCounter('grr_worker_states_run')
   rdf_msg = rdf_flows.GrrMessage(msg)
   res = f(self, message=rdf_msg, event=rdf_msg.payload)
   return res
  return Decorated
 return Decorator

def EventHandler ( source_restriction = False , auth_required = True , allow_client_access = False ) : def Decorator ( f ) : @ functools . wraps ( f ) def Decorated ( self , msg ) : if ( auth_required and ( msg . auth_state != msg . AuthorizationState . AUTHENTICATED ) ) : raise RuntimeError ( ( 'Message from %s not authenticated.' % msg . source ) ) if ( ( not allow_client_access ) and msg . source and rdf_client . ClientURN . Validate ( msg . source ) ) : raise RuntimeError ( 'Event does not support clients.' ) if source_restriction : source_check_method = getattr ( self , 'CheckSource' ) if ( not source_check_method ) : raise RuntimeError ( 'CheckSource method not found.' ) if ( not source_check_method ( msg . source ) ) : raise RuntimeError ( 'Message source invalid.' ) stats . STATS . IncrementCounter ( 'grr_worker_states_run' ) rdf_msg = rdf_flows . GrrMessage ( msg ) res = f ( self , message = rdf_msg , event = rdf_msg . payload ) return res return Decorated return Decorator
a convenience decorator for event handlers .