Merge "make fakeldap._match_query work for an arbitrary number of groups"
This commit is contained in:
commit
9ec12e2e54
@ -47,18 +47,14 @@ def _match_query(query, attrs):
|
|||||||
"""Match an ldap query to an attribute dictionary.
|
"""Match an ldap query to an attribute dictionary.
|
||||||
|
|
||||||
The characters &, |, and ! are supported in the query. No syntax checking
|
The characters &, |, and ! are supported in the query. No syntax checking
|
||||||
is performed, so malformed querys will not work correctly.
|
is performed, so malformed queries will not work correctly.
|
||||||
"""
|
"""
|
||||||
# cut off the parentheses
|
# cut off the parentheses
|
||||||
inner = query[1:-1]
|
inner = query[1:-1]
|
||||||
if inner.startswith(('&', '|')):
|
if inner.startswith(('&', '|')):
|
||||||
# cut off the & or |
|
# cut off the & or |
|
||||||
groups = _paren_groups(inner[1:])
|
groups = _paren_groups(inner[1:])
|
||||||
try:
|
return all(_match_query(group, attrs) for group in groups)
|
||||||
l, r = groups
|
|
||||||
return _match_query(l, attrs) and _match_query(r, attrs)
|
|
||||||
except ValueError: # just one group
|
|
||||||
return _match_query(groups[0], attrs)
|
|
||||||
if inner.startswith('!'):
|
if inner.startswith('!'):
|
||||||
# cut off the ! and the nested parentheses
|
# cut off the ! and the nested parentheses
|
||||||
return not _match_query(query[2:-1], attrs)
|
return not _match_query(query[2:-1], attrs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user