<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12571] CalendarServer/trunk/txdav/dps</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12571">12571</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-02-05 09:44:38 -0800 (Wed, 05 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Break dps modules into client and server</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavdpsclientpy">CalendarServer/trunk/txdav/dps/client.py</a></li>
<li><a href="#CalendarServertrunktxdavdpsservicepy">CalendarServer/trunk/txdav/dps/service.py</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavdpscommandspy">CalendarServer/trunk/txdav/dps/commands.py</a></li>
<li><a href="#CalendarServertrunktxdavdpsserverpy">CalendarServer/trunk/txdav/dps/server.py</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#CalendarServertrunktxdavdpsprotocolpy">CalendarServer/trunk/txdav/dps/protocol.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktxdavdpsclientpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/dps/client.py (12570 => 12571)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/client.py        2014-02-05 01:04:49 UTC (rev 12570)
+++ CalendarServer/trunk/txdav/dps/client.py        2014-02-05 17:44:38 UTC (rev 12571)
</span><span class="lines">@@ -14,19 +14,179 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><span class="cx"> 
</span><del>-from txdav.dps.service import DirectoryService
</del><span class="cx"> from twext.who.idirectory import RecordType
</span><span class="cx"> from twext.python.log import Logger
</span><span class="cx"> from twisted.internet import reactor
</span><del>-from twisted.internet.defer import inlineCallbacks
</del><ins>+from twext.who.directory import DirectoryService as BaseDirectoryService
+from twext.who.directory import DirectoryRecord as BaseDirectoryRecord
+from twext.who.util import ConstantsContainer
+import twext.who.idirectory
+import txdav.who.idirectory
</ins><span class="cx"> 
</span><ins>+from zope.interface import implementer
+
+from txdav.dps.commands import (
+    RecordWithShortNameCommand, RecordWithUIDCommand,
+    RecordWithGUIDCommand, RecordsWithRecordTypeCommand,
+    RecordsWithEmailAddressCommand
+)
+
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.internet.protocol import ClientCreator
+from twisted.protocols import amp
+import cPickle as pickle
+
</ins><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+##
+## Client implementation of Directory Proxy Service
+##
+
+
+@implementer(twext.who.idirectory.IDirectoryService)
+class DirectoryService(BaseDirectoryService):
+    &quot;&quot;&quot;
+    Client side of directory proxy
+    &quot;&quot;&quot;
+
+    recordType = ConstantsContainer(
+        (twext.who.idirectory.RecordType,
+         txdav.who.idirectory.RecordType)
+    )
+
+
+    def _dictToRecord(self, serializedFields):
+        &quot;&quot;&quot;
+        This to be replaced by something awesome
+        &quot;&quot;&quot;
+        if not serializedFields:
+            return None
+
+        fields = {}
+        for fieldName, value in serializedFields.iteritems():
+            try:
+                field = self.fieldName.lookupByName(fieldName)
+            except ValueError:
+                # unknown field
+                pass
+            else:
+                fields[field] = value
+        fields[self.fieldName.recordType] = self.recordType.user
+        return DirectoryRecord(self, fields)
+
+
+    def _processSingleRecord(self, result):
+        serializedFields = pickle.loads(result['fields'])
+        return self._dictToRecord(serializedFields)
+
+
+    def _processMultipleRecords(self, result):
+        serializedFieldsList = pickle.loads(result['fieldsList'])
+        results = []
+        for serializedFields in serializedFieldsList:
+            record = self._dictToRecord(serializedFields)
+            if record is not None:
+                results.append(record)
+        return results
+
+
+    @inlineCallbacks
+    def _getConnection(self):
+        # path = config.DirectoryProxy.SocketPath
+        path = &quot;data/Logs/state/directory-proxy.sock&quot;
+        if getattr(self, &quot;_connection&quot;, None) is None:
+            log.debug(&quot;Creating connection&quot;)
+            connection = (yield ClientCreator(reactor, amp.AMP).connectUNIX(path))
+            self._connection = connection
+        else:
+            log.debug(&quot;Already have connection&quot;)
+        returnValue(self._connection)
+
+
+    def recordWithShortName(self, recordType, shortName):
+
+        def _call(ampProto):
+            return ampProto.callRemote(
+                RecordWithShortNameCommand,
+                recordType=recordType.description.encode(&quot;utf-8&quot;),
+                shortName=shortName.encode(&quot;utf-8&quot;)
+            )
+
+        d = self._getConnection()
+        d.addCallback(_call)
+        d.addCallback(self._processSingleRecord)
+        return d
+
+
+    def recordWithUID(self, uid):
+
+        def _call(ampProto):
+            return ampProto.callRemote(
+                RecordWithUIDCommand,
+                uid=uid.encode(&quot;utf-8&quot;)
+            )
+
+        d = self._getConnection()
+        d.addCallback(_call)
+        d.addCallback(self._processSingleRecord)
+        return d
+
+
+    def recordWithGUID(self, guid):
+
+        def _call(ampProto):
+            return ampProto.callRemote(
+                RecordWithGUIDCommand,
+                guid=guid.encode(&quot;utf-8&quot;)
+            )
+
+        d = self._getConnection()
+        d.addCallback(_call)
+        d.addCallback(self._processSingleRecord)
+        return d
+
+
+    def recordsWithRecordType(self, recordType):
+
+        def _call(ampProto):
+            return ampProto.callRemote(
+                RecordsWithRecordTypeCommand,
+                recordType=recordType.description.encode(&quot;utf-8&quot;)
+            )
+
+        d = self._getConnection()
+        d.addCallback(_call)
+        d.addCallback(self._processMultipleRecords)
+        return d
+
+
+    def recordsWithEmailAddress(self, emailAddress):
+
+        def _call(ampProto):
+            return ampProto.callRemote(
+                RecordsWithEmailAddressCommand,
+                emailAddress=emailAddress
+            )
+
+        d = self._getConnection()
+        d.addCallback(_call)
+        d.addCallback(self._processMultipleRecords)
+        return d
+
+
+class DirectoryRecord(BaseDirectoryRecord):
+    pass
+
+
+
+# Test client:
+
+
</ins><span class="cx"> @inlineCallbacks
</span><span class="cx"> def makeEvenBetterRequest():
</span><span class="cx">     ds = DirectoryService(None)
</span><del>-    record = (yield ds.recordWithShortName(RecordType.user, &quot;sagen&quot;))
</del><ins>+    record = (yield ds.recordWithShortName(RecordType.user, &quot;wsanchez&quot;))
</ins><span class="cx">     print(&quot;short name: {r}&quot;.format(r=record))
</span><span class="cx">     record = (yield ds.recordWithUID(&quot;__dre__&quot;))
</span><span class="cx">     print(&quot;uid: {r}&quot;.format(r=record))
</span></span></pre></div>
<a id="CalendarServertrunktxdavdpscommandspy"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/dps/commands.py (0 => 12571)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/commands.py                                (rev 0)
+++ CalendarServer/trunk/txdav/dps/commands.py        2014-02-05 17:44:38 UTC (rev 12571)
</span><span class="lines">@@ -0,0 +1,82 @@
</span><ins>+##
+# Copyright (c) 2014 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from twisted.protocols import amp
+
+
+class RecordWithShortNameCommand(amp.Command):
+    arguments = [
+        ('recordType', amp.String()),
+        ('shortName', amp.String()),
+    ]
+    response = [
+        ('fields', amp.String()),
+    ]
+
+
+class RecordWithUIDCommand(amp.Command):
+    arguments = [
+        ('uid', amp.String()),
+    ]
+    response = [
+        ('fields', amp.String()),
+    ]
+
+
+class RecordWithGUIDCommand(amp.Command):
+    arguments = [
+        ('guid', amp.String()),
+    ]
+    response = [
+        ('fields', amp.String()),
+    ]
+
+
+class RecordsWithRecordTypeCommand(amp.Command):
+    arguments = [
+        ('recordType', amp.String()),
+    ]
+    response = [
+        ('fieldsList', amp.String()),
+    ]
+
+
+class RecordsWithEmailAddressCommand(amp.Command):
+    arguments = [
+        ('emailAddress', amp.String()),
+    ]
+    response = [
+        ('fieldsList', amp.String()),
+    ]
+
+
+class UpdateRecordsCommand(amp.Command):
+    arguments = [
+        ('fieldsList', amp.String()),
+        ('create', amp.Boolean(optional=True)),
+    ]
+    response = [
+        ('success', amp.Boolean()),
+    ]
+
+
+class RemoveRecordsCommand(amp.Command):
+    arguments = [
+        ('uids', amp.ListOf(amp.String())),
+    ]
+    response = [
+        ('success', amp.Boolean()),
+    ]
</ins></span></pre></div>
<a id="CalendarServertrunktxdavdpsprotocolpy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/trunk/txdav/dps/protocol.py (12570 => 12571)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/protocol.py        2014-02-05 01:04:49 UTC (rev 12570)
+++ CalendarServer/trunk/txdav/dps/protocol.py        2014-02-05 17:44:38 UTC (rev 12571)
</span><span class="lines">@@ -1,195 +0,0 @@
</span><del>-##
-# Copyright (c) 2014 Apple Inc. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-##
-
-from twext.who.idirectory import RecordType
-from twisted.protocols import amp
-from twisted.internet.defer import inlineCallbacks, returnValue
-from twext.python.log import Logger
-import uuid
-import cPickle as pickle
-
-log = Logger()
-
-
-
-class RecordWithShortNameCommand(amp.Command):
-    arguments = [
-        ('recordType', amp.String()),
-        ('shortName', amp.String()),
-    ]
-    response = [
-        ('fields', amp.String()),
-    ]
-
-
-class RecordWithUIDCommand(amp.Command):
-    arguments = [
-        ('uid', amp.String()),
-    ]
-    response = [
-        ('fields', amp.String()),
-    ]
-
-
-class RecordWithGUIDCommand(amp.Command):
-    arguments = [
-        ('guid', amp.String()),
-    ]
-    response = [
-        ('fields', amp.String()),
-    ]
-
-
-class RecordsWithRecordTypeCommand(amp.Command):
-    arguments = [
-        ('recordType', amp.String()),
-    ]
-    response = [
-        ('fieldsList', amp.String()),
-    ]
-
-
-class RecordsWithEmailAddressCommand(amp.Command):
-    arguments = [
-        ('emailAddress', amp.String()),
-    ]
-    response = [
-        ('fieldsList', amp.String()),
-    ]
-
-
-class UpdateRecordsCommand(amp.Command):
-    arguments = [
-        ('fieldsList', amp.String()),
-        ('create', amp.Boolean(optional=True)),
-    ]
-    response = [
-        ('success', amp.Boolean()),
-    ]
-
-
-class RemoveRecordsCommand(amp.Command):
-    arguments = [
-        ('uids', amp.ListOf(amp.String())),
-    ]
-    response = [
-        ('success', amp.Boolean()),
-    ]
-
-
-class DirectoryProxyAMPProtocol(amp.AMP):
-    &quot;&quot;&quot;
-    Server side of directory proxy
-    &quot;&quot;&quot;
-
-    def __init__(self, directory):
-        &quot;&quot;&quot;
-        &quot;&quot;&quot;
-        amp.AMP.__init__(self)
-        self._directory = directory
-
-
-    def recordToDict(self, record):
-        &quot;&quot;&quot;
-        This to be replaced by something awesome
-        &quot;&quot;&quot;
-        fields = {}
-        if record is not None:
-            for field, value in record.fields.iteritems():
-                # print(&quot;%s: %s&quot; % (field.name, value))
-                valueType = self._directory.fieldName.valueType(field)
-                if valueType is unicode:
-                    fields[field.name] = value
-        return fields
-
-
-    @RecordWithShortNameCommand.responder
-    @inlineCallbacks
-    def recordWithShortName(self, recordType, shortName):
-        recordType = recordType  # keep as bytes
-        shortName = shortName.decode(&quot;utf-8&quot;)
-        log.debug(&quot;RecordWithShortName: {r} {n}&quot;, r=recordType, n=shortName)
-        record = (yield self._directory.recordWithShortName(
-            RecordType.lookupByName(recordType), shortName)
-        )
-        fields = self.recordToDict(record)
-        response = {
-            &quot;fields&quot;: pickle.dumps(fields),
-        }
-        log.debug(&quot;Responding with: {response}&quot;, response=response)
-        returnValue(response)
-
-
-    @RecordWithUIDCommand.responder
-    @inlineCallbacks
-    def recordWithUID(self, uid):
-        uid = uid.decode(&quot;utf-8&quot;)
-        log.debug(&quot;RecordWithUID: {u}&quot;, u=uid)
-        record = (yield self._directory.recordWithUID(uid))
-        fields = self.recordToDict(record)
-        response = {
-            &quot;fields&quot;: pickle.dumps(fields),
-        }
-        log.debug(&quot;Responding with: {response}&quot;, response=response)
-        returnValue(response)
-
-
-    @RecordWithGUIDCommand.responder
-    @inlineCallbacks
-    def recordWithGUID(self, guid):
-        guid = uuid.UUID(guid)
-        log.debug(&quot;RecordWithGUID: {g}&quot;, g=guid)
-        record = (yield self._directory.recordWithGUID(guid))
-        fields = self.recordToDict(record)
-        response = {
-            &quot;fields&quot;: pickle.dumps(fields),
-        }
-        log.debug(&quot;Responding with: {response}&quot;, response=response)
-        returnValue(response)
-
-
-    @RecordsWithRecordTypeCommand.responder
-    @inlineCallbacks
-    def recordsWithRecordType(self, recordType):
-        recordType = recordType  # as bytes
-        log.debug(&quot;RecordsWithRecordType: {r}&quot;, r=recordType)
-        records = (yield self._directory.recordsWithRecordType(
-            RecordType.lookupByName(recordType))
-        )
-        fieldsList = []
-        for record in records:
-            fieldsList.append(self.recordToDict(record))
-        response = {
-            &quot;fieldsList&quot;: pickle.dumps(fieldsList),
-        }
-        log.debug(&quot;Responding with: {response}&quot;, response=response)
-        returnValue(response)
-
-
-    @RecordsWithEmailAddressCommand.responder
-    @inlineCallbacks
-    def recordsWithEmailAddress(self, emailAddress):
-        emailAddress = emailAddress.decode(&quot;utf-8&quot;)
-        log.debug(&quot;RecordsWithEmailAddress: {e}&quot;, e=emailAddress)
-        records = (yield self._directory.recordsWithEmailAddress(emailAddress))
-        fieldsList = []
-        for record in records:
-            fieldsList.append(self.recordToDict(record))
-        response = {
-            &quot;fieldsList&quot;: pickle.dumps(fieldsList),
-        }
-        log.debug(&quot;Responding with: {response}&quot;, response=response)
-        returnValue(response)
</del></span></pre></div>
<a id="CalendarServertrunktxdavdpsserverpy"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/txdav/dps/server.py (0 => 12571)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/server.py                                (rev 0)
+++ CalendarServer/trunk/txdav/dps/server.py        2014-02-05 17:44:38 UTC (rev 12571)
</span><span class="lines">@@ -0,0 +1,296 @@
</span><ins>+##
+# Copyright (c) 2014 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from twext.who.idirectory import RecordType
+from twisted.protocols import amp
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twext.python.log import Logger
+import uuid
+import cPickle as pickle
+from txdav.dps.commands import (
+    RecordWithShortNameCommand, RecordWithUIDCommand, RecordWithGUIDCommand,
+    RecordsWithRecordTypeCommand, RecordsWithEmailAddressCommand,
+    # UpdateRecordsCommand, RemoveRecordsCommand
+)
+from twisted.internet.protocol import Factory
+from twisted.python.usage import Options, UsageError
+from twistedcaldav.config import config
+from twistedcaldav.stdconfig import DEFAULT_CONFIG, DEFAULT_CONFIG_FILE
+from zope.interface import implementer
+from twisted.plugin import IPlugin
+from twisted.application import service
+from twext.who.opendirectory import DirectoryService as ODDirectoryService
+from txdav.who.xml import DirectoryService as XMLDirectoryService
+from twisted.python.filepath import FilePath
+from twisted.application.strports import service as strPortsService
+
+log = Logger()
+
+
+##
+## Server implementation of Directory Proxy Service
+##
+
+
+class DirectoryProxyAMPProtocol(amp.AMP):
+    &quot;&quot;&quot;
+    Server side of directory proxy
+    &quot;&quot;&quot;
+
+    def __init__(self, directory):
+        &quot;&quot;&quot;
+        &quot;&quot;&quot;
+        amp.AMP.__init__(self)
+        self._directory = directory
+
+
+    def recordToDict(self, record):
+        &quot;&quot;&quot;
+        This to be replaced by something awesome
+        &quot;&quot;&quot;
+        fields = {}
+        if record is not None:
+            for field, value in record.fields.iteritems():
+                # print(&quot;%s: %s&quot; % (field.name, value))
+                valueType = self._directory.fieldName.valueType(field)
+                if valueType is unicode:
+                    fields[field.name] = value
+        return fields
+
+
+    @RecordWithShortNameCommand.responder
+    @inlineCallbacks
+    def recordWithShortName(self, recordType, shortName):
+        recordType = recordType  # keep as bytes
+        shortName = shortName.decode(&quot;utf-8&quot;)
+        log.debug(&quot;RecordWithShortName: {r} {n}&quot;, r=recordType, n=shortName)
+        record = (yield self._directory.recordWithShortName(
+            RecordType.lookupByName(recordType), shortName)
+        )
+        fields = self.recordToDict(record)
+        response = {
+            &quot;fields&quot;: pickle.dumps(fields),
+        }
+        log.debug(&quot;Responding with: {response}&quot;, response=response)
+        returnValue(response)
+
+
+    @RecordWithUIDCommand.responder
+    @inlineCallbacks
+    def recordWithUID(self, uid):
+        uid = uid.decode(&quot;utf-8&quot;)
+        log.debug(&quot;RecordWithUID: {u}&quot;, u=uid)
+        try:
+            record = (yield self._directory.recordWithUID(uid))
+        except Exception as e:
+            log.error(&quot;Failed in recordWithUID&quot;, error=e)
+            record = None
+        fields = self.recordToDict(record)
+        response = {
+            &quot;fields&quot;: pickle.dumps(fields),
+        }
+        log.debug(&quot;Responding with: {response}&quot;, response=response)
+        returnValue(response)
+
+
+    @RecordWithGUIDCommand.responder
+    @inlineCallbacks
+    def recordWithGUID(self, guid):
+        guid = uuid.UUID(guid)
+        log.debug(&quot;RecordWithGUID: {g}&quot;, g=guid)
+        record = (yield self._directory.recordWithGUID(guid))
+        fields = self.recordToDict(record)
+        response = {
+            &quot;fields&quot;: pickle.dumps(fields),
+        }
+        log.debug(&quot;Responding with: {response}&quot;, response=response)
+        returnValue(response)
+
+
+    @RecordsWithRecordTypeCommand.responder
+    @inlineCallbacks
+    def recordsWithRecordType(self, recordType):
+        recordType = recordType  # as bytes
+        log.debug(&quot;RecordsWithRecordType: {r}&quot;, r=recordType)
+        records = (yield self._directory.recordsWithRecordType(
+            RecordType.lookupByName(recordType))
+        )
+        fieldsList = []
+        for record in records:
+            fieldsList.append(self.recordToDict(record))
+        response = {
+            &quot;fieldsList&quot;: pickle.dumps(fieldsList),
+        }
+        log.debug(&quot;Responding with: {response}&quot;, response=response)
+        returnValue(response)
+
+
+    @RecordsWithEmailAddressCommand.responder
+    @inlineCallbacks
+    def recordsWithEmailAddress(self, emailAddress):
+        emailAddress = emailAddress.decode(&quot;utf-8&quot;)
+        log.debug(&quot;RecordsWithEmailAddress: {e}&quot;, e=emailAddress)
+        records = (yield self._directory.recordsWithEmailAddress(emailAddress))
+        fieldsList = []
+        for record in records:
+            fieldsList.append(self.recordToDict(record))
+        response = {
+            &quot;fieldsList&quot;: pickle.dumps(fieldsList),
+        }
+        log.debug(&quot;Responding with: {response}&quot;, response=response)
+        returnValue(response)
+
+
+
+
+class DirectoryProxyAMPFactory(Factory):
+    &quot;&quot;&quot;
+    &quot;&quot;&quot;
+    protocol = DirectoryProxyAMPProtocol
+
+
+    def __init__(self, directory):
+        self._directory = directory
+
+    def buildProtocol(self, addr):
+        return DirectoryProxyAMPProtocol(self._directory)
+
+
+
+
+
+class DirectoryProxyOptions(Options):
+    optParameters = [[
+        &quot;config&quot;, &quot;f&quot;, DEFAULT_CONFIG_FILE, &quot;Path to configuration file.&quot;
+    ]]
+
+
+    def __init__(self, *args, **kwargs):
+        super(DirectoryProxyOptions, self).__init__(*args, **kwargs)
+
+        self.overrides = {}
+
+
+    def _coerceOption(self, configDict, key, value):
+        &quot;&quot;&quot;
+        Coerce the given C{val} to type of C{configDict[key]}
+        &quot;&quot;&quot;
+        if key in configDict:
+            if isinstance(configDict[key], bool):
+                value = value == &quot;True&quot;
+
+            elif isinstance(configDict[key], (int, float, long)):
+                value = type(configDict[key])(value)
+
+            elif isinstance(configDict[key], (list, tuple)):
+                value = value.split(',')
+
+            elif isinstance(configDict[key], dict):
+                raise UsageError(
+                    &quot;Dict options not supported on the command line&quot;
+                )
+
+            elif value == 'None':
+                value = None
+
+        return value
+
+
+    def _setOverride(self, configDict, path, value, overrideDict):
+        &quot;&quot;&quot;
+        Set the value at path in configDict
+        &quot;&quot;&quot;
+        key = path[0]
+
+        if len(path) == 1:
+            overrideDict[key] = self._coerceOption(configDict, key, value)
+            return
+
+        if key in configDict:
+            if not isinstance(configDict[key], dict):
+                raise UsageError(
+                    &quot;Found intermediate path element that is not a dictionary&quot;
+                )
+
+            if key not in overrideDict:
+                overrideDict[key] = {}
+
+            self._setOverride(
+                configDict[key], path[1:],
+                value, overrideDict[key]
+            )
+
+
+    def opt_option(self, option):
+        &quot;&quot;&quot;
+        Set an option to override a value in the config file. True, False, int,
+        and float options are supported, as well as comma seperated lists. Only
+        one option may be given for each --option flag, however multiple
+        --option flags may be specified.
+        &quot;&quot;&quot;
+
+        if &quot;=&quot; in option:
+            path, value = option.split('=')
+            self._setOverride(
+                DEFAULT_CONFIG,
+                path.split('/'),
+                value,
+                self.overrides
+            )
+        else:
+            self.opt_option('%s=True' % (option,))
+
+    opt_o = opt_option
+
+    def postOptions(self):
+        config.load(self['config'])
+        config.updateDefaults(self.overrides)
+        self.parent['pidfile'] = None
+
+
+@implementer(IPlugin, service.IServiceMaker)
+class DirectoryProxyServiceMaker(object):
+
+    tapname = &quot;caldav_directoryproxy&quot;
+    description = &quot;Directory Proxy Service&quot;
+    options = DirectoryProxyOptions
+
+    def makeService(self, options):
+        &quot;&quot;&quot;
+        Return a service
+        &quot;&quot;&quot;
+        try:
+            from setproctitle import setproctitle
+        except ImportError:
+            pass
+        else:
+            setproctitle(&quot;CalendarServer Directory Proxy Service&quot;)
+
+        directoryType = config.DirectoryProxy.DirectoryType
+        if directoryType == &quot;OD&quot;:
+            directory = ODDirectoryService()
+        elif directoryType == &quot;LDAP&quot;:
+            pass
+        elif directoryType == &quot;XML&quot;:
+            directory = XMLDirectoryService(FilePath(&quot;foo.xml&quot;))
+        else:
+            log.error(&quot;Invalid DirectoryType: {dt}&quot;, dt=directoryType)
+
+
+        desc = &quot;unix:{path}:mode=660&quot;.format(
+            path=config.DirectoryProxy.SocketPath
+        )
+        return strPortsService(desc, DirectoryProxyAMPFactory(directory))
</ins></span></pre></div>
<a id="CalendarServertrunktxdavdpsservicepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/dps/service.py (12570 => 12571)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/dps/service.py        2014-02-05 01:04:49 UTC (rev 12570)
+++ CalendarServer/trunk/txdav/dps/service.py        2014-02-05 17:44:38 UTC (rev 12571)
</span><span class="lines">@@ -14,29 +14,18 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><span class="cx"> 
</span><del>-# Temporary:
-from txdav.who.xml import DirectoryService as XMLDirectoryService
</del><span class="cx"> 
</span><del>-
</del><span class="cx"> from twext.who.directory import DirectoryService as BaseDirectoryService
</span><span class="cx"> from twext.who.directory import DirectoryRecord as BaseDirectoryRecord
</span><span class="cx"> from twext.who.util import ConstantsContainer
</span><span class="cx"> import twext.who.idirectory
</span><span class="cx"> import txdav.who.idirectory
</span><span class="cx"> 
</span><del>-from twisted.python.usage import Options, UsageError
-from twisted.plugin import IPlugin
-from twisted.application import service
</del><span class="cx"> from zope.interface import implementer
</span><del>-from twistedcaldav.config import config
-from twistedcaldav.stdconfig import DEFAULT_CONFIG, DEFAULT_CONFIG_FILE
-from twisted.application.strports import service as strPortsService
-from twisted.internet.protocol import Factory
</del><span class="cx"> from twext.python.log import Logger
</span><del>-from twisted.python.filepath import FilePath
</del><span class="cx"> 
</span><del>-from .protocol import (
-    DirectoryProxyAMPProtocol, RecordWithShortNameCommand, RecordWithUIDCommand,
</del><ins>+from .commands import (
+    RecordWithShortNameCommand, RecordWithUIDCommand,
</ins><span class="cx">     RecordWithGUIDCommand, RecordsWithRecordTypeCommand,
</span><span class="cx">     RecordsWithEmailAddressCommand
</span><span class="cx"> )
</span><span class="lines">@@ -50,6 +39,7 @@
</span><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+@implementer(twext.who.idirectory.IDirectoryService)
</ins><span class="cx"> class DirectoryService(BaseDirectoryService):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Client side of directory proxy
</span><span class="lines">@@ -70,8 +60,13 @@
</span><span class="cx"> 
</span><span class="cx">         fields = {}
</span><span class="cx">         for fieldName, value in serializedFields.iteritems():
</span><del>-            field = self.fieldName.lookupByName(fieldName)
-            fields[field] = value
</del><ins>+            try:
+                field = self.fieldName.lookupByName(fieldName)
+            except ValueError:
+                # unknown field
+                pass
+            else:
+                fields[field] = value
</ins><span class="cx">         fields[self.fieldName.recordType] = self.recordType.user
</span><span class="cx">         return DirectoryRecord(self, fields)
</span><span class="cx"> 
</span><span class="lines">@@ -177,136 +172,3 @@
</span><span class="cx"> 
</span><span class="cx"> class DirectoryRecord(BaseDirectoryRecord):
</span><span class="cx">     pass
</span><del>-
-
-
-
-class DirectoryProxyAMPFactory(Factory):
-    &quot;&quot;&quot;
-    &quot;&quot;&quot;
-    protocol = DirectoryProxyAMPProtocol
-
-
-    def __init__(self, directory):
-        self._directory = directory
-
-    def buildProtocol(self, addr):
-        return DirectoryProxyAMPProtocol(self._directory)
-
-
-
-
-
-class DirectoryProxyOptions(Options):
-    optParameters = [[
-        &quot;config&quot;, &quot;f&quot;, DEFAULT_CONFIG_FILE, &quot;Path to configuration file.&quot;
-    ]]
-
-
-    def __init__(self, *args, **kwargs):
-        super(DirectoryProxyOptions, self).__init__(*args, **kwargs)
-
-        self.overrides = {}
-
-
-    def _coerceOption(self, configDict, key, value):
-        &quot;&quot;&quot;
-        Coerce the given C{val} to type of C{configDict[key]}
-        &quot;&quot;&quot;
-        if key in configDict:
-            if isinstance(configDict[key], bool):
-                value = value == &quot;True&quot;
-
-            elif isinstance(configDict[key], (int, float, long)):
-                value = type(configDict[key])(value)
-
-            elif isinstance(configDict[key], (list, tuple)):
-                value = value.split(',')
-
-            elif isinstance(configDict[key], dict):
-                raise UsageError(
-                    &quot;Dict options not supported on the command line&quot;
-                )
-
-            elif value == 'None':
-                value = None
-
-        return value
-
-
-    def _setOverride(self, configDict, path, value, overrideDict):
-        &quot;&quot;&quot;
-        Set the value at path in configDict
-        &quot;&quot;&quot;
-        key = path[0]
-
-        if len(path) == 1:
-            overrideDict[key] = self._coerceOption(configDict, key, value)
-            return
-
-        if key in configDict:
-            if not isinstance(configDict[key], dict):
-                raise UsageError(
-                    &quot;Found intermediate path element that is not a dictionary&quot;
-                )
-
-            if key not in overrideDict:
-                overrideDict[key] = {}
-
-            self._setOverride(
-                configDict[key], path[1:],
-                value, overrideDict[key]
-            )
-
-
-    def opt_option(self, option):
-        &quot;&quot;&quot;
-        Set an option to override a value in the config file. True, False, int,
-        and float options are supported, as well as comma seperated lists. Only
-        one option may be given for each --option flag, however multiple
-        --option flags may be specified.
-        &quot;&quot;&quot;
-
-        if &quot;=&quot; in option:
-            path, value = option.split('=')
-            self._setOverride(
-                DEFAULT_CONFIG,
-                path.split('/'),
-                value,
-                self.overrides
-            )
-        else:
-            self.opt_option('%s=True' % (option,))
-
-    opt_o = opt_option
-
-    def postOptions(self):
-        config.load(self['config'])
-        config.updateDefaults(self.overrides)
-        self.parent['pidfile'] = None
-
-
-@implementer(IPlugin, service.IServiceMaker)
-class DirectoryProxyServiceMaker(object):
-
-    tapname = &quot;caldav_directoryproxy&quot;
-    description = &quot;Directory Proxy Service&quot;
-    options = DirectoryProxyOptions
-
-    def makeService(self, options):
-        &quot;&quot;&quot;
-        Return a service
-        &quot;&quot;&quot;
-        try:
-            from setproctitle import setproctitle
-        except ImportError:
-            pass
-        else:
-            setproctitle(&quot;CalendarServer Directory Proxy Service&quot;)
-
-        directory = XMLDirectoryService(FilePath(&quot;foo.xml&quot;))
-
-        desc = &quot;unix:{path}:mode=660&quot;.format(
-            path=config.DirectoryProxy.SocketPath
-        )
-        return strPortsService(desc, DirectoryProxyAMPFactory(directory))
</del></span></pre>
</div>
</div>

</body>
</html>