[CalendarServer-changes] [10741] CalendarServer/trunk/twext/who
source_changes at macosforge.org
source_changes at macosforge.org
Fri Feb 15 13:19:17 PST 2013
Revision: 10741
http://trac.calendarserver.org//changeset/10741
Author: wsanchez at apple.com
Date: 2013-02-15 13:19:17 -0800 (Fri, 15 Feb 2013)
Log Message:
-----------
Handle QueryFlags.caseInsensitive
Modified Paths:
--------------
CalendarServer/trunk/twext/who/test/test_xml.py
CalendarServer/trunk/twext/who/xml.py
Modified: CalendarServer/trunk/twext/who/test/test_xml.py
===================================================================
--- CalendarServer/trunk/twext/who/test/test_xml.py 2013-02-15 21:10:44 UTC (rev 10740)
+++ CalendarServer/trunk/twext/who/test/test_xml.py 2013-02-15 21:19:17 UTC (rev 10741)
@@ -403,9 +403,7 @@
))
self.assertRecords(records, ("__sagen__",))
- test_queryCaseInsensitive.todo = "Not implemented."
-
@inlineCallbacks
def test_queryCaseInsensitiveNoIndex(self):
service = self._testService()
@@ -527,9 +525,7 @@
))
self.assertRecords(records, ("__wsanchez__",))
- test_queryStartsWithCaseInsensitive.todo = "Not implemented."
-
@inlineCallbacks
def test_queryStartsWithCaseInsensitiveNoIndex(self):
service = self._testService()
@@ -635,9 +631,7 @@
))
self.assertRecords(records, ("__wsanchez__",))
- test_queryContainsCaseInsensitive.todo = "Not implemented."
-
@inlineCallbacks
def test_queryContainsCaseInsensitiveNoIndex(self):
service = self._testService()
Modified: CalendarServer/trunk/twext/who/xml.py
===================================================================
--- CalendarServer/trunk/twext/who/xml.py 2013-02-15 21:10:44 UTC (rev 10740)
+++ CalendarServer/trunk/twext/who/xml.py 2013-02-15 21:19:17 UTC (rev 10741)
@@ -358,32 +358,42 @@
@param expression: an expression
@type expression: L{object}
"""
- fieldIndex = self.index[expression.fieldName]
- matchValue = expression.fieldValue
-
+ #
+ # Flags
+ #
predicate = lambda x: x
+ normalize = lambda x: x
if expression.flags is not None:
for flag in iterFlags(expression.flags):
if flag == QueryFlags.NOT:
predicate = lambda x: not x
elif flag == QueryFlags.caseInsensitive:
- raise NotImplementedError("Unknown query flag: %s" % (describe(flag),))
+ normalize = lambda x: x.lower()
else:
raise NotImplementedError("Unknown query flag: %s" % (describe(flag),))
+ #
+ # Find matching index keys
+ #
+ fieldIndex = self.index[expression.fieldName]
+ matchValue = normalize(expression.fieldValue)
+
if expression.matchType == MatchType.startsWith:
- indexKeys = (key for key in fieldIndex if predicate(key.startswith(matchValue)))
+ indexKeys = (key for key in fieldIndex if predicate(normalize(key).startswith(matchValue)))
elif expression.matchType == MatchType.contains:
- indexKeys = (key for key in fieldIndex if predicate(matchValue in key))
+ indexKeys = (key for key in fieldIndex if predicate(matchValue in normalize(key)))
elif expression.matchType == MatchType.equals:
if predicate(True):
indexKeys = (matchValue,)
else:
- indexKeys = (key for key in fieldIndex if key != matchValue)
+ indexKeys = (key for key in fieldIndex if normalize(key) != matchValue)
else:
raise NotImplementedError("Unknown match type: %s" % (describe(expression.matchType),))
+ #
+ # Lookup and return the results
+ #
matchingRecords = set()
for key in indexKeys:
matchingRecords |= fieldIndex.get(key, frozenset())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130215/52150cb1/attachment-0001.html>
More information about the calendarserver-changes
mailing list