[CalendarServer-changes] [10738] CalendarServer/trunk/twext/who/xml.py
source_changes at macosforge.org
source_changes at macosforge.org
Fri Feb 15 12:43:04 PST 2013
Revision: 10738
http://trac.calendarserver.org//changeset/10738
Author: wsanchez at apple.com
Date: 2013-02-15 12:43:04 -0800 (Fri, 15 Feb 2013)
Log Message:
-----------
Add NOT handling
Modified Paths:
--------------
CalendarServer/trunk/twext/who/xml.py
Modified: CalendarServer/trunk/twext/who/xml.py
===================================================================
--- CalendarServer/trunk/twext/who/xml.py 2013-02-15 20:42:46 UTC (rev 10737)
+++ CalendarServer/trunk/twext/who/xml.py 2013-02-15 20:43:04 UTC (rev 10738)
@@ -39,11 +39,11 @@
from twext.who.idirectory import DirectoryServiceError
from twext.who.idirectory import NoSuchRecordError, UnknownRecordTypeError
from twext.who.idirectory import RecordType, FieldName as BaseFieldName
-from twext.who.idirectory import MatchType
+from twext.who.idirectory import MatchType, QueryFlags
from twext.who.idirectory import DirectoryQueryMatchExpression
from twext.who.directory import DirectoryService as BaseDirectoryService
from twext.who.directory import DirectoryRecord as BaseDirectoryRecord
-from twext.who.util import MergedConstants, describe
+from twext.who.util import MergedConstants, describe, iterFlags
@@ -361,15 +361,26 @@
fieldIndex = self.index[expression.fieldName]
matchValue = expression.fieldValue
+ predicate = lambda x: x
+
if expression.flags is not None:
- raise NotImplementedError("Unknown query flags: %s" % (expression.flags,))
+ 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),))
+ else:
+ raise NotImplementedError("Unknown query flag: %s" % (describe(flag),))
if expression.matchType == MatchType.startsWith:
- indexKeys = (key for key in fieldIndex if key.startswith(matchValue))
+ indexKeys = (key for key in fieldIndex if predicate(key.startswith(matchValue)))
elif expression.matchType == MatchType.contains:
- indexKeys = (key for key in fieldIndex if matchValue in key)
+ indexKeys = (key for key in fieldIndex if predicate(matchValue in key))
elif expression.matchType == MatchType.equals:
- indexKeys = (expression.fieldValue,)
+ if predicate(True):
+ indexKeys = (matchValue,)
+ else:
+ indexKeys = (key for key in fieldIndex if key != matchValue)
else:
raise NotImplementedError("Unknown match type: %s" % (describe(expression.matchType),))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130215/71f94fb6/attachment-0001.html>
More information about the calendarserver-changes
mailing list