def _match_query(query, attrs, attrs_checked):
 inner = query[1:(-1)]
 if inner.startswith(('&', '|')):
  if (inner[0] == '&'):
   matchfn = all
  else:
   matchfn = any
  groups = _paren_groups(inner[1:])
  return matchfn((_match_query(group, attrs, attrs_checked) for group in groups))
 if inner.startswith('!'):
  return (not _match_query(query[2:(-1)], attrs, attrs_checked))
 (k, _sep, v) = inner.partition('=')
 attrs_checked.add(k.lower())
 return _match(k, v, attrs)

def _match_query ( query , attrs , attrs_checked ) : inner = query [ 1 : ( - 1 ) ] if inner . startswith ( ( '&' , '|' ) ) : if ( inner [ 0 ] == '&' ) : matchfn = all else : matchfn = any groups = _paren_groups ( inner [ 1 : ] ) return matchfn ( ( _match_query ( group , attrs , attrs_checked ) for group in groups ) ) if inner . startswith ( '!' ) : return ( not _match_query ( query [ 2 : ( - 1 ) ] , attrs , attrs_checked ) ) ( k , _sep , v ) = inner . partition ( '=' ) attrs_checked . add ( k . lower ( ) ) return _match ( k , v , attrs )
match an ldap query to an attribute dictionary .