[CalendarServer-changes] [3106] PyOpenDirectory/trunk/pysrc/dsquery.py
source_changes at macosforge.org
source_changes at macosforge.org
Sat Oct 4 15:40:17 PDT 2008
Revision: 3106
http://trac.macosforge.org/projects/calendarserver/changeset/3106
Author: cdaboo at apple.com
Date: 2008-10-04 15:40:16 -0700 (Sat, 04 Oct 2008)
Log Message:
-----------
Add OD "NOT" operator for compound searches.
Modified Paths:
--------------
PyOpenDirectory/trunk/pysrc/dsquery.py
Modified: PyOpenDirectory/trunk/pysrc/dsquery.py
===================================================================
--- PyOpenDirectory/trunk/pysrc/dsquery.py 2008-10-03 14:27:27 UTC (rev 3105)
+++ PyOpenDirectory/trunk/pysrc/dsquery.py 2008-10-04 22:40:16 UTC (rev 3106)
@@ -1,5 +1,5 @@
##
-# Copyright (c) 2006-2007 Apple Inc. All rights reserved.
+# Copyright (c) 2006-2008 Apple Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# DRI: Cyrus Daboo, cdaboo at apple.com
##
"""
@@ -54,22 +53,30 @@
AND = "&"
OR = "|"
+ NOT = "!"
def __init__(self, operator, subexpressions):
- assert(operator == expression.AND or operator == expression.OR)
+ assert(operator == expression.AND or operator == expression.OR or operator == expression.NOT)
self.operator = operator
self.subexpressions = subexpressions
def generate(self):
result = ""
- if len(self.subexpressions) > 1:
+ if self.operator == expression.NOT:
result += "("
result += self.operator
- for sub in self.subexpressions:
- result += sub.generate()
- if len(self.subexpressions) > 1:
+ result += self.subexpressions.generate()
result += ")"
+ else:
+ if len(self.subexpressions) > 1:
+ result += "("
+ result += self.operator
+ for sub in self.subexpressions:
+ result += sub.generate()
+ if len(self.subexpressions) > 1:
+ result += ")"
return result
+
# Do some tests
if __name__=='__main__':
@@ -97,6 +104,27 @@
match("ServicesLocator", "GUID:VGUID:calendar", 0xBAD),
)
), "(ServicesLocator=*GUID:VGUID:calendar*)"),
+ (expression(
+ expression.NOT, match(dsattributes.kDSNAttrNickName, "", dsattributes.eDSStartsWith )
+ ), "(!(" + dsattributes.kDSNAttrNickName + "=*))"),
+ (expression(
+ expression.AND, (
+ expression(
+ expression.NOT, match(dsattributes.kDSNAttrNickName, "Billy", dsattributes.eDSContains )
+ ),
+ expression(
+ expression.NOT, match(dsattributes.kDSNAttrEMailAddress, "Billy", dsattributes.eDSContains )
+ ),
+ ),
+ ), "(&(!(" + dsattributes.kDSNAttrNickName + "=*Billy*))(!(" + dsattributes.kDSNAttrEMailAddress + "=*Billy*)))"),
+ (expression(
+ expression.NOT, expression(
+ expression.OR, (
+ match(dsattributes.kDSNAttrNickName, "", dsattributes.eDSStartsWith ),
+ match(dsattributes.kDSNAttrEMailAddress, "", dsattributes.eDSStartsWith ),
+ ),
+ ),
+ ), "(!(|("+dsattributes.kDSNAttrNickName+"=*)("+dsattributes.kDSNAttrEMailAddress+"=*)))"),
)
for expr, result in exprs:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20081004/ce6ad623/attachment.html
More information about the calendarserver-changes
mailing list