[CalendarServer-changes] [13125] CalendarServer/branches/users/sagen/move2who-4

source_changes at macosforge.org source_changes at macosforge.org
Wed Apr 2 11:59:40 PDT 2014


Revision: 13125
          http://trac.calendarserver.org//changeset/13125
Author:   sagen at apple.com
Date:     2014-04-02 11:59:40 -0700 (Wed, 02 Apr 2014)
Log Message:
-----------
Handle GUID searches better in recordsMatchingFields

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/principal.py
    CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/method/report.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/dps/server.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py
    CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py

Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/principal.py	2014-04-02 18:53:05 UTC (rev 13124)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/principal.py	2014-04-02 18:59:40 UTC (rev 13125)
@@ -117,7 +117,7 @@
     cua = normalizeCUAddr(origCUAddr)
 
     if cua.startswith("urn:uuid:"):
-        return "guid", cua[9:]
+        return "guid", uuid.UUID(cua[9:])
 
     elif cua.startswith("mailto:"):
         return "emailAddresses", cua[7:]

Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/method/report.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/method/report.py	2014-04-02 18:53:05 UTC (rev 13124)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/method/report.py	2014-04-02 18:59:40 UTC (rev 13125)
@@ -117,8 +117,8 @@
         #
         # Requested report is not supported.
         #
-        log.error("Unsupported REPORT %s for resource %s (no method %s)"
-                  % (encodeXMLName(namespace, name), self, method_name))
+        log.error("Unsupported REPORT {name} for resource {resource} (no method {method})",
+                  name=encodeXMLName(namespace, name), resource=self, method=method_name)
 
         raise HTTPError(ErrorResponse(
             responsecode.FORBIDDEN,

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py	2014-04-02 18:53:05 UTC (rev 13124)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py	2014-04-02 18:59:40 UTC (rev 13125)
@@ -262,6 +262,10 @@
     ):
         newFields = []
         for fieldName, searchTerm, matchFlags, matchType in fields:
+
+            if isinstance(searchTerm, uuid.UUID):
+                searchTerm = unicode(searchTerm)
+
             newFields.append(
                 (
                     fieldName.encode("utf-8"),

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/dps/server.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/dps/server.py	2014-04-02 18:53:05 UTC (rev 13124)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/dps/server.py	2014-04-02 18:59:40 UTC (rev 13125)
@@ -190,6 +190,14 @@
         for fieldName, searchTerm, matchFlags, matchType in fields:
             fieldName = fieldName.decode("utf-8")
             searchTerm = searchTerm.decode("utf-8")
+            try:
+                field = self._directory.fieldName.lookupByName(fieldName)
+            except ValueError:
+                field = None
+            if field:
+                valueType = self._directory.fieldName.valueType(field)
+                if valueType is uuid.UUID:
+                    searchTerm = uuid.UUID(searchTerm)
             matchFlags = MatchFlags.lookupByName(matchFlags.decode("utf-8"))
             matchType = MatchType.lookupByName(matchType.decode("utf-8"))
             newFields.append((fieldName, searchTerm, matchFlags, matchType))

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py	2014-04-02 18:53:05 UTC (rev 13124)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py	2014-04-02 18:59:40 UTC (rev 13125)
@@ -15,6 +15,7 @@
 ##
 
 import os
+import uuid
 
 from twext.who.expression import (
     Operand, MatchType, MatchFlags, MatchExpression
@@ -213,6 +214,23 @@
 
 
     @inlineCallbacks
+    def test_recordsMatchingFields_nonUnicode(self):
+        fields = (
+            (u"guid", uuid.UUID("A3B1158F-0564-4F5B-81E4-A89EA5FF81B0"),
+                MatchFlags.caseInsensitive, MatchType.equals),
+        )
+        records = (yield self.directory.recordsMatchingFields(
+            fields, operand=Operand.OR, recordType=None
+        ))
+        matchingShortNames = set()
+        for r in records:
+            for shortName in r.shortNames:
+                matchingShortNames.add(shortName)
+        self.assertTrue("dre" in matchingShortNames)
+        self.assertFalse("wsanchez" in matchingShortNames)
+
+
+    @inlineCallbacks
     def test_recordsFromMatchExpression(self):
         expression = MatchExpression(
             FieldName.uid,

Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py	2014-04-02 18:53:05 UTC (rev 13124)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py	2014-04-02 18:59:40 UTC (rev 13125)
@@ -151,8 +151,6 @@
                     fieldName=fieldName
                 )
                 continue
-            if self.fieldName.valueType(field) is uuid.UUID and isinstance(searchTerm, unicode):
-                searchTerm = uuid.UUID(searchTerm)
             subExpression = MatchExpression(
                 field,
                 searchTerm,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140402/b22c0591/attachment-0001.html>


More information about the calendarserver-changes mailing list