def match_filter(filters, userargs, exec_dirs=[]):
 first_not_executable_filter = None
 for f in filters:
  if f.match(userargs):
   if (not f.get_exec(exec_dirs=exec_dirs)):
    if (not first_not_executable_filter):
     first_not_executable_filter = f
    continue
   return f
 if first_not_executable_filter:
  raise FilterMatchNotExecutable(match=first_not_executable_filter)
 raise NoFilterMatched()

def match_filter ( filters , userargs , exec_dirs = [ ] ) : first_not_executable_filter = None for f in filters : if f . match ( userargs ) : if ( not f . get_exec ( exec_dirs = exec_dirs ) ) : if ( not first_not_executable_filter ) : first_not_executable_filter = f continue return f if first_not_executable_filter : raise FilterMatchNotExecutable ( match = first_not_executable_filter ) raise NoFilterMatched ( )
checks user command and arguments through command filters and returns the first matching filter .