[CalendarServer-changes] [12403] twext/trunk/twext/who/ldap
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:23:54 PDT 2014
Revision: 12403
http://trac.calendarserver.org//changeset/12403
Author: wsanchez at apple.com
Date: 2014-01-20 13:38:20 -0800 (Mon, 20 Jan 2014)
Log Message:
-----------
More wild cards.
Modified Paths:
--------------
twext/trunk/twext/who/ldap/_service.py
twext/trunk/twext/who/ldap/test/test_service.py
Modified: twext/trunk/twext/who/ldap/_service.py
===================================================================
--- twext/trunk/twext/who/ldap/_service.py 2014-01-20 20:53:35 UTC (rev 12402)
+++ twext/trunk/twext/who/ldap/_service.py 2014-01-20 21:38:20 UTC (rev 12403)
@@ -335,7 +335,7 @@
def _recordsFromQueryString(self, queryString):
connection = yield self._connect()
- self.log.debug("Performing LDAP query: {query}", query=queryString)
+ self.log.info("Performing LDAP query: {query}", query=queryString)
try:
reply = connection.search_s(
Modified: twext/trunk/twext/who/ldap/test/test_service.py
===================================================================
--- twext/trunk/twext/who/ldap/test/test_service.py 2014-01-20 20:53:35 UTC (rev 12402)
+++ twext/trunk/twext/who/ldap/test/test_service.py 2014-01-20 21:38:20 UTC (rev 12403)
@@ -76,22 +76,6 @@
def setUp(self):
- def parse_expression(
- self, upcall=MockLDAPFilterTest._parse_expression
- ):
- try:
- # Try the stock implementation first.
- return upcall(self)
-
- except MockLDAPUnsupportedOp as e:
- if (
- len(e.args) == 1 and
- e.args[0].startswith(u"Wildcard matches are not supported")
- ):
- return mockldap_parse_wildcard_expression(self)
-
- raise
-
def matches(self, dn, attrs, upcall=MockLDAPFilterTest.matches):
if upcall(self, dn, attrs):
return True
@@ -99,8 +83,8 @@
return mockldap_matches(self, dn, attrs)
- self.patch(MockLDAPFilterTest, "_parse_expression", parse_expression)
- self.patch(MockLDAPFilterTest, "matches", matches)
+ self.patch(MockLDAPFilterTest, "_parse_expression", mockldap_parse)
+ self.patch(MockLDAPFilterTest, "matches", mockldap_matches)
self.xmlSeedService = xmlService(self.mktemp())
self.mockData = mockDirectoryDataFromXMLService(self.xmlSeedService)
@@ -155,23 +139,6 @@
test_queryNotNoIndex.todo = "?"
- def test_queryCaseInsensitive(self):
- return (
- BaseDirectoryServiceQueryTestMixIn.test_queryCaseInsensitive(self)
- )
-
- test_queryCaseInsensitive.todo = "?"
-
-
- def test_queryCaseInsensitiveNoIndex(self):
- return (
- BaseDirectoryServiceQueryTestMixIn
- .test_queryCaseInsensitiveNoIndex(self)
- )
-
- test_queryCaseInsensitiveNoIndex.todo = "?"
-
-
def test_queryStartsWithNot(self):
return BaseDirectoryServiceQueryTestMixIn.test_queryStartsWithNot(self)
@@ -196,24 +163,6 @@
test_queryStartsWithNotNoIndex.todo = "?"
- def test_queryStartsWithCaseInsensitive(self):
- return (
- BaseDirectoryServiceQueryTestMixIn
- .test_queryStartsWithCaseInsensitive(self)
- )
-
- test_queryStartsWithCaseInsensitive.todo = "?"
-
-
- def test_queryStartsWithCaseInsensitiveNoIndex(self):
- return (
- BaseDirectoryServiceQueryTestMixIn
- .test_queryStartsWithCaseInsensitiveNoIndex(self)
- )
-
- test_queryStartsWithCaseInsensitiveNoIndex.todo = "?"
-
-
def test_queryContainsNot(self):
return BaseDirectoryServiceQueryTestMixIn.test_queryContainsNot(self)
@@ -229,25 +178,7 @@
test_queryContainsNotNoIndex.todo = "?"
- def test_queryContainsCaseInsensitive(self):
- return (
- BaseDirectoryServiceQueryTestMixIn
- .test_queryContainsCaseInsensitive(self)
- )
- test_queryContainsCaseInsensitive.todo = "?"
-
-
- def test_queryContainsCaseInsensitiveNoIndex(self):
- return (
- BaseDirectoryServiceQueryTestMixIn
- .test_queryContainsCaseInsensitiveNoIndex(self)
- )
-
- test_queryContainsCaseInsensitiveNoIndex.todo = "?"
-
-
-
class DirectoryServiceConnectionTestMixIn(object):
@inlineCallbacks
def test_connect_defaults(self):
@@ -437,7 +368,7 @@
last = None
-def mockldap_parse_wildcard_expression(self):
+def mockldap_parse(self):
match = self.TEST_RE.match(self.content)
if match is None:
@@ -453,77 +384,88 @@
u"Operation %r is not supported" % (self.op,)
)
- if (u"*" not in valueExpression):
- raise NotImplementedError(u"I only deal with wild cards")
+ def unescape(value):
+ return self.UNESCAPE_RE.sub(lambda m: chr(int(m.group(1), 16)), value)
- values = []
+ if (u"*" in valueExpression):
+ # Wild card expression
- for value in valueExpression.split(u"*"):
- # Resolve all escaped characters
- values.append(self.UNESCAPE_RE.sub(
- lambda m: chr(int(m.group(1), 16)),
- value
- ))
+ values = [unescape(value) for value in valueExpression.split(u"*")]
- exp = WildcardExpression()
+ exp = WildcardExpression()
- if not valueExpression.startswith(u"*"):
- exp.first = values.pop(0)
+ if not valueExpression.startswith(u"*"):
+ exp.first = values.pop(0)
- if not valueExpression.endswith(u"*"):
- exp.last = values.pop(-1)
+ if not valueExpression.endswith(u"*"):
+ exp.last = values.pop(-1)
- exp.middle = values
+ exp.middle = values
- self.value = exp
+ self.value = exp
+ else:
+ self.value = unescape(valueExpression)
-def mockldap_matches(self, dn, attrs):
- exp = self.value
- if not isinstance(exp, WildcardExpression):
- return False
-
+def mockldap_matches(self, dn, attrs):
values = attrs.get(self.attr)
if values is None:
return False
- for value in values:
- start = 0
- end = len(value)
+ if type(values) is unicode:
+ values = [values]
- if exp.first is not None:
- if not value.startswith(exp.first):
- continue
- start = len(exp.first)
+ # Case insensitive? Always true.
+ if True:
+ normalize = lambda s: s.lower()
+ else:
+ normalize = lambda s: s
- if exp.last is not None:
- if not value[start:].endswith(exp.last):
- continue
- end -= len(exp.last)
+ if isinstance(self.value, WildcardExpression):
+ def match_substrings_in_order(substrings, value, start, end):
+ for substring in substrings:
+ if not substring:
+ continue
- if exp.middle:
- if not match_substrings_in_order(exp.middle, value, start, end):
- continue
+ i = value.find(substring, start, end)
+ if i == -1:
+ # Match fails for this substring
+ return False
- return True
+ # Move start up past this substring substring before testing
+ # the next substring
+ start = i + len(substring)
- return False
+ # No mismatches
+ return True
+ for value in values:
+ value = normalize(value)
-def match_substrings_in_order(substrings, value, start, end):
- for substring in substrings:
- if not substring:
- continue
+ start = 0
+ end = len(value)
- i = value.find(substring, start, end)
- if i == -1:
- # Match fails for this substring
- return False
+ if self.value.first is not None:
+ if not value.startswith(normalize(self.value.first)):
+ continue
+ start = len(self.value.first)
- # Move start up past this substring substring before testing the next
- start = i + len(substring)
+ if self.value.last is not None:
+ if not value[start:].endswith(normalize(self.value.last)):
+ continue
+ end -= len(self.value.last)
- # No mismatches
- return True
+ if self.value.middle:
+ if not match_substrings_in_order(
+ (normalize(s) for s in self.value.middle),
+ value, start, end
+ ):
+ continue
+
+ return True
+
+ return False
+
+ return normalize(self.value) in (normalize(s) for s in values)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/1f237ec1/attachment.html>
More information about the calendarserver-changes
mailing list