[CalendarServer-changes] [12400] twext/trunk/twext/who/ldap/test/test_service.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:21:38 PDT 2014


Revision: 12400
          http://trac.calendarserver.org//changeset/12400
Author:   wsanchez at apple.com
Date:     2014-01-20 12:28:04 -0800 (Mon, 20 Jan 2014)
Log Message:
-----------
Handle more wild cards.

Modified Paths:
--------------
    twext/trunk/twext/who/ldap/test/test_service.py

Modified: twext/trunk/twext/who/ldap/test/test_service.py
===================================================================
--- twext/trunk/twext/who/ldap/test/test_service.py	2014-01-20 20:10:14 UTC (rev 12399)
+++ twext/trunk/twext/who/ldap/test/test_service.py	2014-01-20 20:28:04 UTC (rev 12400)
@@ -214,21 +214,6 @@
     test_queryStartsWithCaseInsensitiveNoIndex.todo = "?"
 
 
-    def test_queryContains(self):
-        return BaseDirectoryServiceQueryTestMixIn.test_queryContains(self)
-
-    test_queryContains.todo = "?"
-
-
-    def test_queryContainsNoIndex(self):
-        return (
-            BaseDirectoryServiceQueryTestMixIn
-            .test_queryContainsNoIndex(self)
-        )
-
-    test_queryContainsNoIndex.todo = "?"
-
-
     def test_queryContainsNot(self):
         return BaseDirectoryServiceQueryTestMixIn.test_queryContainsNot(self)
 
@@ -505,22 +490,40 @@
         return False
 
     for value in values:
+        start = 0
+        end = len(value)
+
         if exp.first is not None:
             if not value.startswith(exp.first):
                 continue
-            value = value[len(exp.first):]
+            start = len(exp.first)
 
         if exp.last is not None:
-            if not value.endswith(exp.last):
+            if not value[start:].endswith(exp.last):
                 continue
-            value = value[:-len(exp.last)]
+            end -= len(exp.last)
 
         if exp.middle:
-            for substr in exp.middle:
-                if not substr:
-                    continue
-                raise NotImplementedError("middle: {0}".format(exp.middle))
+            if not match_substrings_in_order(exp.middle, value, start, end):
+                continue
 
         return True
 
     return False
+
+
+def match_substrings_in_order(substrings, value, start, end):
+    for substring in substrings:
+        if not substring:
+            continue
+
+        i = value.find(substring, start, end)
+        if i == -1:
+            # Match fails for this substring
+            return False
+
+        # Move start up past this substring substring before testing the next
+        start = i + len(substring)
+
+    # No mismatches
+    return True
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/b89fa5b2/attachment.html>


More information about the calendarserver-changes mailing list