def _compileCompositeFilter(operator, filters): searchFilter = Filter() if operator == u'!': if len(filters) != 1: raise LDAPFilterInvalidException("'not' filter must have exactly one element") choice = Not().setComponentByName('notFilter', filters[0]) searchFilter.setComponentByName('not', choice, verifyConstraints=False) elif operator == u'&': if len(filters) == 0: raise LDAPFilterInvalidException("'and' filter must have at least one element") choice = And().setComponents(*filters) searchFilter.setComponentByName('and', choice) elif operator == u'|': if len(filters) == 0: raise LDAPFilterInvalidException("'or' filter must have at least one element") choice = Or().setComponents(*filters) searchFilter.setComponentByName('or', choice) return searchFilter
def _compileCompositeFilter(operator, filters): searchFilter = Filter() if operator == u'!': if len(filters) != 1: raise LDAPFilterInvalidException( "'not' filter must have exactly one element") choice = Not().setComponentByName('notFilter', filters[0]) searchFilter.setComponentByName('not', choice, verifyConstraints=False) elif operator == u'&': if len(filters) == 0: raise LDAPFilterInvalidException( "'and' filter must have at least one element") choice = And().setComponents(*filters) searchFilter.setComponentByName('and', choice) elif operator == u'|': if len(filters) == 0: raise LDAPFilterInvalidException( "'or' filter must have at least one element") choice = Or().setComponents(*filters) searchFilter.setComponentByName('or', choice) return searchFilter
def _compileSimpleFilter(attribute, operator, value): searchFilter = Filter() if operator == u':=': # extensibleMatch match = RE_EX_ATTRIBUTE_1.match(attribute) or RE_EX_ATTRIBUTE_2.match(attribute) if not match: raise LDAPFilterInvalidException("invalid filter attribute: '{0}'".format(attribute)) attribute, dn, matchingRule = match.groups() choice = MatchingRuleAssertion() if attribute: choice.setComponentByName('type', attribute) choice.setComponentByName('dnAttributes', bool(dn)) if matchingRule: choice.setComponentByName('matchingRule', matchingRule) choice.setComponentByName('matchValue', value) searchFilter.setComponentByName('extensibleMatch', choice) else: if not RE_ATTRIBUTE.match(attribute): raise LDAPFilterInvalidException("invalid filter attribute: '{0}'".format(attribute)) if value == u'*' and operator == u'=': # present choice = Present(attribute) searchFilter.setComponentByName('present', choice) elif u'*' in value and operator == u'=': # substring components = [] assertions = value.split(u'*') initial = assertions[0] if initial: components.append(SubString().setComponentByName('initial', initial)) for assertion in assertions[1:-1]: components.append(SubString().setComponentByName('any', assertion)) final = assertions[-1] if final: components.append(SubString().setComponentByName('final', final)) subStrings = SubStrings().setComponents(*components) choice = SubstringFilter().setComponents(attribute, subStrings) searchFilter.setComponentByName('substrings', choice) elif u'*' not in value: # simple if operator == u'=': choice = EqualityMatch().setComponents(attribute, value) searchFilter.setComponentByName('equalityMatch', choice) elif operator == u'~=': choice = ApproxMatch().setComponents(attribute, value) searchFilter.setComponentByName('approxMatch', choice) elif operator == u'>=': choice = GreaterOrEqual().setComponents(attribute, value) searchFilter.setComponentByName('greaterOrEqual', choice) elif operator == u'<=': choice = LessOrEqual().setComponents(attribute, value) searchFilter.setComponentByName('lessOrEqual', choice) else: raise LDAPFilterInvalidException("invalid filter '({0}{1}{2})'".format(attribute, operator, value)) return searchFilter
def _compileSimpleFilter(attribute, operator, value): searchFilter = Filter() if operator == u':=': # extensibleMatch match = RE_EX_ATTRIBUTE_1.match( attribute) or RE_EX_ATTRIBUTE_2.match(attribute) if not match: raise LDAPFilterInvalidException( "invalid filter attribute: '{0}'".format(attribute)) attribute, dn, matchingRule = match.groups() choice = MatchingRuleAssertion() if attribute: choice.setComponentByName('type', attribute) choice.setComponentByName('dnAttributes', bool(dn)) if matchingRule: choice.setComponentByName('matchingRule', matchingRule) choice.setComponentByName('matchValue', value) searchFilter.setComponentByName('extensibleMatch', choice) else: if not RE_ATTRIBUTE.match(attribute): raise LDAPFilterInvalidException( "invalid filter attribute: '{0}'".format(attribute)) if value == u'*' and operator == u'=': # present choice = Present(attribute) searchFilter.setComponentByName('present', choice) elif u'*' in value and operator == u'=': # substring components = [] assertions = value.split(u'*') initial = assertions[0] if initial: components.append(SubString().setComponentByName( 'initial', initial)) for assertion in assertions[1:-1]: if not assertion: raise LDAPFilterInvalidException( "consecutive '*' in filter assertion") components.append(SubString().setComponentByName( 'any', assertion)) final = assertions[-1] if final: components.append(SubString().setComponentByName( 'final', final)) subStrings = SubStrings().setComponents(*components) choice = SubstringFilter().setComponents(attribute, subStrings) searchFilter.setComponentByName('substrings', choice) elif u'*' not in value: # simple if operator == u'=': choice = EqualityMatch().setComponents(attribute, value) searchFilter.setComponentByName('equalityMatch', choice) elif operator == u'~=': choice = ApproxMatch().setComponents(attribute, value) searchFilter.setComponentByName('approxMatch', choice) elif operator == u'>=': choice = GreaterOrEqual().setComponents(attribute, value) searchFilter.setComponentByName('greaterOrEqual', choice) elif operator == u'<=': choice = LessOrEqual().setComponents(attribute, value) searchFilter.setComponentByName('lessOrEqual', choice) return searchFilter
def _compileSimpleFilter(attribute, operator, value): # ToDo: extensibleMatch searchFilter = Filter() if value == u'*' and operator == u'=': # present choice = Present(attribute) searchFilter.setComponentByName('present', choice) elif u'*' in value and operator == u'=': # substring components = [] assertions = value.split(u'*') initial = assertions[0] if initial: components.append(SubString().setComponentByName('initial', initial)) for assertion in assertions[1:-1]: if not assertion: raise LDAPInvalidFilterException("consecutive '*' in filter") components.append(SubString().setComponentByName('any', assertion)) final = assertions[-1] if final: components.append(SubString().setComponentByName('final', final)) subStrings = SubStrings().setComponents(*components) choice = SubstringFilter().setComponents(attribute, subStrings) searchFilter.setComponentByName('substrings', choice) elif u'*' not in value: # simple if operator == u'=': choice = EqualityMatch().setComponents(attribute, value) searchFilter.setComponentByName('equalityMatch', choice) elif operator == u'~=': choice = ApproxMatch().setComponents(attribute, value) searchFilter.setComponentByName('approxMatch', choice) elif operator == u'>=': choice = GreaterOrEqual().setComponents(attribute, value) searchFilter.setComponentByName('greaterOrEqual', choice) elif operator == u'<=': choice = LessOrEqual().setComponents(attribute, value) searchFilter.setComponentByName('lessOrEqual', choice) return searchFilter
def _compileSimpleFilter(attribute, operator, value): # ToDo: extensibleMatch searchFilter = Filter() if value == u'*' and operator == u'=': # present choice = Present(attribute) searchFilter.setComponentByName('present', choice) elif u'*' in value and operator == u'=': # substring components = [] assertions = value.split(u'*') initial = assertions[0] if initial: components.append(SubString().setComponentByName( 'initial', initial)) for assertion in assertions[1:-1]: if not assertion: raise LDAPInvalidFilterException( "consecutive '*' in filter") components.append(SubString().setComponentByName( 'any', assertion)) final = assertions[-1] if final: components.append(SubString().setComponentByName( 'final', final)) subStrings = SubStrings().setComponents(*components) choice = SubstringFilter().setComponents(attribute, subStrings) searchFilter.setComponentByName('substrings', choice) elif u'*' not in value: # simple if operator == u'=': choice = EqualityMatch().setComponents(attribute, value) searchFilter.setComponentByName('equalityMatch', choice) elif operator == u'~=': choice = ApproxMatch().setComponents(attribute, value) searchFilter.setComponentByName('approxMatch', choice) elif operator == u'>=': choice = GreaterOrEqual().setComponents(attribute, value) searchFilter.setComponentByName('greaterOrEqual', choice) elif operator == u'<=': choice = LessOrEqual().setComponents(attribute, value) searchFilter.setComponentByName('lessOrEqual', choice) return searchFilter