def test_item_substring_final(self): text = r'*foo' filt = pureldap.LDAPFilter_substrings( type='cn', substrings=[pureldap.LDAPFilter_substrings_final('foo'), ]) self.assertEquals(ldapfilter.parseMaybeSubstring('cn', text), filt)
def test_item_substring_final(self): text = r'(cn=*foo)' filt = pureldap.LDAPFilter_substrings( type='cn', substrings=[pureldap.LDAPFilter_substrings_final('foo'), ]) self.assertEquals(ldapfilter.parseFilter(text), filt) self.assertEquals(filt.asText(), text)
def test_item_substring_iaf(self): text = r'foo*bar*baz' filt = pureldap.LDAPFilter_substrings( type='cn', substrings=[pureldap.LDAPFilter_substrings_initial('foo'), pureldap.LDAPFilter_substrings_any('bar'), pureldap.LDAPFilter_substrings_final('baz'), ]) self.assertEquals(ldapfilter.parseMaybeSubstring('cn', text), filt)
def test_item_substring_iaf(self): text = r'(cn=foo*bar*baz)' filt = pureldap.LDAPFilter_substrings( type='cn', substrings=[pureldap.LDAPFilter_substrings_initial('foo'), pureldap.LDAPFilter_substrings_any('bar'), pureldap.LDAPFilter_substrings_final('baz'), ]) self.assertEquals(ldapfilter.parseFilter(text), filt) self.assertEquals(filt.asText(), text)
def test_substrings_match2(self): o = inmemory.ReadOnlyInMemoryLDAPEntry(dn='cn=foo,dc=example,dc=com', attributes={ 'objectClass': ['a', 'b'], 'aValue': ['abcde'], 'bValue': ['b'], }) result = o.match( pureldap.LDAPFilter_substrings( type='aValue', substrings=[ pureldap.LDAPFilter_substrings_initial('a'), pureldap.LDAPFilter_substrings_final('e'), ])) self.assertEquals(result, True)
def test_andornot(self): text = r'(&(!(|(cn=foo)(cn=bar)))(sn=a*b*c*d))' filt = pureldap.LDAPFilter_and([ pureldap.LDAPFilter_not( pureldap.LDAPFilter_or([ pureldap.LDAPFilter_equalityMatch( attributeDesc=pureldap.LDAPAttributeDescription(value='cn'), assertionValue=pureldap.LDAPAssertionValue(value='foo')), pureldap.LDAPFilter_equalityMatch( attributeDesc=pureldap.LDAPAttributeDescription(value='cn'), assertionValue=pureldap.LDAPAssertionValue(value='bar')), ])), pureldap.LDAPFilter_substrings( type='sn', substrings=[pureldap.LDAPFilter_substrings_initial('a'), pureldap.LDAPFilter_substrings_any('b'), pureldap.LDAPFilter_substrings_any('c'), pureldap.LDAPFilter_substrings_final('d'), ])]) self.assertEquals(ldapfilter.parseFilter(text), filt) self.assertEquals(filt.asText(), text)
simple.setParseAction(_p_simple) present = attr + "=*" present.setParseAction(lambda s, l, t: pureldap.LDAPFilter_present(t[0])) initial = copy.copy(value) initial.setParseAction( lambda s, l, t: pureldap.LDAPFilter_substrings_initial(t[0])) initial.setName('initial') any_value = value + Suppress(Literal("*")) any_value.setParseAction( lambda s, l, t: pureldap.LDAPFilter_substrings_any(t[0])) any = Suppress(Literal("*")) + ZeroOrMore(any_value) any.setName('any') final = copy.copy(value) final.setName('final') final.setParseAction( lambda s, l, t: pureldap.LDAPFilter_substrings_final(t[0])) substring = attr + Suppress( Literal("=")) + Group(Optional(initial) + any + Optional(final)) substring.setName('substring') def _p_substring(s, l, t): attrtype, substrings = t return pureldap.LDAPFilter_substrings(type=attrtype, substrings=substrings) substring.setParseAction(_p_substring) keystring = Word(string.ascii_letters, string.ascii_letters + string.digits + ';-') keystring.setName('keystring')