[CalendarServer-changes] [12160] twext/trunk/twext/who/opendirectory/_service.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:20:39 PDT 2014


Revision: 12160
          http://trac.calendarserver.org//changeset/12160
Author:   wsanchez at apple.com
Date:     2013-12-19 18:05:41 -0800 (Thu, 19 Dec 2013)
Log Message:
-----------
Handle uid, guid better.

Modified Paths:
--------------
    twext/trunk/twext/who/opendirectory/_service.py

Modified: twext/trunk/twext/who/opendirectory/_service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/_service.py	2013-12-20 00:45:34 UTC (rev 12159)
+++ twext/trunk/twext/who/opendirectory/_service.py	2013-12-20 02:05:41 UTC (rev 12160)
@@ -364,8 +364,22 @@
                 raise QueryNotSupportedError(
                     "Unknown match type: {0}".format(matchType)
                 )
-            odAttr = ODAttribute.fromFieldName(expression.fieldName).value
-            # FIXME: Shouldn't the attr and value be quoted somehow?
+
+            if expression.fieldName is self.fieldName.uid:
+                odAttr = ODAttribute.guid.value
+                value = expression.fieldValue
+            else:
+                odAttr = ODAttribute.fromFieldName(expression.fieldName)
+                if odAttr is None:
+                    raise OpenDirectoryQueryError(
+                        "Unknown field name: {0}".format(expression.fieldName)
+                    )
+                odAttr = odAttr.value
+                value = expression.fieldValue
+
+            value = unicode(value)
+
+            # FIXME: Shouldn't the value be quoted somehow?
             queryString = {
                 ODMatchType.equals.value: u"({attr}={value})",
                 ODMatchType.startsWith.value: u"({attr}={value}*)",
@@ -375,17 +389,20 @@
                 ODMatchType.greaterThan.value: u"({attr}>{value})",
             }.get(matchType.value, u"({attr}=*{value}*)").format(
                 attr=odAttr,
-                value=expression.fieldValue
+                value=value
             )
 
         elif isinstance(expression, CompoundExpression):
             queryString = u""
             operand = u"&" if expression.operand is Operand.AND else u"|"
+
             if len(expression.expressions) > 1:
                 queryString += u"("
                 queryString += operand
+
             for subExpression in expression.expressions:
                 queryString += self._queryStringFromExpression(subExpression)
+
             if len(expression.expressions) > 1:
                 queryString += u")"
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/67b645db/attachment.html>


More information about the calendarserver-changes mailing list