[CalendarServer-changes] [12858] CalendarServer/branches/users/sagen/move2who/txdav

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 7 17:31:09 PST 2014


Revision: 12858
          http://trac.calendarserver.org//changeset/12858
Author:   sagen at apple.com
Date:     2014-03-07 17:31:09 -0800 (Fri, 07 Mar 2014)
Log Message:
-----------
Move common "calendar" stuff to txdav/who/directory.py

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/move2who/txdav/dps/client.py
    CalendarServer/branches/users/sagen/move2who/txdav/dps/server.py
    CalendarServer/branches/users/sagen/move2who/txdav/who/directory.py

Modified: CalendarServer/branches/users/sagen/move2who/txdav/dps/client.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who/txdav/dps/client.py	2014-03-08 00:53:53 UTC (rev 12857)
+++ CalendarServer/branches/users/sagen/move2who/txdav/dps/client.py	2014-03-08 01:31:09 UTC (rev 12858)
@@ -104,13 +104,6 @@
 
         # print("FIELDS", serializedFields)
 
-        # MOVE2WHO -- existing code assumes record.emailAddresses always exists,
-        # so adding this here, but perhaps we should change the behavior in
-        # twext.who itself:
-        # Add default empty list of email addresses
-        if self.fieldName.emailAddresses.name not in serializedFields:
-            serializedFields[self.fieldName.emailAddresses.name] = []
-
         fields = {}
         for fieldName, value in serializedFields.iteritems():
             try:
@@ -233,39 +226,6 @@
         )
 
 
-    # def listRecords(self, recordType):
-    #     # MOVE2WHO
-    #     return []
-
-
-    @inlineCallbacks
-    def recordWithCalendarUserAddress(self, address):
-        # FIXME: Circular
-        from txdav.caldav.datastore.scheduling.cuaddress import normalizeCUAddr
-        address = normalizeCUAddr(address)
-        record = None
-        if address.startswith("urn:uuid:"):
-            guid = address[9:]
-            record = yield self.recordWithGUID(guid)
-        elif address.startswith("mailto:"):
-            records = yield self.recordsWithEmailAddress(address[7:])
-            if records:
-                returnValue(records[0])
-            else:
-                returnValue(None)
-        elif address.startswith("/principals/"):
-            parts = address.split("/")
-            if len(parts) == 4:
-                if parts[2] == "__uids__":
-                    guid = parts[3]
-                    record = yield self.recordWithGUID(guid)
-                else:
-                    recordType = self.fieldName.lookupByName(parts[2])
-                    record = yield self.recordWithShortName(recordType, parts[3])
-
-        returnValue(record if record and record.hasCalendars else None)
-
-
     def recordsMatchingTokens(self, tokens, context=None, limitResults=50,
                               timeoutSeconds=10):
         return self._call(
@@ -277,14 +237,7 @@
 
 
 
-    # FIXME: Existing code assumes record type names are plural. Is there any
-    # reason to maintain backwards compatibility?  I suppose there could be
-    # scripts referring to record type of "users", "locations"
-    def recordTypeToOldName(self, recordType):
-        return recordType.name + u"s"
 
-    def oldNameToRecordType(self, oldName):
-        return self.recordType.lookupByName(oldName[:-1])
 
 
 

Modified: CalendarServer/branches/users/sagen/move2who/txdav/dps/server.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who/txdav/dps/server.py	2014-03-08 00:53:53 UTC (rev 12857)
+++ CalendarServer/branches/users/sagen/move2who/txdav/dps/server.py	2014-03-08 01:31:09 UTC (rev 12858)
@@ -21,9 +21,6 @@
 from calendarserver.tap.util import getDBPool, storeFromConfig
 from twext.python.log import Logger
 from twext.who.aggregate import DirectoryService as AggregateDirectoryService
-from twext.who.expression import (
-    MatchType, Operand, MatchExpression, CompoundExpression, MatchFlags
-)
 from twext.who.idirectory import RecordType
 from twext.who.ldap import DirectoryService as LDAPDirectoryService
 from twisted.application import service
@@ -179,34 +176,10 @@
     @inlineCallbacks
     def recordsMatchingTokens(self, tokens, context=None):
         tokens = [t.decode("utf-8") for t in tokens]
-
         log.debug("RecordsMatchingTokens: {t}", t=(", ".join(tokens)))
-
-        fields = [
-            ("fullNames", MatchType.contains),
-            ("emailAddresses", MatchType.startsWith),
-        ]
-        outer = []
-        for token in tokens:
-            inner = []
-            for name, matchType in fields:
-                inner.append(
-                    MatchExpression(
-                        self._directory.fieldName.lookupByName(name),
-                        token,
-                        matchType,
-                        MatchFlags.caseInsensitive
-                    )
-                )
-            outer.append(
-                CompoundExpression(
-                    inner,
-                    Operand.OR
-                )
-            )
-        expression = CompoundExpression(outer, Operand.AND)
-        records = yield self._directory.recordsFromExpression(expression)
-
+        records = yield self._directory.recordsMatchingTokens(
+            tokens, context=context
+        )
         fieldsList = []
         for record in records:
             fieldsList.append(self.recordToDict(record))

Modified: CalendarServer/branches/users/sagen/move2who/txdav/who/directory.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who/txdav/who/directory.py	2014-03-08 00:53:53 UTC (rev 12857)
+++ CalendarServer/branches/users/sagen/move2who/txdav/who/directory.py	2014-03-08 01:31:09 UTC (rev 12858)
@@ -20,6 +20,10 @@
 
 
 import uuid
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twext.who.expression import (
+    MatchType, Operand, MatchExpression, CompoundExpression, MatchFlags
+)
 
 
 __all__ = [
@@ -41,9 +45,76 @@
         self.principalCollection = principalCollection
 
 
+    @inlineCallbacks
+    def recordWithCalendarUserAddress(self, address):
+        # FIXME: Circular
+        from txdav.caldav.datastore.scheduling.cuaddress import normalizeCUAddr
+        address = normalizeCUAddr(address)
+        record = None
+        if address.startswith("urn:uuid:"):
+            guid = address[9:]
+            record = yield self.recordWithGUID(guid)
+        elif address.startswith("mailto:"):
+            records = yield self.recordsWithEmailAddress(address[7:])
+            if records:
+                returnValue(records[0])
+            else:
+                returnValue(None)
+        elif address.startswith("/principals/"):
+            parts = address.split("/")
+            if len(parts) == 4:
+                if parts[2] == "__uids__":
+                    guid = parts[3]
+                    record = yield self.recordWithGUID(guid)
+                else:
+                    recordType = self.fieldName.lookupByName(parts[2])
+                    record = yield self.recordWithShortName(recordType, parts[3])
+
+        returnValue(record if record and record.hasCalendars else None)
+
+
+    def recordsMatchingTokens(self, tokens, context=None, limitResults=50,
+                              timeoutSeconds=10):
+        fields = [
+            ("fullNames", MatchType.contains),
+            ("emailAddresses", MatchType.startsWith),
+        ]
+        outer = []
+        for token in tokens:
+            inner = []
+            for name, matchType in fields:
+                inner.append(
+                    MatchExpression(
+                        self.fieldName.lookupByName(name),
+                        token,
+                        matchType,
+                        MatchFlags.caseInsensitive
+                    )
+                )
+            outer.append(
+                CompoundExpression(
+                    inner,
+                    Operand.OR
+                )
+            )
+        expression = CompoundExpression(outer, Operand.AND)
+        return self.recordsFromExpression(expression)
+
+
+    # FIXME: Existing code assumes record type names are plural. Is there any
+    # reason to maintain backwards compatibility?  I suppose there could be
+    # scripts referring to record type of "users", "locations"
+    def recordTypeToOldName(self, recordType):
+        return recordType.name + u"s"
+
+
+    def oldNameToRecordType(self, oldName):
+        return self.recordType.lookupByName(oldName[:-1])
+
+
+
 class CalendarDirectoryRecordMixin(object):
 
-
     @property
     def calendarUserAddresses(self):
         if not self.hasCalendars:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140307/7eb29cd6/attachment-0001.html>


More information about the calendarserver-changes mailing list