<!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>[12914] CalendarServer/branches/users/sagen/move2who-4</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/12914">12914</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-03-14 12:23:36 -0700 (Fri, 14 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Pulled up trunk</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarserveraccesslogpy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/accesslog.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarserverprovisionrootpy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarserverpushapplepushpy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/push/applepush.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarservertapcaldavpy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/tap/caldav.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarservertaptesttest_utilpy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/tap/test/test_util.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarservertaputilpy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/tap/util.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarservertoolscalverifypy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/calverify.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarservertoolsprincipalspy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarservertoolsshelldirectorypy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/shell/directory.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarservertoolstesttest_principalspy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_principals.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarservertoolsutilpy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/util.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarserverwebcalresourcepy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/webcal/resource.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4confauthaccountstestxml">CalendarServer/branches/users/sagen/move2who-4/conf/auth/accounts-test.xml</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4confauthresourcestestxml">CalendarServer/branches/users/sagen/move2who-4/conf/auth/resources-test.xml</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4contribperformanceloadtesttest_simpy">CalendarServer/branches/users/sagen/move2who-4/contrib/performance/loadtest/test_sim.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavcustomxmlpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/customxml.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryaddressbookpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/addressbook.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryaugmentpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/augment.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorycalendarpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendar.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorycalendaruserproxypy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendaruserproxy.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorycommonpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/common.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorydirectoryprincipalresourcehtml">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/directory-principal-resource.html</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryprincipalpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/principal.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytestaccountsxml">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_augmentpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_augment.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_principalpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_principal.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryutilpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/util.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorywikipy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/wiki.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorybackedaddressbookpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directorybackedaddressbook.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavextensionspy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/extensions.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavfreebusyurlpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/freebusyurl.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavicalpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/ical.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavresourcepy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/resource.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavscheduling_storecaldavresourcepy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/scheduling_store/caldav/resource.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavsharingpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/sharing.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavstdconfigpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/stdconfig.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavstorebridgepy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/storebridge.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_addressbookmultigetpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_addressbookmultiget.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_addressbookquerypy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_addressbookquery.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_calendarquerypy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_calendarquery.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_collectioncontentspy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_collectioncontents.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_icalendarpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_icalendar.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_mkcalendarpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_mkcalendar.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_multigetpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_multiget.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_propspy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_props.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_resourcepy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_resource.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_sharingpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_sharing.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_upgradepy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_upgrade.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_wrappingpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_wrapping.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtestutilpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/util.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtimezoneservicepy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/timezoneservice.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavtimezonestdservicepy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/timezonestdservice.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavupgradepy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/upgrade.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavutilpy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/util.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingcaldavschedulerpy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/caldav/scheduler.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingfreebusypy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/freebusy.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingimipinboundpy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/imip/inbound.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingimplicitpy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/implicit.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingischeduledeliverypy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/ischedule/delivery.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingischeduleresourcepy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/ischedule/resource.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingischeduleschedulerpy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/ischedule/scheduler.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingprocessingpy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/processing.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingschedulerpy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/scheduler.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingworkpy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/work.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoresqlpy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/sql.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoretestattachmentsaccountsxml">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/attachments/accounts.xml</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoretesttest_attachmentspy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/test_attachments.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoretestutilpy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/util.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreutilpy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/util.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavicalendardirectoryservicepy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/icalendardirectoryservice.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcommondatastorefilepy">CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/file.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcommondatastorepoddingconduitpy">CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/podding/conduit.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcommondatastorepoddingresourcepy">CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/podding/resource.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcommondatastorepoddingtesttest_conduitpy">CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/podding/test/test_conduit.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcommondatastoresqlpy">CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/sql.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcommondatastoretestutilpy">CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/test/util.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavdpsclientpy">CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavdpscommandspy">CalendarServer/branches/users/sagen/move2who-4/txdav/dps/commands.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavdpsserverpy">CalendarServer/branches/users/sagen/move2who-4/txdav/dps/server.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavdpstesttestxml">CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test.xml</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavdpstesttest_clientpy">CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhodelegatespy">CalendarServer/branches/users/sagen/move2who-4/txdav/who/delegates.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhogroupspy">CalendarServer/branches/users/sagen/move2who-4/txdav/who/groups.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhotestaccountsaccountsxml">CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/accounts/accounts.xml</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhotestaccountsresourcesxml">CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/accounts/resources.xml</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhotesttest_delegatespy">CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_delegates.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhotesttest_groupspy">CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_groups.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhoxmlpy">CalendarServer/branches/users/sagen/move2who-4/txdav/who/xml.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txweb2channelhttppy">CalendarServer/branches/users/sagen/move2who-4/txweb2/channel/http.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txweb2davresourcepy">CalendarServer/branches/users/sagen/move2who-4/txweb2/dav/resource.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txweb2serverpy">CalendarServer/branches/users/sagen/move2who-4/txweb2/server.py</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhoaugmentpy">CalendarServer/branches/users/sagen/move2who-4/txdav/who/augment.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhodirectorypy">CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhotestaccountsaugmentsxml">CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/accounts/augments.xml</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhotesttest_utilpy">CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_util.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhoutilpy">CalendarServer/branches/users/sagen/move2who-4/txdav/who/util.py</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryaggregatepy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/aggregate.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryappleopendirectorypy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/appleopendirectory.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorycachingdirectorypy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/cachingdirectory.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorydirectorypy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/directory.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryldapdirectorypy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/ldapdirectory.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_aggregatepy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_aggregate.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_buildquerypy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_buildquery.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_cachedirectorypy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_cachedirectory.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_directorypy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_directory.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_modifypy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_modify.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_proxyprincipalmemberspy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_proxyprincipalmembers.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_resourcespy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_resources.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_xmlfilepy">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_xmlfile.py</a></li>
</ul>

<h3>Property Changed</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagenmove2who4">CalendarServer/branches/users/sagen/move2who-4/</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserssagenmove2who4"></a>
<div class="propset"><h4>Property changes: CalendarServer/branches/users/sagen/move2who-4</h4>
<pre class="diff"><span>
</span></pre></div>
<a id="svnmergeinfo"></a>
<div class="modfile"><h4>Modified: svn:mergeinfo</h4></div>
<span class="cx">/CalendarServer/branches/config-separation:4379-4443
</span><span class="cx">/CalendarServer/branches/egg-info-351:4589-4625
</span><span class="cx">/CalendarServer/branches/generic-sqlstore:6167-6191
</span><span class="cx">/CalendarServer/branches/new-store:5594-5934
</span><span class="cx">/CalendarServer/branches/new-store-no-caldavfile:5911-5935
</span><span class="cx">/CalendarServer/branches/new-store-no-caldavfile-2:5936-5981
</span><span class="cx">/CalendarServer/branches/release/CalendarServer-4.3-dev:10180-10190,10192
</span><span class="cx">/CalendarServer/branches/release/CalendarServer-5.1-dev:11846
</span><span class="cx">/CalendarServer/branches/release/CalendarServer-5.2-dev:11972,12357-12358,12794,12814
</span><span class="cx">/CalendarServer/branches/users/cdaboo/batchupload-6699:6700-7198
</span><span class="cx">/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692:5693-5702
</span><span class="cx">/CalendarServer/branches/users/cdaboo/component-set-fixes:8130-8346
</span><span class="cx">/CalendarServer/branches/users/cdaboo/cross-pod-sharing:12038-12191
</span><span class="cx">/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627:3628-3644
</span><span class="cx">/CalendarServer/branches/users/cdaboo/fix-no-ischedule:11607-11871
</span><span class="cx">/CalendarServer/branches/users/cdaboo/implicituidrace:8137-8141
</span><span class="cx">/CalendarServer/branches/users/cdaboo/ischedule-dkim:9747-9979
</span><span class="cx">/CalendarServer/branches/users/cdaboo/json:11622-11912
</span><span class="cx">/CalendarServer/branches/users/cdaboo/managed-attachments:9985-10145
</span><span class="cx">/CalendarServer/branches/users/cdaboo/more-sharing-5591:5592-5601
</span><span class="cx">/CalendarServer/branches/users/cdaboo/partition-4464:4465-4957
</span><span class="cx">/CalendarServer/branches/users/cdaboo/performance-tweaks:11824-11836
</span><span class="cx">/CalendarServer/branches/users/cdaboo/pods:7297-7377
</span><span class="cx">/CalendarServer/branches/users/cdaboo/pycalendar:7085-7206
</span><span class="cx">/CalendarServer/branches/users/cdaboo/pycard:7227-7237
</span><span class="cx">/CalendarServer/branches/users/cdaboo/queued-attendee-refreshes:7740-8287
</span><span class="cx">/CalendarServer/branches/users/cdaboo/relative-config-paths-5070:5071-5105
</span><span class="cx">/CalendarServer/branches/users/cdaboo/reverse-proxy-pods:11875-11900
</span><span class="cx">/CalendarServer/branches/users/cdaboo/scheduling-queue-refresh:11783-12557
</span><span class="cx">/CalendarServer/branches/users/cdaboo/shared-calendars-5187:5188-5440
</span><span class="cx">/CalendarServer/branches/users/cdaboo/sharing-in-the-store:11935-12016
</span><span class="cx">/CalendarServer/branches/users/cdaboo/store-scheduling:10876-11129
</span><span class="cx">/CalendarServer/branches/users/cdaboo/timezones:7443-7699
</span><span class="cx">/CalendarServer/branches/users/cdaboo/txn-debugging:8730-8743
</span><span class="cx">/CalendarServer/branches/users/gaya/cleanrevisions:12152-12334
</span><span class="cx">/CalendarServer/branches/users/gaya/sharedgroupfixes:12120-12142
</span><span class="cx">/CalendarServer/branches/users/gaya/sharedgroups-3:11088-11204
</span><span class="cx">/CalendarServer/branches/users/glyph/always-abort-txn-on-error:9958-9969
</span><span class="cx">/CalendarServer/branches/users/glyph/case-insensitive-uid:8772-8805
</span><span class="cx">/CalendarServer/branches/users/glyph/conn-limit:6574-6577
</span><span class="cx">/CalendarServer/branches/users/glyph/contacts-server-merge:4971-5080
</span><span class="cx">/CalendarServer/branches/users/glyph/dalify:6932-7023
</span><span class="cx">/CalendarServer/branches/users/glyph/db-reconnect:6824-6876
</span><span class="cx">/CalendarServer/branches/users/glyph/deploybuild:7563-7572
</span><span class="cx">/CalendarServer/branches/users/glyph/digest-auth-redux:10624-10635
</span><span class="cx">/CalendarServer/branches/users/glyph/disable-quota:7718-7727
</span><span class="cx">/CalendarServer/branches/users/glyph/dont-start-postgres:6592-6614
</span><span class="cx">/CalendarServer/branches/users/glyph/enforce-max-requests:11640-11643
</span><span class="cx">/CalendarServer/branches/users/glyph/hang-fix:11465-11491
</span><span class="cx">/CalendarServer/branches/users/glyph/imip-and-admin-html:7866-7984
</span><span class="cx">/CalendarServer/branches/users/glyph/ipv6-client:9054-9105
</span><span class="cx">/CalendarServer/branches/users/glyph/launchd-wrapper-bis:11413-11436
</span><span class="cx">/CalendarServer/branches/users/glyph/linux-tests:6893-6900
</span><span class="cx">/CalendarServer/branches/users/glyph/log-cleanups:11691-11731
</span><span class="cx">/CalendarServer/branches/users/glyph/migrate-merge:8690-8713
</span><span class="cx">/CalendarServer/branches/users/glyph/misc-portability-fixes:7365-7374
</span><span class="cx">/CalendarServer/branches/users/glyph/more-deferreds-6:6322-6368
</span><span class="cx">/CalendarServer/branches/users/glyph/more-deferreds-7:6369-6445
</span><span class="cx">/CalendarServer/branches/users/glyph/multiget-delete:8321-8330
</span><span class="cx">/CalendarServer/branches/users/glyph/new-export:7444-7485
</span><span class="cx">/CalendarServer/branches/users/glyph/one-home-list-api:10048-10073
</span><span class="cx">/CalendarServer/branches/users/glyph/oracle:7106-7155
</span><span class="cx">/CalendarServer/branches/users/glyph/oracle-nulls:7340-7351
</span><span class="cx">/CalendarServer/branches/users/glyph/other-html:8062-8091
</span><span class="cx">/CalendarServer/branches/users/glyph/parallel-sim:8240-8251
</span><span class="cx">/CalendarServer/branches/users/glyph/parallel-upgrade:8376-8400
</span><span class="cx">/CalendarServer/branches/users/glyph/parallel-upgrade_to_1:8571-8583
</span><span class="cx">/CalendarServer/branches/users/glyph/q:9560-9688
</span><span class="cx">/CalendarServer/branches/users/glyph/queue-locking-and-timing:10204-10289
</span><span class="cx">/CalendarServer/branches/users/glyph/quota:7604-7637
</span><span class="cx">/CalendarServer/branches/users/glyph/sendfdport:5388-5424
</span><span class="cx">/CalendarServer/branches/users/glyph/shared-pool-fixes:8436-8443
</span><span class="cx">/CalendarServer/branches/users/glyph/shared-pool-take2:8155-8174
</span><span class="cx">/CalendarServer/branches/users/glyph/sharedpool:6490-6550
</span><span class="cx">/CalendarServer/branches/users/glyph/sharing-api:9192-9205
</span><span class="cx">/CalendarServer/branches/users/glyph/skip-lonely-vtimezones:8524-8535
</span><span class="cx">/CalendarServer/branches/users/glyph/sql-store:5929-6073
</span><span class="cx">/CalendarServer/branches/users/glyph/start-service-start-loop:11060-11065
</span><span class="cx">/CalendarServer/branches/users/glyph/subtransactions:7248-7258
</span><span class="cx">/CalendarServer/branches/users/glyph/table-alias:8651-8664
</span><span class="cx">/CalendarServer/branches/users/glyph/uidexport:7673-7676
</span><span class="cx">/CalendarServer/branches/users/glyph/unshare-when-access-revoked:10562-10595
</span><span class="cx">/CalendarServer/branches/users/glyph/use-system-twisted:5084-5149
</span><span class="cx">/CalendarServer/branches/users/glyph/uuid-normalize:9268-9296
</span><span class="cx">/CalendarServer/branches/users/glyph/warning-cleanups:11347-11357
</span><span class="cx">/CalendarServer/branches/users/glyph/whenNotProposed:11881-11897
</span><span class="cx">/CalendarServer/branches/users/glyph/xattrs-from-files:7757-7769
</span><span class="cx">/CalendarServer/branches/users/sagen/applepush:8126-8184
</span><span class="cx">/CalendarServer/branches/users/sagen/inboxitems:7380-7381
</span><span class="cx">/CalendarServer/branches/users/sagen/locations-resources:5032-5051
</span><span class="cx">/CalendarServer/branches/users/sagen/locations-resources-2:5052-5061
</span><span class="cx">/CalendarServer/branches/users/sagen/purge_old_events:6735-6746
</span><span class="cx">/CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
</span><span class="cx">/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
</span><span class="cx">/CalendarServer/branches/users/sagen/resources-2:5084-5093
</span><span class="cx">/CalendarServer/branches/users/sagen/testing:10827-10851,10853-10855
</span><span class="cx">/CalendarServer/branches/users/wsanchez/transations:5515-5593
</span><span class="cx">   + /CalDAVTester/trunk:11193-11198
</span><span class="cx">/CalendarServer/branches/config-separation:4379-4443
</span><span class="cx">/CalendarServer/branches/egg-info-351:4589-4625
</span><span class="cx">/CalendarServer/branches/generic-sqlstore:6167-6191
</span><span class="cx">/CalendarServer/branches/new-store:5594-5934
</span><span class="cx">/CalendarServer/branches/new-store-no-caldavfile:5911-5935
</span><span class="cx">/CalendarServer/branches/new-store-no-caldavfile-2:5936-5981
</span><span class="cx">/CalendarServer/branches/release/CalendarServer-4.3-dev:10180-10190,10192
</span><span class="cx">/CalendarServer/branches/release/CalendarServer-5.1-dev:11846
</span><span class="cx">/CalendarServer/branches/release/CalendarServer-5.2-dev:11972,12357-12358,12794,12814
</span><span class="cx">/CalendarServer/branches/users/cdaboo/batchupload-6699:6700-7198
</span><span class="cx">/CalendarServer/branches/users/cdaboo/cached-subscription-calendars-5692:5693-5702
</span><span class="cx">/CalendarServer/branches/users/cdaboo/component-set-fixes:8130-8346
</span><span class="cx">/CalendarServer/branches/users/cdaboo/cross-pod-sharing:12038-12191
</span><span class="cx">/CalendarServer/branches/users/cdaboo/directory-cache-on-demand-3627:3628-3644
</span><span class="cx">/CalendarServer/branches/users/cdaboo/fix-no-ischedule:11607-11871
</span><span class="cx">/CalendarServer/branches/users/cdaboo/implicituidrace:8137-8141
</span><span class="cx">/CalendarServer/branches/users/cdaboo/ischedule-dkim:9747-9979
</span><span class="cx">/CalendarServer/branches/users/cdaboo/json:11622-11912
</span><span class="cx">/CalendarServer/branches/users/cdaboo/managed-attachments:9985-10145
</span><span class="cx">/CalendarServer/branches/users/cdaboo/more-sharing-5591:5592-5601
</span><span class="cx">/CalendarServer/branches/users/cdaboo/partition-4464:4465-4957
</span><span class="cx">/CalendarServer/branches/users/cdaboo/performance-tweaks:11824-11836
</span><span class="cx">/CalendarServer/branches/users/cdaboo/pods:7297-7377
</span><span class="cx">/CalendarServer/branches/users/cdaboo/pycalendar:7085-7206
</span><span class="cx">/CalendarServer/branches/users/cdaboo/pycard:7227-7237
</span><span class="cx">/CalendarServer/branches/users/cdaboo/queued-attendee-refreshes:7740-8287
</span><span class="cx">/CalendarServer/branches/users/cdaboo/relative-config-paths-5070:5071-5105
</span><span class="cx">/CalendarServer/branches/users/cdaboo/reverse-proxy-pods:11875-11900
</span><span class="cx">/CalendarServer/branches/users/cdaboo/scheduling-queue-refresh:11783-12557
</span><span class="cx">/CalendarServer/branches/users/cdaboo/shared-calendars-5187:5188-5440
</span><span class="cx">/CalendarServer/branches/users/cdaboo/sharing-in-the-store:11935-12016
</span><span class="cx">/CalendarServer/branches/users/cdaboo/store-scheduling:10876-11129
</span><span class="cx">/CalendarServer/branches/users/cdaboo/timezones:7443-7699
</span><span class="cx">/CalendarServer/branches/users/cdaboo/txn-debugging:8730-8743
</span><span class="cx">/CalendarServer/branches/users/gaya/cleanrevisions:12152-12334
</span><span class="cx">/CalendarServer/branches/users/gaya/sharedgroupfixes:12120-12142
</span><span class="cx">/CalendarServer/branches/users/gaya/sharedgroups-3:11088-11204
</span><span class="cx">/CalendarServer/branches/users/glyph/always-abort-txn-on-error:9958-9969
</span><span class="cx">/CalendarServer/branches/users/glyph/case-insensitive-uid:8772-8805
</span><span class="cx">/CalendarServer/branches/users/glyph/conn-limit:6574-6577
</span><span class="cx">/CalendarServer/branches/users/glyph/contacts-server-merge:4971-5080
</span><span class="cx">/CalendarServer/branches/users/glyph/dalify:6932-7023
</span><span class="cx">/CalendarServer/branches/users/glyph/db-reconnect:6824-6876
</span><span class="cx">/CalendarServer/branches/users/glyph/deploybuild:7563-7572
</span><span class="cx">/CalendarServer/branches/users/glyph/digest-auth-redux:10624-10635
</span><span class="cx">/CalendarServer/branches/users/glyph/disable-quota:7718-7727
</span><span class="cx">/CalendarServer/branches/users/glyph/dont-start-postgres:6592-6614
</span><span class="cx">/CalendarServer/branches/users/glyph/enforce-max-requests:11640-11643
</span><span class="cx">/CalendarServer/branches/users/glyph/hang-fix:11465-11491
</span><span class="cx">/CalendarServer/branches/users/glyph/imip-and-admin-html:7866-7984
</span><span class="cx">/CalendarServer/branches/users/glyph/ipv6-client:9054-9105
</span><span class="cx">/CalendarServer/branches/users/glyph/launchd-wrapper-bis:11413-11436
</span><span class="cx">/CalendarServer/branches/users/glyph/linux-tests:6893-6900
</span><span class="cx">/CalendarServer/branches/users/glyph/log-cleanups:11691-11731
</span><span class="cx">/CalendarServer/branches/users/glyph/migrate-merge:8690-8713
</span><span class="cx">/CalendarServer/branches/users/glyph/misc-portability-fixes:7365-7374
</span><span class="cx">/CalendarServer/branches/users/glyph/more-deferreds-6:6322-6368
</span><span class="cx">/CalendarServer/branches/users/glyph/more-deferreds-7:6369-6445
</span><span class="cx">/CalendarServer/branches/users/glyph/multiget-delete:8321-8330
</span><span class="cx">/CalendarServer/branches/users/glyph/new-export:7444-7485
</span><span class="cx">/CalendarServer/branches/users/glyph/one-home-list-api:10048-10073
</span><span class="cx">/CalendarServer/branches/users/glyph/oracle:7106-7155
</span><span class="cx">/CalendarServer/branches/users/glyph/oracle-nulls:7340-7351
</span><span class="cx">/CalendarServer/branches/users/glyph/other-html:8062-8091
</span><span class="cx">/CalendarServer/branches/users/glyph/parallel-sim:8240-8251
</span><span class="cx">/CalendarServer/branches/users/glyph/parallel-upgrade:8376-8400
</span><span class="cx">/CalendarServer/branches/users/glyph/parallel-upgrade_to_1:8571-8583
</span><span class="cx">/CalendarServer/branches/users/glyph/q:9560-9688
</span><span class="cx">/CalendarServer/branches/users/glyph/queue-locking-and-timing:10204-10289
</span><span class="cx">/CalendarServer/branches/users/glyph/quota:7604-7637
</span><span class="cx">/CalendarServer/branches/users/glyph/sendfdport:5388-5424
</span><span class="cx">/CalendarServer/branches/users/glyph/shared-pool-fixes:8436-8443
</span><span class="cx">/CalendarServer/branches/users/glyph/shared-pool-take2:8155-8174
</span><span class="cx">/CalendarServer/branches/users/glyph/sharedpool:6490-6550
</span><span class="cx">/CalendarServer/branches/users/glyph/sharing-api:9192-9205
</span><span class="cx">/CalendarServer/branches/users/glyph/skip-lonely-vtimezones:8524-8535
</span><span class="cx">/CalendarServer/branches/users/glyph/sql-store:5929-6073
</span><span class="cx">/CalendarServer/branches/users/glyph/start-service-start-loop:11060-11065
</span><span class="cx">/CalendarServer/branches/users/glyph/subtransactions:7248-7258
</span><span class="cx">/CalendarServer/branches/users/glyph/table-alias:8651-8664
</span><span class="cx">/CalendarServer/branches/users/glyph/uidexport:7673-7676
</span><span class="cx">/CalendarServer/branches/users/glyph/unshare-when-access-revoked:10562-10595
</span><span class="cx">/CalendarServer/branches/users/glyph/use-system-twisted:5084-5149
</span><span class="cx">/CalendarServer/branches/users/glyph/uuid-normalize:9268-9296
</span><span class="cx">/CalendarServer/branches/users/glyph/warning-cleanups:11347-11357
</span><span class="cx">/CalendarServer/branches/users/glyph/whenNotProposed:11881-11897
</span><span class="cx">/CalendarServer/branches/users/glyph/xattrs-from-files:7757-7769
</span><span class="cx">/CalendarServer/branches/users/sagen/applepush:8126-8184
</span><span class="cx">/CalendarServer/branches/users/sagen/inboxitems:7380-7381
</span><span class="cx">/CalendarServer/branches/users/sagen/locations-resources:5032-5051
</span><span class="cx">/CalendarServer/branches/users/sagen/locations-resources-2:5052-5061
</span><span class="cx">/CalendarServer/branches/users/sagen/move2who:12819-12860
</span><span class="cx">/CalendarServer/branches/users/sagen/move2who-2:12861-12898
</span><span class="cx">/CalendarServer/branches/users/sagen/move2who-3:12899-12913
</span><span class="cx">/CalendarServer/branches/users/sagen/purge_old_events:6735-6746
</span><span class="cx">/CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
</span><span class="cx">/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
</span><span class="cx">/CalendarServer/branches/users/sagen/resources-2:5084-5093
</span><span class="cx">/CalendarServer/branches/users/sagen/testing:10827-10851,10853-10855
</span><span class="cx">/CalendarServer/branches/users/wsanchez/transations:5515-5593
</span><a id="CalendarServerbranchesuserssagenmove2who4calendarserveraccesslogpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/accesslog.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/accesslog.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/accesslog.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -48,7 +48,6 @@
</span><span class="cx"> from twisted.protocols import amp
</span><span class="cx"> 
</span><span class="cx"> from twistedcaldav.config import config
</span><del>-from twistedcaldav.directory.directory import DirectoryService
</del><span class="cx"> 
</span><span class="cx"> from txdav.xml import element as davxml
</span><span class="cx"> 
</span><span class="lines">@@ -91,22 +90,27 @@
</span><span class="cx">                     if hasattr(request, &quot;authzUser&quot;) and str(request.authzUser.children[0]) != uidn:
</span><span class="cx">                         uidz = str(request.authzUser.children[0])
</span><span class="cx"> 
</span><del>-                    def convertUIDtoShortName(uid):
-                        uid = uid.rstrip(&quot;/&quot;)
-                        uid = uid[uid.rfind(&quot;/&quot;) + 1:]
-                        record = request.site.resource.getDirectory().recordWithUID(uid)
-                        if record:
-                            if record.recordType == DirectoryService.recordType_users:
-                                return record.shortNames[0]
-                            else:
-                                return &quot;(%s)%s&quot; % (record.recordType, record.shortNames[0],)
-                        else:
-                            return uid
</del><ins>+                    # def convertUIDtoShortName(uid):
+                    #     uid = uid.rstrip(&quot;/&quot;)
+                    #     uid = uid[uid.rfind(&quot;/&quot;) + 1:]
+                    #     record = request.site.resource.getDirectory().recordWithUID(uid)
+                    #     if record:
+                    #         if record.recordType == DirectoryService.recordType_users:
+                    #             return record.shortNames[0]
+                    #         else:
+                    #             return &quot;(%s)%s&quot; % (record.recordType, record.shortNames[0],)
+                    #     else:
+                    #         return uid
</ins><span class="cx"> 
</span><del>-                    uidn = convertUIDtoShortName(uidn)
-                    if uidz:
-                        uidz = convertUIDtoShortName(uidz)
</del><ins>+                    # MOVE2WHO
+                    # Better to stick the records directly on the request at
+                    # an earlier point, since we can't do anything deferred
+                    # in here.
</ins><span class="cx"> 
</span><ins>+                    # uidn = convertUIDtoShortName(uidn)
+                    # if uidz:
+                    #     uidz = convertUIDtoShortName(uidz)
+
</ins><span class="cx">                     if uidn and uidz:
</span><span class="cx">                         uid = '&quot;%s as %s&quot;' % (uidn, uidz,)
</span><span class="cx">                     else:
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4calendarserverprovisionrootpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -27,7 +27,7 @@
</span><span class="cx"> from txweb2.http import HTTPError, StatusResponse, RedirectResponse
</span><span class="cx"> 
</span><span class="cx"> from twisted.cred.error import LoginFailed, UnauthorizedLogin
</span><del>-from twisted.internet.defer import inlineCallbacks, returnValue
</del><ins>+from twisted.internet.defer import inlineCallbacks, returnValue, succeed
</ins><span class="cx"> from twisted.python.reflect import namedClass
</span><span class="cx"> from twisted.web.xmlrpc import Proxy
</span><span class="cx"> from twisted.web.error import Error as WebError
</span><span class="lines">@@ -110,7 +110,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def defaultAccessControlList(self):
</span><del>-        return config.RootResourceACL
</del><ins>+        return succeed(config.RootResourceACL)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4calendarserverpushapplepushpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/push/applepush.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/push/applepush.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/push/applepush.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -820,23 +820,25 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def defaultAccessControlList(self):
</span><del>-        return davxml.ACL(
-            # DAV:Read for authenticated principals
-            davxml.ACE(
-                davxml.Principal(davxml.Authenticated()),
-                davxml.Grant(
-                    davxml.Privilege(davxml.Read()),
</del><ins>+        return succeed(
+            davxml.ACL(
+                # DAV:Read for authenticated principals
+                davxml.ACE(
+                    davxml.Principal(davxml.Authenticated()),
+                    davxml.Grant(
+                        davxml.Privilege(davxml.Read()),
+                    ),
+                    davxml.Protected(),
</ins><span class="cx">                 ),
</span><del>-                davxml.Protected(),
-            ),
-            # DAV:Write for authenticated principals
-            davxml.ACE(
-                davxml.Principal(davxml.Authenticated()),
-                davxml.Grant(
-                    davxml.Privilege(davxml.Write()),
</del><ins>+                # DAV:Write for authenticated principals
+                davxml.ACE(
+                    davxml.Principal(davxml.Authenticated()),
+                    davxml.Grant(
+                        davxml.Privilege(davxml.Write()),
+                    ),
+                    davxml.Protected(),
</ins><span class="cx">                 ),
</span><del>-                davxml.Protected(),
-            ),
</del><ins>+            )
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4calendarservertapcaldavpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tap/caldav.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tap/caldav.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tap/caldav.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -90,14 +90,12 @@
</span><span class="cx"> from txdav.common.datastore.work.revision_cleanup import (
</span><span class="cx">     scheduleFirstFindMinRevision
</span><span class="cx"> )
</span><del>-from txdav.dps.server import DirectoryProxyServiceMaker
</del><ins>+from txdav.who.util import directoryFromConfig
</ins><span class="cx"> from txdav.dps.client import DirectoryService as DirectoryProxyClientService
</span><del>-from txdav.who.groups import GroupCacher as NewGroupCacher
</del><ins>+from txdav.who.groups import GroupCacher
</ins><span class="cx"> 
</span><span class="cx"> from twistedcaldav import memcachepool
</span><span class="cx"> from twistedcaldav.config import config, ConfigurationError
</span><del>-from twistedcaldav.directory import calendaruserproxy
-from twistedcaldav.directory.directory import GroupMembershipCacheUpdater
</del><span class="cx"> from twistedcaldav.localization import processLocalizationFiles
</span><span class="cx"> from twistedcaldav.stdconfig import DEFAULT_CONFIG, DEFAULT_CONFIG_FILE
</span><span class="cx"> from twistedcaldav.upgrade import UpgradeFileSystemFormatStep, PostDBImportStep
</span><span class="lines">@@ -536,10 +534,7 @@
</span><span class="cx">             )
</span><span class="cx">             self.monitor.addProcessObject(process, PARENT_ENVIRONMENT)
</span><span class="cx"> 
</span><del>-        if (
-           config.DirectoryProxy.Enabled and
-           config.DirectoryProxy.SocketPath != &quot;&quot;
-        ):
</del><ins>+        if (config.DirectoryProxy.SocketPath != &quot;&quot;):
</ins><span class="cx">             log.info(&quot;Adding directory proxy service&quot;)
</span><span class="cx"> 
</span><span class="cx">             dpsArgv = [
</span><span class="lines">@@ -863,10 +858,10 @@
</span><span class="cx">         CalDAV and CardDAV requests.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         pool, txnFactory = getDBPool(config)
</span><del>-        store = storeFromConfig(config, txnFactory)
</del><ins>+        directory = DirectoryProxyClientService(config.DirectoryRealmName)
+        store = storeFromConfig(config, txnFactory, directory)
</ins><span class="cx">         logObserver = AMPCommonAccessLoggingObserver()
</span><span class="cx">         result = self.requestProcessingService(options, store, logObserver)
</span><del>-        directory = store.directoryService()
</del><span class="cx"> 
</span><span class="cx">         if pool is not None:
</span><span class="cx">             pool.setServiceParent(result)
</span><span class="lines">@@ -938,14 +933,9 @@
</span><span class="cx"> 
</span><span class="cx">         # Optionally set up group cacher
</span><span class="cx">         if config.GroupCaching.Enabled:
</span><del>-            groupCacher = GroupMembershipCacheUpdater(
-                calendaruserproxy.ProxyDBService,
</del><ins>+            groupCacher = GroupCacher(
</ins><span class="cx">                 directory,
</span><del>-                config.GroupCaching.UpdateSeconds,
-                config.GroupCaching.ExpireSeconds,
-                config.GroupCaching.LockSeconds,
-                namespace=config.GroupCaching.MemcachedPool,
-                useExternalProxies=config.GroupCaching.UseExternalProxies,
</del><ins>+                updateSeconds=config.GroupCaching.UpdateSeconds
</ins><span class="cx">             )
</span><span class="cx">         else:
</span><span class="cx">             groupCacher = None
</span><span class="lines">@@ -1245,6 +1235,13 @@
</span><span class="cx">             if store is None:
</span><span class="cx">                 raise StoreNotAvailable()
</span><span class="cx"> 
</span><ins>+            # Create a Directory Proxy &quot;Server&quot; service and hand it to the
+            # store.
+            # FIXME: right now the store passed *to* the directory is the
+            # calendar/contacts data store, but for a multi-server deployment
+            # it will need its own separate store.
+            store.setDirectoryService(directoryFromConfig(config, store=store))
+
</ins><span class="cx">             result = self.requestProcessingService(options, store, logObserver)
</span><span class="cx"> 
</span><span class="cx">             # Optionally set up push notifications
</span><span class="lines">@@ -1281,21 +1278,12 @@
</span><span class="cx"> 
</span><span class="cx">             # Optionally set up group cacher
</span><span class="cx">             if config.GroupCaching.Enabled:
</span><del>-                groupCacher = GroupMembershipCacheUpdater(
-                    calendaruserproxy.ProxyDBService,
</del><ins>+                groupCacher = GroupCacher(
</ins><span class="cx">                     directory,
</span><del>-                    config.GroupCaching.UpdateSeconds,
-                    config.GroupCaching.ExpireSeconds,
-                    config.GroupCaching.LockSeconds,
-                    namespace=config.GroupCaching.MemcachedPool,
-                    useExternalProxies=config.GroupCaching.UseExternalProxies
</del><ins>+                    updateSeconds=config.GroupCaching.UpdateSeconds
</ins><span class="cx">                 )
</span><del>-                newGroupCacher = NewGroupCacher(
-                    DirectoryProxyClientService(None)
-                )
</del><span class="cx">             else:
</span><span class="cx">                 groupCacher = None
</span><del>-                newGroupCacher = None
</del><span class="cx"> 
</span><span class="cx">             # Optionally enable Manhole access
</span><span class="cx">             if config.Manhole.Enabled:
</span><span class="lines">@@ -1326,17 +1314,11 @@
</span><span class="cx">                         &quot;manhole_tap could not be imported&quot;
</span><span class="cx">                     )
</span><span class="cx"> 
</span><del>-            # Optionally enable Directory Proxy
-            if config.DirectoryProxy.Enabled:
-                dps = DirectoryProxyServiceMaker().makeService(None)
-                dps.setServiceParent(result)
-
</del><span class="cx">             def decorateTransaction(txn):
</span><span class="cx">                 txn._pushDistributor = pushDistributor
</span><span class="cx">                 txn._rootResource = result.rootResource
</span><span class="cx">                 txn._mailRetriever = mailRetriever
</span><span class="cx">                 txn._groupCacher = groupCacher
</span><del>-                txn._newGroupCacher = newGroupCacher
</del><span class="cx"> 
</span><span class="cx">             store.callWithNewTransactions(decorateTransaction)
</span><span class="cx"> 
</span><span class="lines">@@ -1376,7 +1358,7 @@
</span><span class="cx">                 Popen(memcachedArgv)
</span><span class="cx"> 
</span><span class="cx">         return self.storageService(
</span><del>-            slaveSvcCreator, logObserver, uid=uid, gid=gid
</del><ins>+            slaveSvcCreator, logObserver, uid=uid, gid=gid, directory=None
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -1389,10 +1371,17 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         def toolServiceCreator(pool, store, ignored, storageService):
</span><ins>+            # Create a Directory Proxy &quot;Server&quot; service and hand it to the
+            # store
+            # FIXME: right now the store passed *to* the directory is the
+            # calendar/contacts data store, but for a multi-server deployment
+            # it will need its own separate store.
+            store.setDirectoryService(directoryFromConfig(config, store=store))
</ins><span class="cx">             return config.UtilityServiceClass(store)
</span><span class="cx"> 
</span><span class="cx">         uid, gid = getSystemIDs(config.UserName, config.GroupName)
</span><del>-        return self.storageService(toolServiceCreator, None, uid=uid, gid=gid)
</del><ins>+        return self.storageService(toolServiceCreator, None, uid=uid, gid=gid,
+                                   directory=None)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def makeService_Agent(self, options):
</span><span class="lines">@@ -1440,7 +1429,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def storageService(
</span><del>-        self, createMainService, logObserver, uid=None, gid=None
</del><ins>+        self, createMainService, logObserver, uid=None, gid=None, directory=None
</ins><span class="cx">     ):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         If necessary, create a service to be started used for storage; for
</span><span class="lines">@@ -1466,6 +1455,9 @@
</span><span class="cx">             running as root (also the gid to chown Attachments to).
</span><span class="cx">         @type gid: C{int}
</span><span class="cx"> 
</span><ins>+        @param directory: The directory service to use.
+        @type directory: L{IStoreDirectoryService} or None
+
</ins><span class="cx">         @return: the appropriate a service to start.
</span><span class="cx">         @rtype: L{IService}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -1480,7 +1472,7 @@
</span><span class="cx">                     maxConnections=config.MaxDBConnectionsPerPool
</span><span class="cx">                 )
</span><span class="cx">                 cp.setServiceParent(ms)
</span><del>-                store = storeFromConfig(config, cp.connection)
</del><ins>+                store = storeFromConfig(config, cp.connection, directory)
</ins><span class="cx"> 
</span><span class="cx">                 pps = PreProcessingService(
</span><span class="cx">                     createMainService, cp, store, logObserver, storageService
</span><span class="lines">@@ -1605,7 +1597,7 @@
</span><span class="cx">                     &quot;Unknown database type {}&quot;.format(config.DBType)
</span><span class="cx">                 )
</span><span class="cx">         else:
</span><del>-            store = storeFromConfig(config, None)
</del><ins>+            store = storeFromConfig(config, None, directory)
</ins><span class="cx">             return createMainService(None, store, logObserver, None)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -1867,14 +1859,9 @@
</span><span class="cx"> 
</span><span class="cx">             # Optionally set up group cacher
</span><span class="cx">             if config.GroupCaching.Enabled:
</span><del>-                groupCacher = GroupMembershipCacheUpdater(
-                    calendaruserproxy.ProxyDBService,
</del><ins>+                groupCacher = GroupCacher(
</ins><span class="cx">                     directory,
</span><del>-                    config.GroupCaching.UpdateSeconds,
-                    config.GroupCaching.ExpireSeconds,
-                    config.GroupCaching.LockSeconds,
-                    namespace=config.GroupCaching.MemcachedPool,
-                    useExternalProxies=config.GroupCaching.UseExternalProxies
</del><ins>+                    updateSeconds=config.GroupCaching.UpdateSeconds
</ins><span class="cx">                 )
</span><span class="cx">             else:
</span><span class="cx">                 groupCacher = None
</span><span class="lines">@@ -1889,7 +1876,10 @@
</span><span class="cx"> 
</span><span class="cx">             return multi
</span><span class="cx"> 
</span><del>-        ssvc = self.storageService(spawnerSvcCreator, None, uid, gid)
</del><ins>+        ssvc = self.storageService(
+            spawnerSvcCreator, None, uid, gid,
+            directory=DirectoryProxyClientService(config.DirectoryRealmName)
+        )
</ins><span class="cx">         ssvc.setServiceParent(s)
</span><span class="cx">         return s
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4calendarservertaptesttest_utilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tap/test/test_util.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tap/test/test_util.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tap/test/test_util.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -14,13 +14,14 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><span class="cx"> 
</span><del>-from calendarserver.tap.util import directoryFromConfig, MemoryLimitService, Stepper
</del><ins>+from calendarserver.tap.util import MemoryLimitService, Stepper
</ins><span class="cx"> from twistedcaldav.util import computeProcessCount
</span><span class="cx"> from twistedcaldav.test.util import TestCase
</span><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from twistedcaldav.directory.augment import AugmentXMLDB
</span><span class="cx"> from twisted.internet.task import Clock
</span><span class="cx"> from twisted.internet.defer import succeed, inlineCallbacks
</span><ins>+from txdav.who.util import directoryFromConfig
</ins><span class="cx"> 
</span><span class="cx"> class ProcessCountTestCase(TestCase):
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4calendarservertaputilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tap/util.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tap/util.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tap/util.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -53,10 +53,8 @@
</span><span class="cx"> from twistedcaldav.cache import CacheStoreNotifierFactory
</span><span class="cx"> from twistedcaldav.directory import calendaruserproxy
</span><span class="cx"> from twistedcaldav.directory.addressbook import DirectoryAddressBookHomeProvisioningResource
</span><del>-from twistedcaldav.directory.aggregate import AggregateDirectoryService
</del><span class="cx"> from twistedcaldav.directory.calendar import DirectoryCalendarHomeProvisioningResource
</span><span class="cx"> from twistedcaldav.directory.digest import QopDigestCredentialFactory
</span><del>-from twistedcaldav.directory.directory import GroupMembershipCache
</del><span class="cx"> from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
</span><span class="cx"> from twistedcaldav.directory.wiki import WikiDirectoryService
</span><span class="cx"> from calendarserver.push.notifier import NotifierFactory
</span><span class="lines">@@ -100,7 +98,12 @@
</span><span class="cx"> from urllib import quote
</span><span class="cx"> from twisted.python.usage import UsageError
</span><span class="cx"> 
</span><ins>+from txdav.dps.client import DirectoryService as DirectoryProxyClientService
</ins><span class="cx"> 
</span><ins>+from twext.who.checker import UsernamePasswordCredentialChecker
+from twext.who.checker import HTTPDigestCredentialChecker
+from twisted.cred.error import UnauthorizedLogin
+from txweb2.dav.auth import IPrincipalCredentials
</ins><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -218,7 +221,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def storeFromConfig(config, txnFactory, directoryService=None):
</del><ins>+def storeFromConfig(config, txnFactory, directoryService):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Produce an L{IDataStore} from the given configuration, transaction factory,
</span><span class="cx">     and notifier factory.
</span><span class="lines">@@ -236,9 +239,6 @@
</span><span class="cx">     if config.EnableResponseCache and config.Memcached.Pools.Default.ClientEnabled:
</span><span class="cx">         notifierFactories[&quot;cache&quot;] = CacheStoreNotifierFactory()
</span><span class="cx"> 
</span><del>-    if directoryService is None:
-        directoryService = directoryFromConfig(config)
-
</del><span class="cx">     quota = config.UserQuota
</span><span class="cx">     if quota == 0:
</span><span class="cx">         quota = None
</span><span class="lines">@@ -281,10 +281,11 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def directoryFromConfig(config):
</del><ins>+def REMOVEMEdirectoryFromConfig(config):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Create an L{AggregateDirectoryService} from the given configuration.
</span><span class="cx">     &quot;&quot;&quot;
</span><ins>+
</ins><span class="cx">     #
</span><span class="cx">     # Setup the Augment Service
</span><span class="cx">     #
</span><span class="lines">@@ -370,7 +371,56 @@
</span><span class="cx">     return directory
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+# MOVE2WHO -- should we move this class somewhere else?
+class PrincipalCredentialChecker(object):
+    credentialInterfaces = (IPrincipalCredentials,)
</ins><span class="cx"> 
</span><ins>+    @inlineCallbacks
+    def requestAvatarId(self, credentials):
+        credentials = IPrincipalCredentials(credentials)
+
+        if credentials.authnPrincipal is None:
+            raise UnauthorizedLogin(&quot;No such user: %s&quot; % (credentials.credentials.username,))
+
+        # See if record is enabledForLogin
+        if not credentials.authnPrincipal.record.isLoginEnabled():
+            raise UnauthorizedLogin(
+                &quot;User not allowed to log in: {user}&quot;.format(
+                    user=credentials.credentials.username
+                )
+            )
+
+        # Handle Kerberos as a separate behavior
+        try:
+            from twistedcaldav.authkerb import NegotiateCredentials
+        except ImportError:
+            NegotiateCredentials = None
+
+        if NegotiateCredentials and isinstance(credentials.credentials,
+                                               NegotiateCredentials):
+            # If we get here with Kerberos, then authentication has already succeeded
+            returnValue(
+                (
+                    credentials.authnPrincipal.principalURL(),
+                    credentials.authzPrincipal.principalURL(),
+                    credentials.authnPrincipal,
+                    credentials.authzPrincipal,
+                )
+            )
+        else:
+            if (yield credentials.authnPrincipal.record.verifyCredentials(credentials.credentials)):
+                returnValue(
+                    (
+                        credentials.authnPrincipal.principalURL(),
+                        credentials.authzPrincipal.principalURL(),
+                        credentials.authnPrincipal,
+                        credentials.authzPrincipal,
+                    )
+                )
+            else:
+                raise UnauthorizedLogin(&quot;Incorrect credentials for %s&quot; % (credentials.credentials.username,))
+
+
</ins><span class="cx"> def getRootResource(config, newStore, resources=None):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Set up directory service and resource hierarchy based on config.
</span><span class="lines">@@ -407,22 +457,26 @@
</span><span class="cx">     addressBookResourceClass = DirectoryAddressBookHomeProvisioningResource
</span><span class="cx">     directoryBackedAddressBookResourceClass = DirectoryBackedAddressBookResource
</span><span class="cx">     apnSubscriptionResourceClass = APNSubscriptionResource
</span><ins>+    principalResourceClass = DirectoryPrincipalProvisioningResource
</ins><span class="cx"> 
</span><span class="cx">     directory = newStore.directoryService()
</span><ins>+    principalCollection = principalResourceClass(&quot;/principals/&quot;, directory)
</ins><span class="cx"> 
</span><span class="cx">     #
</span><span class="cx">     # Setup the ProxyDB Service
</span><span class="cx">     #
</span><del>-    proxydbClass = namedClass(config.ProxyDBService.type)
</del><span class="cx"> 
</span><del>-    log.info(&quot;Configuring proxydb service of type: {cls}&quot;, cls=proxydbClass)
</del><ins>+    # MOVE2WHO
+    # proxydbClass = namedClass(config.ProxyDBService.type)
</ins><span class="cx"> 
</span><del>-    try:
-        calendaruserproxy.ProxyDBService = proxydbClass(**config.ProxyDBService.params)
-    except IOError:
-        log.error(&quot;Could not start proxydb service&quot;)
-        raise
</del><ins>+    # log.info(&quot;Configuring proxydb service of type: {cls}&quot;, cls=proxydbClass)
</ins><span class="cx"> 
</span><ins>+    # try:
+    #     calendaruserproxy.ProxyDBService = proxydbClass(**config.ProxyDBService.params)
+    # except IOError:
+    #     log.error(&quot;Could not start proxydb service&quot;)
+    #     raise
+
</ins><span class="cx">     #
</span><span class="cx">     # Configure the Site and Wrappers
</span><span class="cx">     #
</span><span class="lines">@@ -431,9 +485,11 @@
</span><span class="cx"> 
</span><span class="cx">     portal = Portal(auth.DavRealm())
</span><span class="cx"> 
</span><del>-    portal.registerChecker(directory)
</del><ins>+    portal.registerChecker(UsernamePasswordCredentialChecker(directory))
+    portal.registerChecker(HTTPDigestCredentialChecker(directory))
+    portal.registerChecker(PrincipalCredentialChecker())
</ins><span class="cx"> 
</span><del>-    realm = directory.realmName or &quot;&quot;
</del><ins>+    realm = directory.realmName.encode(&quot;utf-8&quot;) or &quot;&quot;
</ins><span class="cx"> 
</span><span class="cx">     log.info(&quot;Configuring authentication for realm: {realm}&quot;, realm=realm)
</span><span class="cx"> 
</span><span class="lines">@@ -491,7 +547,7 @@
</span><span class="cx">     #
</span><span class="cx">     log.info(&quot;Setting up document root at: {root}&quot;, root=config.DocumentRoot)
</span><span class="cx"> 
</span><del>-    principalCollection = directory.principalCollection
</del><ins>+    # principalCollection = directory.principalCollection
</ins><span class="cx"> 
</span><span class="cx">     if config.EnableCalDAV:
</span><span class="cx">         log.info(&quot;Setting up calendar collection: {cls}&quot;, cls=calendarResourceClass)
</span><span class="lines">@@ -712,6 +768,7 @@
</span><span class="cx">     #
</span><span class="cx">     # Configure ancillary data
</span><span class="cx">     #
</span><ins>+    # MOVE2WHO
</ins><span class="cx">     log.info(&quot;Configuring authentication wrapper&quot;)
</span><span class="cx"> 
</span><span class="cx">     overrides = {}
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4calendarservertoolscalverifypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/calverify.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/calverify.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/calverify.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -431,7 +431,7 @@
</span><span class="cx">         configuration, creating one first if necessary.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self._directory is None:
</span><del>-            self._directory = getDirectory(self.config) #directoryFromConfig(self.config)
</del><ins>+            self._directory = getDirectory(self.config)
</ins><span class="cx">         return self._directory
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4calendarservertoolsprincipalspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/principals.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -26,17 +26,15 @@
</span><span class="cx"> from twisted.internet import reactor
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue, succeed
</span><span class="cx"> from txdav.xml import element as davxml
</span><ins>+from txdav.who.delegates import addDelegate, removeDelegate
</ins><span class="cx"> 
</span><del>-from txdav.xml.base import decodeXMLName, encodeXMLName
</del><span class="cx"> 
</span><span class="cx"> from twistedcaldav.config import config
</span><del>-from twistedcaldav.directory.directory import UnknownRecordTypeError, DirectoryError
</del><span class="cx"> from txdav.who.groups import schedulePolledGroupCachingUpdate
</span><span class="cx"> 
</span><span class="cx"> from calendarserver.tools.util import (
</span><del>-    booleanArgument, proxySubprincipal, action_addProxyPrincipal,
-    principalForPrincipalID, prettyPrincipal, ProxyError,
-    action_removeProxyPrincipal
</del><ins>+    booleanArgument, proxySubprincipal,
+    recordForPrincipalID, prettyPrincipal, prettyRecord, ProxyError
</ins><span class="cx"> )
</span><span class="cx"> from twistedcaldav.directory.augment import allowedAutoScheduleModes
</span><span class="cx"> 
</span><span class="lines">@@ -45,11 +43,6 @@
</span><span class="cx"> 
</span><span class="cx"> def usage(e=None):
</span><span class="cx">     if e:
</span><del>-        if isinstance(e, UnknownRecordTypeError):
-            print(&quot;Valid record types:&quot;)
-            for recordType in config.directory.recordTypes():
-                print(&quot;    %s&quot; % (recordType,))
-
</del><span class="cx">         print(e)
</span><span class="cx">         print(&quot;&quot;)
</span><span class="cx"> 
</span><span class="lines">@@ -74,10 +67,10 @@
</span><span class="cx">     print(&quot;  --search &lt;search-string&gt;: search for matching principals&quot;)
</span><span class="cx">     print(&quot;  --list-principal-types: list all of the known principal types&quot;)
</span><span class="cx">     print(&quot;  --list-principals type: list all principals of the given type&quot;)
</span><del>-    print(&quot;  --read-property=property: read DAV property (eg.: {DAV:}group-member-set)&quot;)
</del><span class="cx">     print(&quot;  --list-read-proxies: list proxies with read-only access&quot;)
</span><span class="cx">     print(&quot;  --list-write-proxies: list proxies with read-write access&quot;)
</span><span class="cx">     print(&quot;  --list-proxies: list all proxies&quot;)
</span><ins>+    print(&quot;  --list-proxy-for: principals this principal is a proxy for&quot;)
</ins><span class="cx">     print(&quot;  --add-read-proxy=principal: add a read-only proxy&quot;)
</span><span class="cx">     print(&quot;  --add-write-proxy=principal: add a read-write proxy&quot;)
</span><span class="cx">     print(&quot;  --remove-proxy=principal: remove a proxy&quot;)
</span><span class="lines">@@ -118,30 +111,29 @@
</span><span class="cx">         resource, directory, store, and whatever has been assigned to &quot;params&quot;.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self.function is not None:
</span><del>-            rootResource = self.rootResource()
-            directory = rootResource.getDirectory()
-            yield self.function(rootResource, directory, self.store, *self.params)
</del><ins>+            yield self.function(self.store, *self.params)
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> attrMap = {
</span><del>-    'GeneratedUID' : { 'attr' : 'guid', },
-    'RealName' : { 'attr' : 'fullName', },
-    'RecordName' : { 'attr' : 'shortNames', },
-    'AutoSchedule' : { 'attr' : 'autoSchedule', },
-    'AutoAcceptGroup' : { 'attr' : 'autoAcceptGroup', },
</del><ins>+    'GeneratedUID': {'attr': 'guid', },
+    'RealName': {'attr': 'fullName', },
+    'RecordName': {'attr': 'shortNames', },
+    'AutoSchedule': {'attr': 'autoSchedule', },
+    'AutoAcceptGroup': {'attr': 'autoAcceptGroup', },
</ins><span class="cx"> 
</span><del>-    'Comment' : { 'extras' : True, 'attr' : 'comment', },
-    'Description' : { 'extras' : True, 'attr' : 'description', },
-    'Type' : { 'extras' : True, 'attr' : 'type', },
</del><ins>+    'Comment': {'extras': True, 'attr': 'comment', },
+    'Description': {'extras': True, 'attr': 'description', },
+    'Type': {'extras': True, 'attr': 'type', },
</ins><span class="cx"> 
</span><span class="cx">     # For &quot;Locations&quot;, i.e. scheduled spaces
</span><del>-    'Capacity' : { 'extras' : True, 'attr' : 'capacity', },
-    'Floor' : { 'extras' : True, 'attr' : 'floor', },
-    'AssociatedAddress' : { 'extras' : True, 'attr' : 'associatedAddress', },
</del><ins>+    'Capacity': {'extras': True, 'attr': 'capacity', },
+    'Floor': {'extras': True, 'attr': 'floor', },
+    'AssociatedAddress': {'extras': True, 'attr': 'associatedAddress', },
</ins><span class="cx"> 
</span><span class="cx">     # For &quot;Addresses&quot;, i.e. nonscheduled areas containing Locations
</span><del>-    'AbbreviatedName' : { 'extras' : True, 'attr' : 'abbreviatedName', },
-    'StreetAddress' : { 'extras' : True, 'attr' : 'streetAddress', },
-    'Geo' : { 'extras' : True, 'attr' : 'geo', },
</del><ins>+    'AbbreviatedName': {'extras': True, 'attr': 'abbreviatedName', },
+    'StreetAddress': {'extras': True, 'attr': 'streetAddress', },
+    'Geo': {'extras': True, 'attr': 'geo', },
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -156,10 +148,10 @@
</span><span class="cx">                 &quot;search=&quot;,
</span><span class="cx">                 &quot;list-principal-types&quot;,
</span><span class="cx">                 &quot;list-principals=&quot;,
</span><del>-                &quot;read-property=&quot;,
</del><span class="cx">                 &quot;list-read-proxies&quot;,
</span><span class="cx">                 &quot;list-write-proxies&quot;,
</span><span class="cx">                 &quot;list-proxies&quot;,
</span><ins>+                &quot;list-proxy-for&quot;,
</ins><span class="cx">                 &quot;add-read-proxy=&quot;,
</span><span class="cx">                 &quot;add-write-proxy=&quot;,
</span><span class="cx">                 &quot;remove-proxy=&quot;,
</span><span class="lines">@@ -185,7 +177,7 @@
</span><span class="cx">     # Get configuration
</span><span class="cx">     #
</span><span class="cx">     configFileName = None
</span><del>-    addType = None
</del><ins>+    # addType = None
</ins><span class="cx">     listPrincipalTypes = False
</span><span class="cx">     listPrincipals = None
</span><span class="cx">     searchPrincipals = None
</span><span class="lines">@@ -193,6 +185,10 @@
</span><span class="cx">     verbose = False
</span><span class="cx"> 
</span><span class="cx">     for opt, arg in optargs:
</span><ins>+
+        # Args come in as encoded bytes
+        arg = arg.decode(&quot;utf-8&quot;)
+
</ins><span class="cx">         if opt in (&quot;-h&quot;, &quot;--help&quot;):
</span><span class="cx">             usage()
</span><span class="cx"> 
</span><span class="lines">@@ -202,11 +198,11 @@
</span><span class="cx">         elif opt in (&quot;-f&quot;, &quot;--config&quot;):
</span><span class="cx">             configFileName = arg
</span><span class="cx"> 
</span><del>-        elif opt in (&quot;-a&quot;, &quot;--add&quot;):
-            addType = arg
</del><ins>+        # elif opt in (&quot;-a&quot;, &quot;--add&quot;):
+        #     addType = arg
</ins><span class="cx"> 
</span><del>-        elif opt in (&quot;-r&quot;, &quot;--remove&quot;):
-            principalActions.append((action_removePrincipal,))
</del><ins>+        # elif opt in (&quot;-r&quot;, &quot;--remove&quot;):
+        #     principalActions.append((action_removePrincipal,))
</ins><span class="cx"> 
</span><span class="cx">         elif opt in (&quot;&quot;, &quot;--list-principal-types&quot;):
</span><span class="cx">             listPrincipalTypes = True
</span><span class="lines">@@ -217,13 +213,6 @@
</span><span class="cx">         elif opt in (&quot;&quot;, &quot;--search&quot;):
</span><span class="cx">             searchPrincipals = arg
</span><span class="cx"> 
</span><del>-        elif opt in (&quot;&quot;, &quot;--read-property&quot;):
-            try:
-                qname = decodeXMLName(arg)
-            except ValueError, e:
-                abort(e)
-            principalActions.append((action_readProperty, qname))
-
</del><span class="cx">         elif opt in (&quot;&quot;, &quot;--list-read-proxies&quot;):
</span><span class="cx">             principalActions.append((action_listProxies, &quot;read&quot;))
</span><span class="cx"> 
</span><span class="lines">@@ -233,6 +222,9 @@
</span><span class="cx">         elif opt in (&quot;-L&quot;, &quot;--list-proxies&quot;):
</span><span class="cx">             principalActions.append((action_listProxies, &quot;read&quot;, &quot;write&quot;))
</span><span class="cx"> 
</span><ins>+        elif opt in (&quot;--list-proxy-for&quot;):
+            principalActions.append((action_listProxyFor, &quot;read&quot;, &quot;write&quot;))
+
</ins><span class="cx">         elif opt in (&quot;--add-read-proxy&quot;, &quot;--add-write-proxy&quot;):
</span><span class="cx">             if &quot;read&quot; in opt:
</span><span class="cx">                 proxyType = &quot;read&quot;
</span><span class="lines">@@ -240,74 +232,63 @@
</span><span class="cx">                 proxyType = &quot;write&quot;
</span><span class="cx">             else:
</span><span class="cx">                 raise AssertionError(&quot;Unknown proxy type&quot;)
</span><del>-
-            try:
-                principalForPrincipalID(arg, checkOnly=True)
-            except ValueError, e:
-                abort(e)
-
</del><span class="cx">             principalActions.append((action_addProxy, proxyType, arg))
</span><span class="cx"> 
</span><span class="cx">         elif opt in (&quot;&quot;, &quot;--remove-proxy&quot;):
</span><del>-            try:
-                principalForPrincipalID(arg, checkOnly=True)
-            except ValueError, e:
-                abort(e)
-
</del><span class="cx">             principalActions.append((action_removeProxy, arg))
</span><span class="cx"> 
</span><del>-        elif opt in (&quot;&quot;, &quot;--set-auto-schedule&quot;):
-            try:
-                autoSchedule = booleanArgument(arg)
-            except ValueError, e:
-                abort(e)
</del><ins>+        # elif opt in (&quot;&quot;, &quot;--set-auto-schedule&quot;):
+        #     try:
+        #         autoSchedule = booleanArgument(arg)
+        #     except ValueError, e:
+        #         abort(e)
</ins><span class="cx"> 
</span><del>-            principalActions.append((action_setAutoSchedule, autoSchedule))
</del><ins>+        #     principalActions.append((action_setAutoSchedule, autoSchedule))
</ins><span class="cx"> 
</span><del>-        elif opt in (&quot;&quot;, &quot;--get-auto-schedule&quot;):
-            principalActions.append((action_getAutoSchedule,))
</del><ins>+        # elif opt in (&quot;&quot;, &quot;--get-auto-schedule&quot;):
+        #     principalActions.append((action_getAutoSchedule,))
</ins><span class="cx"> 
</span><del>-        elif opt in (&quot;&quot;, &quot;--set-auto-schedule-mode&quot;):
-            try:
-                if arg not in allowedAutoScheduleModes:
-                    raise ValueError(&quot;Unknown auto-schedule mode: %s&quot; % (arg,))
-                autoScheduleMode = arg
-            except ValueError, e:
-                abort(e)
</del><ins>+        # elif opt in (&quot;&quot;, &quot;--set-auto-schedule-mode&quot;):
+        #     try:
+        #         if arg not in allowedAutoScheduleModes:
+        #             raise ValueError(&quot;Unknown auto-schedule mode: %s&quot; % (arg,))
+        #         autoScheduleMode = arg
+        #     except ValueError, e:
+        #         abort(e)
</ins><span class="cx"> 
</span><del>-            principalActions.append((action_setAutoScheduleMode, autoScheduleMode))
</del><ins>+        #     principalActions.append((action_setAutoScheduleMode, autoScheduleMode))
</ins><span class="cx"> 
</span><del>-        elif opt in (&quot;&quot;, &quot;--get-auto-schedule-mode&quot;):
-            principalActions.append((action_getAutoScheduleMode,))
</del><ins>+        # elif opt in (&quot;&quot;, &quot;--get-auto-schedule-mode&quot;):
+        #     principalActions.append((action_getAutoScheduleMode,))
</ins><span class="cx"> 
</span><del>-        elif opt in (&quot;&quot;, &quot;--set-auto-accept-group&quot;):
-            try:
-                principalForPrincipalID(arg, checkOnly=True)
-            except ValueError, e:
-                abort(e)
</del><ins>+        # elif opt in (&quot;&quot;, &quot;--set-auto-accept-group&quot;):
+        #     try:
+        #         yield recordForPrincipalID(arg, checkOnly=True)
+        #     except ValueError, e:
+        #         abort(e)
</ins><span class="cx"> 
</span><del>-            principalActions.append((action_setAutoAcceptGroup, arg))
</del><ins>+        #     principalActions.append((action_setAutoAcceptGroup, arg))
</ins><span class="cx"> 
</span><del>-        elif opt in (&quot;&quot;, &quot;--get-auto-accept-group&quot;):
-            principalActions.append((action_getAutoAcceptGroup,))
</del><ins>+        # elif opt in (&quot;&quot;, &quot;--get-auto-accept-group&quot;):
+        #     principalActions.append((action_getAutoAcceptGroup,))
</ins><span class="cx"> 
</span><del>-        elif opt in (&quot;&quot;, &quot;--set-geo&quot;):
-            principalActions.append((action_setValue, &quot;Geo&quot;, arg))
</del><ins>+        # elif opt in (&quot;&quot;, &quot;--set-geo&quot;):
+        #     principalActions.append((action_setValue, &quot;Geo&quot;, arg))
</ins><span class="cx"> 
</span><del>-        elif opt in (&quot;&quot;, &quot;--get-geo&quot;):
-            principalActions.append((action_getValue, &quot;Geo&quot;))
</del><ins>+        # elif opt in (&quot;&quot;, &quot;--get-geo&quot;):
+        #     principalActions.append((action_getValue, &quot;Geo&quot;))
</ins><span class="cx"> 
</span><del>-        elif opt in (&quot;&quot;, &quot;--set-street-address&quot;):
-            principalActions.append((action_setValue, &quot;StreetAddress&quot;, arg))
</del><ins>+        # elif opt in (&quot;&quot;, &quot;--set-street-address&quot;):
+        #     principalActions.append((action_setValue, &quot;StreetAddress&quot;, arg))
</ins><span class="cx"> 
</span><del>-        elif opt in (&quot;&quot;, &quot;--get-street-address&quot;):
-            principalActions.append((action_getValue, &quot;StreetAddress&quot;))
</del><ins>+        # elif opt in (&quot;&quot;, &quot;--get-street-address&quot;):
+        #     principalActions.append((action_getValue, &quot;StreetAddress&quot;))
</ins><span class="cx"> 
</span><del>-        elif opt in (&quot;&quot;, &quot;--set-address&quot;):
-            principalActions.append((action_setValue, &quot;AssociatedAddress&quot;, arg))
</del><ins>+        # elif opt in (&quot;&quot;, &quot;--set-address&quot;):
+        #     principalActions.append((action_setValue, &quot;AssociatedAddress&quot;, arg))
</ins><span class="cx"> 
</span><del>-        elif opt in (&quot;&quot;, &quot;--get-address&quot;):
-            principalActions.append((action_getValue, &quot;AssociatedAddress&quot;))
</del><ins>+        # elif opt in (&quot;&quot;, &quot;--get-address&quot;):
+        #     principalActions.append((action_getValue, &quot;AssociatedAddress&quot;))
</ins><span class="cx"> 
</span><span class="cx">         else:
</span><span class="cx">             raise NotImplementedError(opt)
</span><span class="lines">@@ -322,32 +303,34 @@
</span><span class="cx">         function = runListPrincipalTypes
</span><span class="cx">         params = ()
</span><span class="cx"> 
</span><del>-    elif addType:
</del><ins>+    # elif addType:
</ins><span class="cx"> 
</span><del>-        try:
-            addType = matchStrings(addType, [&quot;locations&quot;, &quot;resources&quot;, &quot;addresses&quot;])
-        except ValueError, e:
-            print(e)
-            return
</del><ins>+    #     try:
+    #         addType = matchStrings(addType, [&quot;locations&quot;, &quot;resources&quot;, &quot;addresses&quot;])
+    #     except ValueError, e:
+    #         print(e)
+    #         return
</ins><span class="cx"> 
</span><del>-        try:
-            fullName, shortName, guid = parseCreationArgs(args)
-        except ValueError, e:
-            print(e)
-            return
</del><ins>+    #     try:
+    #         fullName, shortName, guid = parseCreationArgs(args)
+    #     except ValueError, e:
+    #         print(e)
+    #         return
</ins><span class="cx"> 
</span><del>-        if shortName is not None:
-            shortNames = [shortName]
-        else:
-            shortNames = ()
</del><ins>+    #     if shortName is not None:
+    #         shortNames = [shortName]
+    #     else:
+    #         shortNames = ()
</ins><span class="cx"> 
</span><del>-        function = runAddPrincipal
-        params = (addType, guid, shortNames, fullName)
</del><ins>+    #     function = runAddPrincipal
+    #     params = (addType, guid, shortNames, fullName)
</ins><span class="cx"> 
</span><span class="cx">     elif listPrincipals:
</span><span class="cx">         try:
</span><del>-            listPrincipals = matchStrings(listPrincipals, [&quot;users&quot;, &quot;groups&quot;,
-                &quot;locations&quot;, &quot;resources&quot;, &quot;addresses&quot;])
</del><ins>+            listPrincipals = matchStrings(
+                listPrincipals,
+                [&quot;users&quot;, &quot;groups&quot;, &quot;locations&quot;, &quot;resources&quot;, &quot;addresses&quot;]
+            )
</ins><span class="cx">         except ValueError, e:
</span><span class="cx">             print(e)
</span><span class="cx">             return
</span><span class="lines">@@ -363,21 +346,19 @@
</span><span class="cx">         params = (searchPrincipals,)
</span><span class="cx"> 
</span><span class="cx">     else:
</span><del>-        #
-        # Do a quick sanity check that arguments look like principal
-        # identifiers.
-        #
</del><span class="cx">         if not args:
</span><span class="cx">             usage(&quot;No principals specified.&quot;)
</span><span class="cx"> 
</span><del>-        for arg in args:
-            try:
-                principalForPrincipalID(arg, checkOnly=True)
-            except ValueError, e:
-                abort(e)
</del><ins>+        # We don't have a directory yet
+        # for arg in args:
+        #     try:
+        #         yield recordForPrincipalID(arg, checkOnly=True)
+        #     except ValueError, e:
+        #         abort(e)
</ins><span class="cx"> 
</span><ins>+        unicodeArgs = [a.decode(&quot;utf-8&quot;) for a in args]
</ins><span class="cx">         function = runPrincipalActions
</span><del>-        params = (args, principalActions)
</del><ins>+        params = (unicodeArgs, principalActions)
</ins><span class="cx"> 
</span><span class="cx">     PrincipalService.function = function
</span><span class="cx">     PrincipalService.params = params
</span><span class="lines">@@ -385,74 +366,86 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def runListPrincipalTypes(service, rootResource, directory, store):
</del><ins>+def runListPrincipalTypes(service, store):
+    directory = store.directoryService()
</ins><span class="cx">     for recordType in directory.recordTypes():
</span><del>-        print(recordType)
</del><ins>+        print(directory.recordTypeToOldString(recordType))
</ins><span class="cx">     return succeed(None)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def runListPrincipals(service, rootResource, directory, store, listPrincipals):
</del><ins>+@inlineCallbacks
+def runListPrincipals(service, store, listPrincipals):
+    directory = store.directoryService()
+    recordType = directory.oldNameToRecordType(listPrincipals)
</ins><span class="cx">     try:
</span><del>-        records = list(directory.listRecords(listPrincipals))
</del><ins>+        records = list((yield directory.recordsWithRecordType(recordType)))
</ins><span class="cx">         if records:
</span><span class="cx">             printRecordList(records)
</span><span class="cx">         else:
</span><span class="cx">             print(&quot;No records of type %s&quot; % (listPrincipals,))
</span><span class="cx">     except UnknownRecordTypeError, e:
</span><span class="cx">         usage(e)
</span><del>-    return succeed(None)
</del><ins>+    returnValue(None)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> @inlineCallbacks
</span><del>-def runPrincipalActions(service, rootResource, directory, store, principalIDs,
-    actions):
</del><ins>+def runPrincipalActions(service, store, principalIDs, actions):
+    directory = store.directoryService()
</ins><span class="cx">     for principalID in principalIDs:
</span><del>-        # Resolve the given principal IDs to principals
</del><ins>+        # Resolve the given principal IDs to records
</ins><span class="cx">         try:
</span><del>-            principal = principalForPrincipalID(principalID, directory=directory)
</del><ins>+            record = yield recordForPrincipalID(directory, principalID)
</ins><span class="cx">         except ValueError:
</span><del>-            principal = None
</del><ins>+            record = None
</ins><span class="cx"> 
</span><del>-        if principal is None:
</del><ins>+        if record is None:
</ins><span class="cx">             sys.stderr.write(&quot;Invalid principal ID: %s\n&quot; % (principalID,))
</span><span class="cx">             continue
</span><span class="cx"> 
</span><span class="cx">         # Performs requested actions
</span><span class="cx">         for action in actions:
</span><del>-            (yield action[0](rootResource, directory, store, principal,
-                *action[1:]))
</del><ins>+            (yield action[0](store, record, *action[1:]))
</ins><span class="cx">             print(&quot;&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> @inlineCallbacks
</span><del>-def runSearch(service, rootResource, directory, store, searchTerm):
-
</del><ins>+def runSearch(service, store, searchTerm):
+    directory = store.directoryService()
</ins><span class="cx">     fields = []
</span><del>-    for fieldName in (&quot;fullName&quot;, &quot;firstName&quot;, &quot;lastName&quot;, &quot;emailAddresses&quot;):
</del><ins>+    for fieldName in (&quot;fullNames&quot;, &quot;emailAddresses&quot;):
</ins><span class="cx">         fields.append((fieldName, searchTerm, True, &quot;contains&quot;))
</span><span class="cx"> 
</span><span class="cx">     records = list((yield directory.recordsMatchingTokens(searchTerm.strip().split())))
</span><span class="cx">     if records:
</span><del>-        records.sort(key=operator.attrgetter('fullName'))
-        print(&quot;%d matches found:&quot; % (len(records),))
</del><ins>+        records.sort(key=operator.attrgetter('fullNames'))
+        print(&quot;{n} matches found:&quot;.format(n=len(records)))
</ins><span class="cx">         for record in records:
</span><del>-            print(&quot;\n%s (%s)&quot; % (record.fullName,
-                {&quot;users&quot; : &quot;User&quot;,
-                 &quot;groups&quot; : &quot;Group&quot;,
-                 &quot;locations&quot; : &quot;Place&quot;,
-                 &quot;resources&quot; : &quot;Resource&quot;,
-                 &quot;addresses&quot; : &quot;Address&quot;,
-                }.get(record.recordType),
-            ))
-            print(&quot;   GUID: %s&quot; % (record.guid,))
-            print(&quot;   Record name(s): %s&quot; % (&quot;, &quot;.join(record.shortNames),))
-            if record.authIDs:
-                print(&quot;   Auth ID(s): %s&quot; % (&quot;, &quot;.join(record.authIDs),))
-            if record.emailAddresses:
-                print(&quot;   Email(s): %s&quot; % (&quot;, &quot;.join(record.emailAddresses),))
</del><ins>+            print(
+                &quot;\n{d} ({rt})&quot;.format(
+                    d=record.displayName,
+                    rt=record.recordType.name
+                )
+            )
+            print(&quot;   UID: {u}&quot;.format(u=record.uid,))
+            print(
+                &quot;   Record name{plural}: {names}&quot;.format(
+                    plural=(&quot;s&quot; if len(record.shortNames) &gt; 1 else &quot;&quot;),
+                    names=(&quot;, &quot;.join(record.shortNames))
+                )
+            )
+            try:
+                if record.emailAddresses:
+                    print(
+                        &quot;   Email{plural}: {emails}&quot;.format(
+                            plural=(&quot;s&quot; if len(record.emailAddresses) &gt; 1 else &quot;&quot;),
+                            emails=(&quot;, &quot;.join(record.emailAddresses))
+                        )
+                    )
+            except AttributeError:
+                pass
</ins><span class="cx">     else:
</span><span class="cx">         print(&quot;No matches found&quot;)
</span><span class="cx"> 
</span><span class="lines">@@ -460,292 +453,318 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-@inlineCallbacks
-def runAddPrincipal(service, rootResource, directory, store, addType, guid,
-    shortNames, fullName):
-    try:
-        yield updateRecord(True, directory, addType, guid=guid,
-            shortNames=shortNames, fullName=fullName)
-        print(&quot;Added '%s'&quot; % (fullName,))
-    except DirectoryError, e:
-        print(e)
</del><ins>+# @inlineCallbacks
+# def runAddPrincipal(service, store, addType, guid, shortNames, fullName):
+#     directory = store.directoryService()
+#     try:
+#         # FIXME STOP USING GUID
+#         yield updateRecord(
+#             True, directory, addType, guid=guid,
+#             shortNames=shortNames, fullName=fullName
+#         )
+#         print(&quot;Added '%s'&quot; % (fullName,))
+#     except DirectoryError, e:
+#         print(e)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def action_removePrincipal(rootResource, directory, store, principal):
-    record = principal.record
-    fullName = record.fullName
-    shortName = record.shortNames[0]
-    guid = record.guid
</del><ins>+# def action_removePrincipal(store, record):
+#     directory = store.directoryService()
+#     fullName = record.displayName
+#     shortName = record.shortNames[0]
</ins><span class="cx"> 
</span><del>-    directory.destroyRecord(record.recordType, guid=guid)
-    print(&quot;Removed '%s' %s %s&quot; % (fullName, shortName, guid))
</del><ins>+#     yield directory.destroyRecord(record.recordType, uid=record.uid)
+#     print(&quot;Removed '%s' %s %s&quot; % (fullName, shortName, record.uid))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> @inlineCallbacks
</span><del>-def action_readProperty(rootResource, directory, store, resource, qname):
-    property = (yield resource.readProperty(qname, None))
-    print(&quot;%r on %s:&quot; % (encodeXMLName(*qname), resource))
-    print(&quot;&quot;)
-    print(property.toxml())
</del><ins>+def action_listProxies(store, record, *proxyTypes):
+    directory = store.directoryService()
+    for proxyType in proxyTypes:
</ins><span class="cx"> 
</span><ins>+        groupRecordType = {
+            &quot;read&quot;: directory.recordType.readDelegateGroup,
+            &quot;write&quot;: directory.recordType.writeDelegateGroup,
+        }.get(proxyType)
</ins><span class="cx"> 
</span><ins>+        pseudoGroup = yield directory.recordWithShortName(
+            groupRecordType,
+            record.uid
+        )
+        proxies = yield pseudoGroup.members()
+        if proxies:
+            print(&quot;%s proxies for %s:&quot; % (
+                {&quot;read&quot;: &quot;Read-only&quot;, &quot;write&quot;: &quot;Read/write&quot;}[proxyType],
+                prettyRecord(record)
+            ))
+            printRecordList(proxies)
+            print(&quot;&quot;)
+        else:
+            print(&quot;No %s proxies for %s&quot; % (proxyType, prettyRecord(record)))
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> @inlineCallbacks
</span><del>-def action_listProxies(rootResource, directory, store, principal, *proxyTypes):
</del><ins>+def action_listProxyFor(store, record, *proxyTypes):
+    directory = store.directoryService()
</ins><span class="cx">     for proxyType in proxyTypes:
</span><del>-        subPrincipal = proxySubprincipal(principal, proxyType)
-        if subPrincipal is None:
-            print(&quot;No %s proxies for %s&quot; % (proxyType,
-                prettyPrincipal(principal)))
-            continue
</del><span class="cx"> 
</span><del>-        membersProperty = (yield subPrincipal.readProperty(davxml.GroupMemberSet, None))
</del><ins>+        groupRecordType = {
+            &quot;read&quot;: directory.recordType.readDelegatorGroup,
+            &quot;write&quot;: directory.recordType.writeDelegatorGroup,
+        }.get(proxyType)
</ins><span class="cx"> 
</span><del>-        if membersProperty.children:
-            print(&quot;%s proxies for %s:&quot; % (
-                {&quot;read&quot;: &quot;Read-only&quot;, &quot;write&quot;: &quot;Read/write&quot;}[proxyType],
-                prettyPrincipal(principal)
</del><ins>+        pseudoGroup = yield directory.recordWithShortName(
+            groupRecordType,
+            record.uid
+        )
+        proxies = yield pseudoGroup.members()
+        if proxies:
+            print(&quot;%s is a %s proxy for:&quot; % (
+                prettyRecord(record),
+                {&quot;read&quot;: &quot;Read-only&quot;, &quot;write&quot;: &quot;Read/write&quot;}[proxyType]
</ins><span class="cx">             ))
</span><del>-            records = []
-            for member in membersProperty.children:
-                proxyPrincipal = principalForPrincipalID(str(member),
-                    directory=directory)
-                records.append(proxyPrincipal.record)
-
-            printRecordList(records)
-            print
</del><ins>+            printRecordList(proxies)
+            print(&quot;&quot;)
</ins><span class="cx">         else:
</span><del>-            print(&quot;No %s proxies for %s&quot; % (proxyType,
-                prettyPrincipal(principal)))
</del><ins>+            print(
+                &quot;{r} is not a {t} proxy for anyone&quot;.format(
+                    r=prettyRecord(record),
+                    t={&quot;read&quot;: &quot;Read-only&quot;, &quot;write&quot;: &quot;Read/write&quot;}[proxyType]
+                )
+            )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> @inlineCallbacks
</span><del>-def action_addProxy(rootResource, directory, store, principal, proxyType, *proxyIDs):
</del><ins>+def _addRemoveProxy(fn, store, record, proxyType, *proxyIDs):
+    directory = store.directoryService()
+    readWrite = (proxyType == &quot;write&quot;)
</ins><span class="cx">     for proxyID in proxyIDs:
</span><del>-        proxyPrincipal = principalForPrincipalID(proxyID, directory=directory)
-        if proxyPrincipal is None:
</del><ins>+        proxyRecord = yield recordForPrincipalID(directory, proxyID)
+        if proxyRecord is None:
</ins><span class="cx">             print(&quot;Invalid principal ID: %s&quot; % (proxyID,))
</span><span class="cx">         else:
</span><del>-            (yield action_addProxyPrincipal(rootResource, directory, store,
-                principal, proxyType, proxyPrincipal))
</del><ins>+            txn = store.newTransaction()
+            yield fn(txn, record, proxyRecord, readWrite)
+            yield txn.commit()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+def action_addProxy(store, record, proxyType, *proxyIDs):
+    return _addRemoveProxy(addDelegate, store, record, proxyType, *proxyIDs)
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> @inlineCallbacks
</span><del>-def setProxies(store, principal, readProxyPrincipals, writeProxyPrincipals, directory=None):
-    &quot;&quot;&quot;
-    Set read/write proxies en masse for a principal
-    @param principal: DirectoryPrincipalResource
-    @param readProxyPrincipals: a list of principal IDs (see principalForPrincipalID)
-    @param writeProxyPrincipals: a list of principal IDs (see principalForPrincipalID)
-    &quot;&quot;&quot;
</del><ins>+def action_removeProxy(store, record, *proxyIDs):
+    # Write
+    yield _addRemoveProxy(removeDelegate, store, record, &quot;write&quot;, *proxyIDs)
+    # Read
+    yield _addRemoveProxy(removeDelegate, store, record, &quot;read&quot;, *proxyIDs)
</ins><span class="cx"> 
</span><del>-    proxyTypes = [
-        (&quot;read&quot;, readProxyPrincipals),
-        (&quot;write&quot;, writeProxyPrincipals),
-    ]
-    for proxyType, proxyIDs in proxyTypes:
-        if proxyIDs is None:
-            continue
-        subPrincipal = proxySubprincipal(principal, proxyType)
-        if subPrincipal is None:
-            raise ProxyError(&quot;Unable to edit %s proxies for %s\n&quot; % (proxyType,
-                prettyPrincipal(principal)))
-        memberURLs = []
-        for proxyID in proxyIDs:
-            proxyPrincipal = principalForPrincipalID(proxyID, directory=directory)
-            proxyURL = proxyPrincipal.url()
-            memberURLs.append(davxml.HRef(proxyURL))
-        membersProperty = davxml.GroupMemberSet(*memberURLs)
-        yield subPrincipal.writeProperty(membersProperty, None)
-        if store is not None:
-            # Schedule work the PeerConnectionPool will pick up as overdue
-            yield schedulePolledGroupCachingUpdate(store)
</del><span class="cx"> 
</span><span class="cx"> 
</span><ins>+# @inlineCallbacks
+# def setProxies(store, principal, readProxyPrincipals, writeProxyPrincipals, directory=None):
+#     &quot;&quot;&quot;
+#     Set read/write proxies en masse for a principal
+#     @param principal: DirectoryPrincipalResource
+#     @param readProxyPrincipals: a list of principal IDs (see principalForPrincipalID)
+#     @param writeProxyPrincipals: a list of principal IDs (see principalForPrincipalID)
+#     &quot;&quot;&quot;
</ins><span class="cx"> 
</span><del>-@inlineCallbacks
-def getProxies(principal, directory=None):
-    &quot;&quot;&quot;
-    Returns a tuple containing the GUIDs for read proxies and write proxies
-    of the given principal
-    &quot;&quot;&quot;
</del><ins>+#     proxyTypes = [
+#         (&quot;read&quot;, readProxyPrincipals),
+#         (&quot;write&quot;, writeProxyPrincipals),
+#     ]
+#     for proxyType, proxyIDs in proxyTypes:
+#         if proxyIDs is None:
+#             continue
+#         subPrincipal = proxySubprincipal(principal, proxyType)
+#         if subPrincipal is None:
+#             raise ProxyError(&quot;Unable to edit %s proxies for %s\n&quot; % (proxyType,
+#                 prettyPrincipal(principal)))
+#         memberURLs = []
+#         for proxyID in proxyIDs:
+#             proxyPrincipal = yield principalForPrincipalID(proxyID, directory=directory)
+#             proxyURL = proxyPrincipal.url()
+#             memberURLs.append(davxml.HRef(proxyURL))
+#         membersProperty = davxml.GroupMemberSet(*memberURLs)
+#         yield subPrincipal.writeProperty(membersProperty, None)
+#         if store is not None:
+#             # Schedule work the PeerConnectionPool will pick up as overdue
+#             yield schedulePolledGroupCachingUpdate(store)
</ins><span class="cx"> 
</span><del>-    proxies = {
-        &quot;read&quot; : [],
-        &quot;write&quot; : [],
-    }
-    for proxyType in proxies.iterkeys():
-        subPrincipal = proxySubprincipal(principal, proxyType)
-        if subPrincipal is not None:
-            membersProperty = (yield subPrincipal.readProperty(davxml.GroupMemberSet, None))
-            if membersProperty.children:
-                for member in membersProperty.children:
-                    proxyPrincipal = principalForPrincipalID(str(member), directory=directory)
-                    proxies[proxyType].append(proxyPrincipal.record.guid)
</del><span class="cx"> 
</span><del>-    returnValue((proxies['read'], proxies['write']))
</del><span class="cx"> 
</span><ins>+# @inlineCallbacks
+# def getProxies(principal, directory=None):
+#     &quot;&quot;&quot;
+#     Returns a tuple containing the GUIDs for read proxies and write proxies
+#     of the given principal
+#     &quot;&quot;&quot;
</ins><span class="cx"> 
</span><ins>+#     proxies = {
+#         &quot;read&quot;: [],
+#         &quot;write&quot;: [],
+#     }
+#     for proxyType in proxies.iterkeys():
+#         subPrincipal = proxySubprincipal(principal, proxyType)
+#         if subPrincipal is not None:
+#             membersProperty = (yield subPrincipal.readProperty(davxml.GroupMemberSet, None))
+#             if membersProperty.children:
+#                 for member in membersProperty.children:
+#                     proxyPrincipal = yield principalForPrincipalID(str(member), directory=directory)
+#                     proxies[proxyType].append(proxyPrincipal.record.guid)
</ins><span class="cx"> 
</span><del>-@inlineCallbacks
-def action_removeProxy(rootResource, directory, store, principal, *proxyIDs, **kwargs):
-    for proxyID in proxyIDs:
-        proxyPrincipal = principalForPrincipalID(proxyID, directory=directory)
-        if proxyPrincipal is None:
-            print(&quot;Invalid principal ID: %s&quot; % (proxyID,))
-        else:
-            (yield action_removeProxyPrincipal(rootResource, directory, store,
-                principal, proxyPrincipal, **kwargs))
</del><ins>+#     returnValue((proxies['read'], proxies['write']))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-@inlineCallbacks
-def action_setAutoSchedule(rootResource, directory, store, principal, autoSchedule):
-    if principal.record.recordType == &quot;groups&quot;:
-        print(&quot;Enabling auto-schedule for %s is not allowed.&quot; % (principal,))
</del><span class="cx"> 
</span><del>-    elif principal.record.recordType == &quot;users&quot; and not config.Scheduling.Options.AutoSchedule.AllowUsers:
-        print(&quot;Enabling auto-schedule for %s is not allowed.&quot; % (principal,))
</del><span class="cx"> 
</span><del>-    else:
-        print(&quot;Setting auto-schedule to %s for %s&quot; % (
-            {True: &quot;true&quot;, False: &quot;false&quot;}[autoSchedule],
-            prettyPrincipal(principal),
-        ))
</del><ins>+# @inlineCallbacks
+# def action_setAutoSchedule(rootResource, directory, store, principal, autoSchedule):
+#     if principal.record.recordType == &quot;groups&quot;:
+#         print(&quot;Enabling auto-schedule for %s is not allowed.&quot; % (principal,))
</ins><span class="cx"> 
</span><del>-        (yield updateRecord(False, directory,
-            principal.record.recordType,
-            guid=principal.record.guid,
-            shortNames=principal.record.shortNames,
-            fullName=principal.record.fullName,
-            autoSchedule=autoSchedule,
-            **principal.record.extras
-        ))
</del><ins>+#     elif principal.record.recordType == &quot;users&quot; and not config.Scheduling.Options.AutoSchedule.AllowUsers:
+#         print(&quot;Enabling auto-schedule for %s is not allowed.&quot; % (principal,))
</ins><span class="cx"> 
</span><ins>+#     else:
+#         print(&quot;Setting auto-schedule to %s for %s&quot; % (
+#             {True: &quot;true&quot;, False: &quot;false&quot;}[autoSchedule],
+#             prettyPrincipal(principal),
+#         ))
</ins><span class="cx"> 
</span><ins>+#         (yield updateRecord(False, directory,
+#             principal.record.recordType,
+#             guid=principal.record.guid,
+#             shortNames=principal.record.shortNames,
+#             fullName=principal.record.fullName,
+#             autoSchedule=autoSchedule,
+#             **principal.record.extras
+#         ))
</ins><span class="cx"> 
</span><del>-def action_getAutoSchedule(rootResource, directory, store, principal):
-    autoSchedule = principal.getAutoSchedule()
-    print(&quot;Auto-schedule for %s is %s&quot; % (
-        prettyPrincipal(principal),
-        {True: &quot;true&quot;, False: &quot;false&quot;}[autoSchedule],
-    ))
</del><span class="cx"> 
</span><span class="cx"> 
</span><ins>+# def action_getAutoSchedule(rootResource, directory, store, principal):
+#     autoSchedule = principal.getAutoSchedule()
+#     print(&quot;Auto-schedule for %s is %s&quot; % (
+#         prettyPrincipal(principal),
+#         {True: &quot;true&quot;, False: &quot;false&quot;}[autoSchedule],
+#     ))
</ins><span class="cx"> 
</span><del>-@inlineCallbacks
-def action_setAutoScheduleMode(rootResource, directory, store, principal, autoScheduleMode):
-    if principal.record.recordType == &quot;groups&quot;:
-        print(&quot;Setting auto-schedule mode for %s is not allowed.&quot; % (principal,))
</del><span class="cx"> 
</span><del>-    elif principal.record.recordType == &quot;users&quot; and not config.Scheduling.Options.AutoSchedule.AllowUsers:
-        print(&quot;Setting auto-schedule mode for %s is not allowed.&quot; % (principal,))
</del><span class="cx"> 
</span><del>-    else:
-        print(&quot;Setting auto-schedule mode to %s for %s&quot; % (
-            autoScheduleMode,
-            prettyPrincipal(principal),
-        ))
</del><ins>+# @inlineCallbacks
+# def action_setAutoScheduleMode(rootResource, directory, store, principal, autoScheduleMode):
+#     if principal.record.recordType == &quot;groups&quot;:
+#         print(&quot;Setting auto-schedule mode for %s is not allowed.&quot; % (principal,))
</ins><span class="cx"> 
</span><del>-        (yield updateRecord(False, directory,
-            principal.record.recordType,
-            guid=principal.record.guid,
-            shortNames=principal.record.shortNames,
-            fullName=principal.record.fullName,
-            autoScheduleMode=autoScheduleMode,
-            **principal.record.extras
-        ))
</del><ins>+#     elif principal.record.recordType == &quot;users&quot; and not config.Scheduling.Options.AutoSchedule.AllowUsers:
+#         print(&quot;Setting auto-schedule mode for %s is not allowed.&quot; % (principal,))
</ins><span class="cx"> 
</span><ins>+#     else:
+#         print(&quot;Setting auto-schedule mode to %s for %s&quot; % (
+#             autoScheduleMode,
+#             prettyPrincipal(principal),
+#         ))
</ins><span class="cx"> 
</span><ins>+#         (yield updateRecord(False, directory,
+#             principal.record.recordType,
+#             guid=principal.record.guid,
+#             shortNames=principal.record.shortNames,
+#             fullName=principal.record.fullName,
+#             autoScheduleMode=autoScheduleMode,
+#             **principal.record.extras
+#         ))
</ins><span class="cx"> 
</span><del>-def action_getAutoScheduleMode(rootResource, directory, store, principal):
-    autoScheduleMode = principal.getAutoScheduleMode()
-    if not autoScheduleMode:
-        autoScheduleMode = &quot;automatic&quot;
-    print(&quot;Auto-schedule mode for %s is %s&quot; % (
-        prettyPrincipal(principal),
-        autoScheduleMode,
-    ))
</del><span class="cx"> 
</span><span class="cx"> 
</span><ins>+# def action_getAutoScheduleMode(rootResource, directory, store, principal):
+#     autoScheduleMode = principal.getAutoScheduleMode()
+#     if not autoScheduleMode:
+#         autoScheduleMode = &quot;automatic&quot;
+#     print(&quot;Auto-schedule mode for %s is %s&quot; % (
+#         prettyPrincipal(principal),
+#         autoScheduleMode,
+#     ))
</ins><span class="cx"> 
</span><del>-@inlineCallbacks
-def action_setAutoAcceptGroup(rootResource, directory, store, principal, autoAcceptGroup):
-    if principal.record.recordType == &quot;groups&quot;:
-        print(&quot;Setting auto-accept-group for %s is not allowed.&quot; % (principal,))
</del><span class="cx"> 
</span><del>-    elif principal.record.recordType == &quot;users&quot; and not config.Scheduling.Options.AutoSchedule.AllowUsers:
-        print(&quot;Setting auto-accept-group for %s is not allowed.&quot; % (principal,))
</del><span class="cx"> 
</span><del>-    else:
-        groupPrincipal = principalForPrincipalID(autoAcceptGroup, directory=directory)
-        if groupPrincipal is None or groupPrincipal.record.recordType != &quot;groups&quot;:
-            print(&quot;Invalid principal ID: %s&quot; % (autoAcceptGroup,))
-        else:
-            print(&quot;Setting auto-accept-group to %s for %s&quot; % (
-                prettyPrincipal(groupPrincipal),
-                prettyPrincipal(principal),
-            ))
</del><ins>+# @inlineCallbacks
+# def action_setAutoAcceptGroup(rootResource, directory, store, principal, autoAcceptGroup):
+#     if principal.record.recordType == &quot;groups&quot;:
+#         print(&quot;Setting auto-accept-group for %s is not allowed.&quot; % (principal,))
</ins><span class="cx"> 
</span><del>-            (yield updateRecord(False, directory,
-                principal.record.recordType,
-                guid=principal.record.guid,
-                shortNames=principal.record.shortNames,
-                fullName=principal.record.fullName,
-                autoAcceptGroup=groupPrincipal.record.guid,
-                **principal.record.extras
-            ))
</del><ins>+#     elif principal.record.recordType == &quot;users&quot; and not config.Scheduling.Options.AutoSchedule.AllowUsers:
+#         print(&quot;Setting auto-accept-group for %s is not allowed.&quot; % (principal,))
</ins><span class="cx"> 
</span><ins>+#     else:
+#         groupPrincipal = yield principalForPrincipalID(autoAcceptGroup, directory=directory)
+#         if groupPrincipal is None or groupPrincipal.record.recordType != &quot;groups&quot;:
+#             print(&quot;Invalid principal ID: %s&quot; % (autoAcceptGroup,))
+#         else:
+#             print(&quot;Setting auto-accept-group to %s for %s&quot; % (
+#                 prettyPrincipal(groupPrincipal),
+#                 prettyPrincipal(principal),
+#             ))
</ins><span class="cx"> 
</span><ins>+#             (yield updateRecord(False, directory,
+#                 principal.record.recordType,
+#                 guid=principal.record.guid,
+#                 shortNames=principal.record.shortNames,
+#                 fullName=principal.record.fullName,
+#                 autoAcceptGroup=groupPrincipal.record.guid,
+#                 **principal.record.extras
+#             ))
</ins><span class="cx"> 
</span><del>-def action_getAutoAcceptGroup(rootResource, directory, store, principal):
-    autoAcceptGroup = principal.getAutoAcceptGroup()
-    if autoAcceptGroup:
-        record = directory.recordWithGUID(autoAcceptGroup)
-        if record is not None:
-            groupPrincipal = directory.principalCollection.principalForUID(record.uid)
-            if groupPrincipal is not None:
-                print(&quot;Auto-accept-group for %s is %s&quot; % (
-                    prettyPrincipal(principal),
-                    prettyPrincipal(groupPrincipal),
-                ))
-                return
-        print(&quot;Invalid auto-accept-group assigned: %s&quot; % (autoAcceptGroup,))
-    else:
-        print(&quot;No auto-accept-group assigned to %s&quot; % (prettyPrincipal(principal),))
</del><span class="cx"> 
</span><span class="cx"> 
</span><ins>+# def action_getAutoAcceptGroup(rootResource, directory, store, principal):
+#     autoAcceptGroup = principal.getAutoAcceptGroup()
+#     if autoAcceptGroup:
+#         record = yield directory.recordWithGUID(autoAcceptGroup)
+#         if record is not None:
+#             groupPrincipal = yield directory.principalCollection.principalForUID(record.uid)
+#             if groupPrincipal is not None:
+#                 print(&quot;Auto-accept-group for %s is %s&quot; % (
+#                     prettyPrincipal(principal),
+#                     prettyPrincipal(groupPrincipal),
+#                 ))
+#                 return
+#         print(&quot;Invalid auto-accept-group assigned: %s&quot; % (autoAcceptGroup,))
+#     else:
+#         print(&quot;No auto-accept-group assigned to %s&quot; % (prettyPrincipal(principal),))
</ins><span class="cx"> 
</span><del>-@inlineCallbacks
-def action_setValue(rootResource, directory, store, principal, name, value):
-    print(&quot;Setting %s to %s for %s&quot; % (
-        name, value, prettyPrincipal(principal),
-    ))
</del><span class="cx"> 
</span><del>-    principal.record.extras[attrMap[name][&quot;attr&quot;]] = value
-    (yield updateRecord(False, directory,
-        principal.record.recordType,
-        guid=principal.record.guid,
-        shortNames=principal.record.shortNames,
-        fullName=principal.record.fullName,
-        **principal.record.extras
-    ))
</del><span class="cx"> 
</span><ins>+# @inlineCallbacks
+# def action_setValue(rootResource, directory, store, principal, name, value):
+#     print(&quot;Setting %s to %s for %s&quot; % (
+#         name, value, prettyPrincipal(principal),
+#     ))
</ins><span class="cx"> 
</span><ins>+#     principal.record.extras[attrMap[name][&quot;attr&quot;]] = value
+#     (yield updateRecord(False, directory,
+#         principal.record.recordType,
+#         guid=principal.record.guid,
+#         shortNames=principal.record.shortNames,
+#         fullName=principal.record.fullName,
+#         **principal.record.extras
+#     ))
</ins><span class="cx"> 
</span><del>-def action_getValue(rootResource, directory, store, principal, name):
-    print(&quot;%s for %s is %s&quot; % (
-        name,
-        prettyPrincipal(principal),
-        principal.record.extras[attrMap[name][&quot;attr&quot;]]
-    ))
</del><span class="cx"> 
</span><span class="cx"> 
</span><ins>+# def action_getValue(rootResource, directory, store, principal, name):
+#     print(&quot;%s for %s is %s&quot; % (
+#         name,
+#         prettyPrincipal(principal),
+#         principal.record.extras[attrMap[name][&quot;attr&quot;]]
+#     ))
</ins><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> def abort(msg, status=1):
</span><span class="cx">     sys.stdout.write(&quot;%s\n&quot; % (msg,))
</span><span class="cx">     try:
</span><span class="lines">@@ -803,14 +822,16 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> def printRecordList(records):
</span><del>-    results = [(record.fullName, record.shortNames[0], record.guid)
-        for record in records]
</del><ins>+    results = [
+        (record.displayName, record.recordType.name, record.uid, record.shortNames)
+        for record in records
+    ]
</ins><span class="cx">     results.sort()
</span><del>-    format = &quot;%-22s %-17s %s&quot;
-    print(format % (&quot;Full name&quot;, &quot;Record name&quot;, &quot;UUID&quot;))
-    print(format % (&quot;---------&quot;, &quot;-----------&quot;, &quot;----&quot;))
-    for fullName, shortName, guid in results:
-        print(format % (fullName, shortName, guid))
</del><ins>+    format = &quot;%-22s %-10s %-20s %s&quot;
+    print(format % (&quot;Full name&quot;, &quot;Type&quot;, &quot;UID&quot;, &quot;Short names&quot;))
+    print(format % (&quot;---------&quot;, &quot;----&quot;, &quot;---&quot;, &quot;-----------&quot;))
+    for fullName, recordType, uid, shortNames in results:
+        print(format % (fullName, recordType, uid, u&quot;, &quot;.join(shortNames)))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -859,16 +880,16 @@
</span><span class="cx">             kwargs[key] = newValue
</span><span class="cx"> 
</span><span class="cx">     if create:
</span><del>-        record = directory.createRecord(recordType, **kwargs)
</del><ins>+        record = yield directory.createRecord(recordType, **kwargs)
</ins><span class="cx">         kwargs['guid'] = record.guid
</span><span class="cx">     else:
</span><span class="cx">         try:
</span><del>-            record = directory.updateRecord(recordType, **kwargs)
</del><ins>+            record = yield directory.updateRecord(recordType, **kwargs)
</ins><span class="cx">         except NotImplementedError:
</span><span class="cx">             # Updating of directory information is not supported by underlying
</span><span class="cx">             # directory implementation, but allow augment information to be
</span><span class="cx">             # updated
</span><del>-            record = directory.recordWithGUID(kwargs[&quot;guid&quot;])
</del><ins>+            record = yield directory.recordWithGUID(kwargs[&quot;guid&quot;])
</ins><span class="cx">             pass
</span><span class="cx"> 
</span><span class="cx">     augmentService = directory.serviceForRecordType(recordType).augmentService
</span><span class="lines">@@ -882,7 +903,7 @@
</span><span class="cx">         augmentRecord.autoAcceptGroup = autoAcceptGroup
</span><span class="cx">     (yield augmentService.addAugmentRecords([augmentRecord]))
</span><span class="cx">     try:
</span><del>-        directory.updateRecord(recordType, **kwargs)
</del><ins>+        yield directory.updateRecord(recordType, **kwargs)
</ins><span class="cx">     except NotImplementedError:
</span><span class="cx">         # Updating of directory information is not supported by underlying
</span><span class="cx">         # directory implementation, but allow augment information to be
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4calendarservertoolsshelldirectorypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/shell/directory.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/shell/directory.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/shell/directory.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -83,11 +83,17 @@
</span><span class="cx">     add(&quot;First Name&quot;, record.firstName)
</span><span class="cx">     add(&quot;Last Name&quot; , record.lastName )
</span><span class="cx"> 
</span><del>-    for email in record.emailAddresses:
-        add(&quot;Email Address&quot;, email)
</del><ins>+    try:
+        for email in record.emailAddresses:
+            add(&quot;Email Address&quot;, email)
+    except AttributeError:
+        pass
</ins><span class="cx"> 
</span><del>-    for cua in record.calendarUserAddresses:
-        add(&quot;Calendar User Address&quot;, cua)
</del><ins>+    try:
+        for cua in record.calendarUserAddresses:
+            add(&quot;Calendar User Address&quot;, cua)
+    except AttributeError:
+        pass
</ins><span class="cx"> 
</span><span class="cx">     add(&quot;Server ID&quot;           , record.serverID)
</span><span class="cx">     add(&quot;Enabled&quot;             , record.enabled)
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4calendarservertoolstesttest_principalspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_principals.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_principals.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_principals.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -17,22 +17,23 @@
</span><span class="cx"> import os
</span><span class="cx"> import sys
</span><span class="cx"> 
</span><ins>+from calendarserver.tools.principals import (
+    parseCreationArgs, matchStrings,
+    updateRecord, principalForPrincipalID, getProxies, setProxies
+)
</ins><span class="cx"> from twext.python.filepath import CachingFilePath as FilePath
</span><span class="cx"> from twisted.internet import reactor
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, Deferred, returnValue
</span><del>-
</del><span class="cx"> from twistedcaldav.config import config
</span><ins>+from twistedcaldav.directory import calendaruserproxy
</ins><span class="cx"> from twistedcaldav.directory.directory import DirectoryError
</span><del>-from twistedcaldav.directory import calendaruserproxy
</del><ins>+from twistedcaldav.test.util import (
+    TestCase, CapturingProcessProtocol, ErrorOutput
+)
+from txdav.who.util import directoryFromConfig
</ins><span class="cx"> 
</span><del>-from twistedcaldav.test.util import TestCase, CapturingProcessProtocol, \
-    ErrorOutput
</del><span class="cx"> 
</span><del>-from calendarserver.tap.util import directoryFromConfig
-from calendarserver.tools.principals import (parseCreationArgs, matchStrings,
-    updateRecord, principalForPrincipalID, getProxies, setProxies)
</del><span class="cx"> 
</span><del>-
</del><span class="cx"> class ManagePrincipalsTestCase(TestCase):
</span><span class="cx"> 
</span><span class="cx">     def setUp(self):
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4calendarservertoolsutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/util.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/util.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/util.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -20,8 +20,6 @@
</span><span class="cx"> 
</span><span class="cx"> __all__ = [
</span><span class="cx">     &quot;loadConfig&quot;,
</span><del>-    &quot;getDirectory&quot;,
-    &quot;dummyDirectoryRecord&quot;,
</del><span class="cx">     &quot;UsageError&quot;,
</span><span class="cx">     &quot;booleanArgument&quot;,
</span><span class="cx"> ]
</span><span class="lines">@@ -48,8 +46,7 @@
</span><span class="cx"> 
</span><span class="cx"> from twistedcaldav import memcachepool
</span><span class="cx"> from twistedcaldav.directory import calendaruserproxy
</span><del>-from twistedcaldav.directory.aggregate import AggregateDirectoryService
-from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord
</del><ins>+# from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord
</ins><span class="cx"> from txdav.who.groups import schedulePolledGroupCachingUpdate
</span><span class="cx"> from calendarserver.push.notifier import NotifierFactory
</span><span class="cx"> 
</span><span class="lines">@@ -78,145 +75,145 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def getDirectory(config=config):
</del><ins>+# def getDirectory(config=config):
</ins><span class="cx"> 
</span><del>-    class MyDirectoryService (AggregateDirectoryService):
-        def getPrincipalCollection(self):
-            if not hasattr(self, &quot;_principalCollection&quot;):
</del><ins>+#     class MyDirectoryService (AggregateDirectoryService):
+#         def getPrincipalCollection(self):
+#             if not hasattr(self, &quot;_principalCollection&quot;):
</ins><span class="cx"> 
</span><del>-                if config.Notifications.Enabled:
-                    # FIXME: NotifierFactory needs reference to the store in order
-                    # to get a txn in order to create a Work item
-                    notifierFactory = NotifierFactory(
-                        None, config.ServerHostName,
-                        config.Notifications.CoalesceSeconds,
-                    )
-                else:
-                    notifierFactory = None
</del><ins>+#                 if config.Notifications.Enabled:
+#                     # FIXME: NotifierFactory needs reference to the store in order
+#                     # to get a txn in order to create a Work item
+#                     notifierFactory = NotifierFactory(
+#                         None, config.ServerHostName,
+#                         config.Notifications.CoalesceSeconds,
+#                     )
+#                 else:
+#                     notifierFactory = None
</ins><span class="cx"> 
</span><del>-                # Need a data store
-                _newStore = CommonDataStore(FilePath(config.DocumentRoot),
-                    notifierFactory, self, True, False)
-                if notifierFactory is not None:
-                    notifierFactory.store = _newStore
</del><ins>+#                 # Need a data store
+#                 _newStore = CommonDataStore(FilePath(config.DocumentRoot),
+#                     notifierFactory, self, True, False)
+#                 if notifierFactory is not None:
+#                     notifierFactory.store = _newStore
</ins><span class="cx"> 
</span><del>-                #
-                # Instantiating a DirectoryCalendarHomeProvisioningResource with a directory
-                # will register it with the directory (still smells like a hack).
-                #
-                # We need that in order to locate calendar homes via the directory.
-                #
-                from twistedcaldav.directory.calendar import DirectoryCalendarHomeProvisioningResource
-                DirectoryCalendarHomeProvisioningResource(self, &quot;/calendars/&quot;, _newStore)
</del><ins>+#                 #
+#                 # Instantiating a DirectoryCalendarHomeProvisioningResource with a directory
+#                 # will register it with the directory (still smells like a hack).
+#                 #
+#                 # We need that in order to locate calendar homes via the directory.
+#                 #
+#                 from twistedcaldav.directory.calendar import DirectoryCalendarHomeProvisioningResource
+#                 DirectoryCalendarHomeProvisioningResource(self, &quot;/calendars/&quot;, _newStore)
</ins><span class="cx"> 
</span><del>-                from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
-                self._principalCollection = DirectoryPrincipalProvisioningResource(&quot;/principals/&quot;, self)
</del><ins>+#                 from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
+#                 self._principalCollection = DirectoryPrincipalProvisioningResource(&quot;/principals/&quot;, self)
</ins><span class="cx"> 
</span><del>-            return self._principalCollection
</del><ins>+#             return self._principalCollection
</ins><span class="cx"> 
</span><del>-        def setPrincipalCollection(self, coll):
-            # See principal.py line 237:  self.directory.principalCollection = self
-            pass
</del><ins>+#         def setPrincipalCollection(self, coll):
+#             # See principal.py line 237:  self.directory.principalCollection = self
+#             pass
</ins><span class="cx"> 
</span><del>-        principalCollection = property(getPrincipalCollection, setPrincipalCollection)
</del><ins>+#         principalCollection = property(getPrincipalCollection, setPrincipalCollection)
</ins><span class="cx"> 
</span><del>-        def calendarHomeForRecord(self, record):
-            principal = self.principalCollection.principalForRecord(record)
-            if principal:
-                try:
-                    return principal.calendarHome()
-                except AttributeError:
-                    pass
-            return None
</del><ins>+#         def calendarHomeForRecord(self, record):
+#             principal = self.principalCollection.principalForRecord(record)
+#             if principal:
+#                 try:
+#                     return principal.calendarHome()
+#                 except AttributeError:
+#                     pass
+#             return None
</ins><span class="cx"> 
</span><del>-        def calendarHomeForShortName(self, recordType, shortName):
-            principal = self.principalCollection.principalForShortName(recordType, shortName)
-            if principal:
-                return principal.calendarHome()
-            return None
</del><ins>+#         def calendarHomeForShortName(self, recordType, shortName):
+#             principal = self.principalCollection.principalForShortName(recordType, shortName)
+#             if principal:
+#                 return principal.calendarHome()
+#             return None
</ins><span class="cx"> 
</span><del>-        def principalForCalendarUserAddress(self, cua):
-            return self.principalCollection.principalForCalendarUserAddress(cua)
</del><ins>+#         def principalForCalendarUserAddress(self, cua):
+#             return self.principalCollection.principalForCalendarUserAddress(cua)
</ins><span class="cx"> 
</span><del>-        def principalForUID(self, uid):
-            return self.principalCollection.principalForUID(uid)
</del><ins>+#         def principalForUID(self, uid):
+#             return self.principalCollection.principalForUID(uid)
</ins><span class="cx"> 
</span><del>-    # Load augment/proxy db classes now
-    if config.AugmentService.type:
-        augmentClass = namedClass(config.AugmentService.type)
-        augmentService = augmentClass(**config.AugmentService.params)
-    else:
-        augmentService = None
</del><ins>+#     # Load augment/proxy db classes now
+#     if config.AugmentService.type:
+#         augmentClass = namedClass(config.AugmentService.type)
+#         augmentService = augmentClass(**config.AugmentService.params)
+#     else:
+#         augmentService = None
</ins><span class="cx"> 
</span><del>-    proxydbClass = namedClass(config.ProxyDBService.type)
-    calendaruserproxy.ProxyDBService = proxydbClass(**config.ProxyDBService.params)
</del><ins>+#     proxydbClass = namedClass(config.ProxyDBService.type)
+#     calendaruserproxy.ProxyDBService = proxydbClass(**config.ProxyDBService.params)
</ins><span class="cx"> 
</span><del>-    # Wait for directory service to become available
-    BaseDirectoryService = namedClass(config.DirectoryService.type)
-    config.DirectoryService.params.augmentService = augmentService
-    directory = BaseDirectoryService(config.DirectoryService.params)
-    while not directory.isAvailable():
-        sleep(5)
</del><ins>+#     # Wait for directory service to become available
+#     BaseDirectoryService = namedClass(config.DirectoryService.type)
+#     config.DirectoryService.params.augmentService = augmentService
+#     directory = BaseDirectoryService(config.DirectoryService.params)
+#     while not directory.isAvailable():
+#         sleep(5)
</ins><span class="cx"> 
</span><del>-    directories = [directory]
</del><ins>+#     directories = [directory]
</ins><span class="cx"> 
</span><del>-    if config.ResourceService.Enabled:
-        resourceClass = namedClass(config.ResourceService.type)
-        config.ResourceService.params.augmentService = augmentService
-        resourceDirectory = resourceClass(config.ResourceService.params)
-        resourceDirectory.realmName = directory.realmName
-        directories.append(resourceDirectory)
</del><ins>+#     if config.ResourceService.Enabled:
+#         resourceClass = namedClass(config.ResourceService.type)
+#         config.ResourceService.params.augmentService = augmentService
+#         resourceDirectory = resourceClass(config.ResourceService.params)
+#         resourceDirectory.realmName = directory.realmName
+#         directories.append(resourceDirectory)
</ins><span class="cx"> 
</span><del>-    aggregate = MyDirectoryService(directories, None)
-    aggregate.augmentService = augmentService
</del><ins>+#     aggregate = MyDirectoryService(directories, None)
+#     aggregate.augmentService = augmentService
</ins><span class="cx"> 
</span><del>-    #
-    # Wire up the resource hierarchy
-    #
-    principalCollection = aggregate.getPrincipalCollection()
-    root = RootResource(
-        config.DocumentRoot,
-        principalCollections=(principalCollection,),
-    )
-    root.putChild(&quot;principals&quot;, principalCollection)
</del><ins>+#     #
+#     # Wire up the resource hierarchy
+#     #
+#     principalCollection = aggregate.getPrincipalCollection()
+#     root = RootResource(
+#         config.DocumentRoot,
+#         principalCollections=(principalCollection,),
+#     )
+#     root.putChild(&quot;principals&quot;, principalCollection)
</ins><span class="cx"> 
</span><del>-    # Need a data store
-    _newStore = CommonDataStore(FilePath(config.DocumentRoot), None, aggregate, True, False)
</del><ins>+#     # Need a data store
+#     _newStore = CommonDataStore(FilePath(config.DocumentRoot), None, aggregate, True, False)
</ins><span class="cx"> 
</span><del>-    from twistedcaldav.directory.calendar import DirectoryCalendarHomeProvisioningResource
-    calendarCollection = DirectoryCalendarHomeProvisioningResource(
-        aggregate, &quot;/calendars/&quot;,
-        _newStore,
-    )
-    root.putChild(&quot;calendars&quot;, calendarCollection)
</del><ins>+#     from twistedcaldav.directory.calendar import DirectoryCalendarHomeProvisioningResource
+#     calendarCollection = DirectoryCalendarHomeProvisioningResource(
+#         aggregate, &quot;/calendars/&quot;,
+#         _newStore,
+#     )
+#     root.putChild(&quot;calendars&quot;, calendarCollection)
</ins><span class="cx"> 
</span><del>-    return aggregate
</del><ins>+#     return aggregate
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class DummyDirectoryService (DirectoryService):
-    realmName = &quot;&quot;
-    baseGUID = &quot;51856FD4-5023-4890-94FE-4356C4AAC3E4&quot;
-    def recordTypes(self):
-        return ()
</del><ins>+# class DummyDirectoryService (DirectoryService):
+#     realmName = &quot;&quot;
+#     baseGUID = &quot;51856FD4-5023-4890-94FE-4356C4AAC3E4&quot;
+#     def recordTypes(self):
+#         return ()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def listRecords(self):
-        return ()
</del><ins>+#     def listRecords(self):
+#         return ()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def recordWithShortName(self):
-        return None
</del><ins>+#     def recordWithShortName(self):
+#         return None
</ins><span class="cx"> 
</span><del>-dummyDirectoryRecord = DirectoryRecord(
-    service=DummyDirectoryService(),
-    recordType=&quot;dummy&quot;,
-    guid=&quot;8EF0892F-7CB6-4B8E-B294-7C5A5321136A&quot;,
-    shortNames=(&quot;dummy&quot;,),
-    fullName=&quot;Dummy McDummerson&quot;,
-    firstName=&quot;Dummy&quot;,
-    lastName=&quot;McDummerson&quot;,
-)
</del><ins>+# dummyDirectoryRecord = DirectoryRecord(
+#     service=DummyDirectoryService(),
+#     recordType=&quot;dummy&quot;,
+#     guid=&quot;8EF0892F-7CB6-4B8E-B294-7C5A5321136A&quot;,
+#     shortNames=(&quot;dummy&quot;,),
+#     fullName=&quot;Dummy McDummerson&quot;,
+#     firstName=&quot;Dummy&quot;,
+#     lastName=&quot;McDummerson&quot;,
+# )
</ins><span class="cx"> 
</span><span class="cx"> class UsageError (StandardError):
</span><span class="cx">     pass
</span><span class="lines">@@ -334,6 +331,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+@inlineCallbacks
</ins><span class="cx"> def principalForPrincipalID(principalID, checkOnly=False, directory=None):
</span><span class="cx"> 
</span><span class="cx">     # Allow a directory parameter to be passed in, but default to config.directory
</span><span class="lines">@@ -351,16 +349,16 @@
</span><span class="cx">             raise ValueError(&quot;Can't resolve all paths yet&quot;)
</span><span class="cx"> 
</span><span class="cx">         if checkOnly:
</span><del>-            return None
</del><ins>+            returnValue(None)
</ins><span class="cx"> 
</span><del>-        return directory.principalCollection.principalForUID(uid)
</del><ins>+        returnValue((yield directory.principalCollection.principalForUID(uid)))
</ins><span class="cx"> 
</span><span class="cx">     if principalID.startswith(&quot;(&quot;):
</span><span class="cx">         try:
</span><span class="cx">             i = principalID.index(&quot;)&quot;)
</span><span class="cx"> 
</span><span class="cx">             if checkOnly:
</span><del>-                return None
</del><ins>+                returnValue(None)
</ins><span class="cx"> 
</span><span class="cx">             recordType = principalID[1:i]
</span><span class="cx">             shortName = principalID[i + 1:]
</span><span class="lines">@@ -368,34 +366,87 @@
</span><span class="cx">             if not recordType or not shortName or &quot;(&quot; in recordType:
</span><span class="cx">                 raise ValueError()
</span><span class="cx"> 
</span><del>-            return directory.principalCollection.principalForShortName(recordType, shortName)
</del><ins>+            returnValue((yield directory.principalCollection.principalForShortName(recordType, shortName)))
</ins><span class="cx"> 
</span><span class="cx">         except ValueError:
</span><span class="cx">             pass
</span><span class="cx"> 
</span><span class="cx">     if &quot;:&quot; in principalID:
</span><span class="cx">         if checkOnly:
</span><del>-            return None
</del><ins>+            returnValue(None)
</ins><span class="cx"> 
</span><span class="cx">         recordType, shortName = principalID.split(&quot;:&quot;, 1)
</span><span class="cx"> 
</span><del>-        return directory.principalCollection.principalForShortName(recordType, shortName)
</del><ins>+        returnValue((yield directory.principalCollection.principalForShortName(recordType, shortName)))
</ins><span class="cx"> 
</span><span class="cx">     try:
</span><span class="cx">         UUID(principalID)
</span><span class="cx"> 
</span><span class="cx">         if checkOnly:
</span><del>-            return None
</del><ins>+            returnValue(None)
</ins><span class="cx"> 
</span><del>-        x = directory.principalCollection.principalForUID(principalID)
-        return x
</del><ins>+        returnValue((yield directory.principalCollection.principalForUID(principalID)))
</ins><span class="cx">     except ValueError:
</span><span class="cx">         pass
</span><span class="cx"> 
</span><span class="cx">     raise ValueError(&quot;Invalid principal identifier: %s&quot; % (principalID,))
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+@inlineCallbacks
+def recordForPrincipalID(directory, principalID, checkOnly=False):
</ins><span class="cx"> 
</span><ins>+    if principalID.startswith(&quot;/&quot;):
+        segments = principalID.strip(&quot;/&quot;).split(&quot;/&quot;)
+        if (len(segments) == 3 and
+            segments[0] == &quot;principals&quot; and segments[1] == &quot;__uids__&quot;):
+            uid = segments[2]
+        else:
+            raise ValueError(&quot;Can't resolve all paths yet&quot;)
+
+        if checkOnly:
+            returnValue(None)
+
+        returnValue((yield directory.recordWithUID(uid)))
+
+    if principalID.startswith(&quot;(&quot;):
+        try:
+            i = principalID.index(&quot;)&quot;)
+
+            if checkOnly:
+                returnValue(None)
+
+            recordType = directory.oldNameToRecordType(principalID[1:i])
+            shortName = principalID[i + 1:]
+
+            if not recordType or not shortName or &quot;(&quot; in recordType:
+                raise ValueError()
+
+            returnValue((yield directory.recordWithShortName(recordType, shortName)))
+
+        except ValueError:
+            pass
+
+    if &quot;:&quot; in principalID:
+        if checkOnly:
+            returnValue(None)
+
+        recordType, shortName = principalID.split(&quot;:&quot;, 1)
+        recordType = directory.oldNameToRecordType(recordType)
+
+        returnValue((yield directory.recordWithShortName(recordType, shortName)))
+
+    try:
+        if checkOnly:
+            returnValue(None)
+
+        returnValue((yield directory.recordWithUID(principalID)))
+    except ValueError:
+        pass
+
+    raise ValueError(&quot;Invalid principal identifier: %s&quot; % (principalID,))
+
+
+
</ins><span class="cx"> def proxySubprincipal(principal, proxyType):
</span><span class="cx">     return principal.getChild(&quot;calendar-proxy-&quot; + proxyType)
</span><span class="cx"> 
</span><span class="lines">@@ -501,12 +552,19 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> def prettyPrincipal(principal):
</span><del>-    record = principal.record
-    return &quot;\&quot;%s\&quot; (%s:%s)&quot; % (record.fullName, record.recordType,
-        record.shortNames[0])
</del><ins>+    prettyRecord(principal.record)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+def prettyRecord(record):
+    return &quot;\&quot;{d}\&quot; {uid} ({rt}) {sn}&quot;.format(
+        d=record.displayName,
+        rt=record.recordType.name,
+        uid=record.uid,
+        sn=(&quot;, &quot;.join(record.shortNames))
+    )
</ins><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class ProxyError(Exception):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Raised when proxy assignments cannot be performed
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4calendarserverwebcalresourcepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/webcal/resource.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/webcal/resource.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/webcal/resource.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -48,15 +48,17 @@
</span><span class="cx"> class WebCalendarResource (ReadOnlyResourceMixIn, DAVFile):
</span><span class="cx"> 
</span><span class="cx">     def defaultAccessControlList(self):
</span><del>-        return davxml.ACL(
-            davxml.ACE(
-                davxml.Principal(davxml.Authenticated()),
-                davxml.Grant(
-                    davxml.Privilege(davxml.Read()),
</del><ins>+        return succeed(
+            davxml.ACL(
+                davxml.ACE(
+                    davxml.Principal(davxml.Authenticated()),
+                    davxml.Grant(
+                        davxml.Privilege(davxml.Read()),
+                    ),
+                    davxml.Protected(),
+                    TwistedACLInheritable(),
</ins><span class="cx">                 ),
</span><del>-                davxml.Protected(),
-                TwistedACLInheritable(),
-            ),
</del><ins>+            )
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4confauthaccountstestxml"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/conf/auth/accounts-test.xml (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/conf/auth/accounts-test.xml        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/conf/auth/accounts-test.xml        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -18,172 +18,339 @@
</span><span class="cx"> 
</span><span class="cx"> &lt;!DOCTYPE accounts SYSTEM &quot;accounts.dtd&quot;&gt;
</span><span class="cx"> 
</span><del>-&lt;accounts realm=&quot;Test Realm&quot;&gt;
-  &lt;user&gt;
</del><ins>+&lt;directory realm=&quot;Test Realm&quot;&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;admin&lt;/uid&gt;
</span><del>-    &lt;guid&gt;admin&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;admin&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;admin&lt;/password&gt;
</span><del>-    &lt;name&gt;Super User&lt;/name&gt;
-    &lt;first-name&gt;Super&lt;/first-name&gt;
-    &lt;last-name&gt;User&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;Super User&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;apprentice&lt;/uid&gt;
</span><del>-    &lt;guid&gt;apprentice&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;apprentice&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;apprentice&lt;/password&gt;
</span><del>-    &lt;name&gt;Apprentice Super User&lt;/name&gt;
-    &lt;first-name&gt;Apprentice&lt;/first-name&gt;
-    &lt;last-name&gt;Super User&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;Apprentice Super User&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;wsanchez&lt;/uid&gt;
</span><del>-    &lt;guid&gt;wsanchez&lt;/guid&gt;
-    &lt;email-address&gt;wsanchez@example.com&lt;/email-address&gt;
</del><ins>+    &lt;short-name&gt;wsanchez&lt;/short-name&gt;
+    &lt;email&gt;wsanchez@example.com&lt;/email&gt;
</ins><span class="cx">     &lt;password&gt;test&lt;/password&gt;
</span><del>-    &lt;name&gt;Wilfredo Sanchez Vega&lt;/name&gt;
-    &lt;first-name&gt;Wilfredo&lt;/first-name&gt;
-    &lt;last-name&gt;Sanchez Vega&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;Wilfredo Sanchez Vega&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;cdaboo&lt;/uid&gt;
</span><del>-    &lt;guid&gt;cdaboo&lt;/guid&gt;
-    &lt;email-address&gt;cdaboo@example.com&lt;/email-address&gt;
</del><ins>+    &lt;short-name&gt;cdaboo&lt;/short-name&gt;
+    &lt;email&gt;cdaboo@example.com&lt;/email&gt;
</ins><span class="cx">     &lt;password&gt;test&lt;/password&gt;
</span><del>-    &lt;name&gt;Cyrus Daboo&lt;/name&gt;
-    &lt;first-name&gt;Cyrus&lt;/first-name&gt;
-    &lt;last-name&gt;Daboo&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;cyrus Daboo&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;sagen&lt;/uid&gt;
</span><del>-    &lt;guid&gt;sagen&lt;/guid&gt;
-    &lt;email-address&gt;sagen@example.com&lt;/email-address&gt;
</del><ins>+    &lt;short-name&gt;sagen&lt;/short-name&gt;
+    &lt;email&gt;sagen@example.com&lt;/email&gt;
</ins><span class="cx">     &lt;password&gt;test&lt;/password&gt;
</span><del>-    &lt;name&gt;Morgen Sagen&lt;/name&gt;
-    &lt;first-name&gt;Morgen&lt;/first-name&gt;
-    &lt;last-name&gt;Sagen&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;Morgen Sagen&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;dre&lt;/uid&gt;
</span><del>-    &lt;guid&gt;andre&lt;/guid&gt;
-    &lt;email-address&gt;dre@example.com&lt;/email-address&gt;
</del><ins>+    &lt;short-name&gt;andre&lt;/short-name&gt;
+    &lt;email&gt;dre@example.com&lt;/email&gt;
</ins><span class="cx">     &lt;password&gt;test&lt;/password&gt;
</span><del>-    &lt;name&gt;Andre LaBranche&lt;/name&gt;
-    &lt;first-name&gt;Andre&lt;/first-name&gt;
-    &lt;last-name&gt;LaBranche&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;Andre LaBranche&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;glyph&lt;/uid&gt;
</span><del>-    &lt;guid&gt;glyph&lt;/guid&gt;
-    &lt;email-address&gt;glyph@example.com&lt;/email-address&gt;
</del><ins>+    &lt;short-name&gt;glyph&lt;/short-name&gt;
+    &lt;email&gt;glyph@example.com&lt;/email&gt;
</ins><span class="cx">     &lt;password&gt;test&lt;/password&gt;
</span><del>-    &lt;name&gt;Glyph Lefkowitz&lt;/name&gt;
-    &lt;first-name&gt;Glyph&lt;/first-name&gt;
-    &lt;last-name&gt;Lefkowitz&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;Glyph Lefkowitz&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;i18nuser&lt;/uid&gt;
</span><del>-    &lt;guid&gt;i18nuser&lt;/guid&gt;
-    &lt;email-address&gt;i18nuser@example.com&lt;/email-address&gt;
</del><ins>+    &lt;short-name&gt;i18nuser&lt;/short-name&gt;
+    &lt;email&gt;i18nuser@example.com&lt;/email&gt;
</ins><span class="cx">     &lt;password&gt;i18nuser&lt;/password&gt;
</span><del>-    &lt;name&gt;まだ&lt;/name&gt;
-    &lt;first-name&gt;ま&lt;/first-name&gt;
-    &lt;last-name&gt;だ&lt;/last-name&gt;
-  &lt;/user&gt;
</del><ins>+    &lt;full-name&gt;まだ&lt;/full-name&gt;
+  &lt;/record&gt;
+
+  &lt;!-- twext.who xml doesn't (yet) support repeat
</ins><span class="cx">   &lt;user repeat=&quot;101&quot;&gt;
</span><span class="cx">     &lt;uid&gt;user%02d&lt;/uid&gt;
</span><span class="cx">     &lt;uid&gt;User %02d&lt;/uid&gt;
</span><del>-    &lt;guid&gt;user%02d&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;user%02d&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;user%02d&lt;/password&gt;
</span><del>-    &lt;name&gt;User %02d&lt;/name&gt;
-    &lt;first-name&gt;User&lt;/first-name&gt;
-    &lt;last-name&gt;%02d&lt;/last-name&gt;
-    &lt;email-address&gt;user%02d@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
</del><ins>+    &lt;full-name&gt;User %02d&lt;/full-name&gt;
+    &lt;email&gt;user%02d@example.com&lt;/email&gt;
+  &lt;/record&gt;
</ins><span class="cx">   &lt;user repeat=&quot;10&quot;&gt;
</span><span class="cx">     &lt;uid&gt;public%02d&lt;/uid&gt;
</span><del>-    &lt;guid&gt;public%02d&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;public%02d&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;public%02d&lt;/password&gt;
</span><del>-    &lt;name&gt;Public %02d&lt;/name&gt;
-    &lt;first-name&gt;Public&lt;/first-name&gt;
-    &lt;last-name&gt;%02d&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Public %02d&lt;/full-name&gt;
+  &lt;/record&gt;
+  --&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user01&lt;/short-name&gt;
+    &lt;uid&gt;user01&lt;/uid&gt;
+    &lt;password&gt;user01&lt;/password&gt;
+    &lt;full-name&gt;User 01&lt;/full-name&gt;
+    &lt;email&gt;user01@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user02&lt;/short-name&gt;
+    &lt;uid&gt;user02&lt;/uid&gt;
+    &lt;password&gt;user02&lt;/password&gt;
+    &lt;full-name&gt;User 02&lt;/full-name&gt;
+    &lt;email&gt;user02@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user03&lt;/short-name&gt;
+    &lt;uid&gt;user03&lt;/uid&gt;
+    &lt;password&gt;user03&lt;/password&gt;
+    &lt;full-name&gt;User 03&lt;/full-name&gt;
+    &lt;email&gt;user03@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user04&lt;/short-name&gt;
+    &lt;uid&gt;user04&lt;/uid&gt;
+    &lt;password&gt;user04&lt;/password&gt;
+    &lt;full-name&gt;User 04&lt;/full-name&gt;
+    &lt;email&gt;user04@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user05&lt;/short-name&gt;
+    &lt;uid&gt;user05&lt;/uid&gt;
+    &lt;password&gt;user05&lt;/password&gt;
+    &lt;full-name&gt;User 05&lt;/full-name&gt;
+    &lt;email&gt;user05@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user06&lt;/short-name&gt;
+    &lt;uid&gt;user06&lt;/uid&gt;
+    &lt;password&gt;user06&lt;/password&gt;
+    &lt;full-name&gt;User 06&lt;/full-name&gt;
+    &lt;email&gt;user06@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user07&lt;/short-name&gt;
+    &lt;uid&gt;user07&lt;/uid&gt;
+    &lt;password&gt;user07&lt;/password&gt;
+    &lt;full-name&gt;User 07&lt;/full-name&gt;
+    &lt;email&gt;user07@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user08&lt;/short-name&gt;
+    &lt;uid&gt;user08&lt;/uid&gt;
+    &lt;password&gt;user08&lt;/password&gt;
+    &lt;full-name&gt;User 08&lt;/full-name&gt;
+    &lt;email&gt;user08@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user09&lt;/short-name&gt;
+    &lt;uid&gt;user09&lt;/uid&gt;
+    &lt;password&gt;user09&lt;/password&gt;
+    &lt;full-name&gt;User 09&lt;/full-name&gt;
+    &lt;email&gt;user09@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user10&lt;/short-name&gt;
+    &lt;uid&gt;user10&lt;/uid&gt;
+    &lt;password&gt;user10&lt;/password&gt;
+    &lt;full-name&gt;User 10&lt;/full-name&gt;
+    &lt;email&gt;user10@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user11&lt;/short-name&gt;
+    &lt;uid&gt;user11&lt;/uid&gt;
+    &lt;password&gt;user11&lt;/password&gt;
+    &lt;full-name&gt;User 11&lt;/full-name&gt;
+    &lt;email&gt;user11@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user12&lt;/short-name&gt;
+    &lt;uid&gt;user12&lt;/uid&gt;
+    &lt;password&gt;user12&lt;/password&gt;
+    &lt;full-name&gt;User 12&lt;/full-name&gt;
+    &lt;email&gt;user12@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user13&lt;/short-name&gt;
+    &lt;uid&gt;user13&lt;/uid&gt;
+    &lt;password&gt;user13&lt;/password&gt;
+    &lt;full-name&gt;User 13&lt;/full-name&gt;
+    &lt;email&gt;user13@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user14&lt;/short-name&gt;
+    &lt;uid&gt;user14&lt;/uid&gt;
+    &lt;password&gt;user14&lt;/password&gt;
+    &lt;full-name&gt;User 14&lt;/full-name&gt;
+    &lt;email&gt;user14@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user15&lt;/short-name&gt;
+    &lt;uid&gt;user15&lt;/uid&gt;
+    &lt;password&gt;user15&lt;/password&gt;
+    &lt;full-name&gt;User 15&lt;/full-name&gt;
+    &lt;email&gt;user15@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user16&lt;/short-name&gt;
+    &lt;uid&gt;user16&lt;/uid&gt;
+    &lt;password&gt;user16&lt;/password&gt;
+    &lt;full-name&gt;User 16&lt;/full-name&gt;
+    &lt;email&gt;user16@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user17&lt;/short-name&gt;
+    &lt;uid&gt;user17&lt;/uid&gt;
+    &lt;password&gt;user17&lt;/password&gt;
+    &lt;full-name&gt;User 17&lt;/full-name&gt;
+    &lt;email&gt;user17@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user18&lt;/short-name&gt;
+    &lt;uid&gt;user18&lt;/uid&gt;
+    &lt;password&gt;user18&lt;/password&gt;
+    &lt;full-name&gt;User 18&lt;/full-name&gt;
+    &lt;email&gt;user18@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user19&lt;/short-name&gt;
+    &lt;uid&gt;user19&lt;/uid&gt;
+    &lt;password&gt;user19&lt;/password&gt;
+    &lt;full-name&gt;User 19&lt;/full-name&gt;
+    &lt;email&gt;user19@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user20&lt;/short-name&gt;
+    &lt;uid&gt;user20&lt;/uid&gt;
+    &lt;password&gt;user20&lt;/password&gt;
+    &lt;full-name&gt;User 20&lt;/full-name&gt;
+    &lt;email&gt;user20@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user21&lt;/short-name&gt;
+    &lt;uid&gt;user21&lt;/uid&gt;
+    &lt;password&gt;user21&lt;/password&gt;
+    &lt;full-name&gt;User 21&lt;/full-name&gt;
+    &lt;email&gt;user21@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user22&lt;/short-name&gt;
+    &lt;uid&gt;user22&lt;/uid&gt;
+    &lt;password&gt;user22&lt;/password&gt;
+    &lt;full-name&gt;User 22&lt;/full-name&gt;
+    &lt;email&gt;user22@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user23&lt;/short-name&gt;
+    &lt;uid&gt;user23&lt;/uid&gt;
+    &lt;password&gt;user23&lt;/password&gt;
+    &lt;full-name&gt;User 23&lt;/full-name&gt;
+    &lt;email&gt;user23@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user24&lt;/short-name&gt;
+    &lt;uid&gt;user24&lt;/uid&gt;
+    &lt;password&gt;user24&lt;/password&gt;
+    &lt;full-name&gt;User 24&lt;/full-name&gt;
+    &lt;email&gt;user24@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user25&lt;/short-name&gt;
+    &lt;uid&gt;user25&lt;/uid&gt;
+    &lt;password&gt;user25&lt;/password&gt;
+    &lt;full-name&gt;User 25&lt;/full-name&gt;
+    &lt;email&gt;user25@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;group&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;group01&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group01&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group01&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group01&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 01&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;user01&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Group 01&lt;/full-name&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user01&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;group02&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group02&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group02&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group02&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 02&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;user06&lt;/member&gt;
-      &lt;member type=&quot;users&quot;&gt;user07&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Group 02&lt;/full-name&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user06&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user07&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;group03&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group03&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group03&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group03&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 03&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;user08&lt;/member&gt;
-      &lt;member type=&quot;users&quot;&gt;user09&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Group 03&lt;/full-name&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user08&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user09&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;group04&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group04&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group04&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group04&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 04&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;groups&quot;&gt;group02&lt;/member&gt;
-      &lt;member type=&quot;groups&quot;&gt;group03&lt;/member&gt;
-      &lt;member type=&quot;users&quot;&gt;user10&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt; &lt;!-- delegategroup --&gt;
</del><ins>+    &lt;full-name&gt;Group 04&lt;/full-name&gt;
+      &lt;member-uid type=&quot;groups&quot;&gt;group02&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;groups&quot;&gt;group03&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user10&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt; &lt;!-- delegategroup --&gt;
</ins><span class="cx">     &lt;uid&gt;group05&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group05&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group05&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group05&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 05&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;groups&quot;&gt;group06&lt;/member&gt;
-      &lt;member type=&quot;users&quot;&gt;user20&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt; &lt;!-- delegatesubgroup --&gt;
</del><ins>+    &lt;full-name&gt;Group 05&lt;/full-name&gt;
+      &lt;member-uid type=&quot;groups&quot;&gt;group06&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user20&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt; &lt;!-- delegatesubgroup --&gt;
</ins><span class="cx">     &lt;uid&gt;group06&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group06&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group06&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group06&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 06&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;user21&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt; &lt;!-- readonlydelegategroup --&gt;
</del><ins>+    &lt;full-name&gt;Group 06&lt;/full-name&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user21&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt; &lt;!-- readonlydelegategroup --&gt;
</ins><span class="cx">     &lt;uid&gt;group07&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group07&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group07&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group07&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 07&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;user22&lt;/member&gt;
-      &lt;member type=&quot;users&quot;&gt;user23&lt;/member&gt;
-      &lt;member type=&quot;users&quot;&gt;user24&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Group 07&lt;/full-name&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user22&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user23&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user24&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;disabledgroup&lt;/uid&gt;
</span><del>-    &lt;guid&gt;disabledgroup&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;disabledgroup&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;disabledgroup&lt;/password&gt;
</span><del>-    &lt;name&gt;Disabled Group&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;user01&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-&lt;/accounts&gt;
</del><ins>+    &lt;full-name&gt;Disabled Group&lt;/full-name&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user01&lt;/member-uid&gt;
+  &lt;/record&gt;
+&lt;/directory&gt;
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4confauthresourcestestxml"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/conf/auth/resources-test.xml (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/conf/auth/resources-test.xml        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/conf/auth/resources-test.xml        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,135 +1,273 @@
</span><del>-&lt;accounts realm=&quot;Test Realm&quot;&gt;
-  &lt;location repeat=&quot;10&quot;&gt;
-    &lt;uid&gt;location%02d&lt;/uid&gt;
-    &lt;guid&gt;location%02d&lt;/guid&gt;
-    &lt;password&gt;location%02d&lt;/password&gt;
-    &lt;name&gt;Room %02d&lt;/name&gt;
-  &lt;/location&gt;
-  &lt;resource repeat=&quot;20&quot;&gt;
-    &lt;uid&gt;resource%02d&lt;/uid&gt;
-    &lt;guid&gt;resource%02d&lt;/guid&gt;
-    &lt;password&gt;resource%02d&lt;/password&gt;
-    &lt;name&gt;Resource %02d&lt;/name&gt;
-  &lt;/resource&gt;
-  &lt;location&gt;
-    &lt;uid&gt;fantastic&lt;/uid&gt;
-    &lt;guid&gt;4D66A20A-1437-437D-8069-2F14E8322234&lt;/guid&gt;
-    &lt;name&gt;Fantastic Conference Room&lt;/name&gt;
</del><ins>+&lt;directory realm=&quot;Test Realm&quot;&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;fantastic&lt;/short-name&gt;
+    &lt;uid&gt;4D66A20A-1437-437D-8069-2F14E8322234&lt;/uid&gt;
+    &lt;full-name&gt;Fantastic Conference Room&lt;/full-name&gt;
</ins><span class="cx">     &lt;extras&gt;
</span><span class="cx">       &lt;associatedAddress&gt;63A2F949-2D8D-4C8D-B8A5-DCF2A94610F3&lt;/associatedAddress&gt;
</span><span class="cx">     &lt;/extras&gt;
</span><del>-  &lt;/location&gt;
-  &lt;location&gt;
</del><ins>+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;jupiter&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;jupiter&lt;/uid&gt;
</span><del>-    &lt;guid&gt;jupiter&lt;/guid&gt;
-    &lt;name&gt;Jupiter Conference Room, Building 2, 1st Floor&lt;/name&gt;
-  &lt;/location&gt;
-  &lt;location&gt;
</del><ins>+    &lt;full-name&gt;Jupiter Conference Room, Building 2, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;uranus&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;uranus&lt;/uid&gt;
</span><del>-    &lt;guid&gt;uranus&lt;/guid&gt;
-    &lt;name&gt;Uranus Conference Room, Building 3, 1st Floor&lt;/name&gt;
-  &lt;/location&gt;
-  &lt;location&gt;
-    &lt;uid&gt;morgensroom&lt;/uid&gt;
-    &lt;guid&gt;03DFF660-8BCC-4198-8588-DD77F776F518&lt;/guid&gt;
-    &lt;name&gt;Morgen's Room&lt;/name&gt;
-  &lt;/location&gt;
-  &lt;location&gt;
</del><ins>+    &lt;full-name&gt;Uranus Conference Room, Building 3, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;morgensroom&lt;/short-name&gt;
+    &lt;uid&gt;03DFF660-8BCC-4198-8588-DD77F776F518&lt;/uid&gt;
+    &lt;full-name&gt;Morgen's Room&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;mercury&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;mercury&lt;/uid&gt;
</span><del>-    &lt;guid&gt;mercury&lt;/guid&gt;
-    &lt;name&gt;Mercury Conference Room, Building 1, 2nd Floor&lt;/name&gt;
-  &lt;/location&gt;
-  &lt;location&gt;
</del><ins>+    &lt;full-name&gt;Mercury Conference Room, Building 1, 2nd Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location09&lt;/short-name&gt;
+    &lt;uid&gt;location09&lt;/uid&gt;
+    &lt;full-name&gt;Room 09&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location08&lt;/short-name&gt;
+    &lt;uid&gt;location08&lt;/uid&gt;
+    &lt;full-name&gt;Room 08&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location07&lt;/short-name&gt;
+    &lt;uid&gt;location07&lt;/uid&gt;
+    &lt;full-name&gt;Room 07&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location06&lt;/short-name&gt;
+    &lt;uid&gt;location06&lt;/uid&gt;
+    &lt;full-name&gt;Room 06&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location05&lt;/short-name&gt;
+    &lt;uid&gt;location05&lt;/uid&gt;
+    &lt;full-name&gt;Room 05&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location04&lt;/short-name&gt;
+    &lt;uid&gt;location04&lt;/uid&gt;
+    &lt;full-name&gt;Room 04&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location03&lt;/short-name&gt;
+    &lt;uid&gt;location03&lt;/uid&gt;
+    &lt;full-name&gt;Room 03&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location02&lt;/short-name&gt;
+    &lt;uid&gt;location02&lt;/uid&gt;
+    &lt;full-name&gt;Room 02&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location01&lt;/short-name&gt;
+    &lt;uid&gt;location01&lt;/uid&gt;
+    &lt;full-name&gt;Room 01&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;delegatedroom&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;delegatedroom&lt;/uid&gt;
</span><del>-    &lt;guid&gt;delegatedroom&lt;/guid&gt;
-    &lt;name&gt;Delegated Conference Room&lt;/name&gt;
-  &lt;/location&gt;
-  &lt;location&gt;
-    &lt;uid&gt;mars&lt;/uid&gt;
-    &lt;guid&gt;redplanet&lt;/guid&gt;
-    &lt;name&gt;Mars Conference Room, Building 1, 1st Floor&lt;/name&gt;
-  &lt;/location&gt;
-  &lt;location&gt;
-    &lt;uid&gt;sharissroom&lt;/uid&gt;
-    &lt;guid&gt;80689D41-DAF8-4189-909C-DB017B271892&lt;/guid&gt;
-    &lt;name&gt;Shari's Room&lt;/name&gt;
</del><ins>+    &lt;full-name&gt;Delegated Conference Room&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;mars&lt;/short-name&gt;
+    &lt;uid&gt;redplanet&lt;/uid&gt;
+    &lt;full-name&gt;Mars Conference Room, Building 1, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;sharissroom&lt;/short-name&gt;
+    &lt;uid&gt;80689D41-DAF8-4189-909C-DB017B271892&lt;/uid&gt;
+    &lt;full-name&gt;Shari's Room&lt;/full-name&gt;
</ins><span class="cx">     &lt;extras&gt;
</span><span class="cx">       &lt;associatedAddress&gt;6F9EE33B-78F6-481B-9289-3D0812FF0D64&lt;/associatedAddress&gt;
</span><span class="cx">     &lt;/extras&gt;
</span><del>-  &lt;/location&gt;
-  &lt;location&gt;
</del><ins>+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;pluto&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;pluto&lt;/uid&gt;
</span><del>-    &lt;guid&gt;pluto&lt;/guid&gt;
-    &lt;name&gt;Pluto Conference Room, Building 2, 1st Floor&lt;/name&gt;
-  &lt;/location&gt;
-  &lt;location&gt;
</del><ins>+    &lt;full-name&gt;Pluto Conference Room, Building 2, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;saturn&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;saturn&lt;/uid&gt;
</span><del>-    &lt;guid&gt;saturn&lt;/guid&gt;
-    &lt;name&gt;Saturn Conference Room, Building 2, 1st Floor&lt;/name&gt;
-  &lt;/location&gt;
-  &lt;location&gt;
-    &lt;uid&gt;pretend&lt;/uid&gt;
-    &lt;guid&gt;06E3BDCB-9C19-485A-B14E-F146A80ADDC6&lt;/guid&gt;
-    &lt;name&gt;Pretend Conference Room&lt;/name&gt;
</del><ins>+    &lt;full-name&gt;Saturn Conference Room, Building 2, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location10&lt;/short-name&gt;
+    &lt;uid&gt;location10&lt;/uid&gt;
+    &lt;full-name&gt;Room 10&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;pretend&lt;/short-name&gt;
+    &lt;uid&gt;06E3BDCB-9C19-485A-B14E-F146A80ADDC6&lt;/uid&gt;
+    &lt;full-name&gt;Pretend Conference Room&lt;/full-name&gt;
</ins><span class="cx">     &lt;extras&gt;
</span><span class="cx">       &lt;associatedAddress&gt;76E7ECA6-08BC-4AE7-930D-F2E7453993A5&lt;/associatedAddress&gt;
</span><span class="cx">     &lt;/extras&gt;
</span><del>-  &lt;/location&gt;
-  &lt;location&gt;
</del><ins>+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;neptune&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;neptune&lt;/uid&gt;
</span><del>-    &lt;guid&gt;neptune&lt;/guid&gt;
-    &lt;name&gt;Neptune Conference Room, Building 2, 1st Floor&lt;/name&gt;
-  &lt;/location&gt;
-  &lt;location&gt;
</del><ins>+    &lt;full-name&gt;Neptune Conference Room, Building 2, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;Earth&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;Earth&lt;/uid&gt;
</span><del>-    &lt;guid&gt;Earth&lt;/guid&gt;
-    &lt;name&gt;Earth Conference Room, Building 1, 1st Floor&lt;/name&gt;
-  &lt;/location&gt;
-  &lt;location&gt;
</del><ins>+    &lt;full-name&gt;Earth Conference Room, Building 1, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;venus&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;venus&lt;/uid&gt;
</span><del>-    &lt;guid&gt;venus&lt;/guid&gt;
-    &lt;name&gt;Venus Conference Room, Building 1, 2nd Floor&lt;/name&gt;
-  &lt;/location&gt;
-  &lt;resource&gt;
-    &lt;uid&gt;sharisotherresource&lt;/uid&gt;
-    &lt;guid&gt;CCE95217-A57B-481A-AC3D-FEC9AB6CE3A9&lt;/guid&gt;
-    &lt;name&gt;Shari's Other Resource&lt;/name&gt;
-  &lt;/resource&gt;
-  &lt;resource&gt;
-    &lt;uid&gt;sharisresource&lt;/uid&gt;
-    &lt;guid&gt;C38BEE7A-36EE-478C-9DCB-CBF4612AFE65&lt;/guid&gt;
-    &lt;name&gt;Shari's Resource&lt;/name&gt;
-  &lt;/resource&gt;
-  &lt;resource&gt;
-    &lt;uid&gt;sharisotherresource1&lt;/uid&gt;
-    &lt;guid&gt;0CE0BF31-5F9E-4801-A489-8C70CF287F5F&lt;/guid&gt;
-    &lt;name&gt;Shari's Other Resource1&lt;/name&gt;
-  &lt;/resource&gt;
-  &lt;address&gt;
-    &lt;uid&gt;testaddress1&lt;/uid&gt;
-    &lt;guid&gt;6F9EE33B-78F6-481B-9289-3D0812FF0D64&lt;/guid&gt;
-    &lt;name&gt;Test Address One&lt;/name&gt;
</del><ins>+    &lt;full-name&gt;Venus Conference Room, Building 1, 2nd Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;sharisotherresource&lt;/short-name&gt;
+    &lt;uid&gt;CCE95217-A57B-481A-AC3D-FEC9AB6CE3A9&lt;/uid&gt;
+    &lt;full-name&gt;Shari's Other Resource&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource15&lt;/short-name&gt;
+    &lt;uid&gt;resource15&lt;/uid&gt;
+    &lt;full-name&gt;Resource 15&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource14&lt;/short-name&gt;
+    &lt;uid&gt;resource14&lt;/uid&gt;
+    &lt;full-name&gt;Resource 14&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource17&lt;/short-name&gt;
+    &lt;uid&gt;resource17&lt;/uid&gt;
+    &lt;full-name&gt;Resource 17&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource16&lt;/short-name&gt;
+    &lt;uid&gt;resource16&lt;/uid&gt;
+    &lt;full-name&gt;Resource 16&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource11&lt;/short-name&gt;
+    &lt;uid&gt;resource11&lt;/uid&gt;
+    &lt;full-name&gt;Resource 11&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource10&lt;/short-name&gt;
+    &lt;uid&gt;resource10&lt;/uid&gt;
+    &lt;full-name&gt;Resource 10&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource13&lt;/short-name&gt;
+    &lt;uid&gt;resource13&lt;/uid&gt;
+    &lt;full-name&gt;Resource 13&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource12&lt;/short-name&gt;
+    &lt;uid&gt;resource12&lt;/uid&gt;
+    &lt;full-name&gt;Resource 12&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource19&lt;/short-name&gt;
+    &lt;uid&gt;resource19&lt;/uid&gt;
+    &lt;full-name&gt;Resource 19&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource18&lt;/short-name&gt;
+    &lt;uid&gt;resource18&lt;/uid&gt;
+    &lt;full-name&gt;Resource 18&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;sharisresource&lt;/short-name&gt;
+    &lt;uid&gt;C38BEE7A-36EE-478C-9DCB-CBF4612AFE65&lt;/uid&gt;
+    &lt;full-name&gt;Shari's Resource&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource20&lt;/short-name&gt;
+    &lt;uid&gt;resource20&lt;/uid&gt;
+    &lt;full-name&gt;Resource 20&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource06&lt;/short-name&gt;
+    &lt;uid&gt;resource06&lt;/uid&gt;
+    &lt;full-name&gt;Resource 06&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource07&lt;/short-name&gt;
+    &lt;uid&gt;resource07&lt;/uid&gt;
+    &lt;full-name&gt;Resource 07&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource04&lt;/short-name&gt;
+    &lt;uid&gt;resource04&lt;/uid&gt;
+    &lt;full-name&gt;Resource 04&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource05&lt;/short-name&gt;
+    &lt;uid&gt;resource05&lt;/uid&gt;
+    &lt;full-name&gt;Resource 05&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource02&lt;/short-name&gt;
+    &lt;uid&gt;resource02&lt;/uid&gt;
+    &lt;full-name&gt;Resource 02&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource03&lt;/short-name&gt;
+    &lt;uid&gt;resource03&lt;/uid&gt;
+    &lt;full-name&gt;Resource 03&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource01&lt;/short-name&gt;
+    &lt;uid&gt;resource01&lt;/uid&gt;
+    &lt;full-name&gt;Resource 01&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;sharisotherresource1&lt;/short-name&gt;
+    &lt;uid&gt;0CE0BF31-5F9E-4801-A489-8C70CF287F5F&lt;/uid&gt;
+    &lt;full-name&gt;Shari's Other Resource1&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource08&lt;/short-name&gt;
+    &lt;uid&gt;resource08&lt;/uid&gt;
+    &lt;full-name&gt;Resource 08&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource09&lt;/short-name&gt;
+    &lt;uid&gt;resource09&lt;/uid&gt;
+    &lt;full-name&gt;Resource 09&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;address&quot;&gt;
+    &lt;short-name&gt;testaddress1&lt;/short-name&gt;
+    &lt;uid&gt;6F9EE33B-78F6-481B-9289-3D0812FF0D64&lt;/uid&gt;
+    &lt;full-name&gt;Test Address One&lt;/full-name&gt;
</ins><span class="cx">     &lt;extras&gt;
</span><span class="cx">       &lt;streetAddress&gt;20300 Stevens Creek Blvd, Cupertino, CA 95014&lt;/streetAddress&gt;
</span><span class="cx">       &lt;geo&gt;37.322281,-122.028345&lt;/geo&gt;
</span><span class="cx">     &lt;/extras&gt;
</span><del>-  &lt;/address&gt;
-  &lt;address&gt;
-    &lt;uid&gt;il2&lt;/uid&gt;
-    &lt;guid&gt;63A2F949-2D8D-4C8D-B8A5-DCF2A94610F3&lt;/guid&gt;
-    &lt;name&gt;IL2&lt;/name&gt;
</del><ins>+  &lt;/record&gt;
+  &lt;record type=&quot;address&quot;&gt;
+    &lt;short-name&gt;il2&lt;/short-name&gt;
+    &lt;uid&gt;63A2F949-2D8D-4C8D-B8A5-DCF2A94610F3&lt;/uid&gt;
+    &lt;full-name&gt;IL2&lt;/full-name&gt;
</ins><span class="cx">     &lt;extras&gt;
</span><span class="cx">       &lt;streetAddress&gt;2 Infinite Loop, Cupertino, CA 95014&lt;/streetAddress&gt;
</span><span class="cx">       &lt;geo&gt;37.332633,-122.030502&lt;/geo&gt;
</span><span class="cx">     &lt;/extras&gt;
</span><del>-  &lt;/address&gt;
-  &lt;address&gt;
-    &lt;uid&gt;il1&lt;/uid&gt;
-    &lt;guid&gt;76E7ECA6-08BC-4AE7-930D-F2E7453993A5&lt;/guid&gt;
-    &lt;name&gt;IL1&lt;/name&gt;
</del><ins>+  &lt;/record&gt;
+  &lt;record type=&quot;address&quot;&gt;
+    &lt;short-name&gt;il1&lt;/short-name&gt;
+    &lt;uid&gt;76E7ECA6-08BC-4AE7-930D-F2E7453993A5&lt;/uid&gt;
+    &lt;full-name&gt;IL1&lt;/full-name&gt;
</ins><span class="cx">     &lt;extras&gt;
</span><span class="cx">       &lt;streetAddress&gt;1 Infinite Loop, Cupertino, CA 95014&lt;/streetAddress&gt;
</span><span class="cx">       &lt;geo&gt;37.331741,-122.030333&lt;/geo&gt;
</span><span class="cx">     &lt;/extras&gt;
</span><del>-  &lt;/address&gt;
-&lt;/accounts&gt;
</del><ins>+  &lt;/record&gt;
+&lt;/directory&gt;
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4contribperformanceloadtesttest_simpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/contrib/performance/loadtest/test_sim.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/contrib/performance/loadtest/test_sim.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/contrib/performance/loadtest/test_sim.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -24,32 +24,34 @@
</span><span class="cx"> from twisted.internet.defer import Deferred, succeed
</span><span class="cx"> from twisted.trial.unittest import TestCase
</span><span class="cx"> 
</span><del>-from twistedcaldav.directory.directory import DirectoryRecord
-
</del><span class="cx"> from contrib.performance.stats import NormalDistribution
</span><span class="cx"> from contrib.performance.loadtest.ical import OS_X_10_6
</span><span class="cx"> from contrib.performance.loadtest.profiles import Eventer, Inviter, Accepter
</span><span class="cx"> from contrib.performance.loadtest.population import (
</span><span class="cx">     SmoothRampUp, ClientType, PopulationParameters, Populator, CalendarClientSimulator,
</span><del>-    ProfileType, SimpleStatistics)
</del><ins>+    ProfileType, SimpleStatistics
+)
</ins><span class="cx"> from contrib.performance.loadtest.sim import (
</span><del>-    Arrival, SimOptions, LoadSimulator, LagTrackingReactor)
</del><ins>+    Arrival, SimOptions, LoadSimulator, LagTrackingReactor,
+    _DirectoryRecord
+)
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> VALID_CONFIG = {
</span><span class="cx">     'server': 'tcp:127.0.0.1:8008',
</span><span class="cx">     'webadmin': {
</span><span class="cx">         'enabled': True,
</span><span class="cx">         'HTTPPort': 8080,
</span><del>-        },
</del><ins>+    },
</ins><span class="cx">     'arrival': {
</span><span class="cx">         'factory': 'contrib.performance.loadtest.population.SmoothRampUp',
</span><span class="cx">         'params': {
</span><span class="cx">             'groups': 10,
</span><span class="cx">             'groupSize': 1,
</span><span class="cx">             'interval': 3,
</span><del>-            },
</del><span class="cx">         },
</span><del>-    }
</del><ins>+    },
+}
</ins><span class="cx"> 
</span><span class="cx"> VALID_CONFIG_PLIST = writePlistToString(VALID_CONFIG)
</span><span class="cx"> 
</span><span class="lines">@@ -104,8 +106,9 @@
</span><span class="cx">     realmName = 'stub'
</span><span class="cx"> 
</span><span class="cx">     def _user(self, name):
</span><del>-        record = DirectoryRecord(self, 'user', name, (name,))
-        record.password = 'password-' + name
</del><ins>+        password = 'password-' + name
+        email = name + &quot;@example.com&quot;
+        record = _DirectoryRecord(name, password, name, email)
</ins><span class="cx">         return record
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -119,10 +122,10 @@
</span><span class="cx">             [self._user('alice'), self._user('bob'), self._user('carol')],
</span><span class="cx">             Populator(None), None, None, 'http://example.org:1234/', None, None)
</span><span class="cx">         users = sorted([
</span><del>-                calsim._createUser(0)[0],
-                calsim._createUser(1)[0],
-                calsim._createUser(2)[0],
-                ])
</del><ins>+            calsim._createUser(0)[0],
+            calsim._createUser(1)[0],
+            calsim._createUser(2)[0],
+        ])
</ins><span class="cx">         self.assertEqual(['alice', 'bob', 'carol'], users)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -171,8 +174,9 @@
</span><span class="cx"> 
</span><span class="cx">         params = PopulationParameters()
</span><span class="cx">         params.addClient(1, ClientType(
</span><del>-                BrokenClient, {'runResult': clientRunResult},
-                [ProfileType(BrokenProfile, {'runResult': profileRunResult})]))
</del><ins>+            BrokenClient, {'runResult': clientRunResult},
+            [ProfileType(BrokenProfile, {'runResult': profileRunResult})])
+        )
</ins><span class="cx">         sim = CalendarClientSimulator(
</span><span class="cx">             [self._user('alice')], Populator(None), params, None, 'http://example.com:1234/', None, None)
</span><span class="cx">         sim.add(1, 1)
</span><span class="lines">@@ -284,8 +288,9 @@
</span><span class="cx">         config[&quot;accounts&quot;] = {
</span><span class="cx">             &quot;loader&quot;: &quot;contrib.performance.loadtest.sim.recordsFromCSVFile&quot;,
</span><span class="cx">             &quot;params&quot;: {
</span><del>-                &quot;path&quot;: accounts.path},
-            }
</del><ins>+                &quot;path&quot;: accounts.path
+            },
+        }
</ins><span class="cx">         configpath = FilePath(self.mktemp())
</span><span class="cx">         configpath.setContent(writePlistToString(config))
</span><span class="cx">         io = StringIO()
</span><span class="lines">@@ -312,8 +317,9 @@
</span><span class="cx">         config[&quot;accounts&quot;] = {
</span><span class="cx">             &quot;loader&quot;: &quot;contrib.performance.loadtest.sim.recordsFromCSVFile&quot;,
</span><span class="cx">             &quot;params&quot;: {
</span><del>-                &quot;path&quot;: &quot;&quot;},
-            }
</del><ins>+                &quot;path&quot;: &quot;&quot;
+            },
+        }
</ins><span class="cx">         configpath = FilePath(self.mktemp())
</span><span class="cx">         configpath.setContent(writePlistToString(config))
</span><span class="cx">         sim = LoadSimulator.fromCommandLine(['--config', configpath.path],
</span><span class="lines">@@ -406,8 +412,9 @@
</span><span class="cx">         section of the configuration file specified.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         config = FilePath(self.mktemp())
</span><del>-        config.setContent(writePlistToString({
-                    &quot;server&quot;: &quot;https://127.0.0.3:8432/&quot;}))
</del><ins>+        config.setContent(
+            writePlistToString({&quot;server&quot;: &quot;https://127.0.0.3:8432/&quot;})
+        )
</ins><span class="cx">         sim = LoadSimulator.fromCommandLine(['--config', config.path])
</span><span class="cx">         self.assertEquals(sim.server, &quot;https://127.0.0.3:8432/&quot;)
</span><span class="cx"> 
</span><span class="lines">@@ -418,16 +425,18 @@
</span><span class="cx">         [arrival] section of the configuration file specified.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         config = FilePath(self.mktemp())
</span><del>-        config.setContent(writePlistToString({
-                    &quot;arrival&quot;: {
-                        &quot;factory&quot;: &quot;contrib.performance.loadtest.population.SmoothRampUp&quot;,
-                        &quot;params&quot;: {
-                            &quot;groups&quot;: 10,
-                            &quot;groupSize&quot;: 1,
-                            &quot;interval&quot;: 3,
-                            },
-                        },
-                    }))
</del><ins>+        config.setContent(
+            writePlistToString({
+                &quot;arrival&quot;: {
+                    &quot;factory&quot;: &quot;contrib.performance.loadtest.population.SmoothRampUp&quot;,
+                    &quot;params&quot;: {
+                        &quot;groups&quot;: 10,
+                        &quot;groupSize&quot;: 1,
+                        &quot;interval&quot;: 3,
+                    },
+                },
+            })
+        )
</ins><span class="cx">         sim = LoadSimulator.fromCommandLine(['--config', config.path])
</span><span class="cx">         self.assertEquals(
</span><span class="cx">             sim.arrival,
</span><span class="lines">@@ -461,11 +470,17 @@
</span><span class="cx">         section of the configuration file specified.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         config = FilePath(self.mktemp())
</span><del>-        config.setContent(writePlistToString({
-                    &quot;clients&quot;: [{
</del><ins>+        config.setContent(
+            writePlistToString(
+                {
+                    &quot;clients&quot;: [
+                        {
</ins><span class="cx">                             &quot;software&quot;: &quot;contrib.performance.loadtest.ical.OS_X_10_6&quot;,
</span><del>-                            &quot;params&quot;: {&quot;foo&quot;: &quot;bar&quot;},
-                            &quot;profiles&quot;: [{
</del><ins>+                            &quot;params&quot;: {
+                                &quot;foo&quot;: &quot;bar&quot;
+                            },
+                            &quot;profiles&quot;: [
+                                {
</ins><span class="cx">                                     &quot;params&quot;: {
</span><span class="cx">                                         &quot;interval&quot;: 25,
</span><span class="cx">                                         &quot;eventStartDistribution&quot;: {
</span><span class="lines">@@ -473,19 +488,38 @@
</span><span class="cx">                                             &quot;params&quot;: {
</span><span class="cx">                                                 &quot;mu&quot;: 123,
</span><span class="cx">                                                 &quot;sigma&quot;: 456,
</span><del>-                                                }}},
-                                    &quot;class&quot;: &quot;contrib.performance.loadtest.profiles.Eventer&quot;}],
</del><ins>+                                            }
+                                        }
+                                    },
+                                    &quot;class&quot;: &quot;contrib.performance.loadtest.profiles.Eventer&quot;
+                                }
+                            ],
</ins><span class="cx">                             &quot;weight&quot;: 3,
</span><del>-                            }]}))
</del><ins>+                        }
+                    ]
+                }
+            )
+        )
</ins><span class="cx"> 
</span><span class="cx">         sim = LoadSimulator.fromCommandLine(
</span><span class="cx">             ['--config', config.path, '--clients', config.path]
</span><span class="cx">         )
</span><span class="cx">         expectedParameters = PopulationParameters()
</span><span class="cx">         expectedParameters.addClient(
</span><del>-            3, ClientType(OS_X_10_6, {&quot;foo&quot;: &quot;bar&quot;}, [ProfileType(Eventer, {
</del><ins>+            3,
+            ClientType(
+                OS_X_10_6,
+                {&quot;foo&quot;: &quot;bar&quot;},
+                [
+                    ProfileType(
+                        Eventer, {
</ins><span class="cx">                             &quot;interval&quot;: 25,
</span><del>-                            &quot;eventStartDistribution&quot;: NormalDistribution(123, 456)})]))
</del><ins>+                            &quot;eventStartDistribution&quot;: NormalDistribution(123, 456)
+                        }
+                    )
+                ]
+            )
+        )
</ins><span class="cx">         self.assertEquals(sim.parameters, expectedParameters)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -512,9 +546,18 @@
</span><span class="cx">         configuration file are added to the logging system.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         config = FilePath(self.mktemp())
</span><del>-        config.setContent(writePlistToString({
-            &quot;observers&quot;: [{&quot;type&quot;:&quot;contrib.performance.loadtest.population.SimpleStatistics&quot;, &quot;params&quot;:{}, }, ]
-        }))
</del><ins>+        config.setContent(
+            writePlistToString(
+                {
+                    &quot;observers&quot;: [
+                        {
+                            &quot;type&quot;: &quot;contrib.performance.loadtest.population.SimpleStatistics&quot;,
+                            &quot;params&quot;: {},
+                        },
+                    ]
+                }
+            )
+        )
</ins><span class="cx">         sim = LoadSimulator.fromCommandLine(['--config', config.path])
</span><span class="cx">         self.assertEquals(len(sim.observers), 1)
</span><span class="cx">         self.assertIsInstance(sim.observers[0], SimpleStatistics)
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavcustomxmlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/customxml.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/customxml.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/customxml.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1456,6 +1456,8 @@
</span><span class="cx"> 
</span><span class="cx"> ResourceType.calendarproxyread = ResourceType(Principal(), Collection(), CalendarProxyRead())
</span><span class="cx"> ResourceType.calendarproxywrite = ResourceType(Principal(), Collection(), CalendarProxyWrite())
</span><ins>+ResourceType.calendarproxyreadfor = ResourceType(Principal(), Collection(), CalendarProxyReadFor())
+ResourceType.calendarproxywritefor = ResourceType(Principal(), Collection(), CalendarProxyWriteFor())
</ins><span class="cx"> 
</span><span class="cx"> ResourceType.timezones = ResourceType(Timezones())
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryaddressbookpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/addressbook.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/addressbook.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/addressbook.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -34,7 +34,6 @@
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue, succeed
</span><span class="cx"> 
</span><span class="cx"> from twistedcaldav.config import config
</span><del>-from twistedcaldav.directory.idirectory import IDirectoryService
</del><span class="cx"> 
</span><span class="cx"> from twistedcaldav.directory.common import CommonUIDProvisioningResource,\
</span><span class="cx">     uidsResourceName, CommonHomeTypeProvisioningResource
</span><span class="lines">@@ -58,14 +57,14 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class DirectoryAddressBookProvisioningResource (
</del><ins>+class DirectoryAddressBookProvisioningResource(
</ins><span class="cx">     ReadOnlyResourceMixIn,
</span><span class="cx">     CalDAVComplianceMixIn,
</span><span class="cx">     DAVResourceWithChildrenMixin,
</span><span class="cx">     DAVResource,
</span><span class="cx"> ):
</span><span class="cx">     def defaultAccessControlList(self):
</span><del>-        return config.ProvisioningResourceACL
</del><ins>+        return succeed(config.ProvisioningResourceACL)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def etag(self):
</span><span class="lines">@@ -77,9 +76,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class DirectoryAddressBookHomeProvisioningResource (
-        DirectoryAddressBookProvisioningResource
-    ):
</del><ins>+class DirectoryAddressBookHomeProvisioningResource(
+    DirectoryAddressBookProvisioningResource
+):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Resource which provisions address book home collections as needed.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="lines">@@ -93,7 +92,8 @@
</span><span class="cx"> 
</span><span class="cx">         super(DirectoryAddressBookHomeProvisioningResource, self).__init__()
</span><span class="cx"> 
</span><del>-        self.directory = IDirectoryService(directory)
</del><ins>+        # MOVE2WHO
+        self.directory = directory  # IDirectoryService(directory)
</ins><span class="cx">         self._url = url
</span><span class="cx">         self._newStore = store
</span><span class="cx"> 
</span><span class="lines">@@ -103,8 +103,14 @@
</span><span class="cx">         #
</span><span class="cx">         # Create children
</span><span class="cx">         #
</span><del>-        for recordType in self.directory.recordTypes():
-            self.putChild(recordType, DirectoryAddressBookHomeTypeProvisioningResource(self, recordType))
</del><ins>+        # ...just &quot;users&quot; though.  If we iterate all of the directory's
+        # recordTypes, we also get the proxy sub principal types.
+        for recordTypeName in [
+            self.directory.recordTypeToOldName(r) for r in [
+                self.directory.recordType.user
+            ]
+        ]:
+            self.putChild(recordTypeName, DirectoryAddressBookHomeTypeProvisioningResource(self, r))
</ins><span class="cx"> 
</span><span class="cx">         self.putChild(uidsResourceName, DirectoryAddressBookHomeUIDProvisioningResource(self))
</span><span class="cx"> 
</span><span class="lines">@@ -114,7 +120,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def listChildren(self):
</span><del>-        return self.directory.recordTypes()
</del><ins>+        return [self.directory.recordTypeToOldName(r) for r in self.directory.recordTypes()]
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def principalCollections(self):
</span><span class="lines">@@ -129,12 +135,13 @@
</span><span class="cx">         return self.directory.principalCollection.principalForRecord(record)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def homeForDirectoryRecord(self, record, request):
</span><del>-        uidResource = self.getChild(uidsResourceName)
</del><ins>+        uidResource = yield self.getChild(uidsResourceName)
</ins><span class="cx">         if uidResource is None:
</span><del>-            return None
</del><ins>+            returnValue(None)
</ins><span class="cx">         else:
</span><del>-            return uidResource.homeResourceForRecord(record, request)
</del><ins>+            returnValue((yield uidResource.homeResourceForRecord(record, request)))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     ##
</span><span class="lines">@@ -151,9 +158,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class DirectoryAddressBookHomeTypeProvisioningResource (
</span><del>-        CommonHomeTypeProvisioningResource,
-        DirectoryAddressBookProvisioningResource
-    ):
</del><ins>+    CommonHomeTypeProvisioningResource,
+    DirectoryAddressBookProvisioningResource
+):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Resource which provisions address book home collections of a specific
</span><span class="cx">     record type as needed.
</span><span class="lines">@@ -174,19 +181,19 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def url(self):
</span><del>-        return joinURL(self._parent.url(), self.recordType)
</del><ins>+        return joinURL(self._parent.url(), self.directory.recordTypeToOldName(self.recordType))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def listChildren(self):
</span><span class="cx">         if config.EnablePrincipalListings:
</span><ins>+            children = []
+            for record in (yield self.directory.listRecords(self.recordType)):
+                if record.enabledForAddressBooks:
+                    for shortName in record.shortNames:
+                        children.append(shortName)
</ins><span class="cx"> 
</span><del>-            def _recordShortnameExpand():
-                for record in self.directory.listRecords(self.recordType):
-                    if record.enabledForAddressBooks:
-                        for shortName in record.shortNames:
-                            yield shortName
-
-            return _recordShortnameExpand()
</del><ins>+            returnValue(children)
</ins><span class="cx">         else:
</span><span class="cx">             # Not a listable collection
</span><span class="cx">             raise HTTPError(responsecode.FORBIDDEN)
</span><span class="lines">@@ -222,9 +229,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class DirectoryAddressBookHomeUIDProvisioningResource (
</span><del>-        CommonUIDProvisioningResource,
-        DirectoryAddressBookProvisioningResource
-    ):
</del><ins>+    CommonUIDProvisioningResource,
+    DirectoryAddressBookProvisioningResource
+):
</ins><span class="cx"> 
</span><span class="cx">     homeResourceTypeName = 'addressbooks'
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryaggregatepy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/aggregate.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/aggregate.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/aggregate.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,385 +0,0 @@
</span><del>-##
-# Copyright (c) 2006-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.
-##
-
-&quot;&quot;&quot;
-Directory service implementation which aggregates multiple directory
-services.
-&quot;&quot;&quot;
-
-__all__ = [
-    &quot;AggregateDirectoryService&quot;,
-    &quot;DuplicateRecordTypeError&quot;,
-]
-
-import itertools
-from twisted.cred.error import UnauthorizedLogin
-
-from twistedcaldav.directory.idirectory import IDirectoryService
-from twistedcaldav.directory.directory import DirectoryService, DirectoryError
-from twistedcaldav.directory.directory import UnknownRecordTypeError
-from twisted.internet.defer import inlineCallbacks, returnValue
-
-class AggregateDirectoryService(DirectoryService):
-    &quot;&quot;&quot;
-    L{IDirectoryService} implementation which aggregates multiple directory
-    services.
-
-    @ivar _recordTypes: A map of record types to L{IDirectoryService}s.
-    @type _recordTypes: L{dict} mapping L{bytes} to L{IDirectoryService}
-        provider.
-    &quot;&quot;&quot;
-    baseGUID = &quot;06FB225F-39E7-4D34-B1D1-29925F5E619B&quot;
-
-    def __init__(self, services, groupMembershipCache):
-        super(AggregateDirectoryService, self).__init__()
-
-        realmName = None
-        recordTypes = {}
-        self.groupMembershipCache = groupMembershipCache
-
-        for service in services:
-            service = IDirectoryService(service)
-
-            if service.realmName != realmName:
-                assert realmName is None, (
-                    &quot;Aggregated directory services must have the same realm name: %r != %r\nServices: %r&quot;
-                    % (service.realmName, realmName, services)
-                )
-                realmName = service.realmName
-
-            if not hasattr(service, &quot;recordTypePrefix&quot;):
-                service.recordTypePrefix = &quot;&quot;
-            prefix = service.recordTypePrefix
-
-            for recordType in (prefix + r for r in service.recordTypes()):
-                if recordType in recordTypes:
-                    raise DuplicateRecordTypeError(
-                        &quot;%r is in multiple services: %s, %s&quot;
-                        % (recordType, recordTypes[recordType], service)
-                    )
-                recordTypes[recordType] = service
-
-            service.aggregateService = self
-
-        self.realmName = realmName
-        self._recordTypes = recordTypes
-
-        # FIXME: This is a temporary workaround until new data store is in
-        # place.  During the purging of deprovisioned users' data, we need
-        # to be able to look up records by uid and shortName.  The purge
-        # tool sticks temporary fake records in here.
-        self._tmpRecords = {
-            &quot;uids&quot; : { },
-            &quot;shortNames&quot; : { },
-        }
-
-
-    def __repr__(self):
-        return &quot;&lt;%s (%s): %r&gt;&quot; % (self.__class__.__name__, self.realmName, self._recordTypes)
-
-
-    #
-    # Define calendarHomesCollection as a property so we can set it on contained services
-    #
-    def _getCalendarHomesCollection(self):
-        return self._calendarHomesCollection
-
-
-    def _setCalendarHomesCollection(self, value):
-        for service in self._recordTypes.values():
-            service.calendarHomesCollection = value
-        self._calendarHomesCollection = value
-
-    calendarHomesCollection = property(_getCalendarHomesCollection, _setCalendarHomesCollection)
-
-    #
-    # Define addressBookHomesCollection as a property so we can set it on contained services
-    #
-    def _getAddressBookHomesCollection(self):
-        return self._addressBookHomesCollection
-
-
-    def _setAddressBookHomesCollection(self, value):
-        for service in self._recordTypes.values():
-            service.addressBookHomesCollection = value
-        self._addressBookHomesCollection = value
-
-    addressBookHomesCollection = property(_getAddressBookHomesCollection, _setAddressBookHomesCollection)
-
-
-    def addService(self, service):
-        &quot;&quot;&quot;
-        Add another service to this aggregate.
-
-        @param service: the service to add
-        @type service: L{IDirectoryService}
-        &quot;&quot;&quot;
-        service = IDirectoryService(service)
-
-        if service.realmName != self.realmName:
-            assert self.realmName is None, (
-                &quot;Aggregated directory services must have the same realm name: %r != %r\nServices: %r&quot;
-                % (service.realmName, self.realmName, service)
-            )
-
-        if not hasattr(service, &quot;recordTypePrefix&quot;):
-            service.recordTypePrefix = &quot;&quot;
-        prefix = service.recordTypePrefix
-
-        for recordType in (prefix + r for r in service.recordTypes()):
-            if recordType in self._recordTypes:
-                raise DuplicateRecordTypeError(
-                    &quot;%r is in multiple services: %s, %s&quot;
-                    % (recordType, self.recordTypes[recordType], service)
-                )
-            self._recordTypes[recordType] = service
-
-        service.aggregateService = self
-
-
-    def recordTypes(self):
-        return set(self._recordTypes)
-
-
-    def listRecords(self, recordType):
-        records = self._query(&quot;listRecords&quot;, recordType)
-        if records is None:
-            return ()
-        else:
-            return records
-
-
-    def recordWithShortName(self, recordType, shortName):
-
-        # FIXME: These temporary records shouldn't be needed when we move
-        # to the new data store API.  They're currently needed when purging
-        # deprovisioned users' data.
-        record = self._tmpRecords[&quot;shortNames&quot;].get(shortName, None)
-        if record:
-            return record
-
-        return self._query(&quot;recordWithShortName&quot;, recordType, shortName)
-
-
-    def recordWithUID(self, uid):
-
-        # FIXME: These temporary records shouldn't be needed when we move
-        # to the new data store API.  They're currently needed when purging
-        # deprovisioned users' data.
-        record = self._tmpRecords[&quot;uids&quot;].get(uid, None)
-        if record:
-            return record
-
-        return self._queryAll(&quot;recordWithUID&quot;, uid)
-
-    recordWithGUID = recordWithUID
-
-    def recordWithAuthID(self, authID):
-        return self._queryAll(&quot;recordWithAuthID&quot;, authID)
-
-
-    def recordWithCalendarUserAddress(self, address):
-        return self._queryAll(&quot;recordWithCalendarUserAddress&quot;, address)
-
-
-    def recordWithCachedGroupsAlias(self, recordType, alias):
-        &quot;&quot;&quot;
-        @param recordType: the type of the record to look up.
-        @param alias: the cached-groups alias of the record to look up.
-        @type alias: C{str}
-
-        @return: a deferred L{IDirectoryRecord} with the given cached-groups
-            alias, or C{None} if no such record is found.
-        &quot;&quot;&quot;
-        service = self.serviceForRecordType(recordType)
-        return service.recordWithCachedGroupsAlias(recordType, alias)
-
-
-    @inlineCallbacks
-    def recordsMatchingFields(self, fields, operand=&quot;or&quot;, recordType=None):
-
-        if recordType:
-            services = (self.serviceForRecordType(recordType),)
-        else:
-            services = set(self._recordTypes.values())
-
-        generators = []
-        for service in services:
-            generator = (yield service.recordsMatchingFields(fields,
-                operand=operand, recordType=recordType))
-            generators.append(generator)
-
-        returnValue(itertools.chain(*generators))
-
-
-    @inlineCallbacks
-    def recordsMatchingTokens(self, tokens, context=None):
-        &quot;&quot;&quot;
-        Combine the results from the sub-services.
-
-        Each token is searched for within each record's full name and email
-        address; if each token is found within a record that record is returned
-        in the results.
-
-        If context is None, all record types are considered.  If context is
-        &quot;location&quot;, only locations are considered.  If context is &quot;attendee&quot;,
-        only users, groups, and resources are considered.
-
-        @param tokens: The tokens to search on
-        @type tokens: C{list} of C{str} (utf-8 bytes)
-
-        @param context: An indication of what the end user is searching for;
-            &quot;attendee&quot;, &quot;location&quot;, or None
-        @type context: C{str}
-
-        @return: a deferred sequence of L{IDirectoryRecord}s which match the
-            given tokens and optional context.
-        &quot;&quot;&quot;
-
-        services = set(self._recordTypes.values())
-
-        generators = []
-        for service in services:
-            generator = (yield service.recordsMatchingTokens(tokens,
-                context=context))
-            generators.append(generator)
-
-        returnValue(itertools.chain(*generators))
-
-
-    def getGroups(self, guids):
-        &quot;&quot;&quot;
-        Returns a set of group records for the list of guids passed in.  For
-        any group that also contains subgroups, those subgroups' records are
-        also returned, and so on.
-        &quot;&quot;&quot;
-        recordType = self.recordType_groups
-        service = self.serviceForRecordType(recordType)
-        return service.getGroups(guids)
-
-
-    def serviceForRecordType(self, recordType):
-        try:
-            return self._recordTypes[recordType]
-        except KeyError:
-            raise UnknownRecordTypeError(recordType)
-
-
-    def _query(self, query, recordType, *args):
-        try:
-            service = self.serviceForRecordType(recordType)
-        except UnknownRecordTypeError:
-            return None
-
-        return getattr(service, query)(
-            recordType[len(service.recordTypePrefix):],
-            *[a[len(service.recordTypePrefix):] for a in args]
-        )
-
-
-    def _queryAll(self, query, *args):
-        for service in self._recordTypes.values():
-            try:
-                record = getattr(service, query)(*args)
-            except UnknownRecordTypeError:
-                record = None
-            if record is not None:
-                return record
-        else:
-            return None
-
-
-    def flushCaches(self):
-        for service in self._recordTypes.values():
-            if hasattr(service, &quot;_initCaches&quot;):
-                service._initCaches()
-
-    userRecordTypes = [DirectoryService.recordType_users]
-
-    def requestAvatarId(self, credentials):
-
-        if credentials.authnPrincipal:
-            return credentials.authnPrincipal.record.service.requestAvatarId(credentials)
-
-        raise UnauthorizedLogin(&quot;No such user: %s&quot; % (credentials.credentials.username,))
-
-
-    def getResourceInfo(self):
-        results = []
-        for service in self._recordTypes.values():
-            for result in service.getResourceInfo():
-                if result:
-                    results.append(result)
-        return results
-
-
-    def getExternalProxyAssignments(self):
-        service = self.serviceForRecordType(self.recordType_locations)
-        return service.getExternalProxyAssignments()
-
-
-    def createRecord(self, recordType, guid=None, shortNames=(), authIDs=set(),
-        fullName=None, firstName=None, lastName=None, emailAddresses=set(),
-        uid=None, password=None, **kwargs):
-        service = self.serviceForRecordType(recordType)
-        return service.createRecord(recordType, guid=guid,
-            shortNames=shortNames, authIDs=authIDs, fullName=fullName,
-            firstName=firstName, lastName=lastName,
-            emailAddresses=emailAddresses, uid=uid, password=password, **kwargs)
-
-
-    def updateRecord(self, recordType, guid=None, shortNames=(), authIDs=set(),
-        fullName=None, firstName=None, lastName=None, emailAddresses=set(),
-        uid=None, password=None, **kwargs):
-        service = self.serviceForRecordType(recordType)
-        return service.updateRecord(recordType, guid=guid,
-            shortNames=shortNames,
-            authIDs=authIDs, fullName=fullName, firstName=firstName,
-            lastName=lastName, emailAddresses=emailAddresses, uid=uid,
-            password=password, **kwargs)
-
-
-    def destroyRecord(self, recordType, guid=None):
-        service = self.serviceForRecordType(recordType)
-        return service.destroyRecord(recordType, guid=guid)
-
-
-    def setRealm(self, realmName):
-        &quot;&quot;&quot;
-        Set a new realm name for this and nested services
-        &quot;&quot;&quot;
-        self.realmName = realmName
-        for service in self._recordTypes.values():
-            service.setRealm(realmName)
-
-
-    def setPrincipalCollection(self, principalCollection):
-        &quot;&quot;&quot;
-        Set the principal service that the directory relies on for doing proxy tests.
-
-        @param principalService: the principal service.
-        @type principalService: L{DirectoryProvisioningResource}
-        &quot;&quot;&quot;
-        self.principalCollection = principalCollection
-        for service in self._recordTypes.values():
-            service.setPrincipalCollection(principalCollection)
-
-
-
-class DuplicateRecordTypeError(DirectoryError):
-    &quot;&quot;&quot;
-    Duplicate record type.
-    &quot;&quot;&quot;
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryappleopendirectorypy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/appleopendirectory.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/appleopendirectory.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/appleopendirectory.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,1584 +0,0 @@
</span><del>-# -*- test-case-name: twistedcaldav.directory.test.test_opendirectory -*-
-##
-# Copyright (c) 2006-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.
-##
-
-&quot;&quot;&quot;
-Apple OpenDirectory directory service implementation.
-&quot;&quot;&quot;
-
-__all__ = [
-    &quot;OpenDirectoryService&quot;,
-    &quot;OpenDirectoryInitError&quot;,
-]
-
-import sys
-import time
-from uuid import UUID
-
-from twisted.internet.defer import succeed, inlineCallbacks, returnValue
-from twisted.cred.credentials import UsernamePassword
-from txweb2.auth.digest import DigestedCredentials
-from twext.python.log import Logger
-
-from twistedcaldav.directory.cachingdirectory import CachingDirectoryService, \
-    CachingDirectoryRecord
-from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord
-from twistedcaldav.directory.directory import DirectoryError, UnknownRecordTypeError
-from twistedcaldav.directory.util import splitIntoBatches
-from twistedcaldav.directory.principal import cuAddressConverter
-
-from calendarserver.platform.darwin.od import opendirectory, dsattributes, dsquery
-
-
-
-class OpenDirectoryService(CachingDirectoryService):
-    &quot;&quot;&quot;
-    OpenDirectory implementation of L{IDirectoryService}.
-    &quot;&quot;&quot;
-    log = Logger()
-
-    baseGUID = &quot;891F8321-ED02-424C-BA72-89C32F215C1E&quot;
-
-    def __repr__(self):
-        return &quot;&lt;%s %r: %r&gt;&quot; % (self.__class__.__name__, self.realmName, self.node)
-
-
-    def __init__(self, params, odModule=None):
-        &quot;&quot;&quot;
-        @param params: a dictionary containing the following keys:
-
-            - node: an OpenDirectory node name to bind to.
-
-            - restrictEnabledRecords: C{True} if a group in the directory is to
-              be used to determine which calendar users are enabled.
-
-            - restrictToGroup: C{str} guid or name of group used to restrict
-              enabled users.
-
-            - cacheTimeout: C{int} number of minutes before cache is
-              invalidated.
-
-            - negativeCache: C{False} cache the fact that a record wasn't found
-        &quot;&quot;&quot;
-        defaults = {
-            'node' : '/Search',
-            'restrictEnabledRecords' : False,
-            'restrictToGroup' : '',
-            'cacheTimeout' : 1, # Minutes
-            'batchSize' : 100, # for splitting up large queries
-            'negativeCaching' : False,
-            'recordTypes' : (
-                self.recordType_users,
-                self.recordType_groups,
-            ),
-            'augmentService' : None,
-            'groupMembershipCache' : None,
-        }
-        ignored = ('requireComputerRecord',)
-        params = self.getParams(params, defaults, ignored)
-
-        self._recordTypes = params['recordTypes']
-
-        super(OpenDirectoryService, self).__init__(params['cacheTimeout'],
-                                                   params['negativeCaching'])
-
-        if odModule is None:
-            odModule = opendirectory
-        self.odModule = odModule
-
-        try:
-            directory = self.odModule.odInit(params['node'])
-        except self.odModule.ODError, e:
-            self.log.error(&quot;OpenDirectory (node=%s) Initialization error: %s&quot; % (params['node'], e))
-            raise
-
-        self.augmentService = params['augmentService']
-        self.groupMembershipCache = params['groupMembershipCache']
-        self.realmName = params['node']
-        self.directory = directory
-        self.node = params['node']
-        self.restrictEnabledRecords = params['restrictEnabledRecords']
-        self.restrictToGroup = params['restrictToGroup']
-        self.batchSize = params['batchSize']
-        try:
-            UUID(self.restrictToGroup)
-        except:
-            self.restrictToGUID = False
-        else:
-            self.restrictToGUID = True
-        self.restrictedTimestamp = 0
-
-        # Set up the /Local/Default node if it's in the search path so we can
-        # send custom queries to it
-        self.localNode = None
-        try:
-            if self.node == &quot;/Search&quot;:
-                result = self.odModule.getNodeAttributes(self.directory, &quot;/Search&quot;,
-                    (dsattributes.kDS1AttrSearchPath,))
-                if &quot;/Local/Default&quot; in result[dsattributes.kDS1AttrSearchPath]:
-                    try:
-                        self.localNode = self.odModule.odInit(&quot;/Local/Default&quot;)
-                    except self.odModule.ODError, e:
-                        self.log.error(&quot;Failed to open /Local/Default): %s&quot; % (e,))
-        except AttributeError:
-            pass
-
-
-    @property
-    def restrictedGUIDs(self):
-        &quot;&quot;&quot;
-        Look up (and cache) the set of guids that are members of the
-        restrictToGroup.  If restrictToGroup is not set, return None to
-        indicate there are no group restrictions.
-        &quot;&quot;&quot;
-        if self.restrictEnabledRecords:
-            if time.time() - self.restrictedTimestamp &gt; self.cacheTimeout:
-                attributeToMatch = dsattributes.kDS1AttrGeneratedUID if self.restrictToGUID else dsattributes.kDSNAttrRecordName
-                valueToMatch = self.restrictToGroup
-                self.log.debug(&quot;Doing restricted group membership check&quot;)
-                self.log.debug(&quot;opendirectory.queryRecordsWithAttribute_list(%r,%r,%r,%r,%r,%r,%r)&quot; % (
-                    self.directory,
-                    attributeToMatch,
-                    valueToMatch,
-                    dsattributes.eDSExact,
-                    False,
-                    dsattributes.kDSStdRecordTypeGroups,
-                    [dsattributes.kDSNAttrGroupMembers, dsattributes.kDSNAttrNestedGroups, ],
-                ))
-                results = self.odModule.queryRecordsWithAttribute_list(
-                    self.directory,
-                    attributeToMatch,
-                    valueToMatch,
-                    dsattributes.eDSExact,
-                    False,
-                    dsattributes.kDSStdRecordTypeGroups,
-                    [dsattributes.kDSNAttrGroupMembers, dsattributes.kDSNAttrNestedGroups, ],
-                )
-
-                if len(results) == 1:
-                    members = results[0][1].get(dsattributes.kDSNAttrGroupMembers, [])
-                    nestedGroups = results[0][1].get(dsattributes.kDSNAttrNestedGroups, [])
-                else:
-                    members = []
-                    nestedGroups = []
-                self._cachedRestrictedGUIDs = set(self._expandGroupMembership(members, nestedGroups, returnGroups=True))
-                self.log.debug(&quot;Got %d restricted group members&quot; % (len(self._cachedRestrictedGUIDs),))
-                self.restrictedTimestamp = time.time()
-            return self._cachedRestrictedGUIDs
-        else:
-            # No restrictions
-            return None
-
-
-    def __cmp__(self, other):
-        if not isinstance(other, DirectoryRecord):
-            return super(DirectoryRecord, self).__eq__(other)
-
-        for attr in (&quot;directory&quot;, &quot;node&quot;):
-            diff = cmp(getattr(self, attr), getattr(other, attr))
-            if diff != 0:
-                return diff
-        return 0
-
-
-    def __hash__(self):
-        h = hash(self.__class__.__name__)
-        for attr in (&quot;node&quot;,):
-            h = (h + hash(getattr(self, attr))) &amp; sys.maxint
-        return h
-
-
-    def _expandGroupMembership(self, members, nestedGroups, processedGUIDs=None, returnGroups=False):
-
-        if processedGUIDs is None:
-            processedGUIDs = set()
-
-        if isinstance(members, str):
-            members = [members]
-
-        if isinstance(nestedGroups, str):
-            nestedGroups = [nestedGroups]
-
-        for memberGUID in members:
-            if memberGUID not in processedGUIDs:
-                processedGUIDs.add(memberGUID)
-                yield memberGUID
-
-        for groupGUID in nestedGroups:
-            if groupGUID in processedGUIDs:
-                continue
-
-            self.log.debug(&quot;opendirectory.queryRecordsWithAttribute_list(%r,%r,%r,%r,%r,%r,%r)&quot; % (
-                self.directory,
-                dsattributes.kDS1AttrGeneratedUID,
-                groupGUID,
-                dsattributes.eDSExact,
-                False,
-                dsattributes.kDSStdRecordTypeGroups,
-                [dsattributes.kDSNAttrGroupMembers, dsattributes.kDSNAttrNestedGroups]
-            ))
-            result = self.odModule.queryRecordsWithAttribute_list(
-                self.directory,
-                dsattributes.kDS1AttrGeneratedUID,
-                groupGUID,
-                dsattributes.eDSExact,
-                False,
-                dsattributes.kDSStdRecordTypeGroups,
-                [dsattributes.kDSNAttrGroupMembers, dsattributes.kDSNAttrNestedGroups]
-            )
-
-            if not result:
-                self.log.error(&quot;Couldn't find group %s when trying to expand nested groups.&quot;
-                             % (groupGUID,))
-                continue
-
-            group = result[0][1]
-
-            processedGUIDs.add(groupGUID)
-            if returnGroups:
-                yield groupGUID
-
-            for GUID in self._expandGroupMembership(
-                group.get(dsattributes.kDSNAttrGroupMembers, []),
-                group.get(dsattributes.kDSNAttrNestedGroups, []),
-                processedGUIDs,
-                returnGroups,
-            ):
-                yield GUID
-
-
-    def recordTypes(self):
-        return self._recordTypes
-
-
-    def listRecords(self, recordType):
-        &quot;&quot;&quot;
-        Retrieve all the records of recordType from the directory, but for
-        expediency don't index them or cache them locally, nor in memcached.
-        &quot;&quot;&quot;
-
-        records = []
-
-        attrs = [
-            dsattributes.kDS1AttrGeneratedUID,
-            dsattributes.kDSNAttrRecordName,
-            dsattributes.kDS1AttrDistinguishedName,
-        ]
-
-        if recordType == DirectoryService.recordType_users:
-            ODRecordType = self._toODRecordTypes[recordType]
-
-        elif recordType in (
-            DirectoryService.recordType_resources,
-            DirectoryService.recordType_locations,
-        ):
-            attrs.append(dsattributes.kDSNAttrResourceInfo)
-            ODRecordType = self._toODRecordTypes[recordType]
-
-        elif recordType == DirectoryService.recordType_groups:
-            attrs.append(dsattributes.kDSNAttrGroupMembers)
-            attrs.append(dsattributes.kDSNAttrNestedGroups)
-            ODRecordType = dsattributes.kDSStdRecordTypeGroups
-
-        self.log.debug(&quot;Querying OD for all %s records&quot; % (recordType,))
-        results = self.odModule.listAllRecordsWithAttributes_list(
-            self.directory, ODRecordType, attrs)
-        self.log.debug(&quot;Retrieved %d %s records&quot; % (len(results), recordType,))
-
-        for key, value in results:
-            recordGUID = value.get(dsattributes.kDS1AttrGeneratedUID)
-            if not recordGUID:
-                self.log.warn(&quot;Ignoring record missing GUID: %s %s&quot; %
-                    (key, value,))
-                continue
-
-            # Skip if group restriction is in place and guid is not
-            # a member (but don't skip any groups)
-            if (recordType != self.recordType_groups and
-                self.restrictedGUIDs is not None):
-                if str(recordGUID) not in self.restrictedGUIDs:
-                    continue
-
-            recordShortNames = self._uniqueTupleFromAttribute(
-                value.get(dsattributes.kDSNAttrRecordName))
-            recordFullName = value.get(
-                dsattributes.kDS1AttrDistinguishedName)
-
-            proxyGUIDs = ()
-            readOnlyProxyGUIDs = ()
-
-            if recordType in (
-                DirectoryService.recordType_resources,
-                DirectoryService.recordType_locations,
-            ):
-                resourceInfo = value.get(dsattributes.kDSNAttrResourceInfo)
-                if resourceInfo is not None:
-                    if type(resourceInfo) is not str:
-                        resourceInfo = resourceInfo[0]
-                    try:
-                        (
-                            _ignore_autoSchedule,
-                            proxy,
-                            readOnlyProxy
-                        ) = self.parseResourceInfo(
-                            resourceInfo,
-                            recordGUID,
-                            recordType,
-                            recordShortNames[0]
-                        )
-                    except ValueError:
-                        continue
-                    if proxy:
-                        proxyGUIDs = (proxy,)
-                    if readOnlyProxy:
-                        readOnlyProxyGUIDs = (readOnlyProxy,)
-
-            # Special case for groups, which have members.
-            if recordType == self.recordType_groups:
-                memberGUIDs = value.get(dsattributes.kDSNAttrGroupMembers)
-                if memberGUIDs is None:
-                    memberGUIDs = ()
-                elif type(memberGUIDs) is str:
-                    memberGUIDs = (memberGUIDs,)
-                nestedGUIDs = value.get(dsattributes.kDSNAttrNestedGroups)
-                if nestedGUIDs:
-                    if type(nestedGUIDs) is str:
-                        nestedGUIDs = (nestedGUIDs,)
-                    memberGUIDs += tuple(nestedGUIDs)
-                else:
-                    nestedGUIDs = ()
-            else:
-                memberGUIDs = ()
-                nestedGUIDs = ()
-
-            record = OpenDirectoryRecord(
-                service=self,
-                recordType=recordType,
-                guid=recordGUID,
-                nodeName=&quot;&quot;,
-                shortNames=recordShortNames,
-                authIDs=(),
-                fullName=recordFullName,
-                firstName=&quot;&quot;,
-                lastName=&quot;&quot;,
-                emailAddresses=&quot;&quot;,
-                memberGUIDs=memberGUIDs,
-                nestedGUIDs=nestedGUIDs,
-                extProxies=proxyGUIDs,
-                extReadOnlyProxies=readOnlyProxyGUIDs,
-            )
-
-            # (Copied from below)
-            # Look up augment information
-            # TODO: this needs to be deferred but for now we hard code
-            # the deferred result because we know it is completing
-            # immediately.
-            if self.augmentService is not None:
-                d = self.augmentService.getAugmentRecord(record.guid,
-                    recordType)
-                d.addCallback(lambda x: record.addAugmentInformation(x))
-            records.append(record)
-
-        self.log.debug(&quot;ListRecords returning %d %s records&quot; % (len(records),
-            recordType))
-
-        return records
-
-
-    def groupsForGUID(self, guid):
-
-        attrs = [
-            dsattributes.kDS1AttrGeneratedUID,
-        ]
-
-        recordType = dsattributes.kDSStdRecordTypeGroups
-
-        guids = set()
-
-        self.log.debug(&quot;Looking up which groups %s is a member of&quot; % (guid,))
-        try:
-            self.log.debug(&quot;opendirectory.queryRecordsWithAttribute_list(%r,%r,%r,%r,%r,%r,%r)&quot; % (
-                self.directory,
-                dsattributes.kDSNAttrGroupMembers,
-                guid,
-                dsattributes.eDSExact,
-                False,
-                recordType,
-                attrs,
-            ))
-            results = self.odModule.queryRecordsWithAttribute_list(
-                self.directory,
-                dsattributes.kDSNAttrGroupMembers,
-                guid,
-                dsattributes.eDSExact,
-                False,
-                recordType,
-                attrs,
-            )
-        except self.odModule.ODError, ex:
-            self.log.error(&quot;OpenDirectory (node=%s) error: %s&quot; % (self.realmName, str(ex)))
-            raise
-
-        for (_ignore_recordShortName, value) in results:
-
-            # Now get useful record info.
-            recordGUID = value.get(dsattributes.kDS1AttrGeneratedUID)
-            if recordGUID:
-                guids.add(recordGUID)
-
-        try:
-            self.log.debug(&quot;opendirectory.queryRecordsWithAttribute_list(%r,%r,%r,%r,%r,%r,%r)&quot; % (
-                self.directory,
-                dsattributes.kDSNAttrNestedGroups,
-                guid,
-                dsattributes.eDSExact,
-                False,
-                recordType,
-                attrs,
-            ))
-            results = self.odModule.queryRecordsWithAttribute_list(
-                self.directory,
-                dsattributes.kDSNAttrNestedGroups,
-                guid,
-                dsattributes.eDSExact,
-                False,
-                recordType,
-                attrs,
-            )
-        except self.odModule.ODError, ex:
-            self.log.error(&quot;OpenDirectory (node=%s) error: %s&quot; % (self.realmName, str(ex)))
-            raise
-
-        for (_ignore_recordShortName, value) in results:
-
-            # Now get useful record info.
-            recordGUID = value.get(dsattributes.kDS1AttrGeneratedUID)
-            if recordGUID:
-                guids.add(recordGUID)
-
-        self.log.debug(&quot;%s is a member of %d groups&quot; % (guid, len(guids)))
-
-        return guids
-
-    _ODFields = {
-        'fullName' : {
-            'odField' : dsattributes.kDS1AttrDistinguishedName,
-            'appliesTo' : set([
-                dsattributes.kDSStdRecordTypeUsers,
-                dsattributes.kDSStdRecordTypeGroups,
-                dsattributes.kDSStdRecordTypeResources,
-                dsattributes.kDSStdRecordTypePlaces,
-            ]),
-        },
-        'firstName' : {
-            'odField' : dsattributes.kDS1AttrFirstName,
-            'appliesTo' : set([
-                dsattributes.kDSStdRecordTypeUsers,
-            ]),
-        },
-        'lastName' : {
-            'odField' : dsattributes.kDS1AttrLastName,
-            'appliesTo' : set([
-                dsattributes.kDSStdRecordTypeUsers,
-            ]),
-        },
-        'emailAddresses' : {
-            'odField' : dsattributes.kDSNAttrEMailAddress,
-            'appliesTo' : set([
-                dsattributes.kDSStdRecordTypeUsers,
-                dsattributes.kDSStdRecordTypeGroups,
-            ]),
-        },
-        'recordName' : {
-            'odField' : dsattributes.kDSNAttrRecordName,
-            'appliesTo' : set([
-                dsattributes.kDSStdRecordTypeUsers,
-                dsattributes.kDSStdRecordTypeGroups,
-                dsattributes.kDSStdRecordTypeResources,
-                dsattributes.kDSStdRecordTypePlaces,
-            ]),
-        },
-        'guid' : {
-            'odField' : dsattributes.kDS1AttrGeneratedUID,
-            'appliesTo' : set([
-                dsattributes.kDSStdRecordTypeUsers,
-                dsattributes.kDSStdRecordTypeGroups,
-                dsattributes.kDSStdRecordTypeResources,
-                dsattributes.kDSStdRecordTypePlaces,
-            ]),
-        },
-    }
-
-    _toODRecordTypes = {
-        DirectoryService.recordType_users :
-            dsattributes.kDSStdRecordTypeUsers,
-        DirectoryService.recordType_groups :
-            dsattributes.kDSStdRecordTypeGroups,
-        DirectoryService.recordType_resources :
-            dsattributes.kDSStdRecordTypeResources,
-        DirectoryService.recordType_locations :
-            dsattributes.kDSStdRecordTypePlaces,
-    }
-
-    _fromODRecordTypes = dict([(b, a) for a, b in _toODRecordTypes.iteritems()])
-
-    def _uniqueTupleFromAttribute(self, attribute):
-        if attribute:
-            if isinstance(attribute, str):
-                return (attribute,)
-            else:
-                s = set()
-                return tuple([(s.add(x), x)[1] for x in attribute if x not in s])
-        else:
-            return ()
-
-
-    def _setFromAttribute(self, attribute, lower=False):
-        if attribute:
-            if isinstance(attribute, str):
-                return set((attribute.lower() if lower else attribute,))
-            else:
-                return set([item.lower() if lower else item for item in attribute])
-        else:
-            return ()
-
-
-    def recordsMatchingTokens(self, tokens, context=None, lookupMethod=None):
-        &quot;&quot;&quot;
-        @param tokens: The tokens to search on
-        @type tokens: C{list} of C{str} (utf-8 bytes)
-        @param context: An indication of what the end user is searching
-            for; &quot;attendee&quot;, &quot;location&quot;, or None
-        @type context: C{str}
-        @return: a deferred sequence of L{IDirectoryRecord}s which
-            match the given tokens and optional context.
-
-        Each token is searched for within each record's full name and
-        email address; if each token is found within a record that
-        record is returned in the results.
-
-        If context is None, all record types are considered.  If
-        context is &quot;location&quot;, only locations are considered.  If
-        context is &quot;attendee&quot;, only users, groups, and resources
-        are considered.
-        &quot;&quot;&quot;
-
-        if lookupMethod is None:
-            lookupMethod = self.odModule.queryRecordsWithAttributes_list
-
-        def collectResults(results):
-            self.log.debug(&quot;Got back %d records from OD&quot; % (len(results),))
-            for _ignore_key, value in results:
-                # self.log.debug(&quot;OD result: {key} {value}&quot;, key=key, value=value)
-                try:
-                    recordNodeName = value.get(
-                        dsattributes.kDSNAttrMetaNodeLocation)
-                    recordShortNames = self._uniqueTupleFromAttribute(
-                        value.get(dsattributes.kDSNAttrRecordName))
-
-                    recordGUID = value.get(dsattributes.kDS1AttrGeneratedUID)
-
-                    recordType = value.get(dsattributes.kDSNAttrRecordType)
-                    if isinstance(recordType, list):
-                        recordType = recordType[0]
-                    if not recordType:
-                        continue
-                    recordType = self._fromODRecordTypes[recordType]
-
-                    # Skip if group restriction is in place and guid is not
-                    # a member (but don't skip any groups)
-                    if (recordType != self.recordType_groups and
-                        self.restrictedGUIDs is not None):
-                        if str(recordGUID) not in self.restrictedGUIDs:
-                            continue
-
-                    recordAuthIDs = self._setFromAttribute(
-                        value.get(dsattributes.kDSNAttrAltSecurityIdentities))
-                    recordFullName = value.get(
-                        dsattributes.kDS1AttrDistinguishedName)
-                    recordFirstName = value.get(dsattributes.kDS1AttrFirstName)
-                    recordLastName = value.get(dsattributes.kDS1AttrLastName)
-                    recordEmailAddresses = self._setFromAttribute(
-                        value.get(dsattributes.kDSNAttrEMailAddress),
-                        lower=True)
-
-                    # Special case for groups, which have members.
-                    if recordType == self.recordType_groups:
-                        memberGUIDs = value.get(dsattributes.kDSNAttrGroupMembers)
-                        if memberGUIDs is None:
-                            memberGUIDs = ()
-                        elif type(memberGUIDs) is str:
-                            memberGUIDs = (memberGUIDs,)
-                        nestedGUIDs = value.get(dsattributes.kDSNAttrNestedGroups)
-                        if nestedGUIDs:
-                            if type(nestedGUIDs) is str:
-                                nestedGUIDs = (nestedGUIDs,)
-                            memberGUIDs += tuple(nestedGUIDs)
-                        else:
-                            nestedGUIDs = ()
-                    else:
-                        nestedGUIDs = ()
-                        memberGUIDs = ()
-
-                    # Create records but don't store them in our index or
-                    # send them to memcached, because these are transient,
-                    # existing only so we can create principal resource
-                    # objects that are used to generate the REPORT result.
-
-                    record = OpenDirectoryRecord(
-                        service=self,
-                        recordType=recordType,
-                        guid=recordGUID,
-                        nodeName=recordNodeName,
-                        shortNames=recordShortNames,
-                        authIDs=recordAuthIDs,
-                        fullName=recordFullName,
-                        firstName=recordFirstName,
-                        lastName=recordLastName,
-                        emailAddresses=recordEmailAddresses,
-                        memberGUIDs=memberGUIDs,
-                        nestedGUIDs=nestedGUIDs,
-                        extProxies=(),
-                        extReadOnlyProxies=(),
-                    )
-
-                    # (Copied from below)
-                    # Look up augment information
-                    # TODO: this needs to be deferred but for now we hard code
-                    # the deferred result because we know it is completing
-                    # immediately.
-                    if self.augmentService is not None:
-                        d = self.augmentService.getAugmentRecord(record.guid,
-                            recordType)
-                        d.addCallback(lambda x: record.addAugmentInformation(x))
-
-                    yield record
-
-                except KeyError:
-                    pass
-
-
-        def multiQuery(directory, queries, recordTypes, attrs):
-            byGUID = {}
-            sets = []
-
-            caseInsensitive = True
-            for compound in queries:
-                compound = compound.generate()
-
-                try:
-                    startTime = time.time()
-                    queryResults = lookupMethod(
-                        directory,
-                        compound,
-                        caseInsensitive,
-                        recordTypes,
-                        attrs,
-                    )
-                    totalTime = time.time() - startTime
-
-                    newSet = set()
-                    for recordName, data in queryResults:
-                        guid = data.get(dsattributes.kDS1AttrGeneratedUID, None)
-                        if guid:
-                            byGUID[guid] = (recordName, data)
-                            newSet.add(guid)
-
-                    self.log.debug(&quot;Attendee OD query: Types %s, Query %s, %.2f sec, %d results&quot; %
-                        (recordTypes, compound, totalTime, len(queryResults)))
-                    sets.append(newSet)
-
-                except self.odModule.ODError, e:
-                    self.log.error(&quot;Ignoring OD Error: %d %s&quot; %
-                        (e.message[1], e.message[0]))
-                    continue
-
-            results = []
-            for guid in set.intersection(*sets):
-                recordName, data = byGUID.get(guid, None)
-                if data is not None:
-                    results.append((data[dsattributes.kDSNAttrRecordName], data))
-            return results
-
-        localQueries = buildLocalQueriesFromTokens(tokens, self._ODFields)
-        nestedQuery = buildNestedQueryFromTokens(tokens, self._ODFields)
-
-        # Starting with the record types corresponding to the context...
-        recordTypes = self.recordTypesForSearchContext(context)
-        # ...limit to the types this service supports...
-        recordTypes = [r for r in recordTypes if r in self.recordTypes()]
-        # ...and map those to OD representations...
-        recordTypes = [self._toODRecordTypes[r] for r in recordTypes]
-
-        if recordTypes:
-            # Perform the complex/nested query.  If there was more than one
-            # token, this won't match anything in /Local, therefore we run
-            # the un-nested queries below and AND the results ourselves in
-            # multiQuery.
-            results = multiQuery(
-                self.directory,
-                [nestedQuery],
-                recordTypes,
-                [
-                    dsattributes.kDS1AttrGeneratedUID,
-                    dsattributes.kDSNAttrRecordName,
-                    dsattributes.kDSNAttrAltSecurityIdentities,
-                    dsattributes.kDSNAttrRecordType,
-                    dsattributes.kDS1AttrDistinguishedName,
-                    dsattributes.kDS1AttrFirstName,
-                    dsattributes.kDS1AttrLastName,
-                    dsattributes.kDSNAttrEMailAddress,
-                    dsattributes.kDSNAttrMetaNodeLocation,
-                    dsattributes.kDSNAttrGroupMembers,
-                    dsattributes.kDSNAttrNestedGroups,
-                ]
-            )
-            if self.localNode is not None and len(tokens) &gt; 1:
-                # /Local is in our search path and the complex query above
-                # would not have matched anything in /Local.  So now run
-                # the un-nested queries.
-                results.extend(
-                    multiQuery(
-                        self.localNode,
-                        localQueries,
-                        recordTypes,
-                        [
-                            dsattributes.kDS1AttrGeneratedUID,
-                            dsattributes.kDSNAttrRecordName,
-                            dsattributes.kDSNAttrAltSecurityIdentities,
-                            dsattributes.kDSNAttrRecordType,
-                            dsattributes.kDS1AttrDistinguishedName,
-                            dsattributes.kDS1AttrFirstName,
-                            dsattributes.kDS1AttrLastName,
-                            dsattributes.kDSNAttrEMailAddress,
-                            dsattributes.kDSNAttrMetaNodeLocation,
-                            dsattributes.kDSNAttrGroupMembers,
-                            dsattributes.kDSNAttrNestedGroups,
-                        ]
-                    )
-                )
-            return succeed(collectResults(results))
-        else:
-            return succeed([])
-
-
-    def recordsMatchingFields(self, fields, operand=&quot;or&quot;, recordType=None,
-        lookupMethod=None):
-
-        if lookupMethod is None:
-            lookupMethod = self.odModule.queryRecordsWithAttribute_list
-
-        # Note that OD applies case-sensitivity globally across the entire
-        # query, not per expression, so the current code uses whatever is
-        # specified in the last field in the fields list
-
-        def collectResults(results):
-            self.log.debug(&quot;Got back %d records from OD&quot; % (len(results),))
-            for _ignore_key, value in results:
-                # self.log.debug(&quot;OD result: {key} {value}&quot;, key=key, value=value)
-                try:
-                    recordNodeName = value.get(
-                        dsattributes.kDSNAttrMetaNodeLocation)
-                    recordShortNames = self._uniqueTupleFromAttribute(
-                        value.get(dsattributes.kDSNAttrRecordName))
-
-                    recordGUID = value.get(dsattributes.kDS1AttrGeneratedUID)
-
-                    recordType = value.get(dsattributes.kDSNAttrRecordType)
-                    if isinstance(recordType, list):
-                        recordType = recordType[0]
-                    if not recordType:
-                        continue
-                    recordType = self._fromODRecordTypes[recordType]
-
-                    # Skip if group restriction is in place and guid is not
-                    # a member (but don't skip any groups)
-                    if (recordType != self.recordType_groups and
-                        self.restrictedGUIDs is not None):
-                        if str(recordGUID) not in self.restrictedGUIDs:
-                            continue
-
-                    recordAuthIDs = self._setFromAttribute(
-                        value.get(dsattributes.kDSNAttrAltSecurityIdentities))
-                    recordFullName = value.get(
-                        dsattributes.kDS1AttrDistinguishedName)
-                    recordFirstName = value.get(dsattributes.kDS1AttrFirstName)
-                    recordLastName = value.get(dsattributes.kDS1AttrLastName)
-                    recordEmailAddresses = self._setFromAttribute(
-                        value.get(dsattributes.kDSNAttrEMailAddress),
-                        lower=True)
-
-                    # Special case for groups, which have members.
-                    if recordType == self.recordType_groups:
-                        memberGUIDs = value.get(dsattributes.kDSNAttrGroupMembers)
-                        if memberGUIDs is None:
-                            memberGUIDs = ()
-                        elif type(memberGUIDs) is str:
-                            memberGUIDs = (memberGUIDs,)
-                        nestedGUIDs = value.get(dsattributes.kDSNAttrNestedGroups)
-                        if nestedGUIDs:
-                            if type(nestedGUIDs) is str:
-                                nestedGUIDs = (nestedGUIDs,)
-                            memberGUIDs += tuple(nestedGUIDs)
-                        else:
-                            nestedGUIDs = ()
-                    else:
-                        nestedGUIDs = ()
-                        memberGUIDs = ()
-
-                    # Create records but don't store them in our index or
-                    # send them to memcached, because these are transient,
-                    # existing only so we can create principal resource
-                    # objects that are used to generate the REPORT result.
-
-                    record = OpenDirectoryRecord(
-                        service=self,
-                        recordType=recordType,
-                        guid=recordGUID,
-                        nodeName=recordNodeName,
-                        shortNames=recordShortNames,
-                        authIDs=recordAuthIDs,
-                        fullName=recordFullName,
-                        firstName=recordFirstName,
-                        lastName=recordLastName,
-                        emailAddresses=recordEmailAddresses,
-                        memberGUIDs=memberGUIDs,
-                        nestedGUIDs=nestedGUIDs,
-                        extProxies=(),
-                        extReadOnlyProxies=(),
-                    )
-
-                    # (Copied from below)
-                    # Look up augment information
-                    # TODO: this needs to be deferred but for now we hard code
-                    # the deferred result because we know it is completing
-                    # immediately.
-                    if self.augmentService is not None:
-                        d = self.augmentService.getAugmentRecord(record.guid,
-                            recordType)
-                        d.addCallback(lambda x: record.addAugmentInformation(x))
-
-                    yield record
-
-                except KeyError:
-                    pass
-
-
-        def multiQuery(directory, queries, attrs, operand):
-            byGUID = {}
-            sets = []
-
-            for query, recordTypes in queries.iteritems():
-                ODField, value, caseless, matchType = query
-                if matchType == &quot;starts-with&quot;:
-                    comparison = dsattributes.eDSStartsWith
-                elif matchType == &quot;contains&quot;:
-                    comparison = dsattributes.eDSContains
-                else:
-                    comparison = dsattributes.eDSExact
-
-                self.log.debug(&quot;Calling OD: Types %s, Field %s, Value %s, Match %s, Caseless %s&quot; %
-                    (recordTypes, ODField, value, matchType, caseless))
-
-                try:
-                    queryResults = lookupMethod(
-                        directory,
-                        ODField,
-                        value,
-                        comparison,
-                        caseless,
-                        recordTypes,
-                        attrs,
-                    )
-
-                    if operand == dsquery.expression.OR:
-                        for recordName, data in queryResults:
-                            guid = data.get(dsattributes.kDS1AttrGeneratedUID, None)
-                            if guid:
-                                byGUID[guid] = (recordName, data)
-                    else: # AND
-                        newSet = set()
-                        for recordName, data in queryResults:
-                            guid = data.get(dsattributes.kDS1AttrGeneratedUID, None)
-                            if guid:
-                                byGUID[guid] = (recordName, data)
-                                newSet.add(guid)
-
-                        sets.append(newSet)
-
-                except self.odModule.ODError, e:
-                    self.log.error(&quot;Ignoring OD Error: %d %s&quot; %
-                        (e.message[1], e.message[0]))
-                    continue
-
-            if operand == dsquery.expression.OR:
-                return byGUID.values()
-
-            else:
-                results = []
-                for guid in set.intersection(*sets):
-                    recordName, data = byGUID.get(guid, None)
-                    if data is not None:
-                        results.append((data[dsattributes.kDSNAttrRecordName], data))
-                return results
-
-        operand = (dsquery.expression.OR if operand == &quot;or&quot;
-            else dsquery.expression.AND)
-
-        if recordType is None:
-            # The client is looking for records in any of the four types
-            recordTypes = set(self._toODRecordTypes.values())
-        else:
-            # The client is after only one recordType
-            recordTypes = [self._toODRecordTypes[recordType]]
-
-        queries = buildQueries(recordTypes, fields, self._ODFields)
-
-        results = multiQuery(
-            self.directory,
-            queries,
-            [
-                dsattributes.kDS1AttrGeneratedUID,
-                dsattributes.kDSNAttrRecordName,
-                dsattributes.kDSNAttrAltSecurityIdentities,
-                dsattributes.kDSNAttrRecordType,
-                dsattributes.kDS1AttrDistinguishedName,
-                dsattributes.kDS1AttrFirstName,
-                dsattributes.kDS1AttrLastName,
-                dsattributes.kDSNAttrEMailAddress,
-                dsattributes.kDSNAttrMetaNodeLocation,
-                dsattributes.kDSNAttrGroupMembers,
-                dsattributes.kDSNAttrNestedGroups,
-            ],
-            operand
-        )
-        return succeed(collectResults(results))
-
-
-    def queryDirectory(self, recordTypes, indexType, indexKey,
-        lookupMethod=None):
-
-        if lookupMethod is None:
-            lookupMethod = self.odModule.queryRecordsWithAttribute_list
-
-        origIndexKey = indexKey
-        if indexType == self.INDEX_TYPE_CUA:
-            # The directory doesn't contain CUAs, so we need to convert
-            # the CUA to the appropriate field name and value:
-            queryattr, indexKey = cuAddressConverter(indexKey)
-            # queryattr will be one of:
-            # guid, emailAddresses, or recordName
-            # ...which will need to be mapped to DS
-            queryattr = self._ODFields[queryattr]['odField']
-
-        else:
-            queryattr = {
-                self.INDEX_TYPE_SHORTNAME : dsattributes.kDSNAttrRecordName,
-                self.INDEX_TYPE_GUID      : dsattributes.kDS1AttrGeneratedUID,
-                self.INDEX_TYPE_AUTHID    : dsattributes.kDSNAttrAltSecurityIdentities,
-            }.get(indexType)
-            assert queryattr is not None, &quot;Invalid type for record faulting query&quot;
-        # Make all OD queries case insensitive
-        caseInsensitive = True
-
-        results = []
-        for recordType in recordTypes:
-
-            attrs = [
-                dsattributes.kDS1AttrGeneratedUID,
-                dsattributes.kDSNAttrRecordName,
-                dsattributes.kDSNAttrAltSecurityIdentities,
-                dsattributes.kDSNAttrRecordType,
-                dsattributes.kDS1AttrDistinguishedName,
-                dsattributes.kDS1AttrFirstName,
-                dsattributes.kDS1AttrLastName,
-                dsattributes.kDSNAttrEMailAddress,
-                dsattributes.kDSNAttrMetaNodeLocation,
-            ]
-
-            if recordType == DirectoryService.recordType_users:
-                listRecordTypes = [self._toODRecordTypes[recordType]]
-
-            elif recordType in (
-                DirectoryService.recordType_resources,
-                DirectoryService.recordType_locations,
-            ):
-                if queryattr == dsattributes.kDSNAttrEMailAddress:
-                    continue
-
-                listRecordTypes = [self._toODRecordTypes[recordType]]
-
-            elif recordType == DirectoryService.recordType_groups:
-
-                if queryattr == dsattributes.kDSNAttrEMailAddress:
-                    continue
-
-                listRecordTypes = [dsattributes.kDSStdRecordTypeGroups]
-                attrs.append(dsattributes.kDSNAttrGroupMembers)
-                attrs.append(dsattributes.kDSNAttrNestedGroups)
-
-            else:
-                raise UnknownRecordTypeError(&quot;Unknown OpenDirectory record type: %s&quot; % (recordType))
-
-            # Because we're getting transient OD error -14987, try 3 times:
-            for _ignore in xrange(3):
-                try:
-                    self.log.debug(&quot;opendirectory.queryRecordsWithAttribute_list(%r,%r,%r,%r,%r,%r,%r)&quot; % (
-                        self.directory,
-                        queryattr,
-                        indexKey,
-                        dsattributes.eDSExact,
-                        caseInsensitive,
-                        listRecordTypes,
-                        attrs,
-                    ))
-                    lookedUp = lookupMethod(
-                            self.directory,
-                            queryattr,
-                            indexKey,
-                            dsattributes.eDSExact,
-                            caseInsensitive,
-                            listRecordTypes,
-                            attrs,
-                        )
-                    results.extend(lookedUp)
-
-                except self.odModule.ODError, ex:
-                    if ex.message[1] == -14987:
-                        # Fall through and retry
-                        self.log.error(&quot;OpenDirectory (node=%s) error: %s&quot; % (self.realmName, str(ex)))
-                    elif ex.message[1] == -14140 or ex.message[1] == -14200:
-                        # Unsupported attribute on record - don't fail
-                        return
-                    else:
-                        self.log.error(&quot;OpenDirectory (node=%s) error: %s&quot; % (self.realmName, str(ex)))
-                        raise
-                else:
-                    # Success, so break the retry loop
-                    break
-
-        self.log.debug(&quot;opendirectory.queryRecordsWithAttribute_list matched records: %s&quot; % (len(results),))
-
-        enabledRecords = []
-        disabledRecords = []
-
-        for (recordShortName, value) in results:
-
-            # Now get useful record info.
-            recordGUID = value.get(dsattributes.kDS1AttrGeneratedUID)
-            recordShortNames = self._uniqueTupleFromAttribute(value.get(dsattributes.kDSNAttrRecordName))
-            recordType = value.get(dsattributes.kDSNAttrRecordType)
-            if isinstance(recordType, list):
-                recordType = recordType[0]
-            recordAuthIDs = self._setFromAttribute(value.get(dsattributes.kDSNAttrAltSecurityIdentities))
-            recordFullName = value.get(dsattributes.kDS1AttrDistinguishedName)
-            recordFirstName = value.get(dsattributes.kDS1AttrFirstName)
-            recordLastName = value.get(dsattributes.kDS1AttrLastName)
-            recordEmailAddresses = self._setFromAttribute(value.get(dsattributes.kDSNAttrEMailAddress), lower=True)
-            recordNodeName = value.get(dsattributes.kDSNAttrMetaNodeLocation)
-
-            if not recordType:
-                self.log.debug(&quot;Record (unknown)%s in node %s has no recordType; ignoring.&quot;
-                               % (recordShortName, recordNodeName))
-                continue
-
-            recordType = self._fromODRecordTypes[recordType]
-
-            if not recordGUID:
-                self.log.debug(&quot;Record (%s)%s in node %s has no GUID; ignoring.&quot;
-                               % (recordType, recordShortName, recordNodeName))
-                continue
-
-            if recordGUID.lower().startswith(&quot;ffffeeee-dddd-cccc-bbbb-aaaa&quot;):
-                self.log.debug(&quot;Ignoring system record (%s)%s in node %s.&quot;
-                               % (recordType, recordShortName, recordNodeName))
-                continue
-
-            # If restrictToGroup is in effect, all guids which are not a member
-            # of that group are disabled (overriding the augments db).
-            if (self.restrictedGUIDs is not None):
-                unrestricted = recordGUID in self.restrictedGUIDs
-            else:
-                unrestricted = True
-
-            # Special case for groups, which have members.
-            if recordType == self.recordType_groups:
-                memberGUIDs = value.get(dsattributes.kDSNAttrGroupMembers)
-                if memberGUIDs is None:
-                    memberGUIDs = ()
-                elif type(memberGUIDs) is str:
-                    memberGUIDs = (memberGUIDs,)
-                nestedGUIDs = value.get(dsattributes.kDSNAttrNestedGroups)
-                if nestedGUIDs:
-                    if type(nestedGUIDs) is str:
-                        nestedGUIDs = (nestedGUIDs,)
-                    memberGUIDs += tuple(nestedGUIDs)
-                else:
-                    nestedGUIDs = ()
-            else:
-                memberGUIDs = ()
-                nestedGUIDs = ()
-
-            # Special case for resources and locations
-            autoSchedule = False
-            proxyGUIDs = ()
-            readOnlyProxyGUIDs = ()
-            if recordType in (DirectoryService.recordType_resources, DirectoryService.recordType_locations):
-                resourceInfo = value.get(dsattributes.kDSNAttrResourceInfo)
-                if resourceInfo is not None:
-                    if type(resourceInfo) is not str:
-                        resourceInfo = resourceInfo[0]
-                    try:
-                        autoSchedule, proxy, read_only_proxy = self.parseResourceInfo(resourceInfo, recordGUID, recordType, recordShortName)
-                    except ValueError:
-                        continue
-                    if proxy:
-                        proxyGUIDs = (proxy,)
-                    if read_only_proxy:
-                        readOnlyProxyGUIDs = (read_only_proxy,)
-
-            record = OpenDirectoryRecord(
-                service=self,
-                recordType=recordType,
-                guid=recordGUID,
-                nodeName=recordNodeName,
-                shortNames=recordShortNames,
-                authIDs=recordAuthIDs,
-                fullName=recordFullName,
-                firstName=recordFirstName,
-                lastName=recordLastName,
-                emailAddresses=recordEmailAddresses,
-                memberGUIDs=memberGUIDs,
-                nestedGUIDs=nestedGUIDs,
-                extProxies=proxyGUIDs,
-                extReadOnlyProxies=readOnlyProxyGUIDs,
-            )
-
-            # Look up augment information
-            # TODO: this needs to be deferred but for now we hard code the deferred result because
-            # we know it is completing immediately.
-            if self.augmentService is not None:
-                d = self.augmentService.getAugmentRecord(record.guid,
-                    recordType)
-                d.addCallback(lambda x: record.addAugmentInformation(x))
-
-            # Override based on ResourceInfo
-            if autoSchedule:
-                record.autoSchedule = True
-
-            if not unrestricted:
-                self.log.debug(&quot;%s is not enabled because it's not a member of group: %s&quot; % (recordGUID, self.restrictToGroup))
-                record.enabledForCalendaring = False
-                record.enabledForAddressBooks = False
-
-            record.applySACLs()
-
-            if record.enabledForCalendaring:
-                enabledRecords.append(record)
-            else:
-                disabledRecords.append(record)
-
-        record = None
-        if len(enabledRecords) == 1:
-            record = enabledRecords[0]
-        elif len(enabledRecords) == 0 and len(disabledRecords) == 1:
-            record = disabledRecords[0]
-        elif indexType == self.INDEX_TYPE_GUID and len(enabledRecords) &gt; 1:
-            self.log.error(&quot;Duplicate records found for GUID %s:&quot; % (indexKey,))
-            for duplicateRecord in enabledRecords:
-                self.log.error(&quot;Duplicate: %s&quot; % (&quot;, &quot;.join(duplicateRecord.shortNames)))
-
-        if record:
-            if isinstance(origIndexKey, unicode):
-                origIndexKey = origIndexKey.encode(&quot;utf-8&quot;)
-            self.log.debug(&quot;Storing (%s %s) %s in internal cache&quot; % (indexType, origIndexKey, record))
-
-            self.recordCacheForType(recordType).addRecord(record, indexType, origIndexKey)
-
-
-    def getResourceInfo(self):
-        &quot;&quot;&quot;
-        Resource information including proxy assignments for resource and
-        locations, as well as auto-schedule settings, used to live in the
-        directory.  This method fetches old resource info for migration
-        purposes.
-        &quot;&quot;&quot;
-        attrs = [
-            dsattributes.kDS1AttrGeneratedUID,
-            dsattributes.kDSNAttrResourceInfo,
-        ]
-
-        for recordType in (dsattributes.kDSStdRecordTypePlaces, dsattributes.kDSStdRecordTypeResources):
-            try:
-                self.log.debug(&quot;opendirectory.listAllRecordsWithAttributes_list(%r,%r,%r)&quot; % (
-                    self.directory,
-                    recordType,
-                    attrs,
-                ))
-                results = self.odModule.listAllRecordsWithAttributes_list(
-                    self.directory,
-                    recordType,
-                    attrs,
-                )
-            except self.odModule.ODError, ex:
-                self.log.error(&quot;OpenDirectory (node=%s) error: %s&quot; % (self.realmName, str(ex)))
-                raise
-
-            for (recordShortName, value) in results:
-                recordGUID = value.get(dsattributes.kDS1AttrGeneratedUID)
-                resourceInfo = value.get(dsattributes.kDSNAttrResourceInfo)
-                if resourceInfo is not None:
-                    if type(resourceInfo) is not str:
-                        resourceInfo = resourceInfo[0]
-                    try:
-                        autoSchedule, proxy, readOnlyProxy = self.parseResourceInfo(resourceInfo,
-                            recordGUID, recordType, recordShortName)
-                    except ValueError:
-                        continue
-                    yield recordGUID, autoSchedule, proxy, readOnlyProxy
-
-
-    def isAvailable(self):
-        &quot;&quot;&quot;
-        Returns True if all configured directory nodes are accessible, False otherwise
-        &quot;&quot;&quot;
-
-        if self.node == &quot;/Search&quot;:
-            result = self.odModule.getNodeAttributes(self.directory, &quot;/Search&quot;,
-                (dsattributes.kDS1AttrSearchPath,))
-            nodes = result[dsattributes.kDS1AttrSearchPath]
-        else:
-            nodes = [self.node]
-
-        try:
-            for node in nodes:
-                self.odModule.getNodeAttributes(self.directory, node, [dsattributes.kDSNAttrNodePath])
-        except self.odModule.ODError:
-            self.log.warn(&quot;OpenDirectory Node %s not available&quot; % (node,))
-            return False
-
-        return True
-
-
-    @inlineCallbacks
-    def getGroups(self, guids):
-        &quot;&quot;&quot;
-        Returns a set of group records for the list of guids passed in.  For
-        any group that also contains subgroups, those subgroups' records are
-        also returned, and so on.
-        &quot;&quot;&quot;
-
-        recordsByGUID = {}
-        valuesToFetch = guids
-
-        loop = 1
-        while valuesToFetch:
-            self.log.debug(&quot;getGroups loop %d&quot; % (loop,))
-
-            results = []
-
-            for batch in splitIntoBatches(valuesToFetch, self.batchSize):
-                fields = []
-                for value in batch:
-                    fields.append([&quot;guid&quot;, value, False, &quot;equals&quot;])
-                self.log.debug(&quot;getGroups fetching batch of %d&quot; %
-                    (len(fields),))
-                result = list((yield self.recordsMatchingFields(fields,
-                    recordType=self.recordType_groups)))
-                results.extend(result)
-                self.log.debug(&quot;getGroups got back batch of %d for subtotal of %d&quot; %
-                    (len(result), len(results)))
-
-            # Reset values for next iteration
-            valuesToFetch = set()
-
-            for record in results:
-                guid = record.guid
-                if guid not in recordsByGUID:
-                    recordsByGUID[guid] = record
-
-                # record.nestedGUIDs() contains the sub groups of this group
-                for memberGUID in record.nestedGUIDs():
-                    if memberGUID not in recordsByGUID:
-                        self.log.debug(&quot;getGroups group %s contains group %s&quot; %
-                            (record.guid, memberGUID))
-                        valuesToFetch.add(memberGUID)
-
-            loop += 1
-
-        returnValue(recordsByGUID.values())
-
-
-
-def buildQueries(recordTypes, fields, mapping):
-    &quot;&quot;&quot;
-    Determine how many queries need to be performed in order to work around opendirectory
-    quirks, where searching on fields that don't apply to a given recordType returns incorrect
-    results (either none, or all records).
-    &quot;&quot;&quot;
-
-    queries = {}
-    for recordType in recordTypes:
-        for field, value, caseless, matchType in fields:
-            if field in mapping:
-                if recordType in mapping[field]['appliesTo']:
-                    ODField = mapping[field]['odField']
-                    key = (ODField, value, caseless, matchType)
-                    queries.setdefault(key, []).append(recordType)
-
-    return queries
-
-
-
-def buildLocalQueriesFromTokens(tokens, mapping):
-    &quot;&quot;&quot;
-    OD /Local doesn't support nested complex queries, so create a list of
-    complex queries that will be ANDed together in recordsMatchingTokens()
-
-    @param tokens: The tokens to search on
-    @type tokens: C{list} of C{str}
-    @param mapping: The mapping of DirectoryRecord attributes to OD attributes
-    @type mapping: C{dict}
-    @return: A list of expression objects
-    @type: C{list}
-    &quot;&quot;&quot;
-
-    if len(tokens) == 0:
-        return None
-
-    fields = [
-        (&quot;fullName&quot;, dsattributes.eDSContains),
-        (&quot;emailAddresses&quot;, dsattributes.eDSStartsWith),
-    ]
-
-    results = []
-    for token in tokens:
-        queries = []
-        for field, comparison in fields:
-            ODField = mapping[field]['odField']
-            query = dsquery.match(ODField, token, comparison)
-            queries.append(query)
-        results.append(dsquery.expression(dsquery.expression.OR, queries))
-    return results
-
-
-
-def buildNestedQueryFromTokens(tokens, mapping):
-    &quot;&quot;&quot;
-    Build a DS query espression such that all the tokens must appear in either
-    the fullName (anywhere), emailAddresses (at the beginning) or record name
-    (at the beginning).
-
-    @param tokens: The tokens to search on
-    @type tokens: C{list} of C{str}
-    @param mapping: The mapping of DirectoryRecord attributes to OD attributes
-    @type mapping: C{dict}
-    @return: The nested expression object
-    @type: dsquery.expression
-    &quot;&quot;&quot;
-
-    if len(tokens) == 0:
-        return None
-
-    fields = [
-        (&quot;fullName&quot;, dsattributes.eDSContains),
-        (&quot;emailAddresses&quot;, dsattributes.eDSStartsWith),
-        (&quot;recordName&quot;, dsattributes.eDSStartsWith),
-    ]
-
-    outer = []
-    for token in tokens:
-        inner = []
-        for field, comparison in fields:
-            ODField = mapping[field]['odField']
-            query = dsquery.match(ODField, token, comparison)
-            inner.append(query)
-        outer.append(dsquery.expression(dsquery.expression.OR, inner))
-    return dsquery.expression(dsquery.expression.AND, outer)
-
-
-
-class OpenDirectoryRecord(CachingDirectoryRecord):
-    &quot;&quot;&quot;
-    OpenDirectory implementation of L{IDirectoryRecord}.
-    &quot;&quot;&quot;
-    def __init__(
-        self, service, recordType, guid, nodeName, shortNames, authIDs,
-        fullName, firstName, lastName, emailAddresses, memberGUIDs, nestedGUIDs,
-        extProxies, extReadOnlyProxies,
-    ):
-        super(OpenDirectoryRecord, self).__init__(
-            service=service,
-            recordType=recordType,
-            guid=guid,
-            shortNames=shortNames,
-            authIDs=authIDs,
-            fullName=fullName,
-            firstName=firstName,
-            lastName=lastName,
-            emailAddresses=emailAddresses,
-            extProxies=extProxies,
-            extReadOnlyProxies=extReadOnlyProxies,
-        )
-        self.nodeName = nodeName
-
-        self._memberGUIDs = tuple(memberGUIDs)
-        self._nestedGUIDs = tuple(nestedGUIDs)
-        self._groupMembershipGUIDs = None
-
-
-    def __repr__(self):
-        if self.service.realmName == self.nodeName:
-            location = self.nodeName
-        else:
-            location = &quot;%s-&gt;%s&quot; % (self.service.realmName, self.nodeName)
-
-        return &quot;&lt;%s[%s@%s(%s)] %s(%s) %r&gt;&quot; % (
-            self.__class__.__name__,
-            self.recordType,
-            self.service.guid,
-            location,
-            self.guid,
-            &quot;,&quot;.join(self.shortNames),
-            self.fullName
-        )
-
-
-    def members(self):
-        if self.recordType != self.service.recordType_groups:
-            return
-
-        for guid in self._memberGUIDs:
-            userRecord = self.service.recordWithGUID(guid)
-            if userRecord is not None:
-                yield userRecord
-
-
-    def groups(self):
-        if self._groupMembershipGUIDs is None:
-            self._groupMembershipGUIDs = self.service.groupsForGUID(self.guid)
-
-        for guid in self._groupMembershipGUIDs:
-            record = self.service.recordWithGUID(guid)
-            if record:
-                yield record
-
-
-    def memberGUIDs(self):
-        return set(self._memberGUIDs)
-
-
-    def nestedGUIDs(self):
-        return set(self._nestedGUIDs)
-
-
-    def verifyCredentials(self, credentials):
-        if isinstance(credentials, UsernamePassword):
-            # Check cached password
-            try:
-                if credentials.password == self.password:
-                    return True
-            except AttributeError:
-                pass
-
-            # Check with directory services
-            try:
-                if self.service.odModule.authenticateUserBasic(self.service.directory, self.nodeName, self.shortNames[0], credentials.password):
-                    # Cache the password to avoid future DS queries
-                    self.password = credentials.password
-                    return True
-            except self.service.odModule.ODError, e:
-                self.log.error(&quot;OpenDirectory (node=%s) error while performing basic authentication for user %s: %s&quot;
-                            % (self.service.realmName, self.shortNames[0], e))
-
-            return False
-
-        elif isinstance(credentials, DigestedCredentials):
-            #
-            # We need a special format for the &quot;challenge&quot; and &quot;response&quot; strings passed into OpenDirectory, as it is
-            # picky about exactly what it receives.
-            #
-            try:
-                if &quot;algorithm&quot; not in credentials.fields:
-                    credentials.fields[&quot;algorithm&quot;] = &quot;md5&quot;
-                challenge = 'Digest realm=&quot;%(realm)s&quot;, nonce=&quot;%(nonce)s&quot;, algorithm=%(algorithm)s' % credentials.fields
-                response = (
-                    'Digest username=&quot;%(username)s&quot;, '
-                    'realm=&quot;%(realm)s&quot;, '
-                    'nonce=&quot;%(nonce)s&quot;, '
-                    'uri=&quot;%(uri)s&quot;, '
-                    'response=&quot;%(response)s&quot;,'
-                    'algorithm=%(algorithm)s'
-                ) % credentials.fields
-            except KeyError, e:
-                self.log.error(
-                    &quot;OpenDirectory (node=%s) error while performing digest authentication for user %s: &quot;
-                    &quot;missing digest response field: %s in: %s&quot;
-                    % (self.service.realmName, self.shortNames[0], e, credentials.fields)
-                )
-                return False
-
-            try:
-                if self.digestcache[credentials.fields[&quot;uri&quot;]] == response:
-                    return True
-            except (AttributeError, KeyError):
-                pass
-
-            try:
-                if self.service.odModule.authenticateUserDigest(
-                    self.service.directory,
-                    self.nodeName,
-                    self.shortNames[0],
-                    challenge,
-                    response,
-                    credentials.method
-                ):
-                    try:
-                        cache = self.digestcache
-                    except AttributeError:
-                        cache = self.digestcache = {}
-
-                    cache[credentials.fields[&quot;uri&quot;]] = response
-
-                    return True
-                else:
-                    self.log.debug(
-&quot;&quot;&quot;OpenDirectory digest authentication failed with:
-    Nodename:  %s
-    Username:  %s
-    Challenge: %s
-    Response:  %s
-    Method:    %s
-&quot;&quot;&quot; % (self.nodeName, self.shortNames[0], challenge, response,
-       credentials.method))
-
-            except self.service.odModule.ODError, e:
-                self.log.error(
-                    &quot;OpenDirectory (node=%s) error while performing digest authentication for user %s: %s&quot;
-                    % (self.service.realmName, self.shortNames[0], e)
-                )
-                return False
-
-            return False
-
-        return super(OpenDirectoryRecord, self).verifyCredentials(credentials)
-
-
-
-class OpenDirectoryInitError(DirectoryError):
-    &quot;&quot;&quot;
-    OpenDirectory initialization error.
-    &quot;&quot;&quot;
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryaugmentpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/augment.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/augment.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/augment.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -46,6 +46,7 @@
</span><span class="cx">     &quot;automatic&quot;,
</span><span class="cx"> ))
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> class AugmentRecord(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Augmented directory record information
</span><span class="lines">@@ -75,13 +76,14 @@
</span><span class="cx">         self.clonedFromDefault = False
</span><span class="cx"> 
</span><span class="cx"> recordTypesMap = {
</span><del>-    &quot;users&quot; : &quot;User&quot;,
-    &quot;groups&quot; : &quot;Group&quot;,
-    &quot;locations&quot; : &quot;Location&quot;,
-    &quot;resources&quot; : &quot;Resource&quot;,
-    &quot;addresses&quot; : &quot;Address&quot;,
</del><ins>+    &quot;users&quot;: &quot;User&quot;,
+    &quot;groups&quot;: &quot;Group&quot;,
+    &quot;locations&quot;: &quot;Location&quot;,
+    &quot;resources&quot;: &quot;Resource&quot;,
+    &quot;addresses&quot;: &quot;Address&quot;,
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> class AugmentDB(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Abstract base class for an augment record database.
</span><span class="lines">@@ -128,7 +130,6 @@
</span><span class="cx"> 
</span><span class="cx">         @return: L{Deferred}
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-
</del><span class="cx">         recordType = recordTypesMap[recordType]
</span><span class="cx"> 
</span><span class="cx">         result = (yield self._lookupAugmentRecord(uid))
</span><span class="lines">@@ -266,9 +267,9 @@
</span><span class="cx">         self.xmlFiles = [fullServerPath(config.DataRoot, path) for path in xmlFiles]
</span><span class="cx">         self.xmlFileStats = {}
</span><span class="cx">         for path in self.xmlFiles:
</span><del>-            self.xmlFileStats[path] = (0, 0) # mtime, size
</del><ins>+            self.xmlFileStats[path] = (0, 0)  # mtime, size
</ins><span class="cx"> 
</span><del>-        self.statSeconds = statSeconds # Don't stat more often than this value
</del><ins>+        self.statSeconds = statSeconds  # Don't stat more often than this value
</ins><span class="cx">         self.lastCached = 0
</span><span class="cx">         self.db = {}
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorycachingdirectorypy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/cachingdirectory.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/cachingdirectory.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/cachingdirectory.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,473 +0,0 @@
</span><del>-# -*- test-case-name: twistedcaldav.directory.test.test_cachedirectory -*-
-##
-# Copyright (c) 2009-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.
-##
-
-&quot;&quot;&quot;
-Caching directory service implementation.
-&quot;&quot;&quot;
-
-__all__ = [
-    &quot;CachingDirectoryService&quot;,
-    &quot;CachingDirectoryRecord&quot;,
-    &quot;DictRecordTypeCache&quot;,
-]
-
-
-import time
-
-import base64
-
-from twext.python.log import Logger
-
-from twistedcaldav.config import config
-from twistedcaldav.memcacheclient import ClientFactory, MemcacheError
-from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord, DirectoryError, UnknownRecordTypeError
-from txdav.caldav.datastore.scheduling.cuaddress import normalizeCUAddr
-from twistedcaldav.directory.util import normalizeUUID
-
-
-class RecordTypeCache(object):
-    &quot;&quot;&quot;
-    Abstract class for a record type cache. We will likely have dict and memcache implementations of this.
-    &quot;&quot;&quot;
-
-    def __init__(self, directoryService, recordType):
-
-        self.directoryService = directoryService
-        self.recordType = recordType
-
-
-    def addRecord(self, record, indexType, indexKey, useMemcache=True,
-        neverExpire=False):
-        raise NotImplementedError()
-
-
-    def removeRecord(self, record):
-        raise NotImplementedError()
-
-
-    def findRecord(self, indexType, indexKey):
-        raise NotImplementedError()
-
-
-
-class DictRecordTypeCache(RecordTypeCache):
-    &quot;&quot;&quot;
-    Cache implementation using a dict, and uses memcached to share records
-    with other instances.
-    &quot;&quot;&quot;
-    log = Logger()
-
-    def __init__(self, directoryService, recordType):
-
-        super(DictRecordTypeCache, self).__init__(directoryService, recordType)
-        self.records = set()
-        self.recordsIndexedBy = {
-            CachingDirectoryService.INDEX_TYPE_GUID     : {},
-            CachingDirectoryService.INDEX_TYPE_SHORTNAME: {},
-            CachingDirectoryService.INDEX_TYPE_CUA    : {},
-            CachingDirectoryService.INDEX_TYPE_AUTHID   : {},
-        }
-        self.directoryService = directoryService
-        self.lastPurgedTime = time.time()
-
-
-    def addRecord(self, record, indexType, indexKey, useMemcache=True,
-        neverExpire=False):
-
-        useMemcache = useMemcache and config.Memcached.Pools.Default.ClientEnabled
-        if neverExpire:
-            record.neverExpire()
-
-        self.records.add(record)
-
-        # Also index/cache on guid
-        indexTypes = [(indexType, indexKey)]
-        if indexType != CachingDirectoryService.INDEX_TYPE_GUID:
-            indexTypes.append((CachingDirectoryService.INDEX_TYPE_GUID,
-                record.guid))
-
-        for indexType, indexKey in indexTypes:
-            self.recordsIndexedBy[indexType][indexKey] = record
-            if useMemcache:
-                key = self.directoryService.generateMemcacheKey(indexType, indexKey,
-                    record.recordType)
-                self.log.debug(&quot;Memcache: storing %s&quot; % (key,))
-                try:
-                    self.directoryService.memcacheSet(key, record)
-                except DirectoryMemcacheError:
-                    self.log.error(&quot;Memcache: failed to store %s&quot; % (key,))
-                    pass
-
-
-    def removeRecord(self, record):
-        if record in self.records:
-            self.records.remove(record)
-            self.log.debug(&quot;Removed record %s&quot; % (record.guid,))
-            for indexType in self.directoryService.indexTypes():
-                try:
-                    indexData = getattr(record, CachingDirectoryService.indexTypeToRecordAttribute[indexType])
-                except AttributeError:
-                    continue
-                if isinstance(indexData, basestring):
-                    indexData = [indexData]
-                for item in indexData:
-                    try:
-                        del self.recordsIndexedBy[indexType][item]
-                    except KeyError:
-                        pass
-
-
-    def findRecord(self, indexType, indexKey):
-        self.purgeExpiredRecords()
-        return self.recordsIndexedBy[indexType].get(indexKey)
-
-
-    def purgeExpiredRecords(self):
-        &quot;&quot;&quot;
-        Scan the cached records and remove any that have expired.
-        Does nothing if we've scanned within the past cacheTimeout seconds.
-        &quot;&quot;&quot;
-        if time.time() - self.lastPurgedTime &gt; self.directoryService.cacheTimeout:
-            for record in list(self.records):
-                if record.isExpired():
-                    self.removeRecord(record)
-            self.lastPurgedTime = time.time()
-
-
-
-class CachingDirectoryService(DirectoryService):
-    &quot;&quot;&quot;
-    Caching Directory implementation of L{IDirectoryService}.
-
-    This is class must be overridden to provide a concrete implementation.
-    &quot;&quot;&quot;
-    log = Logger()
-
-    INDEX_TYPE_GUID = &quot;guid&quot;
-    INDEX_TYPE_SHORTNAME = &quot;shortname&quot;
-    INDEX_TYPE_CUA = &quot;cua&quot;
-    INDEX_TYPE_AUTHID = &quot;authid&quot;
-
-    indexTypeToRecordAttribute = {
-        &quot;guid&quot;     : &quot;guid&quot;,
-        &quot;shortname&quot;: &quot;shortNames&quot;,
-        &quot;cua&quot;      : &quot;calendarUserAddresses&quot;,
-        &quot;authid&quot;   : &quot;authIDs&quot;,
-    }
-
-    def __init__(
-        self,
-        cacheTimeout=1,
-        negativeCaching=False,
-        cacheClass=DictRecordTypeCache,
-    ):
-        &quot;&quot;&quot;
-        @param cacheTimeout: C{int} number of minutes before cache is invalidated.
-        &quot;&quot;&quot;
-
-        self.cacheTimeout = cacheTimeout * 60
-        self.negativeCaching = negativeCaching
-
-        self.cacheClass = cacheClass
-        self._initCaches()
-
-        super(CachingDirectoryService, self).__init__()
-
-
-    def _getMemcacheClient(self, refresh=False):
-        if refresh or not hasattr(self, &quot;memcacheClient&quot;):
-            self.memcacheClient = ClientFactory.getClient(['%s:%s' %
-                (config.Memcached.Pools.Default.BindAddress, config.Memcached.Pools.Default.Port)],
-                debug=0, pickleProtocol=2)
-        return self.memcacheClient
-
-
-    def memcacheSet(self, key, record):
-
-        hideService = isinstance(record, DirectoryRecord)
-
-        try:
-            if hideService:
-                record.service = None # so we don't pickle service
-
-            key = base64.b64encode(key)
-            if not self._getMemcacheClient().set(key, record, time=self.cacheTimeout):
-                self.log.error(&quot;Could not write to memcache, retrying&quot;)
-                if not self._getMemcacheClient(refresh=True).set(
-                    key, record,
-                    time=self.cacheTimeout
-                ):
-                    self.log.error(&quot;Could not write to memcache again, giving up&quot;)
-                    del self.memcacheClient
-                    raise DirectoryMemcacheError(&quot;Failed to write to memcache&quot;)
-        finally:
-            if hideService:
-                record.service = self
-
-
-    def memcacheGet(self, key):
-
-        key = base64.b64encode(key)
-        try:
-            record = self._getMemcacheClient().get(key)
-            if record is not None and isinstance(record, DirectoryRecord):
-                record.service = self
-        except MemcacheError:
-            self.log.error(&quot;Could not read from memcache, retrying&quot;)
-            try:
-                record = self._getMemcacheClient(refresh=True).get(key)
-                if record is not None and isinstance(record, DirectoryRecord):
-                    record.service = self
-            except MemcacheError:
-                self.log.error(&quot;Could not read from memcache again, giving up&quot;)
-                del self.memcacheClient
-                raise DirectoryMemcacheError(&quot;Failed to read from memcache&quot;)
-        return record
-
-
-    def generateMemcacheKey(self, indexType, indexKey, recordType):
-        &quot;&quot;&quot;
-        Return a key that can be used to store/retrieve a record in memcache.
-        if short-name is the indexType the recordType be encoded into the key.
-
-        @param indexType: one of the indexTypes( ) values
-        @type indexType: C{str}
-        @param indexKey: the value being indexed
-        @type indexKey: C{str}
-        @param recordType: the type of record being cached
-        @type recordType: C{str}
-        @return: a memcache key comprised of the passed-in values and the directory
-            service's baseGUID
-        @rtype: C{str}
-        &quot;&quot;&quot;
-        keyVersion = 2
-        if indexType == CachingDirectoryService.INDEX_TYPE_SHORTNAME:
-            return &quot;dir|v%d|%s|%s|%s|%s&quot; % (keyVersion, self.baseGUID, recordType,
-                indexType, indexKey)
-        else:
-            return &quot;dir|v%d|%s|%s|%s&quot; % (keyVersion, self.baseGUID, indexType,
-                indexKey)
-
-
-    def _initCaches(self):
-        self._recordCaches = dict([
-            (recordType, self.cacheClass(self, recordType))
-            for recordType in self.recordTypes()
-        ])
-
-        self._disabledKeys = dict([(indexType, dict()) for indexType in self.indexTypes()])
-
-
-    def indexTypes(self):
-
-        return (
-            CachingDirectoryService.INDEX_TYPE_GUID,
-            CachingDirectoryService.INDEX_TYPE_SHORTNAME,
-            CachingDirectoryService.INDEX_TYPE_CUA,
-            CachingDirectoryService.INDEX_TYPE_AUTHID,
-        )
-
-
-    def recordCacheForType(self, recordType):
-        try:
-            return self._recordCaches[recordType]
-        except KeyError:
-            raise UnknownRecordTypeError(recordType)
-
-
-    def listRecords(self, recordType):
-        return self.recordCacheForType(recordType).records
-
-
-    def recordWithShortName(self, recordType, shortName):
-        return self._lookupRecord((recordType,), CachingDirectoryService.INDEX_TYPE_SHORTNAME, shortName)
-
-
-    def recordWithCalendarUserAddress(self, address):
-        address = normalizeCUAddr(address)
-        record = None
-        if address.startswith(&quot;mailto:&quot;):
-            record = self._lookupRecord(None, CachingDirectoryService.INDEX_TYPE_CUA, address)
-            return record if record and record.enabledForCalendaring else None
-        else:
-            return DirectoryService.recordWithCalendarUserAddress(self, address)
-
-
-    def recordWithAuthID(self, authID):
-        return self._lookupRecord(None, CachingDirectoryService.INDEX_TYPE_AUTHID, authID)
-
-
-    def recordWithGUID(self, guid):
-        guid = normalizeUUID(guid)
-        return self._lookupRecord(None, CachingDirectoryService.INDEX_TYPE_GUID, guid)
-
-    recordWithUID = recordWithGUID
-
-    def _lookupRecord(self, recordTypes, indexType, indexKey):
-
-        if recordTypes is None:
-            recordTypes = self.recordTypes()
-        else:
-            # Only use recordTypes this service supports:
-            supportedRecordTypes = self.recordTypes()
-            recordTypes = [t for t in recordTypes if t in supportedRecordTypes]
-            if not recordTypes:
-                return None
-
-        def lookup():
-            for recordType in recordTypes:
-                record = self.recordCacheForType(recordType).findRecord(indexType, indexKey)
-
-                if record:
-                    if record.isExpired():
-                        self.recordCacheForType(recordType).removeRecord(record)
-                        return None
-                    else:
-                        return record
-            else:
-                return None
-
-        record = lookup()
-        if record:
-            return record
-
-        if self.negativeCaching:
-
-            # Check negative cache (take cache entry timeout into account)
-            try:
-                disabledTime = self._disabledKeys[indexType][indexKey]
-                if time.time() - disabledTime &lt; self.cacheTimeout:
-                    return None
-            except KeyError:
-                pass
-
-        # Check memcache
-        if config.Memcached.Pools.Default.ClientEnabled:
-
-            # The only time the recordType arg matters is when indexType is
-            # short-name, and in that case recordTypes will contain exactly
-            # one recordType, so using recordTypes[0] here is always safe:
-            key = self.generateMemcacheKey(indexType, indexKey, recordTypes[0])
-
-            self.log.debug(&quot;Memcache: checking %s&quot; % (key,))
-
-            try:
-                record = self.memcacheGet(key)
-            except DirectoryMemcacheError:
-                self.log.error(&quot;Memcache: failed to get %s&quot; % (key,))
-                record = None
-
-            if record is None:
-                self.log.debug(&quot;Memcache: miss %s&quot; % (key,))
-            else:
-                self.log.debug(&quot;Memcache: hit %s&quot; % (key,))
-                self.recordCacheForType(record.recordType).addRecord(record, indexType, indexKey, useMemcache=False)
-                return record
-
-            if self.negativeCaching:
-
-                # Check negative memcache
-                try:
-                    val = self.memcacheGet(&quot;-%s&quot; % (key,))
-                except DirectoryMemcacheError:
-                    self.log.error(&quot;Memcache: failed to get -%s&quot; % (key,))
-                    val = None
-                if val == 1:
-                    self.log.debug(&quot;Memcache: negative %s&quot; % (key,))
-                    self._disabledKeys[indexType][indexKey] = time.time()
-                    return None
-
-        # Try query
-        self.log.debug(&quot;Faulting record for attribute '%s' with value '%s'&quot; % (indexType, indexKey,))
-        self.queryDirectory(recordTypes, indexType, indexKey)
-
-        # Now try again from cache
-        record = lookup()
-        if record:
-            self.log.debug(&quot;Found record for attribute '%s' with value '%s'&quot; % (indexType, indexKey,))
-            return record
-
-        if self.negativeCaching:
-
-            # Add to negative cache with timestamp
-            self.log.debug(&quot;Failed to fault record for attribute '%s' with value '%s'&quot; % (indexType, indexKey,))
-            self._disabledKeys[indexType][indexKey] = time.time()
-
-            if config.Memcached.Pools.Default.ClientEnabled:
-                self.log.debug(&quot;Memcache: storing (negative) %s&quot; % (key,))
-                try:
-                    self.memcacheSet(&quot;-%s&quot; % (key,), 1)
-                except DirectoryMemcacheError:
-                    self.log.error(&quot;Memcache: failed to set -%s&quot; % (key,))
-                    pass
-
-        return None
-
-
-    def queryDirectory(self, recordTypes, indexType, indexKey):
-        raise NotImplementedError()
-
-
-
-class CachingDirectoryRecord(DirectoryRecord):
-
-    def __init__(
-        self, service, recordType, guid,
-        shortNames=(), authIDs=set(),
-        fullName=None, firstName=None, lastName=None, emailAddresses=set(),
-        uid=None, **kwargs
-    ):
-        super(CachingDirectoryRecord, self).__init__(
-            service,
-            recordType,
-            guid,
-            shortNames=shortNames,
-            authIDs=authIDs,
-            fullName=fullName,
-            firstName=firstName,
-            lastName=lastName,
-            emailAddresses=emailAddresses,
-            uid=uid,
-            **kwargs
-        )
-
-        self.cachedTime = time.time()
-
-
-    def neverExpire(self):
-        self.cachedTime = 0
-
-
-    def isExpired(self):
-        &quot;&quot;&quot;
-        Returns True if this record was created more than cacheTimeout
-        seconds ago
-        &quot;&quot;&quot;
-        if (
-            self.cachedTime != 0 and
-            time.time() - self.cachedTime &gt; self.service.cacheTimeout
-        ):
-            return True
-        else:
-            return False
-
-
-
-class DirectoryMemcacheError(DirectoryError):
-    &quot;&quot;&quot;
-    Error communicating with memcached.
-    &quot;&quot;&quot;
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorycalendarpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendar.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendar.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendar.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -35,7 +35,6 @@
</span><span class="cx"> from twisted.internet.defer import succeed, inlineCallbacks, returnValue
</span><span class="cx"> 
</span><span class="cx"> from twistedcaldav.config import config
</span><del>-from twistedcaldav.directory.idirectory import IDirectoryService
</del><span class="cx"> from twistedcaldav.directory.common import uidsResourceName, \
</span><span class="cx">     CommonUIDProvisioningResource, CommonHomeTypeProvisioningResource
</span><span class="cx"> 
</span><span class="lines">@@ -48,7 +47,10 @@
</span><span class="cx"> 
</span><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> # FIXME: copied from resource.py to avoid circular dependency
</span><ins>+
+
</ins><span class="cx"> class CalDAVComplianceMixIn(object):
</span><span class="cx">     def davComplianceClasses(self):
</span><span class="cx">         return (
</span><span class="lines">@@ -65,7 +67,7 @@
</span><span class="cx">     DAVResource,
</span><span class="cx"> ):
</span><span class="cx">     def defaultAccessControlList(self):
</span><del>-        return config.ProvisioningResourceACL
</del><ins>+        return succeed(config.ProvisioningResourceACL)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def etag(self):
</span><span class="lines">@@ -91,7 +93,8 @@
</span><span class="cx"> 
</span><span class="cx">         super(DirectoryCalendarHomeProvisioningResource, self).__init__()
</span><span class="cx"> 
</span><del>-        self.directory = IDirectoryService(directory)
</del><ins>+        # MOVE2WHO
+        self.directory = directory  # IDirectoryService(directory)
</ins><span class="cx">         self._url = url
</span><span class="cx">         self._newStore = store
</span><span class="cx"> 
</span><span class="lines">@@ -101,8 +104,14 @@
</span><span class="cx">         #
</span><span class="cx">         # Create children
</span><span class="cx">         #
</span><del>-        for recordType in self.directory.recordTypes():
-            self.putChild(recordType, DirectoryCalendarHomeTypeProvisioningResource(self, recordType))
</del><ins>+        # ...just &quot;users&quot; though.  If we iterate all of the directory's
+        # recordTypes, we also get the proxy sub principal types.
+        for recordTypeName in [
+            self.directory.recordTypeToOldName(r) for r in [
+                self.directory.recordType.user
+            ]
+        ]:
+            self.putChild(recordTypeName, DirectoryCalendarHomeTypeProvisioningResource(self, recordTypeName, r))
</ins><span class="cx"> 
</span><span class="cx">         self.putChild(uidsResourceName, DirectoryCalendarHomeUIDProvisioningResource(self))
</span><span class="cx"> 
</span><span class="lines">@@ -112,7 +121,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def listChildren(self):
</span><del>-        return self.directory.recordTypes()
</del><ins>+        return [self.directory.recordTypeToOldName(r) for r in self.directory.recordTypes()]
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def principalCollections(self):
</span><span class="lines">@@ -127,12 +136,13 @@
</span><span class="cx">         return self.directory.principalCollection.principalForRecord(record)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def homeForDirectoryRecord(self, record, request):
</span><del>-        uidResource = self.getChild(uidsResourceName)
</del><ins>+        uidResource = yield self.getChild(uidsResourceName)
</ins><span class="cx">         if uidResource is None:
</span><del>-            return None
</del><ins>+            returnValue(None)
</ins><span class="cx">         else:
</span><del>-            return uidResource.homeResourceForRecord(record, request)
</del><ins>+            returnValue((yield uidResource.homeResourceForRecord(record, request)))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     ##
</span><span class="lines">@@ -149,42 +159,43 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class DirectoryCalendarHomeTypeProvisioningResource(
</span><del>-        CommonHomeTypeProvisioningResource,
-        DirectoryCalendarProvisioningResource
-    ):
</del><ins>+    CommonHomeTypeProvisioningResource,
+    DirectoryCalendarProvisioningResource
+):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Resource which provisions calendar home collections of a specific
</span><span class="cx">     record type as needed.
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    def __init__(self, parent, recordType):
</del><ins>+    def __init__(self, parent, name, recordType):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         @param parent: the parent of this resource
</span><span class="cx">         @param recordType: the directory record type to provision.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         assert parent is not None
</span><ins>+        assert name is not None
</ins><span class="cx">         assert recordType is not None
</span><span class="cx"> 
</span><span class="cx">         super(DirectoryCalendarHomeTypeProvisioningResource, self).__init__()
</span><span class="cx"> 
</span><span class="cx">         self.directory = parent.directory
</span><ins>+        self.name = name
</ins><span class="cx">         self.recordType = recordType
</span><span class="cx">         self._parent = parent
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def url(self):
</span><del>-        return joinURL(self._parent.url(), self.recordType)
</del><ins>+        return joinURL(self._parent.url(), self.name)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def listChildren(self):
</span><span class="cx">         if config.EnablePrincipalListings:
</span><del>-
-            def _recordShortnameExpand():
-                for record in self.directory.listRecords(self.recordType):
-                    if record.enabledForCalendaring:
-                        for shortName in record.shortNames:
-                            yield shortName
-
-            return _recordShortnameExpand()
</del><ins>+            children = []
+            for record in (yield self.directory.listRecords(self.recordType)):
+                if record.enabledForCalendaring:
+                    for shortName in record.shortNames:
+                        children.append(shortName)
+            returnValue(children)
</ins><span class="cx">         else:
</span><span class="cx">             # Not a listable collection
</span><span class="cx">             raise HTTPError(responsecode.FORBIDDEN)
</span><span class="lines">@@ -203,7 +214,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def displayName(self):
</span><del>-        return self.recordType
</del><ins>+        return self.name
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     ##
</span><span class="lines">@@ -220,9 +231,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class DirectoryCalendarHomeUIDProvisioningResource (
</span><del>-        CommonUIDProvisioningResource,
-        DirectoryCalendarProvisioningResource
-    ):
</del><ins>+    CommonUIDProvisioningResource,
+    DirectoryCalendarProvisioningResource
+):
</ins><span class="cx"> 
</span><span class="cx">     homeResourceTypeName = 'calendars'
</span><span class="cx"> 
</span><span class="lines">@@ -258,7 +269,7 @@
</span><span class="cx">             else:
</span><span class="cx">                 # ...otherwise permissions are fixed, and are not subject to
</span><span class="cx">                 # inheritance rules, etc.
</span><del>-                return succeed(self.defaultAccessControlList())
</del><ins>+                return self.defaultAccessControlList()
</ins><span class="cx"> 
</span><span class="cx">         d = getWikiACL(self, request)
</span><span class="cx">         d.addCallback(gotACL)
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorycalendaruserproxypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendaruserproxy.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendaruserproxy.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/calendaruserproxy.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -29,37 +29,41 @@
</span><span class="cx"> 
</span><span class="cx"> import itertools
</span><span class="cx"> import time
</span><ins>+import uuid
</ins><span class="cx"> 
</span><ins>+from twext.python.log import Logger
+from twext.who.idirectory import RecordType as BaseRecordType
</ins><span class="cx"> from twisted.internet.defer import succeed, inlineCallbacks, returnValue
</span><del>-from txweb2 import responsecode
-from txweb2.http import HTTPError, StatusResponse
-from txdav.xml import element as davxml
-from txdav.xml.base import dav_namespace
-from txweb2.dav.util import joinURL
-from txweb2.dav.noneprops import NonePropertyStore
</del><ins>+from twisted.python.modules import getModule
+from twisted.web.template import XMLFile, Element, renderer
+from twistedcaldav.config import config, fullServerPath
+from twistedcaldav.database import (
+    AbstractADBAPIDatabase, ADBAPISqliteMixin, ADBAPIPostgreSQLMixin
+)
+from twistedcaldav.directory.util import normalizeUUID
+from twistedcaldav.directory.util import (
+    formatLink, formatLinks, formatPrincipals
+)
</ins><span class="cx"> 
</span><del>-from twext.python.log import Logger
-
-from twisted.web.template import XMLFile, Element, renderer
-from twisted.python.modules import getModule
</del><ins>+from twistedcaldav.extensions import (
+    DAVPrincipalResource, DAVResourceWithChildrenMixin
+)
</ins><span class="cx"> from twistedcaldav.extensions import DirectoryElement
</span><del>-from twistedcaldav.directory.principal import formatLink
-from twistedcaldav.directory.principal import formatLinks
-from twistedcaldav.directory.principal import formatPrincipals
-
-from twistedcaldav.directory.util import normalizeUUID
-from twistedcaldav.config import config, fullServerPath
-from twistedcaldav.database import AbstractADBAPIDatabase, ADBAPISqliteMixin, \
-    ADBAPIPostgreSQLMixin
-from twistedcaldav.extensions import DAVPrincipalResource, \
-    DAVResourceWithChildrenMixin
</del><span class="cx"> from twistedcaldav.extensions import ReadOnlyWritePropertiesResourceMixIn
</span><span class="cx"> from twistedcaldav.memcacher import Memcacher
</span><span class="cx"> from twistedcaldav.resource import CalDAVComplianceMixIn
</span><ins>+from txdav.who.delegates import RecordType as DelegateRecordType
+from txdav.xml import element as davxml
+from txdav.xml.base import dav_namespace
+from txweb2 import responsecode
+from txweb2.dav.noneprops import NonePropertyStore
+from txweb2.dav.util import joinURL
+from txweb2.http import HTTPError, StatusResponse
</ins><span class="cx"> 
</span><span class="cx"> thisModule = getModule(__name__)
</span><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> class PermissionsMixIn (ReadOnlyWritePropertiesResourceMixIn):
</span><span class="cx">     def defaultAccessControlList(self):
</span><span class="cx">         aces = (
</span><span class="lines">@@ -86,13 +90,13 @@
</span><span class="cx">             for principal in config.AdminPrincipals
</span><span class="cx">         ))
</span><span class="cx"> 
</span><del>-        return davxml.ACL(*aces)
</del><ins>+        return succeed(davxml.ACL(*aces))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def accessControlList(self, request, inheritance=True, expanding=False,
</span><span class="cx">                           inherited_aces=None):
</span><span class="cx">         # Permissions here are fixed, and are not subject to inheritance rules, etc.
</span><del>-        return succeed(self.defaultAccessControlList())
</del><ins>+        return self.defaultAccessControlList()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -119,13 +123,20 @@
</span><span class="cx">         record = self.resource.parent.record
</span><span class="cx">         resource = self.resource
</span><span class="cx">         parent = self.resource.parent
</span><ins>+        try:
+            if isinstance(record.guid, uuid.UUID):
+                guid = str(record.guid).upper()
+            else:
+                guid = record.guid
+        except AttributeError:
+            guid = &quot;&quot;
</ins><span class="cx">         return tag.fillSlots(
</span><span class="cx">             directoryGUID=record.service.guid,
</span><span class="cx">             realm=record.service.realmName,
</span><del>-            guid=record.guid,
-            recordType=record.recordType,
</del><ins>+            guid=guid,
+            recordType=record.service.recordTypeToOldName(record.recordType),
</ins><span class="cx">             shortNames=record.shortNames,
</span><del>-            fullName=record.fullName,
</del><ins>+            fullName=record.displayName,
</ins><span class="cx">             principalUID=parent.principalUID(),
</span><span class="cx">             principalURL=formatLink(parent.principalURL()),
</span><span class="cx">             proxyPrincipalUID=resource.principalUID(),
</span><span class="lines">@@ -209,9 +220,13 @@
</span><span class="cx"> 
</span><span class="cx">     def resourceType(self):
</span><span class="cx">         if self.proxyType == &quot;calendar-proxy-read&quot;:
</span><del>-            return davxml.ResourceType.calendarproxyread #@UndefinedVariable
</del><ins>+            return davxml.ResourceType.calendarproxyread  # @UndefinedVariable
</ins><span class="cx">         elif self.proxyType == &quot;calendar-proxy-write&quot;:
</span><del>-            return davxml.ResourceType.calendarproxywrite #@UndefinedVariable
</del><ins>+            return davxml.ResourceType.calendarproxywrite  # @UndefinedVariable
+        elif self.proxyType == &quot;calendar-proxy-read-for&quot;:
+            return davxml.ResourceType.calendarproxyreadfor  # @UndefinedVariable
+        elif self.proxyType == &quot;calendar-proxy-write-for&quot;:
+            return davxml.ResourceType.calendarproxywritefor  # @UndefinedVariable
</ins><span class="cx">         else:
</span><span class="cx">             return super(CalendarUserProxyPrincipalResource, self).resourceType()
</span><span class="cx"> 
</span><span class="lines">@@ -270,7 +285,7 @@
</span><span class="cx">         principals = []
</span><span class="cx">         newUIDs = set()
</span><span class="cx">         for uri in members:
</span><del>-            principal = self.pcollection._principalForURI(uri)
</del><ins>+            principal = yield self.pcollection._principalForURI(uri)
</ins><span class="cx">             # Invalid principals MUST result in an error.
</span><span class="cx">             if principal is None or principal.principalURL() != uri:
</span><span class="cx">                 raise HTTPError(StatusResponse(
</span><span class="lines">@@ -282,7 +297,9 @@
</span><span class="cx">             newUIDs.add(principal.principalUID())
</span><span class="cx"> 
</span><span class="cx">         # Get the old set of UIDs
</span><del>-        oldUIDs = (yield self._index().getMembers(self.uid))
</del><ins>+        # oldUIDs = (yield self._index().getMembers(self.uid))
+        oldPrincipals = yield self.groupMembers()
+        oldUIDs = [p.principalUID() for p in oldPrincipals]
</ins><span class="cx"> 
</span><span class="cx">         # Change membership
</span><span class="cx">         yield self.setGroupMemberSetPrincipals(principals)
</span><span class="lines">@@ -293,19 +310,24 @@
</span><span class="cx"> 
</span><span class="cx">         changedUIDs = newUIDs.symmetric_difference(oldUIDs)
</span><span class="cx">         for uid in changedUIDs:
</span><del>-            principal = self.pcollection.principalForUID(uid)
</del><ins>+            principal = yield self.pcollection.principalForUID(uid)
</ins><span class="cx">             if principal:
</span><span class="cx">                 yield principal.cacheNotifier.changed()
</span><span class="cx"> 
</span><span class="cx">         returnValue(True)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def setGroupMemberSetPrincipals(self, principals):
</span><del>-        # Map the principals to UIDs.
-        return self._index().setGroupMembers(
-            self.uid,
-            [p.principalUID() for p in principals],
</del><ins>+
+        # Find our pseudo-record
+        record = yield self.parent.record.service.recordWithShortName(
+            self._recordTypeFromProxyType(),
+            self.parent.principalUID()
</ins><span class="cx">         )
</span><ins>+        # Set the members
+        memberRecords = [p.record for p in principals]
+        yield record.setMembers(memberRecords)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     ##
</span><span class="lines">@@ -349,7 +371,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def _expandMemberUIDs(self, uid=None, relatives=None, uids=None, infinity=False):
</del><ins>+    def _expandMemberPrincipals(self, uid=None, relatives=None, uids=None, infinity=False):
</ins><span class="cx">         if uid is None:
</span><span class="cx">             uid = self.principalUID()
</span><span class="cx">         if relatives is None:
</span><span class="lines">@@ -360,14 +382,14 @@
</span><span class="cx">         if uid not in uids:
</span><span class="cx">             from twistedcaldav.directory.principal import DirectoryPrincipalResource
</span><span class="cx">             uids.add(uid)
</span><del>-            principal = self.pcollection.principalForUID(uid)
</del><ins>+            principal = yield self.pcollection.principalForUID(uid)
</ins><span class="cx">             if isinstance(principal, CalendarUserProxyPrincipalResource):
</span><span class="cx">                 members = yield self._directGroupMembers()
</span><span class="cx">                 for member in members:
</span><span class="cx">                     if member.principalUID() not in uids:
</span><span class="cx">                         relatives.add(member)
</span><span class="cx">                         if infinity:
</span><del>-                            yield self._expandMemberUIDs(member.principalUID(), relatives, uids, infinity=infinity)
</del><ins>+                            yield self._expandMemberPrincipals(member.principalUID(), relatives, uids, infinity=infinity)
</ins><span class="cx">             elif isinstance(principal, DirectoryPrincipalResource):
</span><span class="cx">                 if infinity:
</span><span class="cx">                     members = yield principal.expandedGroupMembers()
</span><span class="lines">@@ -378,30 +400,45 @@
</span><span class="cx">         returnValue(relatives)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def _recordTypeFromProxyType(self):
+        return {
+            &quot;calendar-proxy-read&quot;: DelegateRecordType.readDelegateGroup,
+            &quot;calendar-proxy-write&quot;: DelegateRecordType.writeDelegateGroup,
+            &quot;calendar-proxy-read-for&quot;: DelegateRecordType.readDelegatorGroup,
+            &quot;calendar-proxy-write-for&quot;: DelegateRecordType.writeDelegatorGroup,
+        }.get(self.proxyType)
+
+
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def _directGroupMembers(self):
</span><del>-        # Get member UIDs from database and map to principal resources
-        members = yield self._index().getMembers(self.uid)
-        found = []
-        for uid in members:
-            p = self.pcollection.principalForUID(uid)
-            if p:
-                # Only principals enabledForLogin can be a delegate
-                # (and groups as well)
-                if (p.record.enabledForLogin or
-                    p.record.recordType == p.record.service.recordType_groups):
-                    found.append(p)
-                # Make sure any outstanding deletion timer entries for
-                # existing principals are removed
-                yield self._index().refreshPrincipal(uid)
-            else:
-                self.log.warn(&quot;Delegate is missing from directory: %s&quot; % (uid,))
</del><ins>+        &quot;&quot;&quot;
+        Fault in the record representing the sub principal for this proxy type
+        (either read-only or read-write), then fault in the direct members of
+        that record.
+        &quot;&quot;&quot;
+        memberPrincipals = []
+        record = yield self.parent.record.service.recordWithShortName(
+            self._recordTypeFromProxyType(),
+            self.parent.principalUID()
+        )
+        if record is not None:
+            memberRecords = yield record.members()
+            for record in memberRecords:
+                if record is not None:
+                    principal = yield self.pcollection.principalForRecord(
+                        record
+                    )
+                    if principal is not None:
+                        if (
+                            principal.record.loginAllowed or
+                            principal.record.recordType is BaseRecordType.group
+                        ):
+                            memberPrincipals.append(principal)
+        returnValue(memberPrincipals)
</ins><span class="cx"> 
</span><del>-        returnValue(found)
</del><span class="cx"> 
</span><del>-
</del><span class="cx">     def groupMembers(self):
</span><del>-        return self._expandMemberUIDs()
</del><ins>+        return self._expandMemberPrincipals()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -410,18 +447,12 @@
</span><span class="cx">         Return the complete, flattened set of principals belonging to this
</span><span class="cx">         group.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        returnValue((yield self._expandMemberUIDs(infinity=True)))
</del><ins>+        returnValue((yield self._expandMemberPrincipals(infinity=True)))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def groupMemberships(self):
</span><del>-        # Get membership UIDs and map to principal resources
-        d = self._index().getMemberships(self.uid)
-        d.addCallback(lambda memberships: [
-            p for p
-            in [self.pcollection.principalForUID(uid) for uid in memberships]
-            if p
-        ])
-        return d
</del><ins>+        # Unlikely to ever want to put a subprincipal into a group
+        return succeed([])
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -437,7 +468,7 @@
</span><span class="cx">         @return: True if principal is a proxy (of the correct type) of our parent
</span><span class="cx">         @rtype: C{boolean}
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        readWrite = self.isProxyType(True) # is read-write
</del><ins>+        readWrite = self.isProxyType(True)  # is read-write
</ins><span class="cx">         if principal and self.parent in (yield principal.proxyFor(readWrite)):
</span><span class="cx">             returnValue(True)
</span><span class="cx">         returnValue(False)
</span><span class="lines">@@ -630,7 +661,7 @@
</span><span class="cx"> 
</span><span class="cx">             overdue = yield self._memcacher.checkDeletionTimer(principalUID)
</span><span class="cx"> 
</span><del>-            if overdue == False:
</del><ins>+            if overdue is False:
</ins><span class="cx">                 # Do nothing
</span><span class="cx">                 returnValue(None)
</span><span class="cx"> 
</span><span class="lines">@@ -855,9 +886,9 @@
</span><span class="cx">         )
</span><span class="cx">         if alreadyDone is None:
</span><span class="cx">             for (groupname, member) in (
</span><del>-                    (yield self._db_all_values_for_sql(
-                        &quot;select GROUPNAME, MEMBER from GROUPS&quot;))
-                ):
</del><ins>+                (yield self._db_all_values_for_sql(
+                    &quot;select GROUPNAME, MEMBER from GROUPS&quot;))
+            ):
</ins><span class="cx">                 grouplist = groupname.split(&quot;#&quot;)
</span><span class="cx">                 grouplist[0] = normalizeUUID(grouplist[0])
</span><span class="cx">                 newGroupName = &quot;#&quot;.join(grouplist)
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorycommonpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/common.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/common.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/common.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -68,13 +68,14 @@
</span><span class="cx">         name = record.uid
</span><span class="cx"> 
</span><span class="cx">         if record is None:
</span><del>-            log.debug(&quot;No directory record with GUID %r&quot; % (name,))
</del><ins>+            log.debug(&quot;No directory record with UID %r&quot; % (name,))
</ins><span class="cx">             returnValue(None)
</span><span class="cx"> 
</span><del>-        if not getattr(record, self.enabledAttribute):
-            log.debug(&quot;Directory record %r is not enabled for %s&quot; % (
-                record, self.homeResourceTypeName))
-            returnValue(None)
</del><ins>+        # MOVE2WHO
+        # if not getattr(record, self.enabledAttribute):
+        #     log.debug(&quot;Directory record %r is not enabled for %s&quot; % (
+        #         record, self.homeResourceTypeName))
+        #     returnValue(None)
</ins><span class="cx"> 
</span><span class="cx">         assert len(name) &gt; 4, &quot;Directory record has an invalid GUID: %r&quot; % (
</span><span class="cx">             name,)
</span><span class="lines">@@ -94,7 +95,7 @@
</span><span class="cx">         if name == &quot;&quot;:
</span><span class="cx">             returnValue((self, ()))
</span><span class="cx"> 
</span><del>-        record = self.directory.recordWithUID(name)
</del><ins>+        record = yield self.directory.recordWithUID(name)
</ins><span class="cx">         if record:
</span><span class="cx">             child = yield self.homeResourceForRecord(record, request)
</span><span class="cx">             returnValue((child, segments[1:]))
</span><span class="lines">@@ -149,7 +150,7 @@
</span><span class="cx">         if name == &quot;&quot;:
</span><span class="cx">             returnValue((self, segments[1:]))
</span><span class="cx"> 
</span><del>-        record = self.directory.recordWithShortName(self.recordType, name)
</del><ins>+        record = yield self.directory.recordWithShortName(self.recordType, name)
</ins><span class="cx">         if record is None:
</span><span class="cx">             returnValue(
</span><span class="cx">                 (NotFoundResource(principalCollections=self._parent.principalCollections()), [])
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorydirectoryprincipalresourcehtml"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/directory-principal-resource.html (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/directory-principal-resource.html        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/directory-principal-resource.html        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -11,10 +11,7 @@
</span><span class="cx"> GUID: &lt;t:slot name=&quot;principalGUID&quot;/&gt;
</span><span class="cx"> Record type: &lt;t:slot name=&quot;recordType&quot;/&gt;
</span><span class="cx"> Short names: &lt;t:slot name=&quot;shortNames&quot;/&gt;
</span><del>-Security Identities: &lt;t:slot name=&quot;securityIDs&quot;/&gt;
</del><span class="cx"> Full name: &lt;t:slot name=&quot;fullName&quot;/&gt;
</span><del>-First name: &lt;t:slot name=&quot;firstName&quot;/&gt;
-Last name: &lt;t:slot name=&quot;lastName&quot;/&gt;
</del><span class="cx"> Email addresses:
</span><span class="cx"> &lt;t:slot name=&quot;emailAddresses&quot; /&gt;Principal UID: &lt;t:slot name=&quot;principalUID&quot;/&gt;
</span><span class="cx"> Principal URL: &lt;t:slot name=&quot;principalURL&quot;/&gt;
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorydirectorypy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/directory.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/directory.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/directory.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,1509 +0,0 @@
</span><del>-# -*- test-case-name: twistedcaldav.directory.test -*-
-##
-# Copyright (c) 2006-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.
-##
-
-
-&quot;&quot;&quot;
-Generic directory service classes.
-&quot;&quot;&quot;
-
-__all__ = [
-    &quot;DirectoryService&quot;,
-    &quot;DirectoryRecord&quot;,
-    &quot;DirectoryError&quot;,
-    &quot;DirectoryConfigurationError&quot;,
-    &quot;UnknownRecordTypeError&quot;,
-    &quot;GroupMembershipCacheUpdater&quot;,
-]
-
-from plistlib import readPlistFromString
-
-from twext.python.log import Logger
-from txweb2.dav.auth import IPrincipalCredentials
-from txweb2.dav.util import joinURL
-
-from twisted.cred.checkers import ICredentialsChecker
-from twisted.cred.error import UnauthorizedLogin
-from twisted.internet.defer import succeed, inlineCallbacks, returnValue
-from twisted.python.filepath import FilePath
-
-from twistedcaldav.config import config
-from twistedcaldav.directory.idirectory import IDirectoryService, IDirectoryRecord
-from twistedcaldav.directory.util import uuidFromName, normalizeUUID
-from twistedcaldav.memcacher import Memcacher
-from txdav.caldav.datastore.scheduling.cuaddress import normalizeCUAddr
-from txdav.caldav.datastore.scheduling.ischedule.localservers import Servers
-
-from txdav.caldav.icalendardirectoryservice import ICalendarStoreDirectoryService, \
-    ICalendarStoreDirectoryRecord
-
-from xml.parsers.expat import ExpatError
-
-from zope.interface import implements
-
-import cPickle as pickle
-import datetime
-import grp
-import itertools
-import os
-import pwd
-import sys
-import types
-from urllib import unquote
-
-log = Logger()
-
-
-class DirectoryService(object):
-    implements(IDirectoryService, ICalendarStoreDirectoryService, ICredentialsChecker)
-
-    log = Logger()
-
-    ##
-    # IDirectoryService
-    ##
-
-    realmName = None
-
-    recordType_users = &quot;users&quot;
-    recordType_people = &quot;people&quot;
-    recordType_groups = &quot;groups&quot;
-    recordType_locations = &quot;locations&quot;
-    recordType_resources = &quot;resources&quot;
-    recordType_addresses = &quot;addresses&quot;
-
-    searchContext_location = &quot;location&quot;
-    searchContext_resource = &quot;resource&quot;
-    searchContext_user = &quot;user&quot;
-    searchContext_group = &quot;group&quot;
-    searchContext_attendee = &quot;attendee&quot;
-
-    aggregateService = None
-
-    def _generatedGUID(self):
-        if not hasattr(self, &quot;_guid&quot;):
-            realmName = self.realmName
-
-            assert self.baseGUID, &quot;Class %s must provide a baseGUID attribute&quot; % (self.__class__.__name__,)
-
-            if realmName is None:
-                self.log.error(&quot;Directory service %s has no realm name or GUID; generated service GUID will not be unique.&quot; % (self,))
-                realmName = &quot;&quot;
-            else:
-                self.log.info(&quot;Directory service %s has no GUID; generating service GUID from realm name.&quot; % (self,))
-
-            self._guid = uuidFromName(self.baseGUID, realmName)
-
-        return self._guid
-
-    baseGUID = None
-    guid = property(_generatedGUID)
-
-    # Needed by twistedcaldav.directorybackedaddressbook
-    liveQuery = False
-
-    def setRealm(self, realmName):
-        self.realmName = realmName
-
-
-    def available(self):
-        &quot;&quot;&quot;
-        By default, the directory is available.  This may return a boolean or a
-        Deferred which fires a boolean.
-
-        A return value of &quot;False&quot; means that the directory is currently
-        unavailable due to the service starting up.
-        &quot;&quot;&quot;
-        return True
-    # end directorybackedaddressbook requirements
-
-    ##
-    # ICredentialsChecker
-    ##
-
-    # For ICredentialsChecker
-    credentialInterfaces = (IPrincipalCredentials,)
-
-    def requestAvatarId(self, credentials):
-        credentials = IPrincipalCredentials(credentials)
-
-        # FIXME: ?
-        # We were checking if principal is enabled; seems unnecessary in current
-        # implementation because you shouldn't have a principal object for a
-        # disabled directory principal.
-
-        if credentials.authnPrincipal is None:
-            raise UnauthorizedLogin(&quot;No such user: %s&quot; % (credentials.credentials.username,))
-
-        # See if record is enabledForLogin
-        if not credentials.authnPrincipal.record.isLoginEnabled():
-            raise UnauthorizedLogin(&quot;User not allowed to log in: %s&quot; %
-                (credentials.credentials.username,))
-
-        # Handle Kerberos as a separate behavior
-        try:
-            from twistedcaldav.authkerb import NegotiateCredentials
-        except ImportError:
-            NegotiateCredentials = None
-
-        if NegotiateCredentials and isinstance(credentials.credentials,
-                                               NegotiateCredentials):
-            # If we get here with Kerberos, then authentication has already succeeded
-            return (
-                credentials.authnPrincipal.principalURL(),
-                credentials.authzPrincipal.principalURL(),
-                credentials.authnPrincipal,
-                credentials.authzPrincipal,
-            )
-        else:
-            if credentials.authnPrincipal.record.verifyCredentials(credentials.credentials):
-                return (
-                    credentials.authnPrincipal.principalURL(),
-                    credentials.authzPrincipal.principalURL(),
-                    credentials.authnPrincipal,
-                    credentials.authzPrincipal,
-                )
-            else:
-                raise UnauthorizedLogin(&quot;Incorrect credentials for %s&quot; % (credentials.credentials.username,))
-
-
-    def recordTypes(self):
-        raise NotImplementedError(&quot;Subclass must implement recordTypes()&quot;)
-
-
-    def listRecords(self, recordType):
-        raise NotImplementedError(&quot;Subclass must implement listRecords()&quot;)
-
-
-    def recordWithShortName(self, recordType, shortName):
-        for record in self.listRecords(recordType):
-            if shortName in record.shortNames:
-                return record
-        return None
-
-
-    def recordWithUID(self, uid):
-        uid = normalizeUUID(uid)
-        for record in self.allRecords():
-            if record.uid == uid:
-                return record
-        return None
-
-
-    def recordWithGUID(self, guid):
-        guid = normalizeUUID(guid)
-        for record in self.allRecords():
-            if record.guid == guid:
-                return record
-        return None
-
-
-    def recordWithAuthID(self, authID):
-        for record in self.allRecords():
-            if authID in record.authIDs:
-                return record
-        return None
-
-
-    def recordWithCalendarUserAddress(self, address):
-        address = normalizeCUAddr(address)
-        record = None
-        if address.startswith(&quot;urn:uuid:&quot;):
-            guid = address[9:]
-            record = self.recordWithGUID(guid)
-        elif address.startswith(&quot;mailto:&quot;):
-            for record in self.allRecords():
-                if address[7:] in record.emailAddresses:
-                    break
-            else:
-                return None
-        elif address.startswith(&quot;/principals/&quot;):
-            parts = map(unquote, address.split(&quot;/&quot;))
-            if len(parts) == 4:
-                if parts[2] == &quot;__uids__&quot;:
-                    guid = parts[3]
-                    record = self.recordWithGUID(guid)
-                else:
-                    record = self.recordWithShortName(parts[2], parts[3])
-
-        return record if record and record.enabledForCalendaring else None
-
-
-    def recordWithCachedGroupsAlias(self, recordType, alias):
-        &quot;&quot;&quot;
-        @param recordType: the type of the record to look up.
-        @param alias: the cached-groups alias of the record to look up.
-        @type alias: C{str}
-
-        @return: a deferred L{IDirectoryRecord} with the given cached-groups
-            alias, or C{None} if no such record is found.
-        &quot;&quot;&quot;
-        # The default implementation uses guid
-        return succeed(self.recordWithGUID(alias))
-
-
-    def allRecords(self):
-        for recordType in self.recordTypes():
-            for record in self.listRecords(recordType):
-                yield record
-
-
-    def recordsMatchingFieldsWithCUType(self, fields, operand=&quot;or&quot;,
-        cuType=None):
-        if cuType:
-            recordType = DirectoryRecord.fromCUType(cuType)
-        else:
-            recordType = None
-
-        return self.recordsMatchingFields(fields, operand=operand,
-            recordType=recordType)
-
-
-    def recordTypesForSearchContext(self, context):
-        &quot;&quot;&quot;
-        Map calendarserver-principal-search REPORT context value to applicable record types
-
-        @param context: The context value to map
-        @type context: C{str}
-        @returns: The list of record types the context maps to
-        @rtype: C{list} of C{str}
-        &quot;&quot;&quot;
-        if context == self.searchContext_location:
-            recordTypes = [self.recordType_locations]
-        elif context == self.searchContext_resource:
-            recordTypes = [self.recordType_resources]
-        elif context == self.searchContext_user:
-            recordTypes = [self.recordType_users]
-        elif context == self.searchContext_group:
-            recordTypes = [self.recordType_groups]
-        elif context == self.searchContext_attendee:
-            recordTypes = [self.recordType_users, self.recordType_groups,
-                self.recordType_resources]
-        else:
-            recordTypes = list(self.recordTypes())
-        return recordTypes
-
-
-    def recordsMatchingTokens(self, tokens, context=None):
-        &quot;&quot;&quot;
-        @param tokens: The tokens to search on
-        @type tokens: C{list} of C{str} (utf-8 bytes)
-        @param context: An indication of what the end user is searching
-            for; &quot;attendee&quot;, &quot;location&quot;, or None
-        @type context: C{str}
-        @return: a deferred sequence of L{IDirectoryRecord}s which
-            match the given tokens and optional context.
-
-        Each token is searched for within each record's full name and
-        email address; if each token is found within a record that
-        record is returned in the results.
-
-        If context is None, all record types are considered.  If
-        context is &quot;location&quot;, only locations are considered.  If
-        context is &quot;attendee&quot;, only users, groups, and resources
-        are considered.
-        &quot;&quot;&quot;
-
-        # Default, bruteforce method; override with one optimized for each
-        # service
-
-        def fieldMatches(fieldValue, value):
-            if fieldValue is None:
-                return False
-            elif type(fieldValue) in types.StringTypes:
-                fieldValue = (fieldValue,)
-
-            for testValue in fieldValue:
-                testValue = testValue.lower()
-                value = value.lower()
-
-                try:
-                    testValue.index(value)
-                    return True
-                except ValueError:
-                    pass
-
-            return False
-
-        def recordMatches(record):
-            for token in tokens:
-                for fieldName in [&quot;fullName&quot;, &quot;emailAddresses&quot;]:
-                    try:
-                        fieldValue = getattr(record, fieldName)
-                        if fieldMatches(fieldValue, token):
-                            break
-                    except AttributeError:
-                        # No value
-                        pass
-                else:
-                    return False
-            return True
-
-
-        def yieldMatches(recordTypes):
-            try:
-                for recordType in [r for r in recordTypes if r in self.recordTypes()]:
-                    for record in self.listRecords(recordType):
-                        if recordMatches(record):
-                            yield record
-
-            except UnknownRecordTypeError:
-                # Skip this service since it doesn't understand this record type
-                pass
-
-        recordTypes = self.recordTypesForSearchContext(context)
-        return succeed(yieldMatches(recordTypes))
-
-
-    def recordsMatchingFields(self, fields, operand=&quot;or&quot;, recordType=None):
-        # Default, bruteforce method; override with one optimized for each
-        # service
-
-        def fieldMatches(fieldValue, value, caseless, matchType):
-            if fieldValue is None:
-                return False
-            elif type(fieldValue) in types.StringTypes:
-                fieldValue = (fieldValue,)
-
-            for testValue in fieldValue:
-                if caseless:
-                    testValue = testValue.lower()
-                    value = value.lower()
-
-                if matchType == 'starts-with':
-                    if testValue.startswith(value):
-                        return True
-                elif matchType == 'contains':
-                    try:
-                        testValue.index(value)
-                        return True
-                    except ValueError:
-                        pass
-                else: # exact
-                    if testValue == value:
-                        return True
-
-            return False
-
-        def recordMatches(record):
-            if operand == &quot;and&quot;:
-                for fieldName, value, caseless, matchType in fields:
-                    try:
-                        fieldValue = getattr(record, fieldName)
-                        if not fieldMatches(fieldValue, value, caseless,
-                            matchType):
-                            return False
-                    except AttributeError:
-                        # No property =&gt; no match
-                        return False
-                # we hit on every property
-                return True
-            else: # &quot;or&quot;
-                for fieldName, value, caseless, matchType in fields:
-                    try:
-                        fieldValue = getattr(record, fieldName)
-                        if fieldMatches(fieldValue, value, caseless,
-                            matchType):
-                            return True
-                    except AttributeError:
-                        # No value
-                        pass
-                # we didn't hit any
-                return False
-
-        def yieldMatches(recordType):
-            try:
-                if recordType is None:
-                    recordTypes = list(self.recordTypes())
-                else:
-                    recordTypes = (recordType,)
-
-                for recordType in recordTypes:
-                    for record in self.listRecords(recordType):
-                        if recordMatches(record):
-                            yield record
-
-            except UnknownRecordTypeError:
-                # Skip this service since it doesn't understand this record type
-                pass
-
-        return succeed(yieldMatches(recordType))
-
-
-    def getGroups(self, guids):
-        &quot;&quot;&quot;
-        This implementation returns all groups, not just the ones specified
-        by guids
-        &quot;&quot;&quot;
-        return succeed(self.listRecords(self.recordType_groups))
-
-
-    def getResourceInfo(self):
-        return ()
-
-
-    def isAvailable(self):
-        return True
-
-
-    def getParams(self, params, defaults, ignore=None):
-        &quot;&quot;&quot; Checks configuration parameters for unexpected/ignored keys, and
-            applies default values. &quot;&quot;&quot;
-
-        keys = set(params.keys())
-
-        result = {}
-        for key in defaults.iterkeys():
-            if key in params:
-                result[key] = params[key]
-                keys.remove(key)
-            else:
-                result[key] = defaults[key]
-
-        if ignore:
-            for key in ignore:
-                if key in params:
-                    self.log.warn(&quot;Ignoring obsolete directory service parameter: %s&quot; % (key,))
-                    keys.remove(key)
-
-        if keys:
-            raise DirectoryConfigurationError(&quot;Invalid directory service parameter(s): %s&quot; % (&quot;, &quot;.join(list(keys)),))
-        return result
-
-
-    def parseResourceInfo(self, plist, guid, recordType, shortname):
-        &quot;&quot;&quot;
-        Parse ResourceInfo plist and extract information that the server needs.
-
-        @param plist: the plist that is the attribute value.
-        @type plist: str
-        @param guid: the directory GUID of the record being parsed.
-        @type guid: str
-        @param shortname: the record shortname of the record being parsed.
-        @type shortname: str
-        @return: a C{tuple} of C{bool} for auto-accept, C{str} for proxy GUID, C{str} for read-only proxy GUID.
-        &quot;&quot;&quot;
-        try:
-            plist = readPlistFromString(plist)
-            wpframework = plist.get(&quot;com.apple.WhitePagesFramework&quot;, {})
-            autoaccept = wpframework.get(&quot;AutoAcceptsInvitation&quot;, False)
-            proxy = wpframework.get(&quot;CalendaringDelegate&quot;, None)
-            read_only_proxy = wpframework.get(&quot;ReadOnlyCalendaringDelegate&quot;, None)
-            autoAcceptGroup = wpframework.get(&quot;AutoAcceptGroup&quot;, &quot;&quot;)
-        except (ExpatError, AttributeError), e:
-            self.log.error(
-                &quot;Failed to parse ResourceInfo attribute of record (%s)%s (guid=%s): %s\n%s&quot; %
-                (recordType, shortname, guid, e, plist,)
-            )
-            raise ValueError(&quot;Invalid ResourceInfo&quot;)
-
-        return (autoaccept, proxy, read_only_proxy, autoAcceptGroup)
-
-
-    def getExternalProxyAssignments(self):
-        &quot;&quot;&quot;
-        Retrieve proxy assignments for locations and resources from the
-        directory and return a list of (principalUID, ([memberUIDs)) tuples,
-        suitable for passing to proxyDB.setGroupMembers( )
-
-        This generic implementation fetches all locations and resources.
-        More specialized implementations can perform whatever operation is
-        most efficient for their particular directory service.
-        &quot;&quot;&quot;
-        assignments = []
-
-        resources = itertools.chain(
-            self.listRecords(self.recordType_locations),
-            self.listRecords(self.recordType_resources)
-        )
-        for record in resources:
-            guid = record.guid
-            if record.enabledForCalendaring:
-                assignments.append((&quot;%s#calendar-proxy-write&quot; % (guid,),
-                                   record.externalProxies()))
-                assignments.append((&quot;%s#calendar-proxy-read&quot; % (guid,),
-                                   record.externalReadOnlyProxies()))
-
-        return assignments
-
-
-    def createRecord(self, recordType, guid=None, shortNames=(), authIDs=set(),
-        fullName=None, firstName=None, lastName=None, emailAddresses=set(),
-        uid=None, password=None, **kwargs):
-        &quot;&quot;&quot;
-        Create/persist a directory record based on the given values
-        &quot;&quot;&quot;
-        raise NotImplementedError(&quot;Subclass must implement createRecord&quot;)
-
-
-    def updateRecord(self, recordType, guid=None, shortNames=(), authIDs=set(),
-        fullName=None, firstName=None, lastName=None, emailAddresses=set(),
-        uid=None, password=None, **kwargs):
-        &quot;&quot;&quot;
-        Update/persist a directory record based on the given values
-        &quot;&quot;&quot;
-        raise NotImplementedError(&quot;Subclass must implement updateRecord&quot;)
-
-
-    def destroyRecord(self, recordType, guid=None):
-        &quot;&quot;&quot;
-        Remove a directory record from the directory
-        &quot;&quot;&quot;
-        raise NotImplementedError(&quot;Subclass must implement destroyRecord&quot;)
-
-
-    def createRecords(self, data):
-        &quot;&quot;&quot;
-        Create directory records in bulk
-        &quot;&quot;&quot;
-        raise NotImplementedError(&quot;Subclass must implement createRecords&quot;)
-
-
-    def setPrincipalCollection(self, principalCollection):
-        &quot;&quot;&quot;
-        Set the principal service that the directory relies on for doing proxy tests.
-
-        @param principalService: the principal service.
-        @type principalService: L{DirectoryProvisioningResource}
-        &quot;&quot;&quot;
-        self.principalCollection = principalCollection
-
-
-    def isProxyFor(self, test, other):
-        &quot;&quot;&quot;
-        Test whether one record is a calendar user proxy for the specified record.
-
-        @param test: record to test
-        @type test: L{DirectoryRecord}
-        @param other: record to check against
-        @type other: L{DirectoryRecord}
-
-        @return: C{True} if test is a proxy of other.
-        @rtype: C{bool}
-        &quot;&quot;&quot;
-        return self.principalCollection.isProxyFor(test, other)
-
-
-
-class GroupMembershipCache(Memcacher):
-    &quot;&quot;&quot;
-    Caches group membership information
-
-    This cache is periodically updated by a side car so that worker processes
-    never have to ask the directory service directly for group membership
-    information.
-
-    Keys in this cache are:
-
-    &quot;groups-for:&lt;GUID&gt;&quot; : comma-separated list of groups that GUID is a member
-    of.  Note that when using LDAP, the key for this is an LDAP DN.
-
-    &quot;group-cacher-populated&quot; : contains a datestamp indicating the most recent
-    population.
-    &quot;&quot;&quot;
-    log = Logger()
-
-    def __init__(self, namespace, pickle=True, no_invalidation=False,
-        key_normalization=True, expireSeconds=0, lockSeconds=60):
-
-        super(GroupMembershipCache, self).__init__(namespace, pickle=pickle,
-            no_invalidation=no_invalidation,
-            key_normalization=key_normalization)
-
-        self.expireSeconds = expireSeconds
-        self.lockSeconds = lockSeconds
-
-
-    def setGroupsFor(self, guid, memberships):
-        self.log.debug(&quot;set groups-for %s : %s&quot; % (guid, memberships))
-        return self.set(&quot;groups-for:%s&quot; %
-            (str(guid)), memberships,
-            expireTime=self.expireSeconds)
-
-
-    def getGroupsFor(self, guid):
-        self.log.debug(&quot;get groups-for %s&quot; % (guid,))
-        def _value(value):
-            if value:
-                return value
-            else:
-                return set()
-        d = self.get(&quot;groups-for:%s&quot; % (str(guid),))
-        d.addCallback(_value)
-        return d
-
-
-    def deleteGroupsFor(self, guid):
-        self.log.debug(&quot;delete groups-for %s&quot; % (guid,))
-        return self.delete(&quot;groups-for:%s&quot; % (str(guid),))
-
-
-    def setPopulatedMarker(self):
-        self.log.debug(&quot;set group-cacher-populated&quot;)
-        return self.set(&quot;group-cacher-populated&quot;, str(datetime.datetime.now()))
-
-
-    @inlineCallbacks
-    def isPopulated(self):
-        self.log.debug(&quot;is group-cacher-populated&quot;)
-        value = (yield self.get(&quot;group-cacher-populated&quot;))
-        returnValue(value is not None)
-
-
-    def acquireLock(self):
-        &quot;&quot;&quot;
-        Acquire a memcached lock named group-cacher-lock
-
-        return: Deferred firing True if successful, False if someone already has
-            the lock
-        &quot;&quot;&quot;
-        self.log.debug(&quot;add group-cacher-lock&quot;)
-        return self.add(&quot;group-cacher-lock&quot;, &quot;1&quot;, expireTime=self.lockSeconds)
-
-
-    def extendLock(self):
-        &quot;&quot;&quot;
-        Update the expiration time of the memcached lock
-        Return: Deferred firing True if successful, False otherwise
-        &quot;&quot;&quot;
-        self.log.debug(&quot;extend group-cacher-lock&quot;)
-        return self.set(&quot;group-cacher-lock&quot;, &quot;1&quot;, expireTime=self.lockSeconds)
-
-
-    def releaseLock(self):
-        &quot;&quot;&quot;
-        Release the memcached lock
-        Return: Deferred firing True if successful, False otherwise
-        &quot;&quot;&quot;
-        self.log.debug(&quot;delete group-cacher-lock&quot;)
-        return self.delete(&quot;group-cacher-lock&quot;)
-
-
-
-class GroupMembershipCacheUpdater(object):
-    &quot;&quot;&quot;
-    Responsible for updating memcached with group memberships.  This will run
-    in a sidecar.  There are two sources of proxy data to pull from: the local
-    proxy database, and the location/resource info in the directory system.
-    &quot;&quot;&quot;
-    log = Logger()
-
-    def __init__(self, proxyDB, directory, updateSeconds, expireSeconds,
-        lockSeconds, cache=None, namespace=None, useExternalProxies=False,
-        externalProxiesSource=None):
-        self.proxyDB = proxyDB
-        self.directory = directory
-        self.updateSeconds = updateSeconds
-        self.useExternalProxies = useExternalProxies
-        if useExternalProxies and externalProxiesSource is None:
-            externalProxiesSource = self.directory.getExternalProxyAssignments
-        self.externalProxiesSource = externalProxiesSource
-
-        if cache is None:
-            assert namespace is not None, &quot;namespace must be specified if GroupMembershipCache is not provided&quot;
-            cache = GroupMembershipCache(namespace, expireSeconds=expireSeconds,
-                lockSeconds=lockSeconds)
-        self.cache = cache
-
-
-    @inlineCallbacks
-    def getGroups(self, guids=None):
-        &quot;&quot;&quot;
-        Retrieve all groups and their member info (but don't actually fault in
-        the records of the members), and return two dictionaries.  The first
-        contains group records; the keys for this dictionary are the identifiers
-        used by the directory service to specify members.  In OpenDirectory
-        these would be guids, but in LDAP these could be DNs, or some other
-        attribute.  This attribute can be retrieved from a record using
-        record.cachedGroupsAlias().
-        The second dictionary returned maps that member attribute back to the
-        corresponding guid.  These dictionaries are used to reverse-index the
-        groups that users are in by expandedMembers().
-
-        @param guids: if provided, retrieve only the groups corresponding to
-            these guids (including their sub groups)
-        @type guids: list of guid strings
-        &quot;&quot;&quot;
-        groups = {}
-        aliases = {}
-
-        if guids is None: # get all group guids
-            records = self.directory.listRecords(self.directory.recordType_groups)
-        else: # get only the ones we know have been delegated to
-            records = (yield self.directory.getGroups(guids))
-
-        for record in records:
-            alias = record.cachedGroupsAlias()
-            groups[alias] = record.memberGUIDs()
-            aliases[record.guid] = alias
-
-        returnValue((groups, aliases))
-
-
-    def expandedMembers(self, groups, guid, members=None, seen=None):
-        &quot;&quot;&quot;
-        Return the complete, flattened set of members of a group, including
-        all sub-groups, based on the group hierarchy described in the
-        groups dictionary.
-        &quot;&quot;&quot;
-        if members is None:
-            members = set()
-        if seen is None:
-            seen = set()
-
-        if guid not in seen:
-            seen.add(guid)
-            for member in groups[guid]:
-                members.add(member)
-                if member in groups: # it's a group then
-                    self.expandedMembers(groups, member, members=members,
-                                         seen=seen)
-        return members
-
-
-    @inlineCallbacks
-    def updateCache(self, fast=False):
-        &quot;&quot;&quot;
-        Iterate the proxy database to retrieve all the principals who have been
-        delegated to.  Fault these principals in.  For any of these principals
-        that are groups, expand the members of that group and store those in
-        the cache
-
-        If fast=True, we're in quick-start mode, used only by the master process
-        to start servicing requests as soon as possible.  In this mode we look
-        for DataRoot/memberships_cache which is a pickle of a dictionary whose
-        keys are guids (except when using LDAP where the keys will be DNs), and
-        the values are lists of group guids.  If the cache file does not exist
-        we switch to fast=False.
-
-        The return value is mainly used for unit tests; it's a tuple containing
-        the (possibly modified) value for fast, and the number of members loaded
-        into the cache (which can be zero if fast=True and isPopulated(), or
-        fast=False and the cache is locked by someone else).
-
-        The pickled snapshot file is a dict whose keys represent a record and
-        the values are the guids of the groups that record is a member of.  The
-        keys are normally guids except in the case of a directory system like LDAP
-        where there can be a different attribute used for referring to members,
-        such as a DN.
-        &quot;&quot;&quot;
-
-        # TODO: add memcached eviction protection
-
-        useLock = True
-
-        # See if anyone has completely populated the group membership cache
-        isPopulated = (yield self.cache.isPopulated())
-
-        if fast:
-            # We're in quick-start mode.  Check first to see if someone has
-            # populated the membership cache, and if so, return immediately
-            if isPopulated:
-                self.log.info(&quot;Group membership cache is already populated&quot;)
-                returnValue((fast, 0, 0))
-
-            # We don't care what others are doing right now, we need to update
-            useLock = False
-
-        self.log.info(&quot;Updating group membership cache&quot;)
-
-        dataRoot = FilePath(config.DataRoot)
-        membershipsCacheFile = dataRoot.child(&quot;memberships_cache&quot;)
-        extProxyCacheFile = dataRoot.child(&quot;external_proxy_cache&quot;)
-
-        if not membershipsCacheFile.exists():
-            self.log.info(&quot;Group membership snapshot file does not yet exist&quot;)
-            fast = False
-            previousMembers = {}
-            callGroupsChanged = False
-        else:
-            self.log.info(&quot;Group membership snapshot file exists: %s&quot; %
-                (membershipsCacheFile.path,))
-            callGroupsChanged = True
-            try:
-                previousMembers = pickle.loads(membershipsCacheFile.getContent())
-            except:
-                self.log.warn(&quot;Could not parse snapshot; will regenerate cache&quot;)
-                fast = False
-                previousMembers = {}
-                callGroupsChanged = False
-
-        if useLock:
-            self.log.info(&quot;Attempting to acquire group membership cache lock&quot;)
-            acquiredLock = (yield self.cache.acquireLock())
-            if not acquiredLock:
-                self.log.info(&quot;Group membership cache lock held by another process&quot;)
-                returnValue((fast, 0, 0))
-            self.log.info(&quot;Acquired lock&quot;)
-
-        if not fast and self.useExternalProxies:
-
-            # Load in cached copy of external proxies so we can diff against them
-            previousAssignments = []
-            if extProxyCacheFile.exists():
-                self.log.info(&quot;External proxies snapshot file exists: %s&quot; %
-                    (extProxyCacheFile.path,))
-                try:
-                    previousAssignments = pickle.loads(extProxyCacheFile.getContent())
-                except:
-                    self.log.warn(&quot;Could not parse external proxies snapshot&quot;)
-                    previousAssignments = []
-
-            if useLock:
-                yield self.cache.extendLock()
-
-            self.log.info(&quot;Retrieving proxy assignments from directory&quot;)
-            assignments = self.externalProxiesSource()
-            self.log.info(&quot;%d proxy assignments retrieved from directory&quot; %
-                (len(assignments),))
-
-            if useLock:
-                yield self.cache.extendLock()
-
-            changed, removed = diffAssignments(previousAssignments, assignments)
-            # changed is the list of proxy assignments (either new or updates).
-            # removed is the list of principals who used to have an external
-            #   delegate but don't anymore.
-
-            # populate proxy DB from external resource info
-            if changed:
-                self.log.info(&quot;Updating proxy assignments&quot;)
-                assignmentCount = 0
-                totalNumAssignments = len(changed)
-                currentAssignmentNum = 0
-                for principalUID, members in changed:
-                    currentAssignmentNum += 1
-                    if currentAssignmentNum % 1000 == 0:
-                        self.log.info(&quot;...proxy assignment %d of %d&quot; % (currentAssignmentNum,
-                            totalNumAssignments))
-                    try:
-                        current = (yield self.proxyDB.getMembers(principalUID))
-                        if members != current:
-                            assignmentCount += 1
-                            yield self.proxyDB.setGroupMembers(principalUID, members)
-                    except Exception, e:
-                        self.log.error(&quot;Unable to update proxy assignment: principal=%s, members=%s, error=%s&quot; % (principalUID, members, e))
-                self.log.info(&quot;Updated %d assignment%s in proxy database&quot; %
-                    (assignmentCount, &quot;&quot; if assignmentCount == 1 else &quot;s&quot;))
-
-            if removed:
-                self.log.info(&quot;Deleting proxy assignments&quot;)
-                assignmentCount = 0
-                totalNumAssignments = len(removed)
-                currentAssignmentNum = 0
-                for principalUID in removed:
-                    currentAssignmentNum += 1
-                    if currentAssignmentNum % 1000 == 0:
-                        self.log.info(&quot;...proxy assignment %d of %d&quot; % (currentAssignmentNum,
-                            totalNumAssignments))
-                    try:
-                        assignmentCount += 1
-                        yield self.proxyDB.setGroupMembers(principalUID, [])
-                    except Exception, e:
-                        self.log.error(&quot;Unable to remove proxy assignment: principal=%s, members=%s, error=%s&quot; % (principalUID, members, e))
-                self.log.info(&quot;Removed %d assignment%s from proxy database&quot; %
-                    (assignmentCount, &quot;&quot; if assignmentCount == 1 else &quot;s&quot;))
-
-            # Store external proxy snapshot
-            self.log.info(&quot;Taking snapshot of external proxies to %s&quot; %
-                (extProxyCacheFile.path,))
-            extProxyCacheFile.setContent(pickle.dumps(assignments))
-
-        if fast:
-            # If there is an on-disk snapshot of the membership information,
-            # load that and put into memcached, bypassing the faulting in of
-            # any records, so that the server can start up quickly.
-
-            self.log.info(&quot;Loading group memberships from snapshot&quot;)
-            members = pickle.loads(membershipsCacheFile.getContent())
-
-        else:
-            # Fetch the group hierarchy from the directory, fetch the list
-            # of delegated-to guids, intersect those and build a dictionary
-            # containing which delegated-to groups a user is a member of
-
-            self.log.info(&quot;Retrieving list of all proxies&quot;)
-            # This is always a set of guids:
-            delegatedGUIDs = set((yield self.proxyDB.getAllMembers()))
-            self.log.info(&quot;There are %d proxies&quot; % (len(delegatedGUIDs),))
-            self.log.info(&quot;Retrieving group hierarchy from directory&quot;)
-
-            # &quot;groups&quot; maps a group to its members; the keys and values consist
-            # of whatever directory attribute is used to refer to members.  The
-            # attribute value comes from record.cachedGroupsAlias().
-            # &quot;aliases&quot; maps the record.cachedGroupsAlias() value for a group
-            # back to the group's guid.
-            groups, aliases = (yield self.getGroups(guids=delegatedGUIDs))
-            groupGUIDs = set(aliases.keys())
-            self.log.info(&quot;%d groups retrieved from the directory&quot; %
-                (len(groupGUIDs),))
-
-            delegatedGUIDs = delegatedGUIDs.intersection(groupGUIDs)
-            self.log.info(&quot;%d groups are proxies&quot; % (len(delegatedGUIDs),))
-
-            # Reverse index the group membership from cache
-            members = {}
-            for groupGUID in delegatedGUIDs:
-                groupMembers = self.expandedMembers(groups, aliases[groupGUID])
-                # groupMembers is in cachedGroupsAlias() format
-                for member in groupMembers:
-                    memberships = members.setdefault(member, set())
-                    memberships.add(groupGUID)
-
-            self.log.info(&quot;There are %d users delegated-to via groups&quot; %
-                (len(members),))
-
-            # Store snapshot
-            self.log.info(&quot;Taking snapshot of group memberships to %s&quot; %
-                (membershipsCacheFile.path,))
-            membershipsCacheFile.setContent(pickle.dumps(members))
-
-            # Update ownership
-            uid = gid = -1
-            if config.UserName:
-                uid = pwd.getpwnam(config.UserName).pw_uid
-            if config.GroupName:
-                gid = grp.getgrnam(config.GroupName).gr_gid
-            os.chown(membershipsCacheFile.path, uid, gid)
-            if extProxyCacheFile.exists():
-                os.chown(extProxyCacheFile.path, uid, gid)
-
-        self.log.info(&quot;Storing %d group memberships in memcached&quot; %
-                       (len(members),))
-        changedMembers = set()
-        totalNumMembers = len(members)
-        currentMemberNum = 0
-        for member, groups in members.iteritems():
-            currentMemberNum += 1
-            if currentMemberNum % 1000 == 0:
-                self.log.info(&quot;...membership %d of %d&quot; % (currentMemberNum,
-                    totalNumMembers))
-            # self.log.debug(&quot;%s is in %s&quot; % (member, groups))
-            yield self.cache.setGroupsFor(member, groups)
-            if groups != previousMembers.get(member, None):
-                # This principal has had a change in group membership
-                # so invalidate the PROPFIND response cache
-                changedMembers.add(member)
-            try:
-                # Remove from previousMembers; anything still left in
-                # previousMembers when this loop is done will be
-                # deleted from cache (since only members that were
-                # previously in delegated-to groups but are no longer
-                # would still be in previousMembers)
-                del previousMembers[member]
-            except KeyError:
-                pass
-
-        # Remove entries for principals that no longer are in delegated-to
-        # groups
-        for member, groups in previousMembers.iteritems():
-            yield self.cache.deleteGroupsFor(member)
-            changedMembers.add(member)
-
-        # For principals whose group membership has changed, call groupsChanged()
-        if callGroupsChanged and not fast and hasattr(self.directory, &quot;principalCollection&quot;):
-            for member in changedMembers:
-                record = yield self.directory.recordWithCachedGroupsAlias(
-                    self.directory.recordType_users, member)
-                if record is not None:
-                    principal = self.directory.principalCollection.principalForRecord(record)
-                    if principal is not None:
-                        self.log.debug(&quot;Group membership changed for %s (%s)&quot; %
-                            (record.shortNames[0], record.guid,))
-                        if hasattr(principal, &quot;groupsChanged&quot;):
-                            yield principal.groupsChanged()
-
-        yield self.cache.setPopulatedMarker()
-
-        if useLock:
-            self.log.info(&quot;Releasing lock&quot;)
-            yield self.cache.releaseLock()
-
-        self.log.info(&quot;Group memberships cache updated&quot;)
-
-        returnValue((fast, len(members), len(changedMembers)))
-
-
-
-def diffAssignments(old, new):
-    &quot;&quot;&quot;
-    Compare two proxy assignment lists and return their differences in the form of
-    two lists -- one for added/updated assignments, and one for removed assignments.
-    @param old: list of (group, set(members)) tuples
-    @type old: C{list}
-    @param new: list of (group, set(members)) tuples
-    @type new: C{list}
-    @return: Tuple of two lists; the first list contains tuples of (proxy-principal,
-        set(members)), and represents all the new or updated assignments.  The
-        second list contains all the proxy-principals which used to have a delegate
-        but don't anymore.
-    &quot;&quot;&quot;
-    old = dict(old)
-    new = dict(new)
-    changed = []
-    removed = []
-    for key in old.iterkeys():
-        if key not in new:
-            removed.append(key)
-        else:
-            if old[key] != new[key]:
-                changed.append((key, new[key]))
-    for key in new.iterkeys():
-        if key not in old:
-            changed.append((key, new[key]))
-    return changed, removed
-
-
-
-class DirectoryRecord(object):
-    log = Logger()
-
-    implements(IDirectoryRecord, ICalendarStoreDirectoryRecord)
-
-    def __repr__(self):
-        return &quot;&lt;%s[%s@%s(%s)] %s(%s) %r @ %s&gt;&quot; % (
-            self.__class__.__name__,
-            self.recordType,
-            self.service.guid,
-            self.service.realmName,
-            self.guid,
-            &quot;,&quot;.join(self.shortNames),
-            self.fullName,
-            self.serverURI(),
-        )
-
-
-    def __init__(
-        self, service, recordType, guid=None,
-        shortNames=(), authIDs=set(), fullName=None,
-        firstName=None, lastName=None, emailAddresses=set(),
-        calendarUserAddresses=set(),
-        autoSchedule=False, autoScheduleMode=None,
-        autoAcceptGroup=&quot;&quot;,
-        enabledForCalendaring=None,
-        enabledForAddressBooks=None,
-        uid=None,
-        enabledForLogin=True,
-        extProxies=(), extReadOnlyProxies=(),
-        **kwargs
-    ):
-        assert service.realmName is not None
-        assert recordType
-        assert shortNames and isinstance(shortNames, tuple)
-
-        guid = normalizeUUID(guid)
-
-        if uid is None:
-            uid = guid
-
-        if fullName is None:
-            fullName = &quot;&quot;
-
-        self.service = service
-        self.recordType = recordType
-        self.guid = guid
-        self.uid = uid
-        self.enabled = False
-        self.serverID = &quot;&quot;
-        self.shortNames = shortNames
-        self.authIDs = authIDs
-        self.fullName = fullName
-        self.firstName = firstName
-        self.lastName = lastName
-        self.emailAddresses = emailAddresses
-        self.enabledForCalendaring = enabledForCalendaring
-        self.autoSchedule = autoSchedule
-        self.autoScheduleMode = autoScheduleMode
-        self.autoAcceptGroup = autoAcceptGroup
-        self.enabledForAddressBooks = enabledForAddressBooks
-        self.enabledForLogin = enabledForLogin
-        self.extProxies = extProxies
-        self.extReadOnlyProxies = extReadOnlyProxies
-        self.extras = kwargs
-
-
-    def get_calendarUserAddresses(self):
-        &quot;&quot;&quot;
-        Dynamically construct a calendarUserAddresses attribute which describes
-        this L{DirectoryRecord}.
-
-        @see: L{IDirectoryRecord.calendarUserAddresses}.
-        &quot;&quot;&quot;
-        if not self.enabledForCalendaring:
-            return frozenset()
-        cuas = set(
-            [&quot;mailto:%s&quot; % (emailAddress,)
-             for emailAddress in self.emailAddresses]
-        )
-        if self.guid:
-            cuas.add(&quot;urn:uuid:%s&quot; % (self.guid,))
-            cuas.add(joinURL(&quot;/principals&quot;, &quot;__uids__&quot;, self.guid) + &quot;/&quot;)
-        for shortName in self.shortNames:
-            cuas.add(joinURL(&quot;/principals&quot;, self.recordType, shortName,) + &quot;/&quot;)
-
-        return frozenset(cuas)
-
-    calendarUserAddresses = property(get_calendarUserAddresses)
-
-    def __cmp__(self, other):
-        if not isinstance(other, DirectoryRecord):
-            return NotImplemented
-
-        for attr in (&quot;service&quot;, &quot;recordType&quot;, &quot;shortNames&quot;, &quot;guid&quot;):
-            diff = cmp(getattr(self, attr), getattr(other, attr))
-            if diff != 0:
-                return diff
-        return 0
-
-
-    def __hash__(self):
-        h = hash(self.__class__.__name__)
-        for attr in (&quot;service&quot;, &quot;recordType&quot;, &quot;shortNames&quot;, &quot;guid&quot;,
-                     &quot;enabled&quot;, &quot;enabledForCalendaring&quot;):
-            h = (h + hash(getattr(self, attr))) &amp; sys.maxint
-
-        return h
-
-
-    def cacheToken(self):
-        &quot;&quot;&quot;
-        Generate a token that can be uniquely used to identify the state of this record for use
-        in a cache.
-        &quot;&quot;&quot;
-        return hash((
-            self.__class__.__name__,
-            self.service.realmName,
-            self.recordType,
-            self.shortNames,
-            self.guid,
-            self.enabled,
-            self.enabledForCalendaring,
-        ))
-
-
-    def addAugmentInformation(self, augment):
-
-        if augment:
-            self.enabled = augment.enabled
-            self.serverID = augment.serverID
-            self.enabledForCalendaring = augment.enabledForCalendaring
-            self.enabledForAddressBooks = augment.enabledForAddressBooks
-            self.autoSchedule = augment.autoSchedule
-            self.autoScheduleMode = augment.autoScheduleMode
-            self.autoAcceptGroup = augment.autoAcceptGroup
-            self.enabledForLogin = augment.enabledForLogin
-
-            if (self.enabledForCalendaring or self.enabledForAddressBooks) and self.recordType == self.service.recordType_groups:
-                self.enabledForCalendaring = False
-                self.enabledForAddressBooks = False
-
-                # For augment records cloned from the Default augment record,
-                # don't emit this message:
-                if not augment.clonedFromDefault:
-                    self.log.error(&quot;Group '%s(%s)' cannot be enabled for calendaring or address books&quot; % (self.guid, self.shortNames[0],))
-
-        else:
-            # Groups are by default always enabled
-            self.enabled = (self.recordType == self.service.recordType_groups)
-            self.serverID = &quot;&quot;
-            self.enabledForCalendaring = False
-            self.enabledForAddressBooks = False
-            self.enabledForLogin = False
-
-
-    def applySACLs(self):
-        &quot;&quot;&quot;
-        Disable calendaring and addressbooks as dictated by SACLs
-        &quot;&quot;&quot;
-
-        if config.EnableSACLs and self.CheckSACL:
-            username = self.shortNames[0]
-            if self.CheckSACL(username, &quot;calendar&quot;) != 0:
-                self.log.debug(&quot;%s is not enabled for calendaring due to SACL&quot;
-                               % (username,))
-                self.enabledForCalendaring = False
-            if self.CheckSACL(username, &quot;addressbook&quot;) != 0:
-                self.log.debug(&quot;%s is not enabled for addressbooks due to SACL&quot;
-                               % (username,))
-                self.enabledForAddressBooks = False
-
-
-    def displayName(self):
-        return self.fullName if self.fullName else self.shortNames[0]
-
-
-    def isLoginEnabled(self):
-        &quot;&quot;&quot;
-        Returns True if the user should be allowed to log in, based on the
-        enabledForLogin attribute, which is currently controlled by the
-        DirectoryService implementation.
-        &quot;&quot;&quot;
-        return self.enabledForLogin
-
-
-    def members(self):
-        return ()
-
-
-    def expandedMembers(self, members=None, seen=None):
-        &quot;&quot;&quot;
-        Return the complete, flattened set of members of a group, including
-        all sub-groups.
-        &quot;&quot;&quot;
-        if members is None:
-            members = set()
-        if seen is None:
-            seen = set()
-
-        if self not in seen:
-            seen.add(self)
-            for member in self.members():
-                members.add(member)
-                if member.recordType == self.service.recordType_groups:
-                    member.expandedMembers(members=members, seen=seen)
-
-        return members
-
-
-    def groups(self):
-        return ()
-
-
-    def cachedGroups(self):
-        &quot;&quot;&quot;
-        Return the set of groups (guids) this record is a member of, based on
-        the data cached by cacheGroupMembership( )
-        &quot;&quot;&quot;
-        return self.service.groupMembershipCache.getGroupsFor(self.cachedGroupsAlias())
-
-
-    def cachedGroupsAlias(self):
-        &quot;&quot;&quot;
-        The GroupMembershipCache uses keys based on this value.  Normally it's
-        a record's guid but in a directory system like LDAP which can use a
-        different attribute to refer to group members, we need to be able to
-        look up an entry in the GroupMembershipCache by that attribute.
-        Subclasses which don't use record.guid to look up group membership
-        should override this method.
-        &quot;&quot;&quot;
-        return self.guid
-
-
-    def externalProxies(self):
-        &quot;&quot;&quot;
-        Return the set of proxies defined in the directory service, as opposed
-        to assignments in the proxy DB itself.
-        &quot;&quot;&quot;
-        return set(self.extProxies)
-
-
-    def externalReadOnlyProxies(self):
-        &quot;&quot;&quot;
-        Return the set of read-only proxies defined in the directory service,
-        as opposed to assignments in the proxy DB itself.
-        &quot;&quot;&quot;
-        return set(self.extReadOnlyProxies)
-
-
-    def memberGUIDs(self):
-        &quot;&quot;&quot;
-        Return the set of GUIDs that are members of this group
-        &quot;&quot;&quot;
-        return set()
-
-
-    def verifyCredentials(self, credentials):
-        return False
-
-
-    def calendarsEnabled(self):
-        return config.EnableCalDAV and self.enabledForCalendaring
-
-
-    def canonicalCalendarUserAddress(self):
-        &quot;&quot;&quot;
-            Return a CUA for this principal, preferring in this order:
-            urn:uuid: form
-            mailto: form
-            first in calendarUserAddresses list
-        &quot;&quot;&quot;
-
-        cua = &quot;&quot;
-        for candidate in self.calendarUserAddresses:
-            # Pick the first one, but urn:uuid: and mailto: can override
-            if not cua:
-                cua = candidate
-            # But always immediately choose the urn:uuid: form
-            if candidate.startswith(&quot;urn:uuid:&quot;):
-                cua = candidate
-                break
-            # Prefer mailto: if no urn:uuid:
-            elif candidate.startswith(&quot;mailto:&quot;):
-                cua = candidate
-        return cua
-
-
-    def enabledAsOrganizer(self):
-        if self.recordType == DirectoryService.recordType_users:
-            return True
-        elif self.recordType == DirectoryService.recordType_groups:
-            return config.Scheduling.Options.AllowGroupAsOrganizer
-        elif self.recordType == DirectoryService.recordType_locations:
-            return config.Scheduling.Options.AllowLocationAsOrganizer
-        elif self.recordType == DirectoryService.recordType_resources:
-            return config.Scheduling.Options.AllowResourceAsOrganizer
-        else:
-            return False
-
-    # Mapping from directory record.recordType to RFC2445 CUTYPE values
-    _cuTypes = {
-        'users' : 'INDIVIDUAL',
-        'groups' : 'GROUP',
-        'resources' : 'RESOURCE',
-        'locations' : 'ROOM',
-    }
-
-    def getCUType(self):
-        return self._cuTypes.get(self.recordType, &quot;UNKNOWN&quot;)
-
-
-    @classmethod
-    def fromCUType(cls, cuType):
-        for key, val in cls._cuTypes.iteritems():
-            if val == cuType:
-                return key
-        return None
-
-
-    def canAutoSchedule(self, organizer):
-        if config.Scheduling.Options.AutoSchedule.Enabled:
-            if (config.Scheduling.Options.AutoSchedule.Always or
-                self.autoSchedule or
-                self.autoAcceptFromOrganizer(organizer)):
-                if (self.getCUType() != &quot;INDIVIDUAL&quot; or
-                    config.Scheduling.Options.AutoSchedule.AllowUsers):
-                    return True
-        return False
-
-
-    def getAutoScheduleMode(self, organizer):
-        autoScheduleMode = self.autoScheduleMode
-        if self.autoAcceptFromOrganizer(organizer):
-            autoScheduleMode = &quot;automatic&quot;
-        return autoScheduleMode
-
-
-    def autoAcceptFromOrganizer(self, organizer):
-        if organizer is not None and self.autoAcceptGroup is not None:
-            service = self.service.aggregateService or self.service
-            organizerRecord = service.recordWithCalendarUserAddress(organizer)
-            if organizerRecord is not None:
-                if organizerRecord.guid in self.autoAcceptMembers():
-                    return True
-        return False
-
-
-    def serverURI(self):
-        &quot;&quot;&quot;
-        URL of the server hosting this record. Return None if hosted on this server.
-        &quot;&quot;&quot;
-        if config.Servers.Enabled and self.serverID:
-            return Servers.getServerURIById(self.serverID)
-        else:
-            return None
-
-
-    def server(self):
-        &quot;&quot;&quot;
-        Server hosting this record. Return None if hosted on this server.
-        &quot;&quot;&quot;
-        if config.Servers.Enabled and self.serverID:
-            return Servers.getServerById(self.serverID)
-        else:
-            return None
-
-
-    def thisServer(self):
-        s = self.server()
-        return s.thisServer if s is not None else True
-
-
-    def autoAcceptMembers(self):
-        &quot;&quot;&quot;
-        Return the list of GUIDs for which this record will automatically accept
-        invites from (assuming no conflicts).  This list is based on the group
-        assigned to record.autoAcceptGroup.  Cache the expanded group membership
-        within the record.
-
-        @return: the list of members of the autoAcceptGroup, or an empty list if
-            not assigned
-        @rtype: C{list} of GUID C{str}
-        &quot;&quot;&quot;
-        if not hasattr(self, &quot;_cachedAutoAcceptMembers&quot;):
-            self._cachedAutoAcceptMembers = []
-            if self.autoAcceptGroup:
-                service = self.service.aggregateService or self.service
-                groupRecord = service.recordWithGUID(self.autoAcceptGroup)
-                if groupRecord is not None:
-                    self._cachedAutoAcceptMembers = [m.guid for m in groupRecord.expandedMembers()]
-
-        return self._cachedAutoAcceptMembers
-
-
-    def isProxyFor(self, other):
-        &quot;&quot;&quot;
-        Test whether the record is a calendar user proxy for the specified record.
-
-        @param other: record to test
-        @type other: L{DirectoryRecord}
-
-        @return: C{True} if it is a proxy.
-        @rtype: C{bool}
-        &quot;&quot;&quot;
-        return self.service.isProxyFor(self, other)
-
-
-
-class DirectoryError(RuntimeError):
-    &quot;&quot;&quot;
-    Generic directory error.
-    &quot;&quot;&quot;
-
-
-
-class DirectoryConfigurationError(DirectoryError):
-    &quot;&quot;&quot;
-    Invalid directory configuration.
-    &quot;&quot;&quot;
-
-
-
-class UnknownRecordTypeError(DirectoryError):
-    &quot;&quot;&quot;
-    Unknown directory record type.
-    &quot;&quot;&quot;
-    def __init__(self, recordType):
-        DirectoryError.__init__(self, &quot;Invalid record type: %s&quot; % (recordType,))
-        self.recordType = recordType
-
-
-# So CheckSACL will be parameterized
-# We do this after DirectoryRecord is defined
-try:
-    from calendarserver.platform.darwin._sacl import CheckSACL
-    DirectoryRecord.CheckSACL = CheckSACL
-except ImportError:
-    DirectoryRecord.CheckSACL = None
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryldapdirectorypy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/ldapdirectory.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/ldapdirectory.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/ldapdirectory.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,2034 +0,0 @@
</span><del>-##
-# Copyright (c) 2008-2009 Aymeric Augustin. All rights reserved.
-# Copyright (c) 2006-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.
-##
-
-&quot;&quot;&quot;
-LDAP directory service implementation.  Supports principal-property-search
-and restrictToGroup features.
-
-The following attributes from standard schemas are used:
-* Core (RFC 4519):
-    . cn | commonName
-    . givenName
-    . member (if not using NIS groups)
-    . ou
-    . sn | surname
-    . uid | userid (if using NIS groups)
-* COSINE (RFC 4524):
-    . mail
-* InetOrgPerson (RFC 2798):
-    . displayName (if cn is unavailable)
-* NIS (RFC):
-    . gecos (if cn is unavailable)
-    . memberUid (if using NIS groups)
-&quot;&quot;&quot;
-
-__all__ = [
-    &quot;LdapDirectoryService&quot;,
-]
-
-import ldap.async
-from ldap.filter import escape_filter_chars as ldapEsc
-
-try:
-    # Note: PAM support is currently untested
-    import PAM
-    pamAvailable = True
-except ImportError:
-    pamAvailable = False
-
-import time
-from twisted.cred.credentials import UsernamePassword
-from twistedcaldav.directory.cachingdirectory import (
-    CachingDirectoryService, CachingDirectoryRecord
-)
-from twistedcaldav.directory.directory import DirectoryConfigurationError
-from twistedcaldav.directory.augment import AugmentRecord
-from twistedcaldav.directory.util import splitIntoBatches, normalizeUUID
-from twisted.internet.defer import succeed, inlineCallbacks, returnValue
-from twisted.internet.threads import deferToThread
-from twext.python.log import Logger
-from txweb2.http import HTTPError, StatusResponse
-from txweb2 import responsecode
-
-
-
-class LdapDirectoryService(CachingDirectoryService):
-    &quot;&quot;&quot;
-    LDAP based implementation of L{IDirectoryService}.
-    &quot;&quot;&quot;
-    log = Logger()
-
-    baseGUID = &quot;5A871574-0C86-44EE-B11B-B9440C3DC4DD&quot;
-
-    def __repr__(self):
-        return &quot;&lt;%s %r: %r&gt;&quot; % (
-            self.__class__.__name__, self.realmName, self.uri
-        )
-
-
-    def __init__(self, params):
-        &quot;&quot;&quot;
-        @param params: a dictionary containing the following keys:
-            cacheTimeout, realmName, uri, tls, tlsCACertFile, tlsCACertDir,
-            tlsRequireCert, credentials, rdnSchema, groupSchema, resourceSchema
-            poddingSchema
-        &quot;&quot;&quot;
-
-        defaults = {
-            &quot;augmentService&quot;: None,
-            &quot;groupMembershipCache&quot;: None,
-            &quot;cacheTimeout&quot;: 1,  # Minutes
-            &quot;negativeCaching&quot;: False,
-            &quot;warningThresholdSeconds&quot;: 3,
-            &quot;batchSize&quot;: 500,  # for splitting up large queries
-            &quot;requestTimeoutSeconds&quot;: 10,
-            &quot;requestResultsLimit&quot;: 200,
-            &quot;optimizeMultiName&quot;: False,
-            &quot;queryLocationsImplicitly&quot;: True,
-            &quot;restrictEnabledRecords&quot;: False,
-            &quot;restrictToGroup&quot;: &quot;&quot;,
-            &quot;recordTypes&quot;: (&quot;users&quot;, &quot;groups&quot;),
-            &quot;uri&quot;: &quot;ldap://localhost/&quot;,
-            &quot;tls&quot;: False,
-            &quot;tlsCACertFile&quot;: None,
-            &quot;tlsCACertDir&quot;: None,
-            &quot;tlsRequireCert&quot;: None,  # never, allow, try, demand, hard
-            &quot;credentials&quot;: {
-                &quot;dn&quot;: None,
-                &quot;password&quot;: None,
-            },
-            &quot;authMethod&quot;: &quot;LDAP&quot;,
-            &quot;rdnSchema&quot;: {
-                &quot;base&quot;: &quot;dc=example,dc=com&quot;,
-                &quot;guidAttr&quot;: &quot;entryUUID&quot;,
-                &quot;users&quot;: {
-                    &quot;rdn&quot;: &quot;ou=People&quot;,
-                    &quot;filter&quot;: None,  # additional filter for this type
-                    &quot;loginEnabledAttr&quot;: &quot;&quot;,  # attribute controlling login
-                    &quot;loginEnabledValue&quot;: &quot;yes&quot;,  # &quot;True&quot; value of above attribute
-                    &quot;calendarEnabledAttr&quot;: &quot;&quot;,  # attribute controlling enabledForCalendaring
-                    &quot;calendarEnabledValue&quot;: &quot;yes&quot;,  # &quot;True&quot; value of above attribute
-                    &quot;mapping&quot;: {  # maps internal record names to LDAP
-                        &quot;recordName&quot;: &quot;uid&quot;,
-                        &quot;fullName&quot;: &quot;cn&quot;,
-                        &quot;emailAddresses&quot;: [&quot;mail&quot;],  # multiple LDAP fields supported
-                        &quot;firstName&quot;: &quot;givenName&quot;,
-                        &quot;lastName&quot;: &quot;sn&quot;,
-                    },
-                },
-                &quot;groups&quot;: {
-                    &quot;rdn&quot;: &quot;ou=Group&quot;,
-                    &quot;filter&quot;: None,  # additional filter for this type
-                    &quot;mapping&quot;: {  # maps internal record names to LDAP
-                        &quot;recordName&quot;: &quot;cn&quot;,
-                        &quot;fullName&quot;: &quot;cn&quot;,
-                        &quot;emailAddresses&quot;: [&quot;mail&quot;],  # multiple LDAP fields supported
-                        &quot;firstName&quot;: &quot;givenName&quot;,
-                        &quot;lastName&quot;: &quot;sn&quot;,
-                    },
-                },
-                &quot;locations&quot;: {
-                    &quot;rdn&quot;: &quot;ou=Places&quot;,
-                    &quot;filter&quot;: None,  # additional filter for this type
-                    &quot;calendarEnabledAttr&quot;: &quot;&quot;,  # attribute controlling enabledForCalendaring
-                    &quot;calendarEnabledValue&quot;: &quot;yes&quot;,  # &quot;True&quot; value of above attribute
-                    &quot;associatedAddressAttr&quot;: &quot;&quot;,
-                    &quot;mapping&quot;: {  # maps internal record names to LDAP
-                        &quot;recordName&quot;: &quot;cn&quot;,
-                        &quot;fullName&quot;: &quot;cn&quot;,
-                        &quot;emailAddresses&quot;: [&quot;mail&quot;],  # multiple LDAP fields supported
-                    },
-                },
-                &quot;resources&quot;: {
-                    &quot;rdn&quot;: &quot;ou=Resources&quot;,
-                    &quot;filter&quot;: None,  # additional filter for this type
-                    &quot;calendarEnabledAttr&quot;: &quot;&quot;,  # attribute controlling enabledForCalendaring
-                    &quot;calendarEnabledValue&quot;: &quot;yes&quot;,  # &quot;True&quot; value of above attribute
-                    &quot;mapping&quot;: {  # maps internal record names to LDAP
-                        &quot;recordName&quot;: &quot;cn&quot;,
-                        &quot;fullName&quot;: &quot;cn&quot;,
-                        &quot;emailAddresses&quot;: [&quot;mail&quot;],  # multiple LDAP fields supported
-                    },
-                },
-                &quot;addresses&quot;: {
-                    &quot;rdn&quot;: &quot;ou=Buildings&quot;,
-                    &quot;filter&quot;: None,  # additional filter for this type
-                    &quot;streetAddressAttr&quot;: &quot;&quot;,
-                    &quot;geoAttr&quot;: &quot;&quot;,
-                    &quot;mapping&quot;: {  # maps internal record names to LDAP
-                        &quot;recordName&quot;: &quot;cn&quot;,
-                        &quot;fullName&quot;: &quot;cn&quot;,
-                    },
-                },
-            },
-            &quot;groupSchema&quot;: {
-                &quot;membersAttr&quot;: &quot;member&quot;,  # how members are specified
-                &quot;nestedGroupsAttr&quot;: None,  # how nested groups are specified
-                &quot;memberIdAttr&quot;: None,  # which attribute the above refer to (None means use DN)
-            },
-            &quot;resourceSchema&quot;: {
-                # Either set this attribute to retrieve the plist version
-                # of resource-info, as in a Leopard OD server, or...
-                &quot;resourceInfoAttr&quot;: None,
-                # ...set the above to None and instead specify these
-                # individually:
-                &quot;autoScheduleAttr&quot;: None,
-                &quot;autoScheduleEnabledValue&quot;: &quot;yes&quot;,
-                &quot;proxyAttr&quot;: None,  # list of GUIDs
-                &quot;readOnlyProxyAttr&quot;: None,  # list of GUIDs
-                &quot;autoAcceptGroupAttr&quot;: None,  # single group GUID
-            },
-            &quot;poddingSchema&quot;: {
-                &quot;serverIdAttr&quot;: None,  # maps to augments server-id
-            },
-        }
-        ignored = None
-        params = self.getParams(params, defaults, ignored)
-
-        self._recordTypes = params[&quot;recordTypes&quot;]
-
-        super(LdapDirectoryService, self).__init__(params[&quot;cacheTimeout&quot;],
-                                                   params[&quot;negativeCaching&quot;])
-
-        self.warningThresholdSeconds = params[&quot;warningThresholdSeconds&quot;]
-        self.batchSize = params[&quot;batchSize&quot;]
-        self.requestTimeoutSeconds = params[&quot;requestTimeoutSeconds&quot;]
-        self.requestResultsLimit = params[&quot;requestResultsLimit&quot;]
-        self.optimizeMultiName = params[&quot;optimizeMultiName&quot;]
-        if self.batchSize &gt; self.requestResultsLimit:
-            self.batchSize = self.requestResultsLimit
-        self.queryLocationsImplicitly = params[&quot;queryLocationsImplicitly&quot;]
-        self.augmentService = params[&quot;augmentService&quot;]
-        self.groupMembershipCache = params[&quot;groupMembershipCache&quot;]
-        self.realmName = params[&quot;uri&quot;]
-        self.uri = params[&quot;uri&quot;]
-        self.tls = params[&quot;tls&quot;]
-        self.tlsCACertFile = params[&quot;tlsCACertFile&quot;]
-        self.tlsCACertDir = params[&quot;tlsCACertDir&quot;]
-        self.tlsRequireCert = params[&quot;tlsRequireCert&quot;]
-        self.credentials = params[&quot;credentials&quot;]
-        self.authMethod = params[&quot;authMethod&quot;]
-        self.rdnSchema = params[&quot;rdnSchema&quot;]
-        self.groupSchema = params[&quot;groupSchema&quot;]
-        self.resourceSchema = params[&quot;resourceSchema&quot;]
-        self.poddingSchema = params[&quot;poddingSchema&quot;]
-
-        self.base = ldap.dn.str2dn(self.rdnSchema[&quot;base&quot;])
-
-        # Certain attributes (such as entryUUID) may be hidden and not
-        # returned by default when queried for all attributes. Therefore it is
-        # necessary to explicitly pass all the possible attributes list
-        # for ldap searches.  Dynamically build the attribute list based on
-        # config.
-        attrSet = set()
-
-        if self.rdnSchema[&quot;guidAttr&quot;]:
-            attrSet.add(self.rdnSchema[&quot;guidAttr&quot;])
-        for recordType in self.recordTypes():
-            if self.rdnSchema[recordType][&quot;attr&quot;]:
-                attrSet.add(self.rdnSchema[recordType][&quot;attr&quot;])
-            for n in (&quot;calendarEnabledAttr&quot;, &quot;associatedAddressAttr&quot;,
-                      &quot;streetAddressAttr&quot;, &quot;geoAttr&quot;):
-                if self.rdnSchema[recordType].get(n, False):
-                    attrSet.add(self.rdnSchema[recordType][n])
-            for attrList in self.rdnSchema[recordType][&quot;mapping&quot;].values():
-                if attrList:
-                    # Since emailAddresses can map to multiple LDAP fields,
-                    # support either string or list
-                    if isinstance(attrList, str):
-                        attrList = [attrList]
-                    for attr in attrList:
-                        attrSet.add(attr)
-            # Also put the guidAttr attribute into the mappings for each type
-            # so recordsMatchingFields can query on guid
-            self.rdnSchema[recordType][&quot;mapping&quot;][&quot;guid&quot;] = self.rdnSchema[&quot;guidAttr&quot;]
-            # Also put the memberIdAttr attribute into the mappings for each type
-            # so recordsMatchingFields can query on memberIdAttr
-            self.rdnSchema[recordType][&quot;mapping&quot;][&quot;memberIdAttr&quot;] = self.groupSchema[&quot;memberIdAttr&quot;]
-        if self.groupSchema[&quot;membersAttr&quot;]:
-            attrSet.add(self.groupSchema[&quot;membersAttr&quot;])
-        if self.groupSchema[&quot;nestedGroupsAttr&quot;]:
-            attrSet.add(self.groupSchema[&quot;nestedGroupsAttr&quot;])
-        if self.groupSchema[&quot;memberIdAttr&quot;]:
-            attrSet.add(self.groupSchema[&quot;memberIdAttr&quot;])
-        if self.rdnSchema[&quot;users&quot;][&quot;loginEnabledAttr&quot;]:
-            attrSet.add(self.rdnSchema[&quot;users&quot;][&quot;loginEnabledAttr&quot;])
-        if self.resourceSchema[&quot;resourceInfoAttr&quot;]:
-            attrSet.add(self.resourceSchema[&quot;resourceInfoAttr&quot;])
-        if self.resourceSchema[&quot;autoScheduleAttr&quot;]:
-            attrSet.add(self.resourceSchema[&quot;autoScheduleAttr&quot;])
-        if self.resourceSchema[&quot;autoAcceptGroupAttr&quot;]:
-            attrSet.add(self.resourceSchema[&quot;autoAcceptGroupAttr&quot;])
-        if self.resourceSchema[&quot;proxyAttr&quot;]:
-            attrSet.add(self.resourceSchema[&quot;proxyAttr&quot;])
-        if self.resourceSchema[&quot;readOnlyProxyAttr&quot;]:
-            attrSet.add(self.resourceSchema[&quot;readOnlyProxyAttr&quot;])
-        if self.poddingSchema[&quot;serverIdAttr&quot;]:
-            attrSet.add(self.poddingSchema[&quot;serverIdAttr&quot;])
-        self.attrlist = list(attrSet)
-
-        self.typeDNs = {}
-        for recordType in self.recordTypes():
-            self.typeDNs[recordType] = ldap.dn.str2dn(
-                self.rdnSchema[recordType][&quot;rdn&quot;].lower()
-            ) + self.base
-
-        self.ldap = None
-
-        # Separate LDAP connection used solely for authenticating clients
-        self.authLDAP = None
-
-        # Restricting access by directory group
-        self.restrictEnabledRecords = params['restrictEnabledRecords']
-        self.restrictToGroup = params['restrictToGroup']
-        self.restrictedTimestamp = 0
-
-
-    def recordTypes(self):
-        return self._recordTypes
-
-
-    def listRecords(self, recordType):
-
-        # Build base for this record Type
-        base = self.typeDNs[recordType]
-
-        # Build filter
-        filterstr = &quot;(!(objectClass=organizationalUnit))&quot;
-        typeFilter = self.rdnSchema[recordType].get(&quot;filter&quot;, &quot;&quot;)
-        if typeFilter:
-            filterstr = &quot;(&amp;%s%s)&quot; % (filterstr, typeFilter)
-
-        # Query the LDAP server
-        self.log.debug(
-            &quot;Querying ldap for records matching base {base} and &quot;
-            &quot;filter {filter} for attributes {attrs}.&quot;,
-            base=ldap.dn.dn2str(base), filter=filterstr,
-            attrs=self.attrlist
-        )
-
-        # This takes a while, so if you don't want to have a &quot;long request&quot;
-        # warning logged, use this instead of timedSearch:
-        # results = self.ldap.search_s(ldap.dn.dn2str(base),
-        #     ldap.SCOPE_SUBTREE, filterstr=filterstr, attrlist=self.attrlist)
-        results = self.timedSearch(
-            ldap.dn.dn2str(base), ldap.SCOPE_SUBTREE,
-            filterstr=filterstr, attrlist=self.attrlist
-        )
-
-        records = []
-        numMissingGuids = 0
-        guidAttr = self.rdnSchema[&quot;guidAttr&quot;]
-        for dn, attrs in results:
-            dn = normalizeDNstr(dn)
-
-            unrestricted = self.isAllowedByRestrictToGroup(dn, attrs)
-
-            try:
-                record = self._ldapResultToRecord(dn, attrs, recordType)
-                # self.log.debug(&quot;Got LDAP record {record}&quot;, record=record)
-            except MissingGuidException:
-                numMissingGuids += 1
-                continue
-
-            if not unrestricted:
-                self.log.debug(
-                    &quot;{dn} is not enabled because it's not a member of group: &quot;
-                    &quot;{group}&quot;, dn=dn, group=self.restrictToGroup
-                )
-                record.enabledForCalendaring = False
-                record.enabledForAddressBooks = False
-
-            records.append(record)
-
-        if numMissingGuids:
-            self.log.info(
-                &quot;{num} {recordType} records are missing {attr}&quot;,
-                num=numMissingGuids, recordType=recordType, attr=guidAttr
-            )
-
-        return records
-
-
-    @inlineCallbacks
-    def recordWithCachedGroupsAlias(self, recordType, alias):
-        &quot;&quot;&quot;
-        @param recordType: the type of the record to look up.
-        @param alias: the cached-groups alias of the record to look up.
-        @type alias: C{str}
-
-        @return: a deferred L{IDirectoryRecord} with the given cached-groups
-            alias, or C{None} if no such record is found.
-        &quot;&quot;&quot;
-        memberIdAttr = self.groupSchema[&quot;memberIdAttr&quot;]
-        attributeToSearch = &quot;memberIdAttr&quot; if memberIdAttr else &quot;dn&quot;
-
-        fields = [[attributeToSearch, alias, False, &quot;equals&quot;]]
-        results = yield self.recordsMatchingFields(
-            fields, recordType=recordType
-        )
-        if results:
-            returnValue(results[0])
-        else:
-            returnValue(None)
-
-
-    def getExternalProxyAssignments(self):
-        &quot;&quot;&quot;
-        Retrieve proxy assignments for locations and resources from the
-        directory and return a list of (principalUID, ([memberUIDs)) tuples,
-        suitable for passing to proxyDB.setGroupMembers( )
-        &quot;&quot;&quot;
-        assignments = []
-
-        guidAttr = self.rdnSchema[&quot;guidAttr&quot;]
-        readAttr = self.resourceSchema[&quot;readOnlyProxyAttr&quot;]
-        writeAttr = self.resourceSchema[&quot;proxyAttr&quot;]
-        if not (guidAttr and readAttr and writeAttr):
-            self.log.error(
-                &quot;LDAP configuration requires guidAttr, proxyAttr, and &quot;
-                &quot;readOnlyProxyAttr in order to use external proxy assignments &quot;
-                &quot;efficiently; falling back to slower method&quot;
-            )
-            # Fall back to the less-specialized version
-            return super(
-                LdapDirectoryService, self
-            ).getExternalProxyAssignments()
-
-        # Build filter
-        filterstr = &quot;(|(%s=*)(%s=*))&quot; % (readAttr, writeAttr)
-        # ...taking into account only calendar-enabled records
-        enabledAttr = self.rdnSchema[&quot;locations&quot;][&quot;calendarEnabledAttr&quot;]
-        enabledValue = self.rdnSchema[&quot;locations&quot;][&quot;calendarEnabledValue&quot;]
-        if enabledAttr and enabledValue:
-            filterstr = &quot;(&amp;(%s=%s)%s)&quot; % (enabledAttr, enabledValue, filterstr)
-
-        attrlist = [guidAttr, readAttr, writeAttr]
-
-        # Query the LDAP server
-        self.log.debug(
-            &quot;Querying ldap for records matching base {base} and filter &quot;
-            &quot;{filter} for attributes {attrs}.&quot;,
-            base=ldap.dn.dn2str(self.base), filter=filterstr,
-            attrs=attrlist
-        )
-
-        results = self.timedSearch(ldap.dn.dn2str(self.base),
-                                   ldap.SCOPE_SUBTREE, filterstr=filterstr,
-                                   attrlist=attrlist)
-
-        for dn, attrs in results:
-            dn = normalizeDNstr(dn)
-            guid = self._getUniqueLdapAttribute(attrs, guidAttr)
-            if guid:
-                guid = normalizeUUID(guid)
-                readDelegate = self._getUniqueLdapAttribute(attrs, readAttr)
-                if readDelegate:
-                    readDelegate = normalizeUUID(readDelegate)
-                    assignments.append(
-                        (&quot;%s#calendar-proxy-read&quot; % (guid,), [readDelegate])
-                    )
-                writeDelegate = self._getUniqueLdapAttribute(attrs, writeAttr)
-                if writeDelegate:
-                    writeDelegate = normalizeUUID(writeDelegate)
-                    assignments.append(
-                        (&quot;%s#calendar-proxy-write&quot; % (guid,), [writeDelegate])
-                    )
-
-        return assignments
-
-
-    def getLDAPConnection(self):
-        if self.ldap is None:
-            self.log.info(&quot;Connecting to LDAP {uri}&quot;, uri=repr(self.uri))
-            self.ldap = self.createLDAPConnection()
-            self.log.info(
-                &quot;Connection established to LDAP {uri}&quot;, uri=repr(self.uri)
-            )
-            if self.credentials.get(&quot;dn&quot;, &quot;&quot;):
-                try:
-                    self.log.info(
-                        &quot;Binding to LDAP {dn}&quot;,
-                        dn=repr(self.credentials.get(&quot;dn&quot;))
-                    )
-                    self.ldap.simple_bind_s(
-                        self.credentials.get(&quot;dn&quot;),
-                        self.credentials.get(&quot;password&quot;),
-                    )
-                    self.log.info(
-                        &quot;Successfully authenticated with LDAP as {dn}&quot;,
-                        dn=repr(self.credentials.get(&quot;dn&quot;))
-                    )
-                except ldap.INVALID_CREDENTIALS:
-                    self.log.error(
-                        &quot;Can't bind to LDAP {uri}: check credentials&quot;,
-                        uri=self.uri
-                    )
-                    raise DirectoryConfigurationError()
-
-        return self.ldap
-
-
-    def createLDAPConnection(self):
-        &quot;&quot;&quot;
-        Create and configure LDAP connection
-        &quot;&quot;&quot;
-        cxn = ldap.initialize(self.uri)
-
-        if self.tlsCACertFile:
-            cxn.set_option(ldap.OPT_X_TLS_CACERTFILE, self.tlsCACertFile)
-        if self.tlsCACertDir:
-            cxn.set_option(ldap.OPT_X_TLS_CACERTDIR, self.tlsCACertDir)
-
-        if self.tlsRequireCert == &quot;never&quot;:
-            cxn.set_option(ldap.OPT_X_TLS, ldap.OPT_X_TLS_NEVER)
-        elif self.tlsRequireCert == &quot;allow&quot;:
-            cxn.set_option(ldap.OPT_X_TLS, ldap.OPT_X_TLS_ALLOW)
-        elif self.tlsRequireCert == &quot;try&quot;:
-            cxn.set_option(ldap.OPT_X_TLS, ldap.OPT_X_TLS_TRY)
-        elif self.tlsRequireCert == &quot;demand&quot;:
-            cxn.set_option(ldap.OPT_X_TLS, ldap.OPT_X_TLS_DEMAND)
-        elif self.tlsRequireCert == &quot;hard&quot;:
-            cxn.set_option(ldap.OPT_X_TLS, ldap.OPT_X_TLS_HARD)
-
-        if self.tls:
-            cxn.start_tls_s()
-
-        return cxn
-
-
-    def authenticate(self, dn, password):
-        &quot;&quot;&quot;
-        Perform simple bind auth, raising ldap.INVALID_CREDENTIALS if
-        bad password
-        &quot;&quot;&quot;
-        TRIES = 3
-
-        for _ignore_i in xrange(TRIES):
-            self.log.debug(&quot;Authenticating {dn}&quot;, dn=dn)
-
-            if self.authLDAP is None:
-                self.log.debug(&quot;Creating authentication connection to LDAP&quot;)
-                self.authLDAP = self.createLDAPConnection()
-
-            try:
-                startTime = time.time()
-                self.authLDAP.simple_bind_s(dn, password)
-                # Getting here means success, so break the retry loop
-                break
-
-            except ldap.INAPPROPRIATE_AUTH:
-                # Seen when using an empty password, treat as invalid creds
-                raise ldap.INVALID_CREDENTIALS()
-
-            except ldap.NO_SUCH_OBJECT:
-                self.log.error(
-                    &quot;LDAP Authentication error for {dn}: NO_SUCH_OBJECT&quot;,
-                    dn=dn
-                )
-                # fall through to try again; could be transient
-
-            except ldap.INVALID_CREDENTIALS:
-                raise
-
-            except ldap.SERVER_DOWN:
-                self.log.error(&quot;Lost connection to LDAP server.&quot;)
-                self.authLDAP = None
-                # Fall through and retry if TRIES has been reached
-
-            except Exception, e:
-                self.log.error(
-                    &quot;LDAP authentication failed with {e}.&quot;, e=e
-                )
-                raise
-
-            finally:
-                totalTime = time.time() - startTime
-                if totalTime &gt; self.warningThresholdSeconds:
-                    self.log.error(
-                        &quot;LDAP auth exceeded threshold: {time:.2f} seconds for &quot;
-                        &quot;{dn}&quot;, time=totalTime, dn=dn
-                    )
-
-        else:
-            self.log.error(
-                &quot;Giving up on LDAP authentication after {count:d} tries.  &quot;
-                &quot;Responding with 503.&quot;, count=TRIES
-            )
-            raise HTTPError(StatusResponse(
-                responsecode.SERVICE_UNAVAILABLE, &quot;LDAP server unavailable&quot;
-            ))
-
-        self.log.debug(&quot;Authentication succeeded for {dn}&quot;, dn=dn)
-
-
-    def timedSearch(
-        self, base, scope, filterstr=&quot;(objectClass=*)&quot;, attrlist=None,
-        timeoutSeconds=-1, resultLimit=0
-    ):
-        &quot;&quot;&quot;
-        Execute an LDAP query, retrying up to 3 times in case the LDAP server
-        has gone down and we need to reconnect. If it takes longer than the
-        configured threshold, emit a log error.
-        The number of records requested is controlled by resultLimit (0=no
-        limit).
-        If timeoutSeconds is not -1, the query will abort after the specified
-        number of seconds and the results retrieved so far are returned.
-        &quot;&quot;&quot;
-        TRIES = 3
-
-        for i in xrange(TRIES):
-            try:
-                s = ldap.async.List(self.getLDAPConnection())
-                s.startSearch(
-                    base, scope, filterstr, attrList=attrlist,
-                    timeout=timeoutSeconds, sizelimit=resultLimit
-                )
-                startTime = time.time()
-                s.processResults()
-            except ldap.NO_SUCH_OBJECT:
-                return []
-            except ldap.FILTER_ERROR, e:
-                self.log.error(
-                    &quot;LDAP filter error: {e} {filter}&quot;, e=e, filter=filterstr
-                )
-                return []
-            except ldap.SIZELIMIT_EXCEEDED, e:
-                self.log.debug(
-                    &quot;LDAP result limit exceeded: {limit:d}&quot;, limit=resultLimit
-                )
-            except ldap.TIMELIMIT_EXCEEDED, e:
-                self.log.warn(
-                    &quot;LDAP timeout exceeded: {t:d} seconds&quot;, t=timeoutSeconds
-                )
-            except ldap.SERVER_DOWN:
-                self.ldap = None
-                self.log.error(
-                    &quot;LDAP server unavailable (tried {count:d} times)&quot;,
-                    count=(i + 1)
-                )
-                continue
-
-            # change format, ignoring resultsType
-            result = [
-                resultItem for _ignore_resultType, resultItem in s.allResults
-            ]
-
-            totalTime = time.time() - startTime
-            if totalTime &gt; self.warningThresholdSeconds:
-                if filterstr and len(filterstr) &gt; 100:
-                    filterstr = &quot;%s...&quot; % (filterstr[:100],)
-                self.log.error(
-                    &quot;LDAP query exceeded threshold: {time:.2f} seconds for &quot;
-                    &quot;{base} {filter} {attrs} (#results={count:d})&quot;,
-                    time=totalTime, base=base, filter=filterstr,
-                    attrs=attrlist, count=len(result),
-                )
-            return result
-
-        raise HTTPError(StatusResponse(
-            responsecode.SERVICE_UNAVAILABLE, &quot;LDAP server unavailable&quot;
-        ))
-
-
-    def isAllowedByRestrictToGroup(self, dn, attrs):
-        &quot;&quot;&quot;
-        Check to see if the principal with the given DN and LDAP attributes is
-        a member of the restrictToGroup.
-
-        @param dn: an LDAP dn
-        @type dn: C{str}
-        @param attrs: LDAP attributes
-        @type attrs: C{dict}
-        @return: True if principal is in the group (or restrictEnabledRecords if turned off).
-        @rtype: C{boolean}
-        &quot;&quot;&quot;
-        if not self.restrictEnabledRecords:
-            return True
-        if self.groupSchema[&quot;memberIdAttr&quot;]:
-            value = self._getUniqueLdapAttribute(
-                attrs, self.groupSchema[&quot;memberIdAttr&quot;]
-            )
-        else:  # No memberIdAttr implies DN
-            value = dn
-        return value in self.restrictedPrincipals
-
-
-    @property
-    def restrictedPrincipals(self):
-        &quot;&quot;&quot;
-        Look up (and cache) the set of guids that are members of the
-        restrictToGroup.  If restrictToGroup is not set, return None to
-        indicate there are no group restrictions.
-        &quot;&quot;&quot;
-        if self.restrictEnabledRecords:
-
-            if time.time() - self.restrictedTimestamp &gt; self.cacheTimeout:
-                # fault in the members of group of name self.restrictToGroup
-                recordType = self.recordType_groups
-                base = self.typeDNs[recordType]
-                # TODO: This shouldn't be hardcoded to cn
-                filterstr = &quot;(cn=%s)&quot; % (self.restrictToGroup,)
-                self.log.debug(
-                    &quot;Retrieving ldap record with base {base} and filter &quot;
-                    &quot;{filter}.&quot;,
-                    base=ldap.dn.dn2str(base), filter=filterstr
-                )
-                result = self.timedSearch(
-                    ldap.dn.dn2str(base),
-                    ldap.SCOPE_SUBTREE,
-                    filterstr=filterstr,
-                    attrlist=self.attrlist
-                )
-
-                members = []
-                nestedGroups = []
-
-                if len(result) == 1:
-                    dn, attrs = result[0]
-                    dn = normalizeDNstr(dn)
-                    if self.groupSchema[&quot;membersAttr&quot;]:
-                        members = self._getMultipleLdapAttributes(
-                            attrs,
-                            self.groupSchema[&quot;membersAttr&quot;]
-                        )
-                        if not self.groupSchema[&quot;memberIdAttr&quot;]:  # DNs
-                            members = [normalizeDNstr(m) for m in members]
-                        members = set(members)
-
-                    if self.groupSchema[&quot;nestedGroupsAttr&quot;]:
-                        nestedGroups = self._getMultipleLdapAttributes(
-                            attrs,
-                            self.groupSchema[&quot;nestedGroupsAttr&quot;]
-                        )
-                        if not self.groupSchema[&quot;memberIdAttr&quot;]:  # DNs
-                            nestedGroups = [
-                                normalizeDNstr(g) for g in nestedGroups
-                            ]
-                        nestedGroups = set(nestedGroups)
-                    else:
-                        # Since all members are lumped into the same attribute,
-                        # treat them all as nestedGroups instead
-                        nestedGroups = members
-                        members = set()
-
-                self._cachedRestrictedPrincipals = set(
-                    self._expandGroupMembership(members, nestedGroups)
-                )
-                self.log.info(
-                    &quot;Got {count} restricted group members&quot;,
-                    count=len(self._cachedRestrictedPrincipals)
-                )
-                self.restrictedTimestamp = time.time()
-            return self._cachedRestrictedPrincipals
-        else:
-            # No restrictions
-            return None
-
-
-    def _expandGroupMembership(self, members, nestedGroups, processedItems=None):
-        &quot;&quot;&quot;
-        A generator which recursively yields principals which are included within nestedGroups
-
-        @param members:  If the LDAP service is configured to use different attributes to
-            indicate member users and member nested groups, members will include the non-groups.
-            Otherwise, members will be empty and only nestedGroups will be used.
-        @type members: C{set}
-        @param nestedGroups:  If the LDAP service is configured to use different attributes to
-            indicate member users and member nested groups, nestedGroups will include only
-            the groups; otherwise nestedGroups will include all members
-        @type members: C{set}
-        @param processedItems: The set of members that have already been looked up in LDAP
-            so the code doesn't have to look up the same member twice or get stuck in a
-            membership loop.
-        @type processedItems: C{set}
-        @return: All members of the group, the values will correspond to memberIdAttr
-            if memberIdAttr is set in the group schema, or DNs otherwise.
-        @rtype: generator of C{str}
-        &quot;&quot;&quot;
-
-        if processedItems is None:
-            processedItems = set()
-
-        if isinstance(members, str):
-            members = [members]
-
-        if isinstance(nestedGroups, str):
-            nestedGroups = [nestedGroups]
-
-        for member in members:
-            if member not in processedItems:
-                processedItems.add(member)
-                yield member
-
-        for group in nestedGroups:
-            if group in processedItems:
-                continue
-
-            recordType = self.recordType_groups
-            base = self.typeDNs[recordType]
-            if self.groupSchema[&quot;memberIdAttr&quot;]:
-                scope = ldap.SCOPE_SUBTREE
-                base = self.typeDNs[recordType]
-                filterstr = &quot;(%s=%s)&quot; % (self.groupSchema[&quot;memberIdAttr&quot;], group)
-            else:  # Use DN
-                scope = ldap.SCOPE_BASE
-                base = ldap.dn.str2dn(group)
-                filterstr = &quot;(objectClass=*)&quot;
-
-            self.log.debug(
-                &quot;Retrieving ldap record with base {base} and filter {filter}.&quot;,
-                base=ldap.dn.dn2str(base), filter=filterstr
-            )
-            result = self.timedSearch(ldap.dn.dn2str(base),
-                                      scope,
-                                      filterstr=filterstr,
-                                      attrlist=self.attrlist)
-
-            if len(result) == 0:
-                continue
-
-            subMembers = set()
-            subNestedGroups = set()
-            if len(result) == 1:
-                dn, attrs = result[0]
-                dn = normalizeDNstr(dn)
-                if self.groupSchema[&quot;membersAttr&quot;]:
-                    subMembers = self._getMultipleLdapAttributes(
-                        attrs,
-                        self.groupSchema[&quot;membersAttr&quot;]
-                    )
-                    if not self.groupSchema[&quot;memberIdAttr&quot;]:  # these are DNs
-                        subMembers = [normalizeDNstr(m) for m in subMembers]
-                    subMembers = set(subMembers)
-
-                if self.groupSchema[&quot;nestedGroupsAttr&quot;]:
-                    subNestedGroups = self._getMultipleLdapAttributes(
-                        attrs,
-                        self.groupSchema[&quot;nestedGroupsAttr&quot;]
-                    )
-                    if not self.groupSchema[&quot;memberIdAttr&quot;]:  # these are DNs
-                        subNestedGroups = [normalizeDNstr(g) for g in subNestedGroups]
-                    subNestedGroups = set(subNestedGroups)
-
-            processedItems.add(group)
-            yield group
-
-            for item in self._expandGroupMembership(subMembers,
-                                                    subNestedGroups,
-                                                    processedItems):
-                yield item
-
-
-    def _getUniqueLdapAttribute(self, attrs, *keys):
-        &quot;&quot;&quot;
-        Get the first value for one or several attributes
-        Useful when attributes have aliases (e.g. sn vs. surname)
-        &quot;&quot;&quot;
-        for key in keys:
-            values = attrs.get(key)
-            if values is not None:
-                return values[0]
-        return None
-
-
-    def _getMultipleLdapAttributes(self, attrs, *keys):
-        &quot;&quot;&quot;
-        Get all values for one or several attributes
-        &quot;&quot;&quot;
-        results = []
-        for key in keys:
-            if key:
-                values = attrs.get(key)
-                if values is not None:
-                    results += values
-        return results
-
-
-    def _ldapResultToRecord(self, dn, attrs, recordType):
-        &quot;&quot;&quot;
-        Convert the attrs returned by a LDAP search into a LdapDirectoryRecord
-        object.
-
-        If guidAttr was specified in the config but is missing from attrs,
-        raises MissingGuidException
-        &quot;&quot;&quot;
-
-        guid = None
-        authIDs = set()
-        fullName = None
-        firstName = &quot;&quot;
-        lastName = &quot;&quot;
-        emailAddresses = set()
-        enabledForCalendaring = None
-        enabledForAddressBooks = None
-        uid = None
-        enabledForLogin = True
-        extras = {}
-
-        shortNames = tuple(self._getMultipleLdapAttributes(attrs, self.rdnSchema[recordType][&quot;mapping&quot;][&quot;recordName&quot;]))
-        if not shortNames:
-            raise MissingRecordNameException()
-
-        # First check for and add guid
-        guidAttr = self.rdnSchema[&quot;guidAttr&quot;]
-        if guidAttr:
-            guid = self._getUniqueLdapAttribute(attrs, guidAttr)
-            if not guid:
-                self.log.debug(
-                    &quot;LDAP data for {shortNames} is missing guid attribute &quot;
-                    &quot;{attr}&quot;,
-                    shortNames=shortNames, attr=guidAttr
-                )
-                raise MissingGuidException()
-            guid = normalizeUUID(guid)
-
-        # Find or build email
-        # (The emailAddresses mapping is a list of ldap fields)
-        emailAddressesMappedTo = self.rdnSchema[recordType][&quot;mapping&quot;].get(&quot;emailAddresses&quot;, &quot;&quot;)
-        # Supporting either string or list for emailAddresses:
-        if isinstance(emailAddressesMappedTo, str):
-            emailAddresses = set(self._getMultipleLdapAttributes(attrs, self.rdnSchema[recordType][&quot;mapping&quot;].get(&quot;emailAddresses&quot;, &quot;&quot;)))
-        else:
-            emailAddresses = set(self._getMultipleLdapAttributes(attrs, *self.rdnSchema[recordType][&quot;mapping&quot;][&quot;emailAddresses&quot;]))
-        emailSuffix = self.rdnSchema[recordType].get(&quot;emailSuffix&quot;, None)
-
-        if len(emailAddresses) == 0 and emailSuffix:
-            emailPrefix = self._getUniqueLdapAttribute(
-                attrs,
-                self.rdnSchema[recordType].get(&quot;attr&quot;, &quot;cn&quot;)
-            )
-            emailAddresses.add(emailPrefix + emailSuffix)
-
-        proxyGUIDs = ()
-        readOnlyProxyGUIDs = ()
-        autoSchedule = False
-        autoAcceptGroup = &quot;&quot;
-        memberGUIDs = []
-
-        # LDAP attribute -&gt; principal matchings
-        if recordType == self.recordType_users:
-            fullName = self._getUniqueLdapAttribute(attrs, self.rdnSchema[recordType][&quot;mapping&quot;][&quot;fullName&quot;])
-            firstName = self._getUniqueLdapAttribute(attrs, self.rdnSchema[recordType][&quot;mapping&quot;][&quot;firstName&quot;])
-            lastName = self._getUniqueLdapAttribute(attrs, self.rdnSchema[recordType][&quot;mapping&quot;][&quot;lastName&quot;])
-            enabledForCalendaring = True
-            enabledForAddressBooks = True
-
-        elif recordType == self.recordType_groups:
-            fullName = self._getUniqueLdapAttribute(attrs, self.rdnSchema[recordType][&quot;mapping&quot;][&quot;fullName&quot;])
-            enabledForCalendaring = False
-            enabledForAddressBooks = False
-            enabledForLogin = False
-
-            if self.groupSchema[&quot;membersAttr&quot;]:
-                members = self._getMultipleLdapAttributes(attrs, self.groupSchema[&quot;membersAttr&quot;])
-                memberGUIDs.extend(members)
-            if self.groupSchema[&quot;nestedGroupsAttr&quot;]:
-                members = self._getMultipleLdapAttributes(attrs, self.groupSchema[&quot;nestedGroupsAttr&quot;])
-                memberGUIDs.extend(members)
-
-            # Normalize members if they're in DN form
-            if not self.groupSchema[&quot;memberIdAttr&quot;]:  # empty = dn
-                guids = list(memberGUIDs)
-                memberGUIDs = []
-                for dnStr in guids:
-                    try:
-                        dnStr = normalizeDNstr(dnStr)
-                        memberGUIDs.append(dnStr)
-                    except Exception, e:
-                        # LDAP returned an illegal DN value, log and ignore it
-                        self.log.warn(&quot;Bad LDAP DN: {dn!r}&quot;, dn=dnStr)
-
-        elif recordType in (self.recordType_resources,
-                            self.recordType_locations):
-            fullName = self._getUniqueLdapAttribute(attrs, self.rdnSchema[recordType][&quot;mapping&quot;][&quot;fullName&quot;])
-            enabledForCalendaring = True
-            enabledForAddressBooks = False
-            enabledForLogin = False
-            if self.resourceSchema[&quot;resourceInfoAttr&quot;]:
-                resourceInfo = self._getUniqueLdapAttribute(
-                    attrs,
-                    self.resourceSchema[&quot;resourceInfoAttr&quot;]
-                )
-                if resourceInfo:
-                    try:
-                        (
-                            autoSchedule,
-                            proxy,
-                            readOnlyProxy,
-                            autoAcceptGroup
-                        ) = self.parseResourceInfo(
-                            resourceInfo,
-                            guid,
-                            recordType,
-                            shortNames[0]
-                        )
-                        if proxy:
-                            proxyGUIDs = (proxy,)
-                        if readOnlyProxy:
-                            readOnlyProxyGUIDs = (readOnlyProxy,)
-                    except ValueError, e:
-                        self.log.error(
-                            &quot;Unable to parse resource info: {e}&quot;, e=e
-                        )
-            else:  # the individual resource attributes might be specified
-                if self.resourceSchema[&quot;autoScheduleAttr&quot;]:
-                    autoScheduleValue = self._getUniqueLdapAttribute(
-                        attrs,
-                        self.resourceSchema[&quot;autoScheduleAttr&quot;]
-                    )
-                    autoSchedule = (
-                        autoScheduleValue == self.resourceSchema[&quot;autoScheduleEnabledValue&quot;]
-                    )
-                if self.resourceSchema[&quot;proxyAttr&quot;]:
-                    proxyGUIDs = set(
-                        self._getMultipleLdapAttributes(
-                            attrs,
-                            self.resourceSchema[&quot;proxyAttr&quot;]
-                        )
-                    )
-                if self.resourceSchema[&quot;readOnlyProxyAttr&quot;]:
-                    readOnlyProxyGUIDs = set(
-                        self._getMultipleLdapAttributes(
-                            attrs,
-                            self.resourceSchema[&quot;readOnlyProxyAttr&quot;]
-                        )
-                    )
-                if self.resourceSchema[&quot;autoAcceptGroupAttr&quot;]:
-                    autoAcceptGroup = self._getUniqueLdapAttribute(
-                        attrs,
-                        self.resourceSchema[&quot;autoAcceptGroupAttr&quot;]
-                    )
-
-            if recordType == self.recordType_locations:
-                if self.rdnSchema[recordType].get(&quot;associatedAddressAttr&quot;, &quot;&quot;):
-                    associatedAddress = self._getUniqueLdapAttribute(
-                        attrs,
-                        self.rdnSchema[recordType][&quot;associatedAddressAttr&quot;]
-                    )
-                    if associatedAddress:
-                        extras[&quot;associatedAddress&quot;] = associatedAddress
-
-        elif recordType == self.recordType_addresses:
-            if self.rdnSchema[recordType].get(&quot;geoAttr&quot;, &quot;&quot;):
-                geo = self._getUniqueLdapAttribute(
-                    attrs,
-                    self.rdnSchema[recordType][&quot;geoAttr&quot;]
-                )
-                if geo:
-                    extras[&quot;geo&quot;] = geo
-            if self.rdnSchema[recordType].get(&quot;streetAddressAttr&quot;, &quot;&quot;):
-                street = self._getUniqueLdapAttribute(
-                    attrs,
-                    self.rdnSchema[recordType][&quot;streetAddressAttr&quot;]
-                )
-                if street:
-                    extras[&quot;streetAddress&quot;] = street
-
-        serverID = None
-        if self.poddingSchema[&quot;serverIdAttr&quot;]:
-            serverID = self._getUniqueLdapAttribute(
-                attrs,
-                self.poddingSchema[&quot;serverIdAttr&quot;]
-            )
-
-        record = LdapDirectoryRecord(
-            service=self,
-            recordType=recordType,
-            guid=guid,
-            shortNames=shortNames,
-            authIDs=authIDs,
-            fullName=fullName,
-            firstName=firstName,
-            lastName=lastName,
-            emailAddresses=emailAddresses,
-            uid=uid,
-            dn=dn,
-            memberGUIDs=memberGUIDs,
-            extProxies=proxyGUIDs,
-            extReadOnlyProxies=readOnlyProxyGUIDs,
-            attrs=attrs,
-            **extras
-        )
-
-        if self.augmentService is not None:
-            # Look up augment information
-            # TODO: this needs to be deferred but for now we hard code
-            # the deferred result because we know it is completing
-            # immediately.
-            d = self.augmentService.getAugmentRecord(record.guid, recordType)
-            d.addCallback(lambda x: record.addAugmentInformation(x))
-
-        else:
-            # Generate augment record based on information retrieved from LDAP
-            augmentRecord = AugmentRecord(
-                guid,
-                enabled=True,
-                serverID=serverID,
-                enabledForCalendaring=enabledForCalendaring,
-                autoSchedule=autoSchedule,
-                autoAcceptGroup=autoAcceptGroup,
-                enabledForAddressBooks=enabledForAddressBooks,  # TODO: add to LDAP?
-                enabledForLogin=enabledForLogin,
-            )
-            record.addAugmentInformation(augmentRecord)
-
-        # Override with LDAP login control if attribute specified
-        if recordType == self.recordType_users:
-            loginEnabledAttr = self.rdnSchema[recordType][&quot;loginEnabledAttr&quot;]
-            if loginEnabledAttr:
-                loginEnabledValue = self.rdnSchema[recordType][&quot;loginEnabledValue&quot;]
-                record.enabledForLogin = self._getUniqueLdapAttribute(
-                    attrs, loginEnabledAttr
-                ) == loginEnabledValue
-
-        # Override with LDAP calendar-enabled control if attribute specified
-        calendarEnabledAttr = self.rdnSchema[recordType].get(&quot;calendarEnabledAttr&quot;, &quot;&quot;)
-        if calendarEnabledAttr:
-            calendarEnabledValue = self.rdnSchema[recordType][&quot;calendarEnabledValue&quot;]
-            record.enabledForCalendaring = self._getUniqueLdapAttribute(
-                attrs,
-                calendarEnabledAttr
-            ) == calendarEnabledValue
-
-        return record
-
-
-    def queryDirectory(
-        self, recordTypes, indexType, indexKey, queryMethod=None
-    ):
-        &quot;&quot;&quot;
-        Queries the LDAP directory for the record which has an attribute value
-        matching the indexType and indexKey parameters.
-
-        recordTypes is a list of record types to limit the search to.
-        indexType specifies one of the CachingDirectoryService constants
-            identifying which attribute to search on.
-        indexKey is the value to search for.
-
-        Nothing is returned -- the resulting record (if any) is placed in
-        the cache.
-        &quot;&quot;&quot;
-
-        if queryMethod is None:
-            queryMethod = self.timedSearch
-
-        self.log.debug(
-            &quot;LDAP query for types {types}, indexType {indexType} and &quot;
-            &quot;indexKey {indexKey}&quot;,
-            types=recordTypes, indexType=indexType, indexKey=indexKey
-        )
-
-        guidAttr = self.rdnSchema[&quot;guidAttr&quot;]
-        for recordType in recordTypes:
-            # Build base for this record Type
-            base = self.typeDNs[recordType]
-
-            # Build filter
-            filterstr = &quot;(!(objectClass=organizationalUnit))&quot;
-            typeFilter = self.rdnSchema[recordType].get(&quot;filter&quot;, &quot;&quot;)
-            if typeFilter:
-                filterstr = &quot;(&amp;%s%s)&quot; % (filterstr, typeFilter)
-
-            if indexType == self.INDEX_TYPE_GUID:
-                # Query on guid only works if guid attribute has been defined.
-                # Support for query on guid even if is auto-generated should
-                # be added.
-                if not guidAttr:
-                    return
-                filterstr = &quot;(&amp;%s(%s=%s))&quot; % (filterstr, guidAttr, indexKey)
-
-            elif indexType == self.INDEX_TYPE_SHORTNAME:
-                filterstr = &quot;(&amp;%s(%s=%s))&quot; % (
-                    filterstr,
-                    self.rdnSchema[recordType][&quot;mapping&quot;][&quot;recordName&quot;],
-                    ldapEsc(indexKey)
-                )
-
-            elif indexType == self.INDEX_TYPE_CUA:
-                # indexKey is of the form &quot;mailto:test@example.net&quot;
-                email = indexKey[7:]  # strip &quot;mailto:&quot;
-                emailSuffix = self.rdnSchema[recordType].get(
-                    &quot;emailSuffix&quot;, None
-                )
-                if (
-                    emailSuffix is not None and
-                    email.partition(&quot;@&quot;)[2] == emailSuffix
-                ):
-                    filterstr = &quot;(&amp;%s(|(&amp;(!(mail=*))(%s=%s))(mail=%s)))&quot; % (
-                        filterstr,
-                        self.rdnSchema[recordType].get(&quot;attr&quot;, &quot;cn&quot;),
-                        email.partition(&quot;@&quot;)[0],
-                        ldapEsc(email)
-                    )
-                else:
-                    # emailAddresses can map to multiple LDAP fields
-                    ldapFields = self.rdnSchema[recordType][&quot;mapping&quot;].get(
-                        &quot;emailAddresses&quot;, &quot;&quot;
-                    )
-                    if isinstance(ldapFields, str):
-                        if ldapFields:
-                            subfilter = (
-                                &quot;(%s=%s)&quot; % (ldapFields, ldapEsc(email))
-                            )
-                        else:
-                            # No LDAP attribute assigned for emailAddresses
-                            continue
-
-                    else:
-                        subfilter = []
-                        for ldapField in ldapFields:
-                            if ldapField:
-                                subfilter.append(
-                                    &quot;(%s=%s)&quot; % (ldapField, ldapEsc(email))
-                                )
-                        if not subfilter:
-                            # No LDAP attribute assigned for emailAddresses
-                            continue
-
-                        subfilter = &quot;(|%s)&quot; % (&quot;&quot;.join(subfilter))
-                    filterstr = &quot;(&amp;%s%s)&quot; % (filterstr, subfilter)
-
-            elif indexType == self.INDEX_TYPE_AUTHID:
-                return
-
-            # Query the LDAP server
-            self.log.debug(
-                &quot;Retrieving ldap record with base %s and filter %s.&quot;,
-                base=ldap.dn.dn2str(base), filter=filterstr,
-            )
-            result = queryMethod(
-                ldap.dn.dn2str(base),
-                ldap.SCOPE_SUBTREE,
-                filterstr=filterstr,
-                attrlist=self.attrlist,
-            )
-
-            if result:
-                dn, attrs = result.pop()
-                dn = normalizeDNstr(dn)
-
-                unrestricted = self.isAllowedByRestrictToGroup(dn, attrs)
-
-                try:
-                    record = self._ldapResultToRecord(dn, attrs, recordType)
-                    self.log.debug(&quot;Got LDAP record {rec}&quot;, rec=record)
-
-                    if not unrestricted:
-                        self.log.debug(
-                            &quot;{dn} is not enabled because it's not a member of &quot;
-                            &quot;group {group!r}&quot;,
-                            dn=dn, group=self.restrictToGroup
-                        )
-                        record.enabledForCalendaring = False
-                        record.enabledForAddressBooks = False
-
-                    record.applySACLs()
-
-                    self.recordCacheForType(recordType).addRecord(
-                        record, indexType, indexKey
-                    )
-
-                    # We got a match, so don't bother checking other types
-                    break
-
-                except MissingRecordNameException:
-                    self.log.warn(
-                        &quot;Ignoring record missing record name &quot;
-                        &quot;attribute: recordType {recordType}, indexType &quot;
-                        &quot;{indexType} and indexKey {indexKey}&quot;,
-                        recordTypes=recordTypes, indexType=indexType,
-                        indexKey=indexKey,
-                    )
-
-                except MissingGuidException:
-                    self.log.warn(
-                        &quot;Ignoring record missing guid attribute: &quot;
-                        &quot;recordType {recordType}, indexType {indexType} and &quot;
-                        &quot;indexKey {indexKey}&quot;,
-                        recordTypes=recordTypes, indexType=indexType,
-                        indexKey=indexKey
-                    )
-
-
-    def recordsMatchingTokens(self, tokens, context=None, limitResults=50, timeoutSeconds=10):
-        &quot;&quot;&quot;
-        # TODO: hook up limitResults to the client limit in the query
-
-        @param tokens: The tokens to search on
-        @type tokens: C{list} of C{str} (utf-8 bytes)
-        @param context: An indication of what the end user is searching
-            for; &quot;attendee&quot;, &quot;location&quot;, or None
-        @type context: C{str}
-        @return: a deferred sequence of L{IDirectoryRecord}s which
-            match the given tokens and optional context.
-
-        Each token is searched for within each record's full name and
-        email address; if each token is found within a record that
-        record is returned in the results.
-
-        If context is None, all record types are considered.  If
-        context is &quot;location&quot;, only locations are considered.  If
-        context is &quot;attendee&quot;, only users, groups, and resources
-        are considered.
-        &quot;&quot;&quot;
-        self.log.debug(
-            &quot;Peforming calendar user search for {tokens} ({context})&quot;,
-            tokens=tokens, context=context
-        )
-        startTime = time.time()
-        records = []
-        recordTypes = self.recordTypesForSearchContext(context)
-        recordTypes = [r for r in recordTypes if r in self.recordTypes()]
-
-        typeCounts = {}
-        for recordType in recordTypes:
-            if limitResults == 0:
-                self.log.debug(&quot;LDAP search aggregate limit reached&quot;)
-                break
-            typeCounts[recordType] = 0
-            base = self.typeDNs[recordType]
-            scope = ldap.SCOPE_SUBTREE
-            extraFilter = self.rdnSchema[recordType].get(&quot;filter&quot;, &quot;&quot;)
-            filterstr = buildFilterFromTokens(
-                recordType,
-                self.rdnSchema[recordType][&quot;mapping&quot;],
-                tokens,
-                extra=extraFilter
-            )
-
-            if filterstr is not None:
-                # Query the LDAP server
-                self.log.debug(
-                    &quot;LDAP search {base} {filter} (limit={limit:d})&quot;,
-                    base=ldap.dn.dn2str(base), filter=filterstr,
-                    limit=limitResults,
-                )
-                results = self.timedSearch(
-                    ldap.dn.dn2str(base),
-                    scope,
-                    filterstr=filterstr,
-                    attrlist=self.attrlist,
-                    timeoutSeconds=timeoutSeconds,
-                    resultLimit=limitResults
-                )
-                numMissingGuids = 0
-                numMissingRecordNames = 0
-                numNotEnabled = 0
-                for dn, attrs in results:
-                    dn = normalizeDNstr(dn)
-                    # Skip if group restriction is in place and guid is not
-                    # a member
-                    if (
-                            recordType != self.recordType_groups and
-                            not self.isAllowedByRestrictToGroup(dn, attrs)
-                    ):
-                        continue
-
-                    try:
-                        record = self._ldapResultToRecord(dn, attrs, recordType)
-
-                        # For non-group records, if not enabled for calendaring do
-                        # not include in principal property search results
-                        if (recordType != self.recordType_groups):
-                            if not record.enabledForCalendaring:
-                                numNotEnabled += 1
-                                continue
-
-                        records.append(record)
-                        typeCounts[recordType] += 1
-                        limitResults -= 1
-
-                    except MissingGuidException:
-                        numMissingGuids += 1
-
-                    except MissingRecordNameException:
-                        numMissingRecordNames += 1
-
-                self.log.debug(
-                    &quot;LDAP search returned {resultCount:d} results, &quot;
-                    &quot;{typeCount:d} usable&quot;,
-                    resultCount=len(results), typeCount=typeCounts[recordType]
-                )
-
-        typeCountsStr = &quot;, &quot;.join(
-            [&quot;%s:%d&quot; % (rt, ct) for (rt, ct) in typeCounts.iteritems()]
-        )
-        totalTime = time.time() - startTime
-        self.log.info(
-            &quot;Calendar user search for {tokens} matched {recordCount:d} &quot;
-            &quot;records ({typeCount}) in {time!.2f} seconds&quot;,
-            tokens=tokens, recordCount=len(records),
-            typeCount=typeCountsStr, time=totalTime,
-        )
-        return succeed(records)
-
-
-    @inlineCallbacks
-    def recordsMatchingFields(self, fields, operand=&quot;or&quot;, recordType=None):
-        &quot;&quot;&quot;
-        Carries out the work of a principal-property-search against LDAP
-        Returns a deferred list of directory records.
-        &quot;&quot;&quot;
-        records = []
-
-        self.log.debug(
-            &quot;Performing principal property search for {fields}&quot;, fields=fields
-        )
-
-        if recordType is None:
-            # Make a copy since we're modifying it
-            recordTypes = list(self.recordTypes())
-
-            # principal-property-search syntax doesn't provide a way to ask
-            # for 3 of the 4 types (either all types or a single type).  This
-            # is wasteful in the case of iCal looking for event attendees
-            # since it always ignores the locations.  This config flag lets
-            # you skip querying for locations in this case:
-            if not self.queryLocationsImplicitly:
-                if self.recordType_locations in recordTypes:
-                    recordTypes.remove(self.recordType_locations)
-        else:
-            recordTypes = [recordType]
-
-        guidAttr = self.rdnSchema[&quot;guidAttr&quot;]
-        for recordType in recordTypes:
-
-            base = self.typeDNs[recordType]
-
-            if fields[0][0] == &quot;dn&quot;:
-                # DN's are not an attribute that can be searched on by filter
-                scope = ldap.SCOPE_BASE
-                filterstr = &quot;(objectClass=*)&quot;
-                base = ldap.dn.str2dn(fields[0][1])
-
-            else:
-                scope = ldap.SCOPE_SUBTREE
-                filterstr = buildFilter(
-                    recordType,
-                    self.rdnSchema[recordType][&quot;mapping&quot;],
-                    fields,
-                    operand=operand,
-                    optimizeMultiName=self.optimizeMultiName
-                )
-
-            if filterstr is not None:
-                # Query the LDAP server
-                self.log.debug(
-                    &quot;LDAP search {base} {scope} {filter}&quot;,
-                    base=ldap.dn.dn2str(base), scope=scope, filter=filterstr
-                )
-                results = (yield deferToThread(
-                    self.timedSearch,
-                    ldap.dn.dn2str(base),
-                    scope,
-                    filterstr=filterstr,
-                    attrlist=self.attrlist,
-                    timeoutSeconds=self.requestTimeoutSeconds,
-                    resultLimit=self.requestResultsLimit)
-                )
-                self.log.debug(
-                    &quot;LDAP search returned {count} results&quot;, count=len(results)
-                )
-                numMissingGuids = 0
-                numMissingRecordNames = 0
-                for dn, attrs in results:
-                    dn = normalizeDNstr(dn)
-                    # Skip if group restriction is in place and guid is not
-                    # a member
-                    if (
-                        recordType != self.recordType_groups and
-                        not self.isAllowedByRestrictToGroup(dn, attrs)
-                    ):
-                        continue
-
-                    try:
-                        record = self._ldapResultToRecord(dn, attrs, recordType)
-
-                        # For non-group records, if not enabled for calendaring do
-                        # not include in principal property search results
-                        if (recordType != self.recordType_groups):
-                            if not record.enabledForCalendaring:
-                                continue
-
-                        records.append(record)
-
-                    except MissingGuidException:
-                        numMissingGuids += 1
-
-                    except MissingRecordNameException:
-                        numMissingRecordNames += 1
-
-                if numMissingGuids:
-                    self.log.warn(
-                        &quot;{count:d} {type} records are missing {attr}&quot;,
-                        count=numMissingGuids, type=recordType, attr=guidAttr
-                    )
-
-                if numMissingRecordNames:
-                    self.log.warn(
-                        &quot;{count:d} {type} records are missing record name&quot;,
-                        count=numMissingRecordNames, type=recordType,
-                    )
-
-        self.log.debug(
-            &quot;Principal property search matched {count} records&quot;,
-            count=len(records)
-        )
-        returnValue(records)
-
-
-    @inlineCallbacks
-    def getGroups(self, guids):
-        &quot;&quot;&quot;
-        Returns a set of group records for the list of guids passed in.  For
-        any group that also contains subgroups, those subgroups' records are
-        also returned, and so on.
-        &quot;&quot;&quot;
-
-        recordsByAlias = {}
-
-        groupsDN = self.typeDNs[self.recordType_groups]
-        memberIdAttr = self.groupSchema[&quot;memberIdAttr&quot;]
-
-        # First time through the loop we search using the attribute
-        # corresponding to guid, since that is what the proxydb uses.
-        # Subsequent iterations fault in groups via the attribute
-        # used to identify members.
-        attributeToSearch = &quot;guid&quot;
-        valuesToFetch = guids
-
-        while valuesToFetch:
-            results = []
-
-            if attributeToSearch == &quot;dn&quot;:
-                # Since DN can't be searched on in a filter we have to call
-                # recordsMatchingFields for *each* DN.
-                for value in valuesToFetch:
-                    fields = [[&quot;dn&quot;, value, False, &quot;equals&quot;]]
-                    result = (
-                        yield self.recordsMatchingFields(
-                            fields,
-                            recordType=self.recordType_groups
-                        )
-                    )
-                    results.extend(result)
-            else:
-                for batch in splitIntoBatches(valuesToFetch, self.batchSize):
-                    fields = []
-                    for value in batch:
-                        fields.append([attributeToSearch, value, False, &quot;equals&quot;])
-                    result = (
-                        yield self.recordsMatchingFields(
-                            fields,
-                            recordType=self.recordType_groups
-                        )
-                    )
-                    results.extend(result)
-
-            # Reset values for next iteration
-            valuesToFetch = set()
-
-            for record in results:
-                alias = record.cachedGroupsAlias()
-                if alias not in recordsByAlias:
-                    recordsByAlias[alias] = record
-
-                # record.memberGUIDs() contains the members of this group,
-                # but it might not be in guid form; it will be data from
-                # self.groupSchema[&quot;memberIdAttr&quot;]
-                for memberAlias in record.memberGUIDs():
-                    if not memberIdAttr:
-                        # Members are identified by dn so we can take a short
-                        # cut:  we know we only need to examine groups, and
-                        # those will be children of the groups DN
-                        if not dnContainedIn(ldap.dn.str2dn(memberAlias),
-                                             groupsDN):
-                            continue
-                    if memberAlias not in recordsByAlias:
-                        valuesToFetch.add(memberAlias)
-
-            # Switch to the LDAP attribute used for identifying members
-            # for subsequent iterations.  If memberIdAttr is not specified
-            # in the config, we'll search using dn.
-            attributeToSearch = &quot;memberIdAttr&quot; if memberIdAttr else &quot;dn&quot;
-
-        returnValue(recordsByAlias.values())
-
-
-    def recordTypeForDN(self, dnStr):
-        &quot;&quot;&quot;
-        Examine a DN to determine which recordType it belongs to
-        @param dn: DN to compare
-        @type dn: string
-        @return: recordType string, or None if no match
-        &quot;&quot;&quot;
-        dn = ldap.dn.str2dn(dnStr.lower())
-        for recordType in self.recordTypes():
-            base = self.typeDNs[recordType]  # already lowercase
-            if dnContainedIn(dn, base):
-                return recordType
-        return None
-
-
-
-def dnContainedIn(child, parent):
-    &quot;&quot;&quot;
-    Return True if child dn is contained within parent dn, otherwise False.
-    &quot;&quot;&quot;
-    return child[-len(parent):] == parent
-
-
-
-def normalizeDNstr(dnStr):
-    &quot;&quot;&quot;
-    Convert to lowercase and remove extra whitespace
-    @param dnStr: dn
-    @type dnStr: C{str}
-    @return: normalized dn C{str}
-    &quot;&quot;&quot;
-    return ' '.join(ldap.dn.dn2str(ldap.dn.str2dn(dnStr.lower())).split())
-
-
-
-def _convertValue(value, matchType):
-    if matchType == &quot;starts-with&quot;:
-        value = &quot;%s*&quot; % (ldapEsc(value),)
-    elif matchType == &quot;contains&quot;:
-        value = &quot;*%s*&quot; % (ldapEsc(value),)
-    # otherwise it's an exact match
-    else:
-        value = ldapEsc(value)
-    return value
-
-
-
-def buildFilter(recordType, mapping, fields, operand=&quot;or&quot;, optimizeMultiName=False):
-    &quot;&quot;&quot;
-    Create an LDAP filter string from a list of tuples representing directory
-    attributes to search
-
-    mapping is a dict mapping internal directory attribute names to ldap names.
-    fields is a list of tuples...
-        (directory field name, value to search, caseless (ignored), matchType)
-    ...where matchType is one of &quot;starts-with&quot;, &quot;contains&quot;, &quot;exact&quot;
-    &quot;&quot;&quot;
-
-    converted = []
-    combined = {}
-    for field, value, caseless, matchType in fields:
-        ldapField = mapping.get(field, None)
-        if ldapField:
-            combined.setdefault(field, []).append((value, caseless, matchType))
-            value = _convertValue(value, matchType)
-            if isinstance(ldapField, str):
-                converted.append(&quot;(%s=%s)&quot; % (ldapField, value))
-            else:
-                subConverted = []
-                for lf in ldapField:
-                    subConverted.append(&quot;(%s=%s)&quot; % (lf, value))
-                converted.append(&quot;(|%s)&quot; % &quot;&quot;.join(subConverted))
-
-    if len(converted) == 0:
-        return None
-
-    if optimizeMultiName and recordType in (&quot;users&quot;, &quot;groups&quot;):
-        for field in [key for key in combined.keys() if key != &quot;guid&quot;]:
-            if len(combined.get(field, [])) &gt; 1:
-                # Client is searching on more than one name -- interpret this as the user
-                # explicitly looking up a user by name (ignoring other record types), and
-                # try the various firstName/lastName permutations:
-                if recordType == &quot;users&quot;:
-                    converted = []
-                    for firstName, _ignore_firstCaseless, firstMatchType in combined[&quot;firstName&quot;]:
-                        for lastName, _ignore_lastCaseless, lastMatchType in combined[&quot;lastName&quot;]:
-                            if firstName != lastName:
-                                firstValue = _convertValue(firstName, firstMatchType)
-                                lastValue = _convertValue(lastName, lastMatchType)
-                                converted.append(
-                                    &quot;(&amp;(%s=%s)(%s=%s))&quot; %
-                                    (mapping[&quot;firstName&quot;], firstValue,
-                                     mapping[&quot;lastName&quot;], lastValue)
-                                )
-                else:
-                    return None
-
-    if len(converted) == 1:
-        filterstr = converted[0]
-    else:
-        operand = (&quot;|&quot; if operand == &quot;or&quot; else &quot;&amp;&quot;)
-        filterstr = &quot;(%s%s)&quot; % (operand, &quot;&quot;.join(converted))
-
-    if filterstr:
-        # To reduce the amount of records returned, filter out the ones
-        # that don't have (possibly) required attribute values (record
-        # name, guid)
-        additional = []
-        for key in (&quot;recordName&quot;, &quot;guid&quot;):
-            if key in mapping:
-                additional.append(&quot;(%s=*)&quot; % (mapping.get(key),))
-        if additional:
-            filterstr = &quot;(&amp;%s%s)&quot; % (&quot;&quot;.join(additional), filterstr)
-
-    return filterstr
-
-
-
-def buildFilterFromTokens(recordType, mapping, tokens, extra=None):
-    &quot;&quot;&quot;
-    Create an LDAP filter string from a list of query tokens.  Each token is
-    searched for in each LDAP attribute corresponding to &quot;fullName&quot; and
-    &quot;emailAddresses&quot; (could be multiple LDAP fields for either).
-
-    @param recordType: The recordType to use to customize the filter
-    @param mapping: A dict mapping internal directory attribute names to ldap names.
-    @type mapping: C{dict}
-    @param tokens: The list of tokens to search for
-    @type tokens: C{list}
-    @param extra: Extra filter to &quot;and&quot; into the final filter
-    @type extra: C{str} or None
-    @return: An LDAP filterstr
-    @rtype: C{str}
-    &quot;&quot;&quot;
-
-    filterStr = None
-
-    # Eliminate any substring duplicates
-    tokenSet = set()
-    for token in tokens:
-        collision = False
-        for existing in tokenSet:
-            if token in existing:
-                collision = True
-                break
-            elif existing in token:
-                tokenSet.remove(existing)
-                break
-        if not collision:
-            tokenSet.add(token)
-
-    tokens = [ldapEsc(t) for t in tokenSet]
-    if len(tokens) == 0:
-        return None
-    tokens.sort()
-
-    attributes = [
-        (&quot;fullName&quot;, &quot;(%s=*%s*)&quot;),
-        (&quot;emailAddresses&quot;, &quot;(%s=%s*)&quot;),
-    ]
-
-    ldapFields = []
-    for attribute, template in attributes:
-        ldapField = mapping.get(attribute, None)
-        if ldapField:
-            if isinstance(ldapField, str):
-                ldapFields.append((ldapField, template))
-            else:
-                for lf in ldapField:
-                    ldapFields.append((lf, template))
-
-    if len(ldapFields) == 0:
-        return None
-
-    tokenFragments = []
-    if extra:
-        tokenFragments.append(extra)
-
-    for token in tokens:
-        fragments = []
-        for ldapField, template in ldapFields:
-            fragments.append(template % (ldapField, token))
-        if len(fragments) == 1:
-            tokenFragment = fragments[0]
-        else:
-            tokenFragment = &quot;(|%s)&quot; % (&quot;&quot;.join(fragments),)
-        tokenFragments.append(tokenFragment)
-
-    if len(tokenFragments) == 1:
-        filterStr = tokenFragments[0]
-    else:
-        filterStr = &quot;(&amp;%s)&quot; % (&quot;&quot;.join(tokenFragments),)
-
-    return filterStr
-
-
-
-class LdapDirectoryRecord(CachingDirectoryRecord):
-    &quot;&quot;&quot;
-    LDAP implementation of L{IDirectoryRecord}.
-    &quot;&quot;&quot;
-    def __init__(
-        self, service, recordType,
-        guid, shortNames, authIDs, fullName,
-        firstName, lastName, emailAddresses,
-        uid, dn, memberGUIDs, extProxies, extReadOnlyProxies,
-        attrs, **kwargs
-    ):
-        super(LdapDirectoryRecord, self).__init__(
-            service=service,
-            recordType=recordType,
-            guid=guid,
-            shortNames=shortNames,
-            authIDs=authIDs,
-            fullName=fullName,
-            firstName=firstName,
-            lastName=lastName,
-            emailAddresses=emailAddresses,
-            extProxies=extProxies,
-            extReadOnlyProxies=extReadOnlyProxies,
-            uid=uid,
-            **kwargs
-        )
-
-        # Save attributes of dn and attrs in case you might need them later
-        self.dn = dn
-        self.attrs = attrs
-
-        # Store copy of member guids
-        self._memberGUIDs = memberGUIDs
-
-        # Identifier of this record as a group member
-        memberIdAttr = self.service.groupSchema[&quot;memberIdAttr&quot;]
-        if memberIdAttr:
-            self._memberId = self.service._getUniqueLdapAttribute(
-                attrs,
-                memberIdAttr
-            )
-        else:
-            self._memberId = normalizeDNstr(self.dn)
-
-
-    def members(self):
-        &quot;&quot;&quot; Return the records representing members of this group &quot;&quot;&quot;
-
-        try:
-            return self._members_storage
-        except AttributeError:
-            self._members_storage = self._members()
-            return self._members_storage
-
-
-    def _members(self):
-        &quot;&quot;&quot; Fault in records for the members of this group &quot;&quot;&quot;
-
-        memberIdAttr = self.service.groupSchema[&quot;memberIdAttr&quot;]
-        results = []
-
-        for memberId in self._memberGUIDs:
-
-            if memberIdAttr:
-
-                base = self.service.base
-                filterstr = &quot;(%s=%s)&quot; % (memberIdAttr, ldapEsc(memberId))
-                self.log.debug(
-                    &quot;Retrieving subtree of {base} with filter {filter}&quot;,
-                    base=ldap.dn.dn2str(base), filter=filterstr,
-                    system=&quot;LdapDirectoryService&quot;
-                )
-                result = self.service.timedSearch(
-                    ldap.dn.dn2str(base),
-                    ldap.SCOPE_SUBTREE,
-                    filterstr=filterstr,
-                    attrlist=self.service.attrlist
-                )
-
-            else:  # using DN
-
-                self.log.debug(
-                    &quot;Retrieving {id}.&quot;,
-                    id=memberId, system=&quot;LdapDirectoryService&quot;
-                )
-                result = self.service.timedSearch(
-                    memberId,
-                    ldap.SCOPE_BASE, attrlist=self.service.attrlist
-                )
-
-            if result:
-
-                dn, attrs = result.pop()
-                dn = normalizeDNstr(dn)
-                self.log.debug(&quot;Retrieved: {dn} {attrs}&quot;, dn=dn, attrs=attrs)
-                recordType = self.service.recordTypeForDN(dn)
-                if recordType is None:
-                    self.log.error(
-                        &quot;Unable to map {dn} to a record type&quot;, dn=dn
-                    )
-                    continue
-
-                shortName = self.service._getUniqueLdapAttribute(
-                    attrs,
-                    self.service.rdnSchema[recordType][&quot;mapping&quot;][&quot;recordName&quot;]
-                )
-
-                if shortName:
-                    record = self.service.recordWithShortName(
-                        recordType,
-                        shortName
-                    )
-                    if record:
-                        results.append(record)
-
-        return results
-
-
-    def groups(self):
-        &quot;&quot;&quot; Return the records representing groups this record is a member of &quot;&quot;&quot;
-        try:
-            return self._groups_storage
-        except AttributeError:
-            self._groups_storage = self._groups()
-            return self._groups_storage
-
-
-    def _groups(self):
-        &quot;&quot;&quot; Fault in the groups of which this record is a member &quot;&quot;&quot;
-
-        recordType = self.service.recordType_groups
-        base = self.service.typeDNs[recordType]
-
-        membersAttrs = []
-        if self.service.groupSchema[&quot;membersAttr&quot;]:
-            membersAttrs.append(self.service.groupSchema[&quot;membersAttr&quot;])
-        if self.service.groupSchema[&quot;nestedGroupsAttr&quot;]:
-            membersAttrs.append(self.service.groupSchema[&quot;nestedGroupsAttr&quot;])
-
-        if len(membersAttrs) == 1:
-            filterstr = &quot;(%s=%s)&quot; % (membersAttrs[0], self._memberId)
-        else:
-            filterstr = &quot;(|%s)&quot; % (
-                &quot;&quot;.join(
-                    [&quot;(%s=%s)&quot; % (a, self._memberId) for a in membersAttrs]
-                ),
-            )
-        self.log.debug(&quot;Finding groups containing {id}&quot;, id=self._memberId)
-        groups = []
-
-        try:
-            results = self.service.timedSearch(
-                ldap.dn.dn2str(base),
-                ldap.SCOPE_SUBTREE,
-                filterstr=filterstr,
-                attrlist=self.service.attrlist
-            )
-
-            for dn, attrs in results:
-                dn = normalizeDNstr(dn)
-                shortName = self.service._getUniqueLdapAttribute(attrs, &quot;cn&quot;)
-                self.log.debug(
-                    &quot;{id} is a member of {shortName}&quot;,
-                    id=self._memberId, shortName=shortName
-                )
-                record = self.service.recordWithShortName(recordType, shortName)
-                if record is not None:
-                    groups.append(record)
-        except ldap.PROTOCOL_ERROR, e:
-            self.log.warn(&quot;{e}&quot;, e=e)
-
-        return groups
-
-
-    def cachedGroupsAlias(self):
-        &quot;&quot;&quot;
-        See directory.py for full description
-
-        LDAP group members can be referred to by attributes other than guid.  _memberId
-        will be set to the appropriate value to look up group-membership with.
-        &quot;&quot;&quot;
-        return self._memberId
-
-
-    def memberGUIDs(self):
-        return set(self._memberGUIDs)
-
-
-    def verifyCredentials(self, credentials):
-        &quot;&quot;&quot; Supports PAM or simple LDAP bind for username+password &quot;&quot;&quot;
-
-        if isinstance(credentials, UsernamePassword):
-
-            # TODO: investigate:
-            # Check that the username supplied matches one of the shortNames
-            # (The DCS might already enforce this constraint, not sure)
-            if credentials.username not in self.shortNames:
-                return False
-
-            # Check cached password
-            try:
-                if credentials.password == self.password:
-                    return True
-            except AttributeError:
-                pass
-
-            if self.service.authMethod.upper() == &quot;PAM&quot;:
-                # Authenticate against PAM (UNTESTED)
-
-                if not pamAvailable:
-                    self.log.error(&quot;PAM module is not installed&quot;)
-                    raise DirectoryConfigurationError()
-
-                def pam_conv(auth, query_list, userData):
-                    return [(credentials.password, 0)]
-
-                auth = PAM.pam()
-                auth.start(&quot;caldav&quot;)
-                auth.set_item(PAM.PAM_USER, credentials.username)
-                auth.set_item(PAM.PAM_CONV, pam_conv)
-                try:
-                    auth.authenticate()
-                except PAM.error:
-                    return False
-                else:
-                    # Cache the password to avoid further LDAP queries
-                    self.password = credentials.password
-                    return True
-
-            elif self.service.authMethod.upper() == &quot;LDAP&quot;:
-
-                # Authenticate against LDAP
-                try:
-                    self.service.authenticate(self.dn, credentials.password)
-                    # Cache the password to avoid further LDAP queries
-                    self.password = credentials.password
-                    return True
-
-                except ldap.INVALID_CREDENTIALS:
-                    self.log.info(
-                        &quot;Invalid credentials for {dn}&quot;,
-                        dn=repr(self.dn), system=&quot;LdapDirectoryService&quot;
-                    )
-                    return False
-
-            else:
-                self.log.error(
-                    &quot;Unknown Authentication Method {method!r}&quot;,
-                    method=self.service.authMethod.upper()
-                )
-                raise DirectoryConfigurationError()
-
-        return super(LdapDirectoryRecord, self).verifyCredentials(credentials)
-
-
-
-class MissingRecordNameException(Exception):
-    &quot;&quot;&quot; Raised when LDAP record is missing recordName &quot;&quot;&quot;
-    pass
-
-
-
-class MissingGuidException(Exception):
-    &quot;&quot;&quot; Raised when LDAP record is missing guidAttr and it's required &quot;&quot;&quot;
-    pass
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryprincipalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/principal.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/principal.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/principal.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -30,53 +30,52 @@
</span><span class="cx"> 
</span><span class="cx"> from urllib import unquote
</span><span class="cx"> from urlparse import urlparse
</span><ins>+import uuid
</ins><span class="cx"> 
</span><ins>+from twext.python.log import Logger
</ins><span class="cx"> from twisted.cred.credentials import UsernamePassword
</span><del>-from twisted.python.failure import Failure
</del><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><span class="cx"> from twisted.internet.defer import succeed
</span><del>-from twisted.web.template import XMLFile, Element, renderer, tags
-from twistedcaldav.directory.util import NotFoundResource
-
-from txweb2.auth.digest import DigestedCredentials
-from txweb2 import responsecode
-from txweb2.http import HTTPError
-from txdav.xml import element as davxml
-from txweb2.dav.util import joinURL
-from txweb2.dav.noneprops import NonePropertyStore
-
-from twext.python.log import Logger
-
-
-try:
-    from twistedcaldav.authkerb import NegotiateCredentials
-    NegotiateCredentials # sigh, pyflakes
-except ImportError:
-    NegotiateCredentials = None
</del><span class="cx"> from twisted.python.modules import getModule
</span><del>-
</del><ins>+from twisted.web.template import XMLFile, Element, renderer
</ins><span class="cx"> from twistedcaldav import caldavxml, customxml
</span><span class="cx"> from twistedcaldav.cache import DisabledCacheNotifier, PropfindCacheMixin
</span><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from twistedcaldav.customxml import calendarserver_namespace
</span><span class="cx"> from twistedcaldav.directory.augment import allowedAutoScheduleModes
</span><span class="cx"> from twistedcaldav.directory.common import uidsResourceName
</span><del>-from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord
-from twistedcaldav.directory.idirectory import IDirectoryService
</del><ins>+from twistedcaldav.directory.util import NotFoundResource
+from twistedcaldav.directory.util import (
+    formatLink, formatLinks, formatPrincipals, formatList
+)
</ins><span class="cx"> from twistedcaldav.directory.wiki import getWikiACL
</span><ins>+from twistedcaldav.extensions import (
+    ReadOnlyResourceMixIn, DAVPrincipalResource, DAVResourceWithChildrenMixin
+)
</ins><span class="cx"> from twistedcaldav.extensions import DirectoryElement
</span><del>-from twistedcaldav.extensions import ReadOnlyResourceMixIn, DAVPrincipalResource, \
-    DAVResourceWithChildrenMixin
</del><span class="cx"> from twistedcaldav.resource import CalendarPrincipalCollectionResource, CalendarPrincipalResource
</span><span class="cx"> from txdav.caldav.datastore.scheduling.cuaddress import normalizeCUAddr
</span><ins>+from txdav.who.directory import CalendarDirectoryRecordMixin
+from txdav.xml import element as davxml
+from txweb2 import responsecode
+from txweb2.auth.digest import DigestedCredentials
+from txweb2.dav.noneprops import NonePropertyStore
+from txweb2.dav.util import joinURL
+from txweb2.http import HTTPError
</ins><span class="cx"> 
</span><ins>+try:
+    from twistedcaldav.authkerb import NegotiateCredentials
+    NegotiateCredentials  # sigh, pyflakes
+except ImportError:
+    NegotiateCredentials = None
+
</ins><span class="cx"> thisModule = getModule(__name__)
</span><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class PermissionsMixIn (ReadOnlyResourceMixIn):
</span><span class="cx">     def defaultAccessControlList(self):
</span><del>-        return authReadACL
</del><ins>+        return succeed(authReadACL)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -94,7 +93,7 @@
</span><span class="cx">         else:
</span><span class="cx">             # ...otherwise permissions are fixed, and are not subject to
</span><span class="cx">             # inheritance rules, etc.
</span><del>-            returnValue(self.defaultAccessControlList())
</del><ins>+            returnValue((yield self.defaultAccessControlList()))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -108,7 +107,7 @@
</span><span class="cx"> def cuTypeConverter(cuType):
</span><span class="cx">     &quot;&quot;&quot; Converts calendar user types to OD type names &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-    return &quot;recordType&quot;, DirectoryRecord.fromCUType(cuType)
</del><ins>+    return &quot;recordType&quot;, CalendarDirectoryRecordMixin.fromCUType(cuType)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -126,7 +125,7 @@
</span><span class="cx">     elif cua.startswith(&quot;/&quot;) or cua.startswith(&quot;http&quot;):
</span><span class="cx">         ignored, collection, id = cua.rsplit(&quot;/&quot;, 2)
</span><span class="cx">         if collection == &quot;__uids__&quot;:
</span><del>-            return &quot;guid&quot;, id
</del><ins>+            return &quot;uid&quot;, id
</ins><span class="cx">         else:
</span><span class="cx">             return &quot;recordName&quot;, id
</span><span class="cx"> 
</span><span class="lines">@@ -150,18 +149,21 @@
</span><span class="cx">         CalendarPrincipalCollectionResource.__init__(self, url)
</span><span class="cx">         DAVResourceWithChildrenMixin.__init__(self)
</span><span class="cx"> 
</span><del>-        self.directory = IDirectoryService(directory)
</del><ins>+        # MOVE2WHO
+        # self.directory = IDirectoryService(directory)
+        self.directory = directory
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def __repr__(self):
</span><span class="cx">         return &quot;&lt;%s: %s %s&gt;&quot; % (self.__class__.__name__, self.directory, self._url)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def locateChild(self, req, segments):
</span><del>-        child = self.getChild(segments[0])
</del><ins>+        child = (yield self.getChild(segments[0]))
</ins><span class="cx">         if child is not None:
</span><del>-            return (child, segments[1:])
-        return (NotFoundResource(principalCollections=self.principalCollections()), ())
</del><ins>+            returnValue((child, segments[1:]))
+        returnValue((NotFoundResource(principalCollections=self.principalCollections()), ()))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def deadProperties(self):
</span><span class="lines">@@ -174,12 +176,14 @@
</span><span class="cx">         return succeed(None)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def principalForShortName(self, recordType, name):
</span><del>-        return self.principalForRecord(self.directory.recordWithShortName(recordType, name))
</del><ins>+        record = (yield self.directory.recordWithShortName(recordType, name))
+        returnValue((yield self.principalForRecord(record)))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def principalForUser(self, user):
</span><del>-        return self.principalForShortName(DirectoryService.recordType_users, user)
</del><ins>+        return self.principalForShortName(self.directory.recordType.lookupByName(&quot;user&quot;), user)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def principalForAuthID(self, user):
</span><span class="lines">@@ -207,7 +211,7 @@
</span><span class="cx"> 
</span><span class="cx">     def principalForRecord(self, record):
</span><span class="cx">         if record is None or not record.enabled:
</span><del>-            return None
</del><ins>+            return succeed(None)
</ins><span class="cx">         return self.principalForUID(record.uid)
</span><span class="cx"> 
</span><span class="cx">     ##
</span><span class="lines">@@ -217,7 +221,7 @@
</span><span class="cx">     _cs_ns = &quot;http://calendarserver.org/ns/&quot;
</span><span class="cx">     _fieldMap = {
</span><span class="cx">         (&quot;DAV:&quot; , &quot;displayname&quot;) :
</span><del>-            (&quot;fullName&quot;, None, &quot;Display Name&quot;, davxml.DisplayName),
</del><ins>+            (&quot;fullNames&quot;, None, &quot;Display Name&quot;, davxml.DisplayName),
</ins><span class="cx">         (&quot;urn:ietf:params:xml:ns:caldav&quot; , &quot;calendar-user-type&quot;) :
</span><span class="cx">             (&quot;&quot;, cuTypeConverter, &quot;Calendar User Type&quot;,
</span><span class="cx">             caldavxml.CalendarUserType),
</span><span class="lines">@@ -281,16 +285,27 @@
</span><span class="cx">         #
</span><span class="cx">         # Create children
</span><span class="cx">         #
</span><del>-        for recordType in self.directory.recordTypes():
-            self.putChild(recordType, DirectoryPrincipalTypeProvisioningResource(self, recordType))
</del><ins>+        for name, recordType in [
+            (self.directory.recordTypeToOldName(r), r)
+            for r in self.directory.recordTypes()
+        ]:
+            self.putChild(
+                name,
+                DirectoryPrincipalTypeProvisioningResource(
+                    self, name, recordType
+                )
+            )
</ins><span class="cx"> 
</span><span class="cx">         self.putChild(uidsResourceName, DirectoryPrincipalUIDProvisioningResource(self))
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def principalForUID(self, uid):
</span><del>-        return self.getChild(uidsResourceName).getChild(uid)
</del><ins>+        child = (yield self.getChild(uidsResourceName))
+        returnValue((yield child.getChild(uid)))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def _principalForURI(self, uri):
</span><span class="cx">         scheme, netloc, path, _ignore_params, _ignore_query, _ignore_fragment = urlparse(uri)
</span><span class="cx"> 
</span><span class="lines">@@ -312,56 +327,62 @@
</span><span class="cx"> 
</span><span class="cx">             if (host != config.ServerHostName and
</span><span class="cx">                 host not in config.Scheduling.Options.PrincipalHostAliases):
</span><del>-                return None
</del><ins>+                returnValue(None)
</ins><span class="cx"> 
</span><span class="cx">             if port != {
</span><span class="cx">                 &quot;http&quot; : config.HTTPPort,
</span><span class="cx">                 &quot;https&quot;: config.SSLPort,
</span><span class="cx">             }[scheme]:
</span><del>-                return None
</del><ins>+                returnValue(None)
</ins><span class="cx"> 
</span><span class="cx">         elif scheme == &quot;urn&quot;:
</span><span class="cx">             if path.startswith(&quot;uuid:&quot;):
</span><del>-                return self.principalForUID(path[5:])
</del><ins>+                returnValue((yield self.principalForUID(path[5:])))
</ins><span class="cx">             else:
</span><del>-                return None
</del><ins>+                returnValue(None)
</ins><span class="cx">         else:
</span><del>-            return None
</del><ins>+            returnValue(None)
</ins><span class="cx"> 
</span><span class="cx">         if not path.startswith(self._url):
</span><del>-            return None
</del><ins>+            returnValue(None)
</ins><span class="cx"> 
</span><span class="cx">         path = path[len(self._url) - 1:]
</span><span class="cx"> 
</span><span class="cx">         segments = [unquote(s) for s in path.rstrip(&quot;/&quot;).split(&quot;/&quot;)]
</span><span class="cx">         if segments[0] == &quot;&quot; and len(segments) == 3:
</span><del>-            typeResource = self.getChild(segments[1])
</del><ins>+            typeResource = yield self.getChild(segments[1])
</ins><span class="cx">             if typeResource is not None:
</span><del>-                principalResource = typeResource.getChild(segments[2])
</del><ins>+                principalResource = yield typeResource.getChild(segments[2])
</ins><span class="cx">                 if principalResource:
</span><del>-                    return principalResource
</del><ins>+                    returnValue(principalResource)
</ins><span class="cx"> 
</span><del>-        return None
</del><ins>+        returnValue(None)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def principalForCalendarUserAddress(self, address):
</span><span class="cx">         # First see if the address is a principal URI
</span><del>-        principal = self._principalForURI(address)
</del><ins>+        principal = yield self._principalForURI(address)
</ins><span class="cx">         if principal:
</span><del>-            if isinstance(principal, DirectoryCalendarPrincipalResource) and principal.record.enabledForCalendaring:
-                return principal
</del><ins>+            if (
+                isinstance(principal, DirectoryCalendarPrincipalResource) and
+                principal.record.hasCalendars
+            ):
+                returnValue(principal)
</ins><span class="cx">         else:
</span><span class="cx">             # Next try looking it up in the directory
</span><del>-            record = self.directory.recordWithCalendarUserAddress(address)
-            if record is not None and record.enabled and record.enabledForCalendaring:
-                return self.principalForRecord(record)
</del><ins>+            record = yield self.directory.recordWithCalendarUserAddress(address)
+            if record is not None and record.hasCalendars:
+                returnValue((yield self.principalForRecord(record)))
</ins><span class="cx"> 
</span><span class="cx">         log.debug(&quot;No principal for calendar user address: %r&quot; % (address,))
</span><del>-        return None
</del><ins>+        returnValue(None)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def principalForRecord(self, record):
</span><del>-        return self.getChild(uidsResourceName).principalForRecord(record)
</del><ins>+        child = (yield self.getChild(uidsResourceName))
+        returnValue((yield child.principalForRecord(record)))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     ##
</span><span class="lines">@@ -375,13 +396,16 @@
</span><span class="cx"> 
</span><span class="cx">     def getChild(self, name):
</span><span class="cx">         if name == &quot;&quot;:
</span><del>-            return self
</del><ins>+            return succeed(self)
</ins><span class="cx">         else:
</span><del>-            return self.putChildren.get(name, None)
</del><ins>+            return succeed(self.putChildren.get(name, None))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def listChildren(self):
</span><del>-        return self.directory.recordTypes()
</del><ins>+        return [
+            self.directory.recordTypeToOldName(r)
+            for r in self.directory.recordTypes()
+        ]
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     ##
</span><span class="lines">@@ -421,14 +445,14 @@
</span><span class="cx">     Collection resource which provisions directory principals of a
</span><span class="cx">     specific type as its children, indexed by short name.
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    def __init__(self, parent, recordType):
</del><ins>+    def __init__(self, parent, name, recordType):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         @param parent: the parent L{DirectoryPrincipalProvisioningResource}.
</span><span class="cx">         @param recordType: the directory record type to provision.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DirectoryProvisioningResource.__init__(
</span><span class="cx">             self,
</span><del>-            joinURL(parent.principalCollectionURL(), recordType) + &quot;/&quot;,
</del><ins>+            joinURL(parent.principalCollectionURL(), name) + &quot;/&quot;,
</ins><span class="cx">             parent.directory
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="lines">@@ -459,22 +483,24 @@
</span><span class="cx"> 
</span><span class="cx">     def getChild(self, name):
</span><span class="cx">         if name == &quot;&quot;:
</span><del>-            return self
</del><ins>+            return succeed(self)
</ins><span class="cx">         else:
</span><span class="cx">             return self.principalForShortName(self.recordType, name)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def listChildren(self):
</span><ins>+        children = []
</ins><span class="cx">         if config.EnablePrincipalListings:
</span><ins>+            try:
+                for record in (yield self.directory.listRecords(self.recordType)):
+                    for shortName in record.shortNames:
+                        children.append(shortName)
+            except AttributeError:
+                log.warn(&quot;Cannot list children of record type {rt}&quot;,
+                         rt=self.recordType.name)
+            returnValue(children)
</ins><span class="cx"> 
</span><del>-
-            def _recordShortnameExpand():
-                for record in self.directory.listRecords(self.recordType):
-                    if record.enabled:
-                        for shortName in record.shortNames:
-                            yield shortName
-
-            return _recordShortnameExpand()
</del><span class="cx">         else:
</span><span class="cx">             # Not a listable collection
</span><span class="cx">             raise HTTPError(responsecode.FORBIDDEN)
</span><span class="lines">@@ -517,16 +543,18 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def principalForRecord(self, record):
</span><del>-        if record is None or not record.enabled:
-            return None
</del><ins>+        # MOVE2WHO
+        if record is None: #  or not record.enabled:
+            return succeed(None)
</ins><span class="cx"> 
</span><del>-        if record.enabledForCalendaring or record.enabledForAddressBooks:
</del><ins>+        # MOVE2WHO
+        if record.hasCalendars or record.hasContacts:
</ins><span class="cx">             # XXX these are different features and one should not automatically
</span><span class="cx">             # imply the other...
</span><span class="cx">             principal = DirectoryCalendarPrincipalResource(self, record)
</span><span class="cx">         else:
</span><span class="cx">             principal = DirectoryPrincipalResource(self, record)
</span><del>-        return principal
</del><ins>+        return succeed(principal)
</ins><span class="cx"> 
</span><span class="cx">     ##
</span><span class="cx">     # Static
</span><span class="lines">@@ -538,9 +566,10 @@
</span><span class="cx">         raise HTTPError(responsecode.NOT_FOUND)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def getChild(self, name):
</span><span class="cx">         if name == &quot;&quot;:
</span><del>-            return self
</del><ins>+            returnValue(self)
</ins><span class="cx"> 
</span><span class="cx">         if &quot;#&quot; in name:
</span><span class="cx">             # This UID belongs to a sub-principal
</span><span class="lines">@@ -549,16 +578,16 @@
</span><span class="cx">             primaryUID = name
</span><span class="cx">             subType = None
</span><span class="cx"> 
</span><del>-        record = self.directory.recordWithUID(primaryUID)
-        primaryPrincipal = self.principalForRecord(record)
</del><ins>+        record = (yield self.directory.recordWithUID(primaryUID))
+        primaryPrincipal = (yield self.principalForRecord(record))
</ins><span class="cx">         if primaryPrincipal is None:
</span><span class="cx">             log.info(&quot;No principal found for UID: %s&quot; % (name,))
</span><del>-            return None
</del><ins>+            returnValue(None)
</ins><span class="cx"> 
</span><span class="cx">         if subType is None:
</span><del>-            return primaryPrincipal
</del><ins>+            returnValue(primaryPrincipal)
</ins><span class="cx">         else:
</span><del>-            return primaryPrincipal.getChild(subType)
</del><ins>+            returnValue((yield primaryPrincipal.getChild(subType)))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def listChildren(self):
</span><span class="lines">@@ -610,17 +639,31 @@
</span><span class="cx">         Top-level renderer in the template.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         record = self.resource.record
</span><ins>+        try:
+            if isinstance(record.guid, uuid.UUID):
+                guid = str(record.guid).upper()
+            else:
+                guid = record.guid
+        except AttributeError:
+            guid = &quot;&quot;
+        try:
+            emailAddresses = record.emailAddresses
+        except AttributeError:
+            emailAddresses = []
</ins><span class="cx">         return tag.fillSlots(
</span><span class="cx">             directoryGUID=str(record.service.guid),
</span><span class="cx">             realm=str(record.service.realmName),
</span><del>-            principalGUID=str(record.guid),
-            recordType=str(record.recordType),
</del><ins>+            principalGUID=guid,
+            recordType=record.service.recordTypeToOldName(record.recordType),
</ins><span class="cx">             shortNames=&quot;,&quot;.join(record.shortNames),
</span><del>-            securityIDs=&quot;,&quot;.join(record.authIDs),
-            fullName=str(record.fullName),
-            firstName=str(record.firstName),
-            lastName=str(record.lastName),
-            emailAddresses=formatList(record.emailAddresses),
</del><ins>+            # MOVE2WHO: need this?
+            # securityIDs=&quot;,&quot;.join(record.authIDs),
+            fullName=str(record.displayName),
+            # MOVE2WHO: need this?
+            # firstName=str(record.firstName),
+            # MOVE2WHO: need this?
+            # lastName=str(record.lastName),
+            emailAddresses=formatList(emailAddresses),
</ins><span class="cx">             principalUID=str(self.resource.principalUID()),
</span><span class="cx">             principalURL=formatLink(self.resource.principalURL()),
</span><span class="cx">             alternateURIs=formatLinks(self.resource.alternateURIs()),
</span><span class="lines">@@ -697,7 +740,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         resource = self.resource
</span><span class="cx">         record = resource.record
</span><del>-        if record.enabledForCalendaring:
</del><ins>+        if record.hasCalendars:
</ins><span class="cx">             return tag.fillSlots(
</span><span class="cx">                 calendarUserAddresses=formatLinks(
</span><span class="cx">                     sorted(resource.calendarUserAddresses())
</span><span class="lines">@@ -715,7 +758,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         resource = self.resource
</span><span class="cx">         record = resource.record
</span><del>-        if record.enabledForAddressBooks:
</del><ins>+        if record.hasContacts:
</ins><span class="cx">             return tag.fillSlots(
</span><span class="cx">                 addressBookHomes=formatLinks(resource.addressBookHomeURLs())
</span><span class="cx">             )
</span><span class="lines">@@ -750,7 +793,8 @@
</span><span class="cx">             (calendarserver_namespace, &quot;first-name&quot;),
</span><span class="cx">             (calendarserver_namespace, &quot;last-name&quot;),
</span><span class="cx">             (calendarserver_namespace, &quot;email-address-set&quot;),
</span><del>-            davxml.ResourceID.qname(),
</del><ins>+            # MOVE2WHO
+            # davxml.ResourceID.qname(),
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx">     cacheNotifierFactory = DisabledCacheNotifier
</span><span class="lines">@@ -778,8 +822,9 @@
</span><span class="cx">         url = joinURL(parent.principalCollectionURL(), self.principalUID()) + slash
</span><span class="cx">         self._url = url
</span><span class="cx"> 
</span><ins>+        # MOVE2WHO - hack: just adding an &quot;s&quot; using recordType.name (need a mapping)
</ins><span class="cx">         self._alternate_urls = tuple([
</span><del>-            joinURL(parent.parent.principalCollectionURL(), record.recordType, shortName) + slash for shortName in record.shortNames
</del><ins>+            joinURL(parent.parent.principalCollectionURL(), record.recordType.name+&quot;s&quot;, shortName) + slash for shortName in record.shortNames
</ins><span class="cx">         ])
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -811,26 +856,33 @@
</span><span class="cx"> 
</span><span class="cx">         namespace, name = qname
</span><span class="cx"> 
</span><del>-        if qname == davxml.ResourceID.qname():
-            returnValue(davxml.ResourceID(davxml.HRef.fromString(&quot;urn:uuid:%s&quot; % (self.record.guid,))))
-        elif namespace == calendarserver_namespace:
-            if name == &quot;first-name&quot;:
-                firstName = self.record.firstName
-                if firstName is not None:
-                    returnValue(customxml.FirstNameProperty(firstName))
-                else:
-                    returnValue(None)
</del><ins>+        # MOVE2WHO -- does principal need ResourceID ?
+        # if qname == davxml.ResourceID.qname():
+        #     returnValue(davxml.ResourceID(davxml.HRef.fromString(&quot;urn:uuid:%s&quot; % (self.record.guid,))))
+        if namespace == calendarserver_namespace:
</ins><span class="cx"> 
</span><del>-            elif name == &quot;last-name&quot;:
-                lastName = self.record.lastName
-                if lastName is not None:
-                    returnValue(customxml.LastNameProperty(lastName))
-                else:
-                    returnValue(None)
</del><ins>+            # MOVE2WHO
+            # if name == &quot;first-name&quot;:
+            #     firstName = self.record.firstName
+            #     if firstName is not None:
+            #         returnValue(customxml.FirstNameProperty(firstName))
+            #     else:
+            #         returnValue(None)
</ins><span class="cx"> 
</span><del>-            elif name == &quot;email-address-set&quot;:
</del><ins>+            # elif name == &quot;last-name&quot;:
+            #     lastName = self.record.lastName
+            #     if lastName is not None:
+            #         returnValue(customxml.LastNameProperty(lastName))
+            #     else:
+            #         returnValue(None)
+
+            if name == &quot;email-address-set&quot;:
+                try:
+                    emails = self.record.emailAddresses
+                except AttributeError:
+                    emails = []
</ins><span class="cx">                 returnValue(customxml.EmailAddressSet(
</span><del>-                    *[customxml.EmailAddressProperty(addr) for addr in sorted(self.record.emailAddresses)]
</del><ins>+                    *[customxml.EmailAddressProperty(addr) for addr in sorted(emails)]
</ins><span class="cx">                 ))
</span><span class="cx"> 
</span><span class="cx">         result = (yield super(DirectoryPrincipalResource, self).readProperty(property, request))
</span><span class="lines">@@ -867,7 +919,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def displayName(self):
</span><del>-        return self.record.displayName()
</del><ins>+        return self.record.displayName
</ins><span class="cx"> 
</span><span class="cx">     ##
</span><span class="cx">     # ACL
</span><span class="lines">@@ -939,51 +991,40 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def proxyFor(self, read_write, resolve_memberships=True):
</del><ins>+    def proxyFor(self, readWrite):
+        &quot;&quot;&quot;
+        Returns the set of principals currently delegating to this principal
+        with the access indicated by the readWrite argument.  If readWrite is
+        True, then write-access delegators are returned, otherwise the read-
+        only-access delegators are returned.
</ins><span class="cx"> 
</span><ins>+        @param readWrite: Whether to look up read-write delegators, or
+            read-only delegators
+        @type readWrite: C{bool}
+
+        @return: A Deferred firing with a set of principals
+        &quot;&quot;&quot;
</ins><span class="cx">         proxyFors = set()
</span><span class="cx"> 
</span><del>-        if resolve_memberships:
-            cache = getattr(self.record.service, &quot;groupMembershipCache&quot;, None)
-            if cache:
-                log.debug(&quot;proxyFor is using groupMembershipCache&quot;)
-                guids = (yield self.record.cachedGroups())
-                memberships = set()
-                for guid in guids:
-                    principal = self.parent.principalForUID(guid)
-                    if principal:
-                        memberships.add(principal)
-            else:
-                memberships = self._getRelatives(&quot;groups&quot;, infinity=True)
-
-            for membership in memberships:
-                results = (yield membership.proxyFor(read_write, False))
-                proxyFors.update(results)
-
</del><span class="cx">         if config.EnableProxyPrincipals:
</span><del>-            # Get proxy group UIDs and map to principal resources
-            proxies = []
-            memberships = (yield self._calendar_user_proxy_index().getMemberships(self.principalUID()))
-            for uid in memberships:
-                subprincipal = self.parent.principalForUID(uid)
-                if subprincipal:
-                    if subprincipal.isProxyType(read_write):
-                        proxies.append(subprincipal.parent)
-                else:
-                    yield self._calendar_user_proxy_index().removeGroup(uid)
</del><ins>+            childName = &quot;calendar-proxy-{rw}-for&quot;.format(
+                rw=(&quot;write&quot; if readWrite else &quot;read&quot;)
+            )
+            proxyForGroup = yield self.getChild(childName)
+            if proxyForGroup:
+                proxyFors = yield proxyForGroup.groupMembers()
</ins><span class="cx"> 
</span><del>-            proxyFors.update(proxies)
</del><ins>+                uids = set()
+                for principal in tuple(proxyFors):
+                    if principal.principalUID() in uids:
+                        proxyFors.remove(principal)
+                    else:
+                        uids.add(principal.principalUID())
</ins><span class="cx"> 
</span><del>-        uids = set()
-        for principal in tuple(proxyFors):
-            if principal.principalUID() in uids:
-                proxyFors.remove(principal)
-            else:
-                uids.add(principal.principalUID())
-
</del><span class="cx">         returnValue(proxyFors)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def _getRelatives(self, method, record=None, relatives=None, records=None, proxy=None, infinity=False):
</span><span class="cx">         if record is None:
</span><span class="cx">             record = self.record
</span><span class="lines">@@ -994,61 +1035,62 @@
</span><span class="cx"> 
</span><span class="cx">         if record not in records:
</span><span class="cx">             records.add(record)
</span><del>-            for relative in getattr(record, method)():
</del><ins>+            for relative in (yield getattr(record, method)()):
</ins><span class="cx">                 if relative not in records:
</span><del>-                    found = self.parent.principalForRecord(relative)
</del><ins>+                    found = (yield self.parent.principalForRecord(relative))
</ins><span class="cx">                     if found is None:
</span><span class="cx">                         log.error(&quot;No principal found for directory record: %r&quot; % (relative,))
</span><span class="cx">                     else:
</span><span class="cx">                         if proxy:
</span><span class="cx">                             if proxy == &quot;read-write&quot;:
</span><del>-                                found = found.getChild(&quot;calendar-proxy-write&quot;)
</del><ins>+                                found = (yield found.getChild(&quot;calendar-proxy-write&quot;))
</ins><span class="cx">                             else:
</span><del>-                                found = found.getChild(&quot;calendar-proxy-read&quot;)
</del><ins>+                                found = (yield found.getChild(&quot;calendar-proxy-read&quot;))
</ins><span class="cx">                         relatives.add(found)
</span><span class="cx"> 
</span><span class="cx">                     if infinity:
</span><del>-                        self._getRelatives(method, relative, relatives, records,
</del><ins>+                        yield self._getRelatives(method, relative, relatives, records,
</ins><span class="cx">                             infinity=infinity)
</span><span class="cx"> 
</span><del>-        return relatives
</del><ins>+        returnValue(relatives)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def groupMembers(self):
</span><del>-        return succeed(self._getRelatives(&quot;members&quot;))
</del><ins>+        return self._getRelatives(&quot;members&quot;)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def expandedGroupMembers(self):
</span><del>-        return succeed(self._getRelatives(&quot;members&quot;, infinity=True))
</del><ins>+        return self._getRelatives(&quot;members&quot;, infinity=True)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def groupMemberships(self, infinity=False):
</span><span class="cx"> 
</span><del>-        cache = getattr(self.record.service, &quot;groupMembershipCache&quot;, None)
-        if cache:
-            log.debug(&quot;groupMemberships is using groupMembershipCache&quot;)
-            guids = (yield self.record.cachedGroups())
-            groups = set()
-            for guid in guids:
-                principal = self.parent.principalForUID(guid)
-                if principal:
-                    groups.add(principal)
-        else:
-            groups = self._getRelatives(&quot;groups&quot;, infinity=infinity)
</del><ins>+        # cache = getattr(self.record.service, &quot;groupMembershipCache&quot;, None)
+        # if cache:
+        #     log.debug(&quot;groupMemberships is using groupMembershipCache&quot;)
+        #     guids = (yield self.record.cachedGroups())
+        #     groups = set()
+        #     for guid in guids:
+        #         principal = yield self.parent.principalForUID(guid)
+        #         if principal:
+        #             groups.add(principal)
+        # else:
+        groups = yield self._getRelatives(&quot;groups&quot;, infinity=infinity)
</ins><span class="cx"> 
</span><del>-        if config.EnableProxyPrincipals:
-            # Get proxy group UIDs and map to principal resources
-            proxies = []
-            memberships = (yield self._calendar_user_proxy_index().getMemberships(self.principalUID()))
-            for uid in memberships:
-                subprincipal = self.parent.principalForUID(uid)
-                if subprincipal:
-                    proxies.append(subprincipal)
-                else:
-                    yield self._calendar_user_proxy_index().removeGroup(uid)
</del><ins>+        # MOVE2WHO
+        # if config.EnableProxyPrincipals:
+        #     # Get proxy group UIDs and map to principal resources
+        #     proxies = []
+        #     memberships = (yield self._calendar_user_proxy_index().getMemberships(self.principalUID()))
+        #     for uid in memberships:
+        #         subprincipal = yield self.parent.principalForUID(uid)
+        #         if subprincipal:
+        #             proxies.append(subprincipal)
+        #         else:
+        #             yield self._calendar_user_proxy_index().removeGroup(uid)
</ins><span class="cx"> 
</span><del>-            groups.update(proxies)
</del><ins>+        #     groups.update(proxies)
</ins><span class="cx"> 
</span><span class="cx">         returnValue(groups)
</span><span class="cx"> 
</span><span class="lines">@@ -1099,7 +1141,9 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def getAutoSchedule(self):
</span><del>-        return self.record.autoSchedule
</del><ins>+        # MOVE2WHO
+        return True
+        # return self.record.autoSchedule
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def canAutoSchedule(self, organizer=None):
</span><span class="lines">@@ -1187,18 +1231,19 @@
</span><span class="cx">         raise HTTPError(responsecode.NOT_FOUND)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def locateChild(self, req, segments):
</span><del>-        child = self.getChild(segments[0])
</del><ins>+        child = (yield self.getChild(segments[0]))
</ins><span class="cx">         if child is not None:
</span><del>-            return (child, segments[1:])
-        return (None, ())
</del><ins>+            returnValue((child, segments[1:]))
+        returnValue((None, ()))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def getChild(self, name):
</span><span class="cx">         if name == &quot;&quot;:
</span><del>-            return self
</del><ins>+            return succeed(self)
</ins><span class="cx"> 
</span><del>-        return None
</del><ins>+        return succeed(None)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def listChildren(self):
</span><span class="lines">@@ -1221,7 +1266,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def addressBooksEnabled(self):
</span><del>-        return config.EnableCardDAV and self.record.enabledForAddressBooks
</del><ins>+        return config.EnableCardDAV and self.record.hasContacts
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -1288,7 +1333,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def calendarHomeURLs(self):
</span><del>-        if self.record.enabledForCalendaring:
</del><ins>+        if self.record.hasCalendars:
</ins><span class="cx">             homeURL = self._homeChildURL(None)
</span><span class="cx">         else:
</span><span class="cx">             homeURL = &quot;&quot;
</span><span class="lines">@@ -1318,7 +1363,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def addressBookHomeURLs(self):
</span><del>-        if self.record.enabledForAddressBooks:
</del><ins>+        if self.record.hasContacts:
</ins><span class="cx">             homeURL = self._addressBookHomeChildURL(None)
</span><span class="cx">         else:
</span><span class="cx">             homeURL = &quot;&quot;
</span><span class="lines">@@ -1391,22 +1436,27 @@
</span><span class="cx"> 
</span><span class="cx">     def getChild(self, name):
</span><span class="cx">         if name == &quot;&quot;:
</span><del>-            return self
</del><ins>+            return succeed(self)
</ins><span class="cx"> 
</span><del>-        if config.EnableProxyPrincipals and name in (&quot;calendar-proxy-read&quot;,
-                                                     &quot;calendar-proxy-write&quot;):
</del><ins>+        if config.EnableProxyPrincipals and name in (
+            &quot;calendar-proxy-read&quot;, &quot;calendar-proxy-write&quot;,
+            &quot;calendar-proxy-read-for&quot;, &quot;calendar-proxy-write-for&quot;,
+            ):
</ins><span class="cx">             # name is required to be str
</span><span class="cx">             from twistedcaldav.directory.calendaruserproxy import (
</span><span class="cx">                 CalendarUserProxyPrincipalResource
</span><span class="cx">             )
</span><del>-            return CalendarUserProxyPrincipalResource(self, str(name))
</del><ins>+            return succeed(CalendarUserProxyPrincipalResource(self, str(name)))
</ins><span class="cx">         else:
</span><del>-            return None
</del><ins>+            return succeed(None)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def listChildren(self):
</span><span class="cx">         if config.EnableProxyPrincipals:
</span><del>-            return (&quot;calendar-proxy-read&quot;, &quot;calendar-proxy-write&quot;)
</del><ins>+            return (
+                &quot;calendar-proxy-read&quot;, &quot;calendar-proxy-write&quot;,
+                &quot;calendar-proxy-read-for&quot;, &quot;calendar-proxy-write-for&quot;,
+            )
</ins><span class="cx">         else:
</span><span class="cx">             return ()
</span><span class="cx"> 
</span><span class="lines">@@ -1425,71 +1475,3 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def formatPrincipals(principals):
-    &quot;&quot;&quot;
-    Format a list of principals into some twisted.web.template DOM objects.
-    &quot;&quot;&quot;
-    def recordKey(principal):
-        try:
-            record = principal.record
-        except AttributeError:
-            try:
-                record = principal.parent.record
-            except:
-                return None
-        return (record.recordType, record.shortNames[0])
-
-
-    def describe(principal):
-        if hasattr(principal, &quot;record&quot;):
-            return &quot; - %s&quot; % (principal.record.fullName,)
-        else:
-            return &quot;&quot;
-
-    return formatList(
-        tags.a(href=principal.principalURL())(
-            str(principal), describe(principal)
-        )
-        for principal in sorted(principals, key=recordKey)
-    )
-
-
-
-def formatList(iterable):
-    &quot;&quot;&quot;
-    Format a list of stuff as an interable.
-    &quot;&quot;&quot;
-    thereAreAny = False
-    try:
-        item = None
-        for item in iterable:
-            thereAreAny = True
-            yield &quot; -&gt; &quot;
-            if item is None:
-                yield &quot;None&quot;
-            else:
-                yield item
-            yield &quot;\n&quot;
-    except Exception, e:
-        log.error(&quot;Exception while rendering: %s&quot; % (e,))
-        Failure().printTraceback()
-        yield &quot;  ** %s **: %s\n&quot; % (e.__class__.__name__, e)
-    if not thereAreAny:
-        yield &quot; '()\n&quot;
-
-
-
-def formatLink(url):
-    &quot;&quot;&quot;
-    Convert a URL string into some twisted.web.template DOM objects for
-    rendering as a link to itself.
-    &quot;&quot;&quot;
-    return tags.a(href=url)(url)
-
-
-
-def formatLinks(urls):
-    &quot;&quot;&quot;
-    Format a list of URL strings as a list of twisted.web.template DOM links.
-    &quot;&quot;&quot;
-    return formatList(formatLink(link) for link in urls)
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytestaccountsxml"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -18,279 +18,297 @@
</span><span class="cx"> 
</span><span class="cx"> &lt;!DOCTYPE accounts SYSTEM &quot;../../../conf/auth/accounts.dtd&quot;&gt;
</span><span class="cx"> 
</span><del>-&lt;accounts realm=&quot;Test&quot;&gt;
-  &lt;user&gt;
-    &lt;uid&gt;admin&lt;/uid&gt;
-    &lt;guid&gt;D11F03A0-97EA-48AF-9A6C-FAC7F3975766&lt;/guid&gt;
</del><ins>+&lt;directory realm=&quot;Test&quot;&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;admin&lt;/short-name&gt;
+    &lt;uid&gt;D11F03A0-97EA-48AF-9A6C-FAC7F3975766&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;nimda&lt;/password&gt;
</span><del>-    &lt;name&gt;Administrators&lt;/name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;wsanchez&lt;/uid&gt;
-    &lt;guid&gt;6423F94A-6B76-4A3A-815B-D52CFD77935D&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;Administrators&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;wsanchez&lt;/short-name&gt;
+    &lt;uid&gt;6423F94A-6B76-4A3A-815B-D52CFD77935D&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;zehcnasw&lt;/password&gt;
</span><del>-    &lt;name&gt;Wilfredo Sanchez&lt;/name&gt;
-    &lt;email-address&gt;wsanchez@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;cdaboo&lt;/uid&gt;
-    &lt;guid&gt;5A985493-EE2C-4665-94CF-4DFEA3A89500&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;Wilfredo Sanchez&lt;/full-name&gt;
+    &lt;email&gt;wsanchez@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;cdaboo&lt;/short-name&gt;
+    &lt;uid&gt;5A985493-EE2C-4665-94CF-4DFEA3A89500&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;oobadc&lt;/password&gt;
</span><del>-    &lt;name&gt;Cyrus Daboo&lt;/name&gt;
-    &lt;email-address&gt;cdaboo@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;lecroy&lt;/uid&gt;
-    &lt;guid&gt;8B4288F6-CC82-491D-8EF9-642EF4F3E7D0&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;Cyrus Daboo&lt;/full-name&gt;
+    &lt;email&gt;cdaboo@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;lecroy&lt;/short-name&gt;
+    &lt;uid&gt;8B4288F6-CC82-491D-8EF9-642EF4F3E7D0&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;yorcel&lt;/password&gt;
</span><del>-    &lt;name&gt;Chris Lecroy&lt;/name&gt;
-    &lt;email-address&gt;lecroy@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;dreid&lt;/uid&gt;
-    &lt;guid&gt;5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;Chris Lecroy&lt;/full-name&gt;
+    &lt;email&gt;lecroy@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;dreid&lt;/short-name&gt;
+    &lt;uid&gt;5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;dierd&lt;/password&gt;
</span><del>-    &lt;name&gt;David Reid&lt;/name&gt;
-    &lt;email-address&gt;dreid@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;doublequotes&lt;/uid&gt;
-    &lt;guid&gt;8E04787E-336D-41ED-A70B-D233AD0DCE6F&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;David Reid&lt;/full-name&gt;
+    &lt;email&gt;dreid@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;doublequotes&lt;/short-name&gt;
+    &lt;uid&gt;8E04787E-336D-41ED-A70B-D233AD0DCE6F&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;setouqelbuod&lt;/password&gt;
</span><del>-    &lt;name&gt;Double &quot;quotey&quot; Quotes&lt;/name&gt;
-    &lt;email-address&gt;doublequotes@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;nocalendar&lt;/uid&gt;
-    &lt;guid&gt;543D28BA-F74F-4D5F-9243-B3E3A61171E5&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;Double &quot;quotey&quot; Quotes&lt;/full-name&gt;
+    &lt;email&gt;doublequotes@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;nocalendar&lt;/short-name&gt;
+    &lt;uid&gt;543D28BA-F74F-4D5F-9243-B3E3A61171E5&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;radnelacon&lt;/password&gt;
</span><del>-    &lt;name&gt;No Calendar&lt;/name&gt;
-    &lt;email-address&gt;nocalendar@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;usera&lt;/uid&gt;
-    &lt;guid&gt;7423F94A-6B76-4A3A-815B-D52CFD77935D&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;No Calendar&lt;/full-name&gt;
+    &lt;email&gt;nocalendar@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;usera&lt;/short-name&gt;
+    &lt;uid&gt;7423F94A-6B76-4A3A-815B-D52CFD77935D&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;a&lt;/password&gt;
</span><del>-    &lt;name&gt;a&lt;/name&gt;
-    &lt;email-address&gt;a@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;userb&lt;/uid&gt;
-    &lt;guid&gt;8A985493-EE2C-4665-94CF-4DFEA3A89500&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;a&lt;/full-name&gt;
+    &lt;email&gt;a@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;userb&lt;/short-name&gt;
+    &lt;uid&gt;8A985493-EE2C-4665-94CF-4DFEA3A89500&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;b&lt;/password&gt;
</span><del>-    &lt;name&gt;b&lt;/name&gt;
-    &lt;email-address&gt;b@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;userc&lt;/uid&gt;
-    &lt;guid&gt;9FF60DAD-0BDE-4508-8C77-15F0CA5C8DD2&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;b&lt;/full-name&gt;
+    &lt;email&gt;b@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;userc&lt;/short-name&gt;
+    &lt;uid&gt;9FF60DAD-0BDE-4508-8C77-15F0CA5C8DD2&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;c&lt;/password&gt;
</span><del>-    &lt;name&gt;c&lt;/name&gt;
-    &lt;email-address&gt;c@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;usercalonly&lt;/uid&gt;
-    &lt;guid&gt;9E1FFAC4-3CCD-45A1-8272-D161C92D2EEE&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;c&lt;/full-name&gt;
+    &lt;email&gt;c@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;usercalonly&lt;/short-name&gt;
+    &lt;uid&gt;9E1FFAC4-3CCD-45A1-8272-D161C92D2EEE&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;a&lt;/password&gt;
</span><del>-    &lt;name&gt;a calonly&lt;/name&gt;
-    &lt;email-address&gt;a-calonly@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;useradbkonly&lt;/uid&gt;
-    &lt;guid&gt;7678EC8A-A069-4E82-9066-7279C6718507&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;a calonly&lt;/full-name&gt;
+    &lt;email&gt;a-calonly@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;useradbkonly&lt;/short-name&gt;
+    &lt;uid&gt;7678EC8A-A069-4E82-9066-7279C6718507&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;a&lt;/password&gt;
</span><del>-    &lt;name&gt;a adbkonly&lt;/name&gt;
-    &lt;email-address&gt;a-adbkonly@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;nonascii&lt;/uid&gt;
-    &lt;uid&gt;nonascii佐藤&lt;/uid&gt;
-    &lt;guid&gt;320B73A1-46E2-4180-9563-782DFDBE1F63&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;a adbkonly&lt;/full-name&gt;
+    &lt;email&gt;a-adbkonly@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;nonascii&lt;/short-name&gt;
+    &lt;short-name&gt;nonascii佐藤&lt;/short-name&gt;
+    &lt;uid&gt;320B73A1-46E2-4180-9563-782DFDBE1F63&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;a&lt;/password&gt;
</span><del>-    &lt;name&gt;佐藤佐藤佐藤&lt;/name&gt;
-    &lt;email-address&gt;nonascii@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;delegator&lt;/uid&gt;
-    &lt;guid&gt;FC465590-E9E9-4746-ACE8-6C756A49FE4D&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;佐藤佐藤佐藤&lt;/full-name&gt;
+    &lt;email&gt;nonascii@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;delegator&lt;/short-name&gt;
+    &lt;uid&gt;FC465590-E9E9-4746-ACE8-6C756A49FE4D&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;a&lt;/password&gt;
</span><del>-    &lt;name&gt;Calendar Delegator&lt;/name&gt;
-    &lt;email-address&gt;calendardelegator@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
-    &lt;uid&gt;occasionaldelegate&lt;/uid&gt;
-    &lt;guid&gt;EC465590-E9E9-4746-ACE8-6C756A49FE4D&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;Calendar Delegator&lt;/full-name&gt;
+    &lt;email&gt;calendardelegator@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;occasionaldelegate&lt;/short-name&gt;
+    &lt;uid&gt;EC465590-E9E9-4746-ACE8-6C756A49FE4D&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;a&lt;/password&gt;
</span><del>-    &lt;name&gt;Occasional Delegate&lt;/name&gt;
-    &lt;email-address&gt;occasional@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-    &lt;user&gt;
-    &lt;uid&gt;delegateviagroup&lt;/uid&gt;
-    &lt;guid&gt;46D9D716-CBEE-490F-907A-66FA6C3767FF&lt;/guid&gt;
</del><ins>+    &lt;full-name&gt;Occasional Delegate&lt;/full-name&gt;
+    &lt;email&gt;occasional@example.com&lt;/email&gt;
+  &lt;/record&gt;
+    &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;delegateviagroup&lt;/short-name&gt;
+    &lt;uid&gt;46D9D716-CBEE-490F-907A-66FA6C3767FF&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;a&lt;/password&gt;
</span><del>-    &lt;name&gt;Delegate Via Group&lt;/name&gt;
-    &lt;email-address&gt;delegateviagroup@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;group&gt;
-    &lt;uid&gt;delegategroup&lt;/uid&gt;
-    &lt;guid&gt;00599DAF-3E75-42DD-9DB7-52617E79943F&lt;/guid&gt;
-    &lt;name&gt;Delegate Group&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;delegateviagroup&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
</del><ins>+    &lt;full-name&gt;Delegate Via Group&lt;/full-name&gt;
+    &lt;email&gt;delegateviagroup@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
+    &lt;short-name&gt;delegategroup&lt;/short-name&gt;
+    &lt;uid&gt;00599DAF-3E75-42DD-9DB7-52617E79943F&lt;/uid&gt;
+    &lt;full-name&gt;Delegate Group&lt;/full-name&gt;
+    &lt;member-uid&gt;delegateviagroup&lt;/member-uid&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user01&lt;/short-name&gt;
+    &lt;uid&gt;user01&lt;/uid&gt;
+    &lt;password&gt;user01&lt;/password&gt;
+    &lt;full-name&gt;User 01&lt;/full-name&gt;
+    &lt;email&gt;user01@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user02&lt;/short-name&gt;
+    &lt;uid&gt;user02&lt;/uid&gt;
+    &lt;password&gt;user02&lt;/password&gt;
+    &lt;full-name&gt;User 02&lt;/full-name&gt;
+    &lt;email&gt;user02@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user03&lt;/short-name&gt;
+    &lt;uid&gt;user03&lt;/uid&gt;
+    &lt;password&gt;user03&lt;/password&gt;
+    &lt;full-name&gt;User 03&lt;/full-name&gt;
+    &lt;email&gt;user03@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user04&lt;/short-name&gt;
+    &lt;uid&gt;user04&lt;/uid&gt;
+    &lt;password&gt;user04&lt;/password&gt;
+    &lt;full-name&gt;User 04&lt;/full-name&gt;
+    &lt;email&gt;user04@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;!-- Repeat is not (yet?) supported in twext.who.xml
</ins><span class="cx">   &lt;user repeat=&quot;100&quot;&gt;
</span><ins>+    &lt;short-name&gt;user%02d&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;user%02d&lt;/uid&gt;
</span><del>-    &lt;guid&gt;user%02d&lt;/guid&gt;
</del><span class="cx">     &lt;password&gt;%02duser&lt;/password&gt;
</span><del>-    &lt;name&gt;~35 User %02d&lt;/name&gt;
</del><ins>+    &lt;full-name&gt;~35 User %02d&lt;/full-name&gt;
</ins><span class="cx">     &lt;first-name&gt;~5&lt;/first-name&gt;
</span><span class="cx">     &lt;last-name&gt;~9 User %02d&lt;/last-name&gt;
</span><del>-    &lt;email-address&gt;~10@example.com&lt;/email-address&gt;
</del><ins>+    &lt;email&gt;~10@example.com&lt;/email&gt;
</ins><span class="cx">   &lt;/user&gt;
</span><del>-  &lt;group&gt;
-    &lt;uid&gt;managers&lt;/uid&gt;
-    &lt;guid&gt;9FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1&lt;/guid&gt;
</del><ins>+  --&gt;
+
+  &lt;record type=&quot;group&quot;&gt;
+    &lt;short-name&gt;managers&lt;/short-name&gt;
+    &lt;uid&gt;9FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;managers&lt;/password&gt;
</span><del>-    &lt;name&gt;Managers&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;lecroy&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Managers&lt;/full-name&gt;
+      &lt;member-uid&gt;lecroy&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
+    &lt;short-name&gt;admin&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;admin&lt;/uid&gt;
</span><del>-    &lt;guid&gt;admin&lt;/guid&gt;
</del><span class="cx">     &lt;password&gt;admin&lt;/password&gt;
</span><del>-    &lt;name&gt;Administrators&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;groups&quot;&gt;managers&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Administrators&lt;/full-name&gt;
+      &lt;member-uid&gt;managers&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
+    &lt;short-name&gt;grunts&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;grunts&lt;/uid&gt;
</span><del>-    &lt;guid&gt;grunts&lt;/guid&gt;
</del><span class="cx">     &lt;password&gt;grunts&lt;/password&gt;
</span><del>-    &lt;name&gt;We do all the work&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member&gt;wsanchez&lt;/member&gt;
-      &lt;member&gt;cdaboo&lt;/member&gt;
-      &lt;member&gt;dreid&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;We do all the work&lt;/full-name&gt;
+      &lt;member-uid&gt;wsanchez&lt;/member-uid&gt;
+      &lt;member-uid&gt;cdaboo&lt;/member-uid&gt;
+      &lt;member-uid&gt;dreid&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
+    &lt;short-name&gt;right_coast&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;right_coast&lt;/uid&gt;
</span><del>-    &lt;guid&gt;right_coast&lt;/guid&gt;
</del><span class="cx">     &lt;password&gt;right_coast&lt;/password&gt;
</span><del>-    &lt;name&gt;East Coast&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member&gt;cdaboo&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;East Coast&lt;/full-name&gt;
+      &lt;member-uid&gt;cdaboo&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
+    &lt;short-name&gt;left_coast&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;left_coast&lt;/uid&gt;
</span><del>-    &lt;guid&gt;left_coast&lt;/guid&gt;
</del><span class="cx">     &lt;password&gt;left_coast&lt;/password&gt;
</span><del>-    &lt;name&gt;West Coast&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member&gt;wsanchez&lt;/member&gt;
-      &lt;member&gt;lecroy&lt;/member&gt;
-      &lt;member&gt;dreid&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;West Coast&lt;/full-name&gt;
+      &lt;member-uid&gt;wsanchez&lt;/member-uid&gt;
+      &lt;member-uid&gt;lecroy&lt;/member-uid&gt;
+      &lt;member-uid&gt;dreid&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
+    &lt;short-name&gt;both_coasts&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;both_coasts&lt;/uid&gt;
</span><del>-    &lt;guid&gt;both_coasts&lt;/guid&gt;
</del><span class="cx">     &lt;password&gt;both_coasts&lt;/password&gt;
</span><del>-    &lt;name&gt;Both Coasts&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;groups&quot;&gt;right_coast&lt;/member&gt;
-      &lt;member type=&quot;groups&quot;&gt;left_coast&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Both Coasts&lt;/full-name&gt;
+      &lt;member-uid&gt;right_coast&lt;/member-uid&gt;
+      &lt;member-uid&gt;left_coast&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
+    &lt;short-name&gt;recursive1_coasts&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;recursive1_coasts&lt;/uid&gt;
</span><del>-    &lt;guid&gt;recursive1_coasts&lt;/guid&gt;
</del><span class="cx">     &lt;password&gt;recursive1_coasts&lt;/password&gt;
</span><del>-    &lt;name&gt;Recursive1 Coasts&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;groups&quot;&gt;recursive2_coasts&lt;/member&gt;
-      &lt;member&gt;wsanchez&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Recursive1 Coasts&lt;/full-name&gt;
+      &lt;member-uid&gt;recursive2_coasts&lt;/member-uid&gt;
+      &lt;member-uid&gt;wsanchez&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
+    &lt;short-name&gt;recursive2_coasts&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;recursive2_coasts&lt;/uid&gt;
</span><del>-    &lt;guid&gt;recursive2_coasts&lt;/guid&gt;
</del><span class="cx">     &lt;password&gt;recursive2_coasts&lt;/password&gt;
</span><del>-    &lt;name&gt;Recursive2 Coasts&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;groups&quot;&gt;recursive1_coasts&lt;/member&gt;
-      &lt;member&gt;cdaboo&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Recursive2 Coasts&lt;/full-name&gt;
+      &lt;member-uid&gt;recursive1_coasts&lt;/member-uid&gt;
+      &lt;member-uid&gt;cdaboo&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
+    &lt;short-name&gt;non_calendar_group&lt;/short-name&gt;
</ins><span class="cx">     &lt;uid&gt;non_calendar_group&lt;/uid&gt;
</span><del>-    &lt;guid&gt;non_calendar_group&lt;/guid&gt;
</del><span class="cx">     &lt;password&gt;non_calendar_group&lt;/password&gt;
</span><del>-    &lt;name&gt;Non-calendar group&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member&gt;cdaboo&lt;/member&gt;
-      &lt;member&gt;lecroy&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
</del><ins>+    &lt;full-name&gt;Non-calendar group&lt;/full-name&gt;
+      &lt;member-uid&gt;cdaboo&lt;/member-uid&gt;
+      &lt;member-uid&gt;lecroy&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;!--
</ins><span class="cx">   &lt;location&gt;
</span><span class="cx">     &lt;uid&gt;mercury&lt;/uid&gt;
</span><del>-    &lt;guid&gt;mercury&lt;/guid&gt;
</del><ins>+    &lt;uid&gt;mercury&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;mercury&lt;/password&gt;
</span><span class="cx">     &lt;name&gt;Mercury Seven&lt;/name&gt;
</span><span class="cx">     &lt;email-address&gt;mercury@example.com&lt;/email-address&gt;
</span><span class="cx">   &lt;/location&gt;
</span><span class="cx">   &lt;location&gt;
</span><span class="cx">     &lt;uid&gt;gemini&lt;/uid&gt;
</span><del>-    &lt;guid&gt;gemini&lt;/guid&gt;
</del><ins>+    &lt;uid&gt;gemini&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;gemini&lt;/password&gt;
</span><span class="cx">     &lt;name&gt;Gemini Twelve&lt;/name&gt;
</span><span class="cx">     &lt;email-address&gt;gemini@example.com&lt;/email-address&gt;
</span><span class="cx">   &lt;/location&gt;
</span><span class="cx">   &lt;location&gt;
</span><span class="cx">     &lt;uid&gt;apollo&lt;/uid&gt;
</span><del>-    &lt;guid&gt;apollo&lt;/guid&gt;
</del><ins>+    &lt;uid&gt;apollo&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;apollo&lt;/password&gt;
</span><span class="cx">     &lt;name&gt;Apollo Eleven&lt;/name&gt;
</span><span class="cx">     &lt;email-address&gt;apollo@example.com&lt;/email-address&gt;
</span><span class="cx">   &lt;/location&gt;
</span><span class="cx">   &lt;location&gt;
</span><span class="cx">     &lt;uid&gt;orion&lt;/uid&gt;
</span><del>-    &lt;guid&gt;orion&lt;/guid&gt;
</del><ins>+    &lt;uid&gt;orion&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;orion&lt;/password&gt;
</span><span class="cx">     &lt;name&gt;Orion&lt;/name&gt;
</span><span class="cx">     &lt;email-address&gt;orion@example.com&lt;/email-address&gt;
</span><span class="cx">   &lt;/location&gt;
</span><span class="cx">   &lt;resource&gt;
</span><span class="cx">     &lt;uid&gt;transporter&lt;/uid&gt;
</span><del>-    &lt;guid&gt;transporter&lt;/guid&gt;
</del><ins>+    &lt;uid&gt;transporter&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;transporter&lt;/password&gt;
</span><span class="cx">     &lt;name&gt;Mass Transporter&lt;/name&gt;
</span><span class="cx">     &lt;email-address&gt;transporter@example.com&lt;/email-address&gt;
</span><span class="cx">   &lt;/resource&gt;
</span><span class="cx">   &lt;resource&gt;
</span><span class="cx">     &lt;uid&gt;ftlcpu&lt;/uid&gt;
</span><del>-    &lt;guid&gt;ftlcpu&lt;/guid&gt;
</del><ins>+    &lt;uid&gt;ftlcpu&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;ftlcpu&lt;/password&gt;
</span><span class="cx">     &lt;name&gt;Faster-Than-Light Microprocessor&lt;/name&gt;
</span><span class="cx">     &lt;email-address&gt;ftlcpu@example.com&lt;/email-address&gt;
</span><span class="cx">   &lt;/resource&gt;
</span><span class="cx">   &lt;resource&gt;
</span><span class="cx">     &lt;uid&gt;non_calendar_proxy&lt;/uid&gt;
</span><del>-    &lt;guid&gt;non_calendar_proxy&lt;/guid&gt;
</del><ins>+    &lt;uid&gt;non_calendar_proxy&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;non_calendar_proxy&lt;/password&gt;
</span><span class="cx">     &lt;name&gt;Non-calendar proxy&lt;/name&gt;
</span><span class="cx">     &lt;email-address&gt;non_calendar_proxy@example.com&lt;/email-address&gt;
</span><span class="cx">   &lt;/resource&gt;
</span><span class="cx">   &lt;resource&gt;
</span><span class="cx">     &lt;uid&gt;disabled&lt;/uid&gt;
</span><del>-    &lt;guid&gt;disabled&lt;/guid&gt;
</del><ins>+    &lt;uid&gt;disabled&lt;/uid&gt;
</ins><span class="cx">     &lt;password&gt;disabled&lt;/password&gt;
</span><span class="cx">     &lt;name&gt;Disabled Record&lt;/name&gt;
</span><span class="cx">     &lt;email-address&gt;disabled@example.com&lt;/email-address&gt;
</span><span class="cx">   &lt;/resource&gt;
</span><del>-&lt;/accounts&gt;
</del><ins>+--&gt;
+&lt;/directory&gt;
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_aggregatepy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_aggregate.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_aggregate.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_aggregate.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,87 +0,0 @@
</span><del>-##
-# Copyright (c) 2005-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 twistedcaldav.directory.xmlfile import XMLDirectoryService
-from twistedcaldav.directory.aggregate import AggregateDirectoryService
-
-from twistedcaldav.directory.test.test_xmlfile import xmlFile, augmentsFile
-
-import twistedcaldav.directory.test.util
-from twistedcaldav.directory import augment
-
-xml_prefix = &quot;xml:&quot;
-
-testServices = (
-    (xml_prefix   , twistedcaldav.directory.test.test_xmlfile.XMLFile),
-)
-
-class AggregatedDirectories (twistedcaldav.directory.test.util.DirectoryTestCase):
-    def _recordTypes(self):
-        recordTypes = set()
-        for prefix, testClass in testServices:
-            for recordType in testClass.recordTypes:
-                recordTypes.add(prefix + recordType)
-        return recordTypes
-
-
-    def _records(key): #@NoSelf
-        def get(self):
-            records = {}
-            for prefix, testClass in testServices:
-                for record, info in getattr(testClass, key).iteritems():
-                    info = dict(info)
-                    info[&quot;prefix&quot;] = prefix
-                    info[&quot;members&quot;] = tuple(
-                        (t, prefix + s) for t, s in info.get(&quot;members&quot;, {})
-                    )
-                    records[prefix + record] = info
-            return records
-        return get
-
-    recordTypes = property(_recordTypes)
-    users = property(_records(&quot;users&quot;))
-    groups = property(_records(&quot;groups&quot;))
-    locations = property(_records(&quot;locations&quot;))
-    resources = property(_records(&quot;resources&quot;))
-    addresses = property(_records(&quot;addresses&quot;))
-
-    recordTypePrefixes = tuple(s[0] for s in testServices)
-
-
-    def service(self):
-        &quot;&quot;&quot;
-        Returns an IDirectoryService.
-        &quot;&quot;&quot;
-        xmlService = XMLDirectoryService(
-            {
-                'xmlFile' : xmlFile,
-                'augmentService' :
-                    augment.AugmentXMLDB(xmlFiles=(augmentsFile.path,)),
-            }
-        )
-        xmlService.recordTypePrefix = xml_prefix
-
-        return AggregateDirectoryService((xmlService,), None)
-
-
-    def test_setRealm(self):
-        &quot;&quot;&quot;
-        setRealm gets propagated to nested services
-        &quot;&quot;&quot;
-        aggregatedService = self.service()
-        aggregatedService.setRealm(&quot;foo.example.com&quot;)
-        for service in aggregatedService._recordTypes.values():
-            self.assertEquals(&quot;foo.example.com&quot;, service.realmName)
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_augmentpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_augment.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_augment.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_augment.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -17,7 +17,6 @@
</span><span class="cx"> from twistedcaldav.test.util import TestCase
</span><span class="cx"> from twistedcaldav.directory.augment import AugmentXMLDB, AugmentSqliteDB, \
</span><span class="cx">     AugmentPostgreSQLDB, AugmentRecord
</span><del>-from twistedcaldav.directory.directory import DirectoryService
</del><span class="cx"> from twisted.internet.defer import inlineCallbacks
</span><span class="cx"> from twistedcaldav.directory.xmlaugmentsparser import XMLAugmentsParser
</span><span class="cx"> import cStringIO
</span><span class="lines">@@ -78,7 +77,7 @@
</span><span class="cx"> class AugmentTests(TestCase):
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def _checkRecord(self, db, items, recordType=DirectoryService.recordType_users):
</del><ins>+    def _checkRecord(self, db, items, recordType=&quot;users&quot;):
</ins><span class="cx"> 
</span><span class="cx">         record = (yield db.getAugmentRecord(items[&quot;uid&quot;], recordType))
</span><span class="cx">         self.assertTrue(record is not None, &quot;Failed record uid: %s&quot; % (items[&quot;uid&quot;],))
</span><span class="lines">@@ -88,7 +87,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def _checkRecordExists(self, db, uid, recordType=DirectoryService.recordType_users):
</del><ins>+    def _checkRecordExists(self, db, uid, recordType=&quot;users&quot;):
</ins><span class="cx"> 
</span><span class="cx">         record = (yield db.getAugmentRecord(uid, recordType))
</span><span class="cx">         self.assertTrue(record is not None, &quot;Failed record uid: %s&quot; % (uid,))
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_buildquerypy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_buildquery.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_buildquery.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_buildquery.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,160 +0,0 @@
</span><del>-##
-# Copyright (c) 2009-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.
-##
-
-try:
-    from calendarserver.platform.darwin.od import dsattributes
-except ImportError:
-    pass
-else:
-    from twistedcaldav.test.util import TestCase
-    from twistedcaldav.directory.appleopendirectory import (buildQueries,
-        buildLocalQueriesFromTokens, OpenDirectoryService, buildNestedQueryFromTokens)
-
-    class BuildQueryTests(TestCase):
-
-        def test_buildQuery(self):
-            self.assertEquals(
-                buildQueries(
-                    [dsattributes.kDSStdRecordTypeUsers],
-                    (
-                        (&quot;firstName&quot;, &quot;morgen&quot;, True, &quot;starts-with&quot;),
-                        (&quot;lastName&quot;, &quot;sagen&quot;, True, &quot;starts-with&quot;),
-                    ),
-                    OpenDirectoryService._ODFields
-                ),
-                {
-                    ('dsAttrTypeStandard:FirstName', 'morgen', True, 'starts-with') : [dsattributes.kDSStdRecordTypeUsers],
-                    ('dsAttrTypeStandard:LastName', 'sagen', True, 'starts-with') : [dsattributes.kDSStdRecordTypeUsers],
-                }
-            )
-            self.assertEquals(
-                buildQueries(
-                    [
-                        dsattributes.kDSStdRecordTypeUsers,
-                    ],
-                    (
-                        (&quot;firstName&quot;, &quot;morgen&quot;, True, &quot;starts-with&quot;),
-                        (&quot;emailAddresses&quot;, &quot;morgen&quot;, True, &quot;contains&quot;),
-                    ),
-                    OpenDirectoryService._ODFields
-                ),
-                {
-                    ('dsAttrTypeStandard:FirstName', 'morgen', True, 'starts-with') : [dsattributes.kDSStdRecordTypeUsers],
-                    ('dsAttrTypeStandard:EMailAddress', 'morgen', True, 'contains') : [dsattributes.kDSStdRecordTypeUsers],
-                }
-            )
-            self.assertEquals(
-                buildQueries(
-                    [
-                        dsattributes.kDSStdRecordTypeGroups,
-                    ],
-                    (
-                        (&quot;firstName&quot;, &quot;morgen&quot;, True, &quot;starts-with&quot;),
-                        (&quot;lastName&quot;, &quot;morgen&quot;, True, &quot;starts-with&quot;),
-                        (&quot;fullName&quot;, &quot;morgen&quot;, True, &quot;starts-with&quot;),
-                        (&quot;emailAddresses&quot;, &quot;morgen&quot;, True, &quot;contains&quot;),
-                    ),
-                    OpenDirectoryService._ODFields
-                ),
-                {
-                    ('dsAttrTypeStandard:RealName', 'morgen', True, 'starts-with') : [dsattributes.kDSStdRecordTypeGroups],
-                    ('dsAttrTypeStandard:EMailAddress', 'morgen', True, 'contains') : [dsattributes.kDSStdRecordTypeGroups],
-                }
-            )
-            self.assertEquals(
-                buildQueries(
-                    [
-                        dsattributes.kDSStdRecordTypeUsers,
-                        dsattributes.kDSStdRecordTypeGroups,
-                    ],
-                    (
-                        (&quot;firstName&quot;, &quot;morgen&quot;, True, &quot;starts-with&quot;),
-                        (&quot;lastName&quot;, &quot;morgen&quot;, True, &quot;starts-with&quot;),
-                        (&quot;fullName&quot;, &quot;morgen&quot;, True, &quot;starts-with&quot;),
-                        (&quot;emailAddresses&quot;, &quot;morgen&quot;, True, &quot;contains&quot;),
-                    ),
-                    OpenDirectoryService._ODFields
-                ),
-                {
-                    ('dsAttrTypeStandard:RealName', 'morgen', True, 'starts-with') : [dsattributes.kDSStdRecordTypeUsers, dsattributes.kDSStdRecordTypeGroups],
-                    ('dsAttrTypeStandard:EMailAddress', 'morgen', True, 'contains') : [dsattributes.kDSStdRecordTypeUsers, dsattributes.kDSStdRecordTypeGroups],
-                    ('dsAttrTypeStandard:FirstName', 'morgen', True, 'starts-with') : [dsattributes.kDSStdRecordTypeUsers],
-                    ('dsAttrTypeStandard:LastName', 'morgen', True, 'starts-with') : [dsattributes.kDSStdRecordTypeUsers],
-                }
-            )
-            self.assertEquals(
-                buildQueries(
-                    [
-                        dsattributes.kDSStdRecordTypeGroups,
-                    ],
-                    (
-                        (&quot;firstName&quot;, &quot;morgen&quot;, True, &quot;starts-with&quot;),
-                    ),
-                    OpenDirectoryService._ODFields
-                ),
-                {
-                }
-            )
-
-
-        def test_buildLocalQueryFromTokens(self):
-            &quot;&quot;&quot;
-            Verify the generating of the simpler queries passed to /Local/Default
-            &quot;&quot;&quot;
-            results = buildLocalQueriesFromTokens([], OpenDirectoryService._ODFields)
-            self.assertEquals(results, None)
-
-            results = buildLocalQueriesFromTokens([&quot;foo&quot;], OpenDirectoryService._ODFields)
-            self.assertEquals(
-                results[0].generate(),
-                &quot;(|(dsAttrTypeStandard:RealName=*foo*)(dsAttrTypeStandard:EMailAddress=foo*))&quot;
-            )
-
-            results = buildLocalQueriesFromTokens([&quot;foo&quot;, &quot;bar&quot;], OpenDirectoryService._ODFields)
-            self.assertEquals(
-                results[0].generate(),
-                &quot;(|(dsAttrTypeStandard:RealName=*foo*)(dsAttrTypeStandard:EMailAddress=foo*))&quot;
-            )
-            self.assertEquals(
-                results[1].generate(),
-                &quot;(|(dsAttrTypeStandard:RealName=*bar*)(dsAttrTypeStandard:EMailAddress=bar*))&quot;
-            )
-
-
-        def test_buildNestedQueryFromTokens(self):
-            &quot;&quot;&quot;
-            Verify the generating of the complex nested queries
-            &quot;&quot;&quot;
-            query = buildNestedQueryFromTokens([], OpenDirectoryService._ODFields)
-            self.assertEquals(query, None)
-
-            query = buildNestedQueryFromTokens([&quot;foo&quot;], OpenDirectoryService._ODFields)
-            self.assertEquals(
-                query.generate(),
-                &quot;(|(dsAttrTypeStandard:RealName=*foo*)(dsAttrTypeStandard:EMailAddress=foo*)(dsAttrTypeStandard:RecordName=foo*))&quot;
-            )
-
-            query = buildNestedQueryFromTokens([&quot;foo&quot;, &quot;bar&quot;], OpenDirectoryService._ODFields)
-            self.assertEquals(
-                query.generate(),
-                &quot;(&amp;(|(dsAttrTypeStandard:RealName=*foo*)(dsAttrTypeStandard:EMailAddress=foo*)(dsAttrTypeStandard:RecordName=foo*))(|(dsAttrTypeStandard:RealName=*bar*)(dsAttrTypeStandard:EMailAddress=bar*)(dsAttrTypeStandard:RecordName=bar*)))&quot;
-            )
-
-            query = buildNestedQueryFromTokens([&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;], OpenDirectoryService._ODFields)
-            self.assertEquals(
-                query.generate(),
-                &quot;(&amp;(|(dsAttrTypeStandard:RealName=*foo*)(dsAttrTypeStandard:EMailAddress=foo*)(dsAttrTypeStandard:RecordName=foo*))(|(dsAttrTypeStandard:RealName=*bar*)(dsAttrTypeStandard:EMailAddress=bar*)(dsAttrTypeStandard:RecordName=bar*))(|(dsAttrTypeStandard:RealName=*baz*)(dsAttrTypeStandard:EMailAddress=baz*)(dsAttrTypeStandard:RecordName=baz*)))&quot;
-            )
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_cachedirectorypy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_cachedirectory.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_cachedirectory.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_cachedirectory.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,405 +0,0 @@
</span><del>-#
-# Copyright (c) 2009-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 uuid import uuid4
-
-from twistedcaldav.directory.cachingdirectory import CachingDirectoryService
-from twistedcaldav.directory.cachingdirectory import CachingDirectoryRecord
-from twistedcaldav.directory.directory import DirectoryService
-from twistedcaldav.directory.util import uuidFromName
-from twistedcaldav.directory.augment import AugmentRecord
-from twistedcaldav.test.util import TestCase
-from twistedcaldav.config import config
-
-
-class TestDirectoryService (CachingDirectoryService):
-
-    realmName = &quot;Dummy Realm&quot;
-    baseGUID = &quot;20CB1593-DE3F-4422-A7D7-BA9C2099B317&quot;
-
-    def recordTypes(self):
-        return (
-            DirectoryService.recordType_users,
-            DirectoryService.recordType_groups,
-            DirectoryService.recordType_locations,
-            DirectoryService.recordType_resources,
-        )
-
-
-    def queryDirectory(self, recordTypes, indexType, indexKey):
-
-        self.queried = True
-
-        for recordType in recordTypes:
-            for record in self.fakerecords[recordType]:
-                cacheIt = False
-                if indexType in (
-                    CachingDirectoryService.INDEX_TYPE_SHORTNAME,
-                    CachingDirectoryService.INDEX_TYPE_CUA,
-                    CachingDirectoryService.INDEX_TYPE_AUTHID,
-                ):
-                    if indexKey in record[indexType]:
-                        cacheIt = True
-                else:
-                    if indexKey == record[indexType]:
-                        cacheIt = True
-
-                if cacheIt:
-                    cacheRecord = CachingDirectoryRecord(
-                        service=self,
-                        recordType=recordType,
-                        guid=record.get(&quot;guid&quot;),
-                        shortNames=record.get(&quot;shortname&quot;),
-                        authIDs=record.get(&quot;authid&quot;),
-                        fullName=record.get(&quot;fullName&quot;),
-                        firstName=&quot;&quot;,
-                        lastName=&quot;&quot;,
-                        emailAddresses=record.get(&quot;email&quot;),
-                    )
-
-                    augmentRecord = AugmentRecord(
-                        uid=cacheRecord.guid,
-                        enabled=True,
-                        enabledForCalendaring=True,
-                    )
-
-                    cacheRecord.addAugmentInformation(augmentRecord)
-
-                    self.recordCacheForType(recordType).addRecord(cacheRecord,
-                        indexType, indexKey)
-
-
-
-class CachingDirectoryTest(TestCase):
-
-    baseGUID = str(uuid4())
-
-
-    def setUp(self):
-        super(CachingDirectoryTest, self).setUp()
-        self.service = TestDirectoryService()
-        self.service.queried = False
-
-
-    def loadRecords(self, records):
-        self.service._initCaches()
-        self.service.fakerecords = records
-        self.service.queried = False
-
-
-    def fakeRecord(
-        self,
-        fullName,
-        recordType,
-        shortNames=None,
-        guid=None,
-        emails=None,
-        members=None,
-        resourceInfo=None,
-        multinames=False
-    ):
-        if shortNames is None:
-            shortNames = (self.shortNameForFullName(fullName),)
-            if multinames:
-                shortNames += (fullName,)
-
-        if guid is None:
-            guid = self.guidForShortName(shortNames[0], recordType=recordType)
-        else:
-            guid = guid.lower()
-
-        if emails is None:
-            emails = (&quot;%s@example.com&quot; % (shortNames[0],),)
-
-        attrs = {
-            &quot;fullName&quot;: fullName,
-            &quot;guid&quot;: guid,
-            &quot;shortname&quot;: shortNames,
-            &quot;email&quot;: emails,
-            &quot;cua&quot;: tuple([&quot;mailto:%s&quot; % email for email in emails]),
-            &quot;authid&quot;: tuple([&quot;Kerberos:%s&quot; % email for email in emails])
-        }
-
-        if members:
-            attrs[&quot;members&quot;] = members
-
-        if resourceInfo:
-            attrs[&quot;resourceInfo&quot;] = resourceInfo
-
-        return attrs
-
-
-    def shortNameForFullName(self, fullName):
-        return fullName.lower().replace(&quot; &quot;, &quot;&quot;)
-
-
-    def guidForShortName(self, shortName, recordType=&quot;&quot;):
-        return uuidFromName(self.baseGUID, &quot;%s%s&quot; % (recordType, shortName))
-
-
-    def dummyRecords(self):
-        SIZE = 10
-        records = {
-            DirectoryService.recordType_users: [
-                self.fakeRecord(&quot;User %02d&quot; % x, DirectoryService.recordType_users, multinames=(x &gt; 5)) for x in range(1, SIZE + 1)
-            ],
-            DirectoryService.recordType_groups: [
-                self.fakeRecord(&quot;Group %02d&quot; % x, DirectoryService.recordType_groups) for x in range(1, SIZE + 1)
-            ],
-            DirectoryService.recordType_resources: [
-                self.fakeRecord(&quot;Resource %02d&quot; % x, DirectoryService.recordType_resources) for x in range(1, SIZE + 1)
-            ],
-            DirectoryService.recordType_locations: [
-                self.fakeRecord(&quot;Location %02d&quot; % x, DirectoryService.recordType_locations) for x in range(1, SIZE + 1)
-            ],
-        }
-        # Add duplicate shortnames
-        records[DirectoryService.recordType_users].append(self.fakeRecord(&quot;Duplicate&quot;, DirectoryService.recordType_users, multinames=True))
-        records[DirectoryService.recordType_groups].append(self.fakeRecord(&quot;Duplicate&quot;, DirectoryService.recordType_groups, multinames=True))
-        records[DirectoryService.recordType_resources].append(self.fakeRecord(&quot;Duplicate&quot;, DirectoryService.recordType_resources, multinames=True))
-        records[DirectoryService.recordType_locations].append(self.fakeRecord(&quot;Duplicate&quot;, DirectoryService.recordType_locations, multinames=True))
-
-        self.loadRecords(records)
-
-
-    def verifyRecords(self, recordType, expectedGUIDs):
-
-        records = self.service.listRecords(recordType)
-        recordGUIDs = set([record.guid for record in records])
-        self.assertEqual(recordGUIDs, expectedGUIDs)
-
-
-
-class GUIDLookups(CachingDirectoryTest):
-
-    def test_emptylist(self):
-        self.dummyRecords()
-
-        self.verifyRecords(DirectoryService.recordType_users, set())
-        self.verifyRecords(DirectoryService.recordType_groups, set())
-        self.verifyRecords(DirectoryService.recordType_resources, set())
-        self.verifyRecords(DirectoryService.recordType_locations, set())
-
-
-    def test_cacheoneguid(self):
-        self.dummyRecords()
-
-        self.assertTrue(self.service.recordWithGUID(self.guidForShortName(&quot;user01&quot;, recordType=DirectoryService.recordType_users)) is not None)
-        self.assertTrue(self.service.queried)
-        self.verifyRecords(DirectoryService.recordType_users, set((
-            self.guidForShortName(&quot;user01&quot;, recordType=DirectoryService.recordType_users),
-        )))
-        self.verifyRecords(DirectoryService.recordType_groups, set())
-        self.verifyRecords(DirectoryService.recordType_resources, set())
-        self.verifyRecords(DirectoryService.recordType_locations, set())
-
-        # Make sure it really is cached and won't cause another query
-        self.service.queried = False
-        self.assertTrue(self.service.recordWithGUID(self.guidForShortName(&quot;user01&quot;, recordType=DirectoryService.recordType_users)) is not None)
-        self.assertFalse(self.service.queried)
-
-        # Make sure guid is case-insensitive
-        self.assertTrue(self.service.recordWithGUID(self.guidForShortName(&quot;user01&quot;, recordType=DirectoryService.recordType_users).lower()) is not None)
-
-
-    def test_cacheoneshortname(self):
-        self.dummyRecords()
-
-        self.assertTrue(self.service.recordWithShortName(
-            DirectoryService.recordType_users,
-            &quot;user02&quot;
-        ) is not None)
-        self.assertTrue(self.service.queried)
-        self.verifyRecords(DirectoryService.recordType_users, set((
-            self.guidForShortName(&quot;user02&quot;, recordType=DirectoryService.recordType_users),
-        )))
-        self.verifyRecords(DirectoryService.recordType_groups, set())
-        self.verifyRecords(DirectoryService.recordType_resources, set())
-        self.verifyRecords(DirectoryService.recordType_locations, set())
-
-        # Make sure it really is cached and won't cause another query
-        self.service.queried = False
-        self.assertTrue(self.service.recordWithShortName(
-            DirectoryService.recordType_users,
-            &quot;user02&quot;
-        ) is not None)
-        self.assertFalse(self.service.queried)
-
-
-    def test_cacheoneemail(self):
-        self.dummyRecords()
-
-        self.assertTrue(self.service.recordWithCalendarUserAddress(
-            &quot;mailto:user03@example.com&quot;
-        ) is not None)
-        self.assertTrue(self.service.queried)
-        self.verifyRecords(DirectoryService.recordType_users, set((
-            self.guidForShortName(&quot;user03&quot;, recordType=DirectoryService.recordType_users),
-        )))
-        self.verifyRecords(DirectoryService.recordType_groups, set())
-        self.verifyRecords(DirectoryService.recordType_resources, set())
-        self.verifyRecords(DirectoryService.recordType_locations, set())
-
-        # Make sure it really is cached and won't cause another query
-        self.service.queried = False
-        self.assertTrue(self.service.recordWithCalendarUserAddress(
-            &quot;mailto:user03@example.com&quot;
-        ) is not None)
-        self.assertFalse(self.service.queried)
-
-
-    def test_cacheonePrincipalsURLWithUIDS(self):
-        self.dummyRecords()
-
-        guid = self.guidForShortName(&quot;user03&quot;, &quot;users&quot;)
-        self.assertTrue(self.service.recordWithCalendarUserAddress(
-            &quot;/principals/__uids__/%s&quot; % (guid,)
-        ) is not None)
-        self.assertTrue(self.service.queried)
-        self.verifyRecords(DirectoryService.recordType_users, set((
-            self.guidForShortName(&quot;user03&quot;, recordType=DirectoryService.recordType_users),
-        )))
-        self.verifyRecords(DirectoryService.recordType_groups, set())
-        self.verifyRecords(DirectoryService.recordType_resources, set())
-        self.verifyRecords(DirectoryService.recordType_locations, set())
-
-        # Make sure it really is cached and won't cause another query
-        self.service.queried = False
-        self.assertTrue(self.service.recordWithCalendarUserAddress(
-            &quot;/principals/__uids__/%s&quot; % (guid,)
-        ) is not None)
-        self.assertFalse(self.service.queried)
-
-
-    def test_cacheonePrincipalsURLWithUsers(self):
-        self.dummyRecords()
-
-        self.assertTrue(self.service.recordWithCalendarUserAddress(
-            &quot;/principals/users/user03&quot;
-        ) is not None)
-        self.assertTrue(self.service.queried)
-        self.verifyRecords(DirectoryService.recordType_users, set((
-            self.guidForShortName(&quot;user03&quot;, recordType=DirectoryService.recordType_users),
-        )))
-        self.verifyRecords(DirectoryService.recordType_groups, set())
-        self.verifyRecords(DirectoryService.recordType_resources, set())
-        self.verifyRecords(DirectoryService.recordType_locations, set())
-
-        # Make sure it really is cached and won't cause another query
-        self.service.queried = False
-        self.assertTrue(self.service.recordWithCalendarUserAddress(
-            &quot;/principals/users/user03&quot;
-        ) is not None)
-        self.assertFalse(self.service.queried)
-
-
-    def test_cacheoneauthid(self):
-        self.dummyRecords()
-
-        self.assertTrue(self.service.recordWithAuthID(
-            &quot;Kerberos:user03@example.com&quot;
-        ) is not None)
-        self.assertTrue(self.service.queried)
-        self.verifyRecords(DirectoryService.recordType_users, set((
-            self.guidForShortName(&quot;user03&quot;, recordType=DirectoryService.recordType_users),
-        )))
-        self.verifyRecords(DirectoryService.recordType_groups, set())
-        self.verifyRecords(DirectoryService.recordType_resources, set())
-        self.verifyRecords(DirectoryService.recordType_locations, set())
-
-        # Make sure it really is cached and won't cause another query
-        self.service.queried = False
-        self.assertTrue(self.service.recordWithAuthID(
-            &quot;Kerberos:user03@example.com&quot;
-        ) is not None)
-        self.assertFalse(self.service.queried)
-
-
-    def test_negativeCaching(self):
-        self.dummyRecords()
-
-        # If negativeCaching is off, each miss will result in a call to
-        # queryDirectory( )
-        self.service.negativeCaching = False
-
-        self.service.queried = False
-        self.assertEquals(self.service.recordWithGUID(self.guidForShortName(&quot;missing&quot;)), None)
-        self.assertTrue(self.service.queried)
-
-        self.service.queried = False
-        self.assertEquals(self.service.recordWithGUID(self.guidForShortName(&quot;missing&quot;)), None)
-        self.assertTrue(self.service.queried)
-
-        # However, if negativeCaching is on, a miss is recorded as such,
-        # preventing a similar queryDirectory( ) until cacheTimeout passes
-        self.service.negativeCaching = True
-
-        self.service.queried = False
-        self.assertEquals(self.service.recordWithGUID(self.guidForShortName(&quot;missing&quot;)), None)
-        self.assertTrue(self.service.queried)
-
-        self.service.queried = False
-        self.assertEquals(self.service.recordWithGUID(self.guidForShortName(&quot;missing&quot;)), None)
-        self.assertFalse(self.service.queried)
-
-        # Simulate time passing by clearing the negative timestamp for this
-        # entry, then try again, this time queryDirectory( ) is called
-        self.service._disabledKeys[self.service.INDEX_TYPE_GUID][self.guidForShortName(&quot;missing&quot;)] = 0
-
-        self.service.queried = False
-        self.assertEquals(self.service.recordWithGUID(self.guidForShortName(&quot;missing&quot;)), None)
-        self.assertTrue(self.service.queried)
-
-
-    def test_duplicateShortNames(self):
-        &quot;&quot;&quot;
-        Verify that when looking up records having duplicate short-names, the record of the
-        proper type is returned
-        &quot;&quot;&quot;
-
-        self.patch(config.Memcached.Pools.Default, &quot;ClientEnabled&quot;, True)
-        self.dummyRecords()
-
-        record = self.service.recordWithShortName(DirectoryService.recordType_users,
-            &quot;Duplicate&quot;)
-        self.assertEquals(record.recordType, DirectoryService.recordType_users)
-
-        record = self.service.recordWithShortName(DirectoryService.recordType_groups,
-            &quot;Duplicate&quot;)
-        self.assertEquals(record.recordType, DirectoryService.recordType_groups)
-
-        record = self.service.recordWithShortName(DirectoryService.recordType_resources,
-            &quot;Duplicate&quot;)
-        self.assertEquals(record.recordType, DirectoryService.recordType_resources)
-
-        record = self.service.recordWithShortName(DirectoryService.recordType_locations,
-            &quot;Duplicate&quot;)
-        self.assertEquals(record.recordType, DirectoryService.recordType_locations)
-
-
-    def test_generateMemcacheKey(self):
-        &quot;&quot;&quot;
-        Verify keys are correctly generated based on the index type -- if index type is
-        short-name, then the recordtype is encoded into the key.
-        &quot;&quot;&quot;
-        self.assertEquals(
-            self.service.generateMemcacheKey(self.service.INDEX_TYPE_GUID, &quot;foo&quot;, &quot;users&quot;),
-            &quot;dir|v2|20CB1593-DE3F-4422-A7D7-BA9C2099B317|guid|foo&quot;,
-        )
-        self.assertEquals(
-            self.service.generateMemcacheKey(self.service.INDEX_TYPE_SHORTNAME, &quot;foo&quot;, &quot;users&quot;),
-            &quot;dir|v2|20CB1593-DE3F-4422-A7D7-BA9C2099B317|users|shortname|foo&quot;,
-        )
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_directorypy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_directory.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_directory.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_directory.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,1201 +0,0 @@
</span><del>-##
-# Copyright (c) 2011-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.internet.defer import inlineCallbacks
-from twisted.python.filepath import FilePath
-
-from twistedcaldav.test.util import TestCase
-from twistedcaldav.test.util import xmlFile, augmentsFile, proxiesFile, dirTest
-from twistedcaldav.config import config
-from twistedcaldav.directory.directory import DirectoryService, DirectoryRecord, GroupMembershipCache, GroupMembershipCacheUpdater, diffAssignments
-from twistedcaldav.directory.xmlfile import XMLDirectoryService
-from twistedcaldav.directory.calendaruserproxyloader import XMLCalendarUserProxyLoader
-from twistedcaldav.directory import augment, calendaruserproxy
-from twistedcaldav.directory.util import normalizeUUID
-from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
-
-import cPickle as pickle
-import uuid
-
-def StubCheckSACL(cls, username, service):
-    services = {
-        &quot;calendar&quot; : [&quot;amanda&quot;, &quot;betty&quot;],
-        &quot;addressbook&quot; : [&quot;amanda&quot;, &quot;carlene&quot;],
-    }
-    if username in services[service]:
-        return 0
-    return 1
-
-
-
-class SACLTests(TestCase):
-
-    def setUp(self):
-        self.patch(DirectoryRecord, &quot;CheckSACL&quot;, StubCheckSACL)
-        self.patch(config, &quot;EnableSACLs&quot;, True)
-        self.service = DirectoryService()
-        self.service.setRealm(&quot;test&quot;)
-        self.service.baseGUID = &quot;0E8E6EC2-8E52-4FF3-8F62-6F398B08A498&quot;
-
-
-    def test_applySACLs(self):
-        &quot;&quot;&quot;
-        Users not in calendar SACL will have enabledForCalendaring set to
-        False.
-        Users not in addressbook SACL will have enabledForAddressBooks set to
-        False.
-        &quot;&quot;&quot;
-
-        data = [
-            (&quot;amanda&quot;, True, True,),
-            (&quot;betty&quot;, True, False,),
-            (&quot;carlene&quot;, False, True,),
-            (&quot;daniel&quot;, False, False,),
-        ]
-        for username, cal, ab in data:
-            record = DirectoryRecord(self.service, &quot;users&quot;, None, (username,),
-                enabledForCalendaring=True, enabledForAddressBooks=True)
-            record.applySACLs()
-            self.assertEquals(record.enabledForCalendaring, cal)
-            self.assertEquals(record.enabledForAddressBooks, ab)
-
-
-
-class GroupMembershipTests (TestCase):
-
-    @inlineCallbacks
-    def setUp(self):
-        super(GroupMembershipTests, self).setUp()
-
-        self.directoryFixture.addDirectoryService(XMLDirectoryService(
-            {
-                'xmlFile' : xmlFile,
-                'augmentService' :
-                    augment.AugmentXMLDB(xmlFiles=(augmentsFile.path,)),
-            }
-        ))
-        calendaruserproxy.ProxyDBService = calendaruserproxy.ProxySqliteDB(&quot;proxies.sqlite&quot;)
-
-        # Set up a principals hierarchy for each service we're testing with
-        self.principalRootResources = {}
-        name = self.directoryService.__class__.__name__
-        url = &quot;/&quot; + name + &quot;/&quot;
-
-        provisioningResource = DirectoryPrincipalProvisioningResource(url, self.directoryService)
-
-        self.site.resource.putChild(name, provisioningResource)
-
-        self.principalRootResources[self.directoryService.__class__.__name__] = provisioningResource
-
-        yield XMLCalendarUserProxyLoader(proxiesFile.path).updateProxyDB()
-
-
-    def tearDown(self):
-        &quot;&quot;&quot; Empty the proxy db between tests &quot;&quot;&quot;
-        return calendaruserproxy.ProxyDBService.clean() #@UndefinedVariable
-
-
-    def _getPrincipalByShortName(self, type, name):
-        provisioningResource = self.principalRootResources[self.directoryService.__class__.__name__]
-        return provisioningResource.principalForShortName(type, name)
-
-
-    def _updateMethod(self):
-        &quot;&quot;&quot;
-        Update a counter in the following test
-        &quot;&quot;&quot;
-        self.count += 1
-
-
-    def test_expandedMembers(self):
-        &quot;&quot;&quot;
-        Make sure expandedMembers( ) returns a complete, flattened set of
-        members of a group, including all sub-groups.
-        &quot;&quot;&quot;
-        bothCoasts = self.directoryService.recordWithShortName(
-            DirectoryService.recordType_groups, &quot;both_coasts&quot;)
-        self.assertEquals(
-            set([r.guid for r in bothCoasts.expandedMembers()]),
-            set(['8B4288F6-CC82-491D-8EF9-642EF4F3E7D0',
-                 '6423F94A-6B76-4A3A-815B-D52CFD77935D',
-                 '5A985493-EE2C-4665-94CF-4DFEA3A89500',
-                 '5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1',
-                 'left_coast',
-                 'right_coast'])
-        )
-
-
-    @inlineCallbacks
-    def test_groupMembershipCache(self):
-        &quot;&quot;&quot;
-        Ensure we get back what we put in
-        &quot;&quot;&quot;
-        cache = GroupMembershipCache(&quot;ProxyDB&quot;, expireSeconds=10)
-
-        yield cache.setGroupsFor(&quot;a&quot;, set([&quot;b&quot;, &quot;c&quot;, &quot;d&quot;])) # a is in b, c, d
-        members = (yield cache.getGroupsFor(&quot;a&quot;))
-        self.assertEquals(members, set([&quot;b&quot;, &quot;c&quot;, &quot;d&quot;]))
-
-        yield cache.setGroupsFor(&quot;b&quot;, set()) # b not in any groups
-        members = (yield cache.getGroupsFor(&quot;b&quot;))
-        self.assertEquals(members, set())
-
-        cache._memcacheProtocol.advanceClock(10)
-
-        members = (yield cache.getGroupsFor(&quot;a&quot;)) # has expired
-        self.assertEquals(members, set())
-
-
-    @inlineCallbacks
-    def test_groupMembershipCacheUpdater(self):
-        &quot;&quot;&quot;
-        Let the GroupMembershipCacheUpdater populate the cache, then make
-        sure proxyFor( ) and groupMemberships( ) work from the cache
-        &quot;&quot;&quot;
-        cache = GroupMembershipCache(&quot;ProxyDB&quot;, expireSeconds=60)
-        # Having a groupMembershipCache assigned to the directory service is the
-        # trigger to use such a cache:
-        self.directoryService.groupMembershipCache = cache
-
-        updater = GroupMembershipCacheUpdater(
-            calendaruserproxy.ProxyDBService, self.directoryService, 30, 30, 30,
-            cache=cache, useExternalProxies=False)
-
-        # Exercise getGroups()
-        groups, aliases = (yield updater.getGroups())
-        self.assertEquals(
-            groups,
-            {
-                '00599DAF-3E75-42DD-9DB7-52617E79943F':
-                    set(['46D9D716-CBEE-490F-907A-66FA6C3767FF']),
-                '9FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1':
-                    set(['8B4288F6-CC82-491D-8EF9-642EF4F3E7D0']),
-                'admin':
-                    set(['9FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1']),
-                'both_coasts':
-                    set(['left_coast', 'right_coast']),
-                'grunts':
-                    set(['5A985493-EE2C-4665-94CF-4DFEA3A89500',
-                         '5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1',
-                         '6423F94A-6B76-4A3A-815B-D52CFD77935D']),
-                'left_coast':
-                    set(['5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1',
-                         '6423F94A-6B76-4A3A-815B-D52CFD77935D',
-                         '8B4288F6-CC82-491D-8EF9-642EF4F3E7D0']),
-                'non_calendar_group':
-                    set(['5A985493-EE2C-4665-94CF-4DFEA3A89500',
-                         '8B4288F6-CC82-491D-8EF9-642EF4F3E7D0']),
-                'recursive1_coasts':
-                    set(['6423F94A-6B76-4A3A-815B-D52CFD77935D',
-                         'recursive2_coasts']),
-                'recursive2_coasts':
-                    set(['5A985493-EE2C-4665-94CF-4DFEA3A89500',
-                         'recursive1_coasts']),
-                'right_coast':
-                    set(['5A985493-EE2C-4665-94CF-4DFEA3A89500'])
-            }
-        )
-        self.assertEquals(
-            aliases,
-            {
-                '00599DAF-3E75-42DD-9DB7-52617E79943F':
-                    '00599DAF-3E75-42DD-9DB7-52617E79943F',
-                '9FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1':
-                    '9FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1',
-                 'admin': 'admin',
-                 'both_coasts': 'both_coasts',
-                 'grunts': 'grunts',
-                 'left_coast': 'left_coast',
-                 'non_calendar_group': 'non_calendar_group',
-                 'recursive1_coasts': 'recursive1_coasts',
-                 'recursive2_coasts': 'recursive2_coasts',
-                 'right_coast': 'right_coast'
-            }
-        )
-
-        # Exercise expandedMembers()
-        self.assertEquals(
-            updater.expandedMembers(groups, &quot;both_coasts&quot;),
-            set(['5A985493-EE2C-4665-94CF-4DFEA3A89500',
-                 '5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1',
-                 '6423F94A-6B76-4A3A-815B-D52CFD77935D',
-                 '8B4288F6-CC82-491D-8EF9-642EF4F3E7D0',
-                 'left_coast',
-                 'right_coast']
-            )
-        )
-
-        # Prevent an update by locking the cache
-        acquiredLock = (yield cache.acquireLock())
-        self.assertTrue(acquiredLock)
-        self.assertEquals((False, 0, 0), (yield updater.updateCache()))
-
-        # You can't lock when already locked:
-        acquiredLockAgain = (yield cache.acquireLock())
-        self.assertFalse(acquiredLockAgain)
-
-        # Allow an update by unlocking the cache
-        yield cache.releaseLock()
-
-        self.assertEquals((False, 9, 9), (yield updater.updateCache()))
-
-        # Verify cache is populated:
-        self.assertTrue((yield cache.isPopulated()))
-
-        delegates = (
-
-            # record name
-            # read-write delegators
-            # read-only delegators
-            # groups delegate is in (restricted to only those groups
-            #   participating in delegation)
-
-            (&quot;wsanchez&quot;,
-             set([&quot;mercury&quot;, &quot;apollo&quot;, &quot;orion&quot;, &quot;gemini&quot;]),
-             set([&quot;non_calendar_proxy&quot;]),
-             set(['left_coast',
-                  'both_coasts',
-                  'recursive1_coasts',
-                  'recursive2_coasts',
-                  'gemini#calendar-proxy-write',
-                ]),
-            ),
-            (&quot;cdaboo&quot;,
-             set([&quot;apollo&quot;, &quot;orion&quot;, &quot;non_calendar_proxy&quot;]),
-             set([&quot;non_calendar_proxy&quot;]),
-             set(['both_coasts',
-                  'non_calendar_group',
-                  'recursive1_coasts',
-                  'recursive2_coasts',
-                ]),
-            ),
-            (&quot;lecroy&quot;,
-             set([&quot;apollo&quot;, &quot;mercury&quot;, &quot;non_calendar_proxy&quot;]),
-             set(),
-             set(['both_coasts',
-                  'left_coast',
-                  'non_calendar_group',
-                ]),
-            ),
-            (&quot;usera&quot;,
-             set(),
-             set(),
-             set(),
-            ),
-            (&quot;userb&quot;,
-             set(['7423F94A-6B76-4A3A-815B-D52CFD77935D']),
-             set(),
-             set(['7423F94A-6B76-4A3A-815B-D52CFD77935D#calendar-proxy-write']),
-            ),
-            (&quot;userc&quot;,
-             set(['7423F94A-6B76-4A3A-815B-D52CFD77935D']),
-             set(),
-             set(['7423F94A-6B76-4A3A-815B-D52CFD77935D#calendar-proxy-write']),
-            ),
-        )
-
-        for name, write, read, groups in delegates:
-            delegate = self._getPrincipalByShortName(DirectoryService.recordType_users, name)
-
-            proxyFor = (yield delegate.proxyFor(True))
-            self.assertEquals(
-                set([p.record.guid for p in proxyFor]),
-                write,
-            )
-            proxyFor = (yield delegate.proxyFor(False))
-            self.assertEquals(
-                set([p.record.guid for p in proxyFor]),
-                read,
-            )
-            groupsIn = (yield delegate.groupMemberships())
-            uids = set()
-            for group in groupsIn:
-                try:
-                    uid = group.uid # a sub-principal
-                except AttributeError:
-                    uid = group.record.guid # a regular group
-                uids.add(uid)
-            self.assertEquals(
-                set(uids),
-                groups,
-            )
-
-        # Verify CalendarUserProxyPrincipalResource.containsPrincipal( ) works
-        delegator = self._getPrincipalByShortName(DirectoryService.recordType_locations, &quot;mercury&quot;)
-        proxyPrincipal = delegator.getChild(&quot;calendar-proxy-write&quot;)
-        for expected, name in [(True, &quot;wsanchez&quot;), (False, &quot;cdaboo&quot;)]:
-            delegate = self._getPrincipalByShortName(DirectoryService.recordType_users, name)
-            self.assertEquals(expected, (yield proxyPrincipal.containsPrincipal(delegate)))
-
-        # Verify that principals who were previously members of delegated-to groups but
-        # are no longer members have their proxyFor info cleaned out of the cache:
-        # Remove wsanchez from all groups in the directory, run the updater, then check
-        # that wsanchez is only a proxy for gemini (since that assignment does not involve groups)
-        self.directoryService.xmlFile = dirTest.child(&quot;accounts-modified.xml&quot;)
-        self.directoryService._alwaysStat = True
-        self.assertEquals((False, 8, 1), (yield updater.updateCache()))
-        delegate = self._getPrincipalByShortName(DirectoryService.recordType_users, &quot;wsanchez&quot;)
-        proxyFor = (yield delegate.proxyFor(True))
-        self.assertEquals(
-          set([p.record.guid for p in proxyFor]),
-          set(['gemini'])
-        )
-
-
-    @inlineCallbacks
-    def test_groupMembershipCacheUpdaterExternalProxies(self):
-        &quot;&quot;&quot;
-        Exercise external proxy assignment support (assignments come from the
-        directory service itself)
-        &quot;&quot;&quot;
-        cache = GroupMembershipCache(&quot;ProxyDB&quot;, expireSeconds=60)
-        # Having a groupMembershipCache assigned to the directory service is the
-        # trigger to use such a cache:
-        self.directoryService.groupMembershipCache = cache
-
-        # This time, we're setting some external proxy assignments for the
-        # &quot;transporter&quot; resource...
-        def fakeExternalProxies():
-            return [
-                (
-                    &quot;transporter#calendar-proxy-write&quot;,
-                    set([&quot;6423F94A-6B76-4A3A-815B-D52CFD77935D&quot;,
-                         &quot;8B4288F6-CC82-491D-8EF9-642EF4F3E7D0&quot;])
-                ),
-                (
-                    &quot;transporter#calendar-proxy-read&quot;,
-                    set([&quot;5A985493-EE2C-4665-94CF-4DFEA3A89500&quot;])
-                ),
-            ]
-
-        updater = GroupMembershipCacheUpdater(
-            calendaruserproxy.ProxyDBService, self.directoryService, 30, 30, 30,
-            cache=cache, useExternalProxies=True,
-            externalProxiesSource=fakeExternalProxies)
-
-        yield updater.updateCache()
-
-        delegates = (
-
-            # record name
-            # read-write delegators
-            # read-only delegators
-            # groups delegate is in (restricted to only those groups
-            #   participating in delegation)
-
-            (&quot;wsanchez&quot;,
-             set([&quot;mercury&quot;, &quot;apollo&quot;, &quot;orion&quot;, &quot;gemini&quot;, &quot;transporter&quot;]),
-             set([&quot;non_calendar_proxy&quot;]),
-             set(['left_coast',
-                  'both_coasts',
-                  'recursive1_coasts',
-                  'recursive2_coasts',
-                  'gemini#calendar-proxy-write',
-                  'transporter#calendar-proxy-write',
-                ]),
-            ),
-            (&quot;cdaboo&quot;,
-             set([&quot;apollo&quot;, &quot;orion&quot;, &quot;non_calendar_proxy&quot;]),
-             set([&quot;non_calendar_proxy&quot;, &quot;transporter&quot;]),
-             set(['both_coasts',
-                  'non_calendar_group',
-                  'recursive1_coasts',
-                  'recursive2_coasts',
-                  'transporter#calendar-proxy-read',
-                ]),
-            ),
-            (&quot;lecroy&quot;,
-             set([&quot;apollo&quot;, &quot;mercury&quot;, &quot;non_calendar_proxy&quot;, &quot;transporter&quot;]),
-             set(),
-             set(['both_coasts',
-                  'left_coast',
-                  'non_calendar_group',
-                  'transporter#calendar-proxy-write',
-                ]),
-            ),
-        )
-
-        for name, write, read, groups in delegates:
-            delegate = self._getPrincipalByShortName(DirectoryService.recordType_users, name)
-
-            proxyFor = (yield delegate.proxyFor(True))
-            self.assertEquals(
-                set([p.record.guid for p in proxyFor]),
-                write,
-            )
-            proxyFor = (yield delegate.proxyFor(False))
-            self.assertEquals(
-                set([p.record.guid for p in proxyFor]),
-                read,
-            )
-            groupsIn = (yield delegate.groupMemberships())
-            uids = set()
-            for group in groupsIn:
-                try:
-                    uid = group.uid # a sub-principal
-                except AttributeError:
-                    uid = group.record.guid # a regular group
-                uids.add(uid)
-            self.assertEquals(
-                set(uids),
-                groups,
-            )
-
-        #
-        # Now remove two external assignments, and those should take effect.
-        #
-        def fakeExternalProxiesRemoved():
-            return [
-                (
-                    &quot;transporter#calendar-proxy-write&quot;,
-                    set([&quot;8B4288F6-CC82-491D-8EF9-642EF4F3E7D0&quot;])
-                ),
-            ]
-
-        updater = GroupMembershipCacheUpdater(
-            calendaruserproxy.ProxyDBService, self.directoryService, 30, 30, 30,
-            cache=cache, useExternalProxies=True,
-            externalProxiesSource=fakeExternalProxiesRemoved)
-
-        yield updater.updateCache()
-
-        delegates = (
-
-            # record name
-            # read-write delegators
-            # read-only delegators
-            # groups delegate is in (restricted to only those groups
-            #   participating in delegation)
-
-            # Note: &quot;transporter&quot; is now gone for wsanchez and cdaboo
-
-            (&quot;wsanchez&quot;,
-             set([&quot;mercury&quot;, &quot;apollo&quot;, &quot;orion&quot;, &quot;gemini&quot;]),
-             set([&quot;non_calendar_proxy&quot;]),
-             set(['left_coast',
-                  'both_coasts',
-                  'recursive1_coasts',
-                  'recursive2_coasts',
-                  'gemini#calendar-proxy-write',
-                ]),
-            ),
-            (&quot;cdaboo&quot;,
-             set([&quot;apollo&quot;, &quot;orion&quot;, &quot;non_calendar_proxy&quot;]),
-             set([&quot;non_calendar_proxy&quot;]),
-             set(['both_coasts',
-                  'non_calendar_group',
-                  'recursive1_coasts',
-                  'recursive2_coasts',
-                ]),
-            ),
-            (&quot;lecroy&quot;,
-             set([&quot;apollo&quot;, &quot;mercury&quot;, &quot;non_calendar_proxy&quot;, &quot;transporter&quot;]),
-             set(),
-             set(['both_coasts',
-                  'left_coast',
-                  'non_calendar_group',
-                  'transporter#calendar-proxy-write',
-                ]),
-            ),
-        )
-
-        for name, write, read, groups in delegates:
-            delegate = self._getPrincipalByShortName(DirectoryService.recordType_users, name)
-
-            proxyFor = (yield delegate.proxyFor(True))
-            self.assertEquals(
-                set([p.record.guid for p in proxyFor]),
-                write,
-            )
-            proxyFor = (yield delegate.proxyFor(False))
-            self.assertEquals(
-                set([p.record.guid for p in proxyFor]),
-                read,
-            )
-            groupsIn = (yield delegate.groupMemberships())
-            uids = set()
-            for group in groupsIn:
-                try:
-                    uid = group.uid # a sub-principal
-                except AttributeError:
-                    uid = group.record.guid # a regular group
-                uids.add(uid)
-            self.assertEquals(
-                set(uids),
-                groups,
-            )
-
-        #
-        # Now remove all external assignments, and those should take effect.
-        #
-        def fakeExternalProxiesEmpty():
-            return []
-
-        updater = GroupMembershipCacheUpdater(
-            calendaruserproxy.ProxyDBService, self.directoryService, 30, 30, 30,
-            cache=cache, useExternalProxies=True,
-            externalProxiesSource=fakeExternalProxiesEmpty)
-
-        yield updater.updateCache()
-
-        delegates = (
-
-            # record name
-            # read-write delegators
-            # read-only delegators
-            # groups delegate is in (restricted to only those groups
-            #   participating in delegation)
-
-            # Note: &quot;transporter&quot; is now gone for everyone
-
-            (&quot;wsanchez&quot;,
-             set([&quot;mercury&quot;, &quot;apollo&quot;, &quot;orion&quot;, &quot;gemini&quot;]),
-             set([&quot;non_calendar_proxy&quot;]),
-             set(['left_coast',
-                  'both_coasts',
-                  'recursive1_coasts',
-                  'recursive2_coasts',
-                  'gemini#calendar-proxy-write',
-                ]),
-            ),
-            (&quot;cdaboo&quot;,
-             set([&quot;apollo&quot;, &quot;orion&quot;, &quot;non_calendar_proxy&quot;]),
-             set([&quot;non_calendar_proxy&quot;]),
-             set(['both_coasts',
-                  'non_calendar_group',
-                  'recursive1_coasts',
-                  'recursive2_coasts',
-                ]),
-            ),
-            (&quot;lecroy&quot;,
-             set([&quot;apollo&quot;, &quot;mercury&quot;, &quot;non_calendar_proxy&quot;]),
-             set(),
-             set(['both_coasts',
-                  'left_coast',
-                      'non_calendar_group',
-                ]),
-            ),
-        )
-
-        for name, write, read, groups in delegates:
-            delegate = self._getPrincipalByShortName(DirectoryService.recordType_users, name)
-
-            proxyFor = (yield delegate.proxyFor(True))
-            self.assertEquals(
-                set([p.record.guid for p in proxyFor]),
-                write,
-            )
-            proxyFor = (yield delegate.proxyFor(False))
-            self.assertEquals(
-                set([p.record.guid for p in proxyFor]),
-                read,
-            )
-            groupsIn = (yield delegate.groupMemberships())
-            uids = set()
-            for group in groupsIn:
-                try:
-                    uid = group.uid # a sub-principal
-                except AttributeError:
-                    uid = group.record.guid # a regular group
-                uids.add(uid)
-            self.assertEquals(
-                set(uids),
-                groups,
-            )
-
-        #
-        # Now add back an external assignments, and those should take effect.
-        #
-        def fakeExternalProxiesAdded():
-            return [
-                (
-                    &quot;transporter#calendar-proxy-write&quot;,
-                    set([&quot;8B4288F6-CC82-491D-8EF9-642EF4F3E7D0&quot;])
-                ),
-            ]
-
-        updater = GroupMembershipCacheUpdater(
-            calendaruserproxy.ProxyDBService, self.directoryService, 30, 30, 30,
-            cache=cache, useExternalProxies=True,
-            externalProxiesSource=fakeExternalProxiesAdded)
-
-        yield updater.updateCache()
-
-        delegates = (
-
-            # record name
-            # read-write delegators
-            # read-only delegators
-            # groups delegate is in (restricted to only those groups
-            #   participating in delegation)
-
-            (&quot;wsanchez&quot;,
-             set([&quot;mercury&quot;, &quot;apollo&quot;, &quot;orion&quot;, &quot;gemini&quot;]),
-             set([&quot;non_calendar_proxy&quot;]),
-             set(['left_coast',
-                  'both_coasts',
-                  'recursive1_coasts',
-                  'recursive2_coasts',
-                  'gemini#calendar-proxy-write',
-                ]),
-            ),
-            (&quot;cdaboo&quot;,
-             set([&quot;apollo&quot;, &quot;orion&quot;, &quot;non_calendar_proxy&quot;]),
-             set([&quot;non_calendar_proxy&quot;]),
-             set(['both_coasts',
-                  'non_calendar_group',
-                  'recursive1_coasts',
-                  'recursive2_coasts',
-                ]),
-            ),
-            (&quot;lecroy&quot;,
-             set([&quot;apollo&quot;, &quot;mercury&quot;, &quot;non_calendar_proxy&quot;, &quot;transporter&quot;]),
-             set(),
-             set(['both_coasts',
-                  'left_coast',
-                  'non_calendar_group',
-                  'transporter#calendar-proxy-write',
-                ]),
-            ),
-        )
-
-        for name, write, read, groups in delegates:
-            delegate = self._getPrincipalByShortName(DirectoryService.recordType_users, name)
-
-            proxyFor = (yield delegate.proxyFor(True))
-            self.assertEquals(
-                set([p.record.guid for p in proxyFor]),
-                write,
-            )
-            proxyFor = (yield delegate.proxyFor(False))
-            self.assertEquals(
-                set([p.record.guid for p in proxyFor]),
-                read,
-            )
-            groupsIn = (yield delegate.groupMemberships())
-            uids = set()
-            for group in groupsIn:
-                try:
-                    uid = group.uid # a sub-principal
-                except AttributeError:
-                    uid = group.record.guid # a regular group
-                uids.add(uid)
-            self.assertEquals(
-                set(uids),
-                groups,
-            )
-
-
-    def test_diffAssignments(self):
-        &quot;&quot;&quot;
-        Ensure external proxy assignment diffing works
-        &quot;&quot;&quot;
-
-        self.assertEquals(
-            (
-                # changed
-                [],
-                # removed
-                [],
-            ),
-            diffAssignments(
-                # old
-                [],
-                # new
-                [],
-            )
-        )
-
-        self.assertEquals(
-            (
-                # changed
-                [],
-                # removed
-                [],
-            ),
-            diffAssignments(
-                # old
-                [(&quot;B&quot;, set([&quot;3&quot;])), (&quot;A&quot;, set([&quot;1&quot;, &quot;2&quot;])), ],
-                # new
-                [(&quot;A&quot;, set([&quot;1&quot;, &quot;2&quot;])), (&quot;B&quot;, set([&quot;3&quot;])), ],
-            )
-        )
-
-        self.assertEquals(
-            (
-                # changed
-                [(&quot;A&quot;, set([&quot;1&quot;, &quot;2&quot;])), (&quot;B&quot;, set([&quot;3&quot;])), ],
-                # removed
-                [],
-            ),
-            diffAssignments(
-                # old
-                [],
-                # new
-                [(&quot;A&quot;, set([&quot;1&quot;, &quot;2&quot;])), (&quot;B&quot;, set([&quot;3&quot;])), ],
-            )
-        )
-
-        self.assertEquals(
-            (
-                # changed
-                [],
-                # removed
-                [&quot;A&quot;, &quot;B&quot;],
-            ),
-            diffAssignments(
-                # old
-                [(&quot;A&quot;, set([&quot;1&quot;, &quot;2&quot;])), (&quot;B&quot;, set([&quot;3&quot;])), ],
-                # new
-                [],
-            )
-        )
-
-        self.assertEquals(
-            (
-                # changed
-                [(&quot;A&quot;, set([&quot;2&quot;])), (&quot;C&quot;, set([&quot;4&quot;, &quot;5&quot;])), (&quot;D&quot;, set([&quot;6&quot;])), ],
-                # removed
-                [&quot;B&quot;],
-            ),
-            diffAssignments(
-                # old
-                [(&quot;A&quot;, set([&quot;1&quot;, &quot;2&quot;])), (&quot;B&quot;, set([&quot;3&quot;])), (&quot;C&quot;, set([&quot;4&quot;])), ],
-                # new
-                [(&quot;D&quot;, set([&quot;6&quot;])), (&quot;C&quot;, set([&quot;4&quot;, &quot;5&quot;])), (&quot;A&quot;, set([&quot;2&quot;])), ],
-            )
-        )
-
-
-    @inlineCallbacks
-    def test_groupMembershipCacheSnapshot(self):
-        &quot;&quot;&quot;
-        The group membership cache creates a snapshot (a pickle file) of
-        the member -&gt; groups dictionary, and can quickly refresh memcached
-        from that snapshot when restarting the server.
-        &quot;&quot;&quot;
-        cache = GroupMembershipCache(&quot;ProxyDB&quot;, expireSeconds=60)
-        # Having a groupMembershipCache assigned to the directory service is the
-        # trigger to use such a cache:
-        self.directoryService.groupMembershipCache = cache
-
-        updater = GroupMembershipCacheUpdater(
-            calendaruserproxy.ProxyDBService, self.directoryService, 30, 30, 30,
-            cache=cache)
-
-        dataRoot = FilePath(config.DataRoot)
-        snapshotFile = dataRoot.child(&quot;memberships_cache&quot;)
-
-        # Snapshot doesn't exist initially
-        self.assertFalse(snapshotFile.exists())
-
-        # Try a fast update (as when the server starts up for the very first
-        # time), but since the snapshot doesn't exist we fault in from the
-        # directory (fast now is False), and snapshot will get created
-
-        # Note that because fast=True and isPopulated() is False, locking is
-        # ignored:
-        yield cache.acquireLock()
-
-        self.assertFalse((yield cache.isPopulated()))
-        fast, numMembers, numChanged = (yield updater.updateCache(fast=True))
-        self.assertEquals(fast, False)
-        self.assertEquals(numMembers, 9)
-        self.assertEquals(numChanged, 9)
-        self.assertTrue(snapshotFile.exists())
-        self.assertTrue((yield cache.isPopulated()))
-
-        yield cache.releaseLock()
-
-        # Try another fast update where the snapshot already exists (as in a
-        # server-restart scenario), which will only read from the snapshot
-        # as indicated by the return value for &quot;fast&quot;.  Note that the cache
-        # is already populated so updateCache( ) in fast mode will not do
-        # anything, and numMembers will be 0.
-        fast, numMembers, numChanged = (yield updater.updateCache(fast=True))
-        self.assertEquals(fast, True)
-        self.assertEquals(numMembers, 0)
-
-        # Try an update which faults in from the directory (fast=False)
-        fast, numMembers, numChanged = (yield updater.updateCache(fast=False))
-        self.assertEquals(fast, False)
-        self.assertEquals(numMembers, 9)
-        self.assertEquals(numChanged, 0)
-
-        # Verify the snapshot contains the pickled dictionary we expect
-        expected = {
-            &quot;46D9D716-CBEE-490F-907A-66FA6C3767FF&quot;:
-                set([
-                    u&quot;00599DAF-3E75-42DD-9DB7-52617E79943F&quot;,
-                ]),
-            &quot;5A985493-EE2C-4665-94CF-4DFEA3A89500&quot;:
-                set([
-                    u&quot;non_calendar_group&quot;,
-                    u&quot;recursive1_coasts&quot;,
-                    u&quot;recursive2_coasts&quot;,
-                    u&quot;both_coasts&quot;
-                ]),
-            &quot;6423F94A-6B76-4A3A-815B-D52CFD77935D&quot;:
-                set([
-                    u&quot;left_coast&quot;,
-                    u&quot;recursive1_coasts&quot;,
-                    u&quot;recursive2_coasts&quot;,
-                    u&quot;both_coasts&quot;
-                ]),
-            &quot;5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1&quot;:
-                set([
-                    u&quot;left_coast&quot;,
-                    u&quot;both_coasts&quot;
-                ]),
-            &quot;8B4288F6-CC82-491D-8EF9-642EF4F3E7D0&quot;:
-                set([
-                    u&quot;non_calendar_group&quot;,
-                    u&quot;left_coast&quot;,
-                    u&quot;both_coasts&quot;
-                ]),
-            &quot;left_coast&quot;:
-                 set([
-                     u&quot;both_coasts&quot;
-                 ]),
-            &quot;recursive1_coasts&quot;:
-                 set([
-                     u&quot;recursive1_coasts&quot;,
-                     u&quot;recursive2_coasts&quot;
-                 ]),
-            &quot;recursive2_coasts&quot;:
-                set([
-                    u&quot;recursive1_coasts&quot;,
-                    u&quot;recursive2_coasts&quot;
-                ]),
-            &quot;right_coast&quot;:
-                set([
-                    u&quot;both_coasts&quot;
-                ])
-        }
-        members = pickle.loads(snapshotFile.getContent())
-        self.assertEquals(members, expected)
-
-        # &quot;Corrupt&quot; the snapshot and verify it is regenerated properly
-        snapshotFile.setContent(&quot;xyzzy&quot;)
-        cache.delete(&quot;group-cacher-populated&quot;)
-        fast, numMembers, numChanged = (yield updater.updateCache(fast=True))
-        self.assertEquals(fast, False)
-        self.assertEquals(numMembers, 9)
-        self.assertEquals(numChanged, 9)
-        self.assertTrue(snapshotFile.exists())
-        members = pickle.loads(snapshotFile.getContent())
-        self.assertEquals(members, expected)
-
-
-    def test_autoAcceptMembers(self):
-        &quot;&quot;&quot;
-        autoAcceptMembers( ) returns an empty list if no autoAcceptGroup is
-        assigned, or the expanded membership if assigned.
-        &quot;&quot;&quot;
-
-        # No auto-accept-group for &quot;orion&quot; in augments.xml
-        orion = self.directoryService.recordWithGUID(&quot;orion&quot;)
-        self.assertEquals(orion.autoAcceptMembers(), [])
-
-        # &quot;both_coasts&quot; group assigned to &quot;apollo&quot; in augments.xml
-        apollo = self.directoryService.recordWithGUID(&quot;apollo&quot;)
-        self.assertEquals(
-            set(apollo.autoAcceptMembers()),
-            set([
-                &quot;8B4288F6-CC82-491D-8EF9-642EF4F3E7D0&quot;,
-                 &quot;5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1&quot;,
-                 &quot;5A985493-EE2C-4665-94CF-4DFEA3A89500&quot;,
-                 &quot;6423F94A-6B76-4A3A-815B-D52CFD77935D&quot;,
-                 &quot;right_coast&quot;,
-                 &quot;left_coast&quot;,
-            ])
-        )
-
-
-    # @inlineCallbacks
-    # def testScheduling(self):
-    #     &quot;&quot;&quot;
-    #     Exercise schedulePolledGroupCachingUpdate
-    #     &quot;&quot;&quot;
-
-    #     groupCacher = StubGroupCacher()
-
-
-    #     def decorateTransaction(txn):
-    #         txn._groupCacher = groupCacher
-
-    #     store = yield buildStore(self, None)
-    #     store.callWithNewTransactions(decorateTransaction)
-    #     wp = (yield schedulePolledGroupCachingUpdate(store))
-    #     yield wp.whenExecuted()
-    #     self.assertTrue(groupCacher.called)
-
-    # testScheduling.skip = &quot;Fix WorkProposal to track delayed calls and cancel them&quot;
-
-
-
-class StubGroupCacher(object):
-    def __init__(self):
-        self.called = False
-        self.updateSeconds = 99
-
-
-    def updateCache(self):
-        self.called = True
-
-
-
-class RecordsMatchingTokensTests(TestCase):
-
-    @inlineCallbacks
-    def setUp(self):
-        super(RecordsMatchingTokensTests, self).setUp()
-
-        self.directoryFixture.addDirectoryService(XMLDirectoryService(
-            {
-                'xmlFile' : xmlFile,
-                'augmentService' :
-                    augment.AugmentXMLDB(xmlFiles=(augmentsFile.path,)),
-            }
-        ))
-        calendaruserproxy.ProxyDBService = calendaruserproxy.ProxySqliteDB(&quot;proxies.sqlite&quot;)
-
-        # Set up a principals hierarchy for each service we're testing with
-        self.principalRootResources = {}
-        name = self.directoryService.__class__.__name__
-        url = &quot;/&quot; + name + &quot;/&quot;
-
-        provisioningResource = DirectoryPrincipalProvisioningResource(url, self.directoryService)
-
-        self.site.resource.putChild(name, provisioningResource)
-
-        self.principalRootResources[self.directoryService.__class__.__name__] = provisioningResource
-
-        yield XMLCalendarUserProxyLoader(proxiesFile.path).updateProxyDB()
-
-
-    def tearDown(self):
-        &quot;&quot;&quot; Empty the proxy db between tests &quot;&quot;&quot;
-        return calendaruserproxy.ProxyDBService.clean() #@UndefinedVariable
-
-
-    @inlineCallbacks
-    def test_recordsMatchingTokens(self):
-        &quot;&quot;&quot;
-        Exercise the default recordsMatchingTokens implementation
-        &quot;&quot;&quot;
-        records = list((yield self.directoryService.recordsMatchingTokens([&quot;Use&quot;, &quot;01&quot;])))
-        self.assertNotEquals(len(records), 0)
-        shorts = [record.shortNames[0] for record in records]
-        self.assertTrue(&quot;user01&quot; in shorts)
-
-        records = list((yield self.directoryService.recordsMatchingTokens(['&quot;quotey&quot;'],
-            context=self.directoryService.searchContext_attendee)))
-        self.assertEquals(len(records), 1)
-        self.assertEquals(records[0].shortNames[0], &quot;doublequotes&quot;)
-
-        records = list((yield self.directoryService.recordsMatchingTokens([&quot;coast&quot;])))
-        self.assertEquals(len(records), 5)
-
-        records = list((yield self.directoryService.recordsMatchingTokens([&quot;poll&quot;],
-            context=self.directoryService.searchContext_location)))
-        self.assertEquals(len(records), 1)
-        self.assertEquals(records[0].shortNames[0], &quot;apollo&quot;)
-
-
-    def test_recordTypesForSearchContext(self):
-        self.assertEquals(
-            [self.directoryService.recordType_locations],
-            self.directoryService.recordTypesForSearchContext(&quot;location&quot;)
-        )
-        self.assertEquals(
-            [self.directoryService.recordType_resources],
-            self.directoryService.recordTypesForSearchContext(&quot;resource&quot;)
-        )
-        self.assertEquals(
-            [self.directoryService.recordType_users],
-            self.directoryService.recordTypesForSearchContext(&quot;user&quot;)
-        )
-        self.assertEquals(
-            [self.directoryService.recordType_groups],
-            self.directoryService.recordTypesForSearchContext(&quot;group&quot;)
-        )
-        self.assertEquals(
-            set([
-                self.directoryService.recordType_resources,
-                self.directoryService.recordType_users,
-                self.directoryService.recordType_groups
-            ]),
-            set(self.directoryService.recordTypesForSearchContext(&quot;attendee&quot;))
-        )
-
-
-
-class GUIDTests(TestCase):
-
-    def setUp(self):
-        self.service = DirectoryService()
-        self.service.setRealm(&quot;test&quot;)
-        self.service.baseGUID = &quot;0E8E6EC2-8E52-4FF3-8F62-6F398B08A498&quot;
-
-
-    def test_normalizeUUID(self):
-
-        # Ensure that record.guid automatically gets normalized to
-        # uppercase+hyphenated form if the value is one that uuid.UUID( )
-        # recognizes.
-
-        data = (
-            (
-                &quot;0543A85A-D446-4CF6-80AE-6579FA60957F&quot;,
-                &quot;0543A85A-D446-4CF6-80AE-6579FA60957F&quot;
-            ),
-            (
-                &quot;0543a85a-d446-4cf6-80ae-6579fa60957f&quot;,
-                &quot;0543A85A-D446-4CF6-80AE-6579FA60957F&quot;
-            ),
-            (
-                &quot;0543A85AD4464CF680AE-6579FA60957F&quot;,
-                &quot;0543A85A-D446-4CF6-80AE-6579FA60957F&quot;
-            ),
-            (
-                &quot;0543a85ad4464cf680ae6579fa60957f&quot;,
-                &quot;0543A85A-D446-4CF6-80AE-6579FA60957F&quot;
-            ),
-            (
-                &quot;foo&quot;,
-                &quot;foo&quot;
-            ),
-            (
-                None,
-                None
-            ),
-        )
-        for original, expected in data:
-            self.assertEquals(expected, normalizeUUID(original))
-            record = DirectoryRecord(self.service, &quot;users&quot;, original,
-                shortNames=(&quot;testing&quot;,))
-            self.assertEquals(expected, record.guid)
-
-
-
-class DirectoryServiceTests(TestCase):
-    &quot;&quot;&quot;
-    Test L{DirectoryService} apis.
-    &quot;&quot;&quot;
-
-    class StubDirectoryService(DirectoryService):
-
-        def __init__(self):
-            self._records = {}
-
-
-        def createRecord(self, recordType, guid=None, shortNames=(), authIDs=set(),
-            fullName=None, firstName=None, lastName=None, emailAddresses=set(),
-            uid=None, password=None, **kwargs):
-            &quot;&quot;&quot;
-            Create/persist a directory record based on the given values
-            &quot;&quot;&quot;
-
-            record = DirectoryRecord(
-                self,
-                recordType,
-                guid=guid,
-                shortNames=shortNames,
-                authIDs=authIDs,
-                fullName=fullName,
-                firstName=firstName,
-                lastName=lastName,
-                emailAddresses=emailAddresses,
-                uid=uid,
-                password=password,
-                **kwargs
-            )
-            self._records.setdefault(recordType, []).append(record)
-
-
-        def recordTypes(self):
-            return self._records.keys()
-
-
-        def listRecords(self, recordType):
-            return self._records[recordType]
-
-
-    def setUp(self):
-        self.service = self.StubDirectoryService()
-        self.service.setRealm(&quot;test&quot;)
-        self.service.baseGUID = &quot;0E8E6EC2-8E52-4FF3-8F62-6F398B08A498&quot;
-
-
-    def test_recordWithCalendarUserAddress_principal_uris(self):
-        &quot;&quot;&quot;
-        Make sure that recordWithCalendarUserAddress handles percent-encoded
-        principal URIs.
-        &quot;&quot;&quot;
-
-        self.service.createRecord(
-            DirectoryService.recordType_users,
-            guid=&quot;user01&quot;,
-            shortNames=(&quot;user 01&quot;, &quot;User 01&quot;),
-            fullName=&quot;User 01&quot;,
-            enabledForCalendaring=True,
-        )
-        self.service.createRecord(
-            DirectoryService.recordType_users,
-            guid=&quot;user02&quot;,
-            shortNames=(&quot;user02&quot;, &quot;User 02&quot;),
-            fullName=&quot;User 02&quot;,
-            enabledForCalendaring=True,
-        )
-
-        record = self.service.recordWithCalendarUserAddress(&quot;/principals/users/user%2001&quot;)
-        self.assertTrue(record is not None)
-        record = self.service.recordWithCalendarUserAddress(&quot;/principals/users/user02&quot;)
-        self.assertTrue(record is not None)
-        record = self.service.recordWithCalendarUserAddress(&quot;/principals/users/user%0202&quot;)
-        self.assertTrue(record is None)
-
-
-
-class DirectoryRecordTests(TestCase):
-    &quot;&quot;&quot;
-    Test L{DirectoryRecord} apis.
-    &quot;&quot;&quot;
-
-    def setUp(self):
-        self.service = DirectoryService()
-        self.service.setRealm(&quot;test&quot;)
-        self.service.baseGUID = &quot;0E8E6EC2-8E52-4FF3-8F62-6F398B08A498&quot;
-
-
-    def test_cacheToken(self):
-        &quot;&quot;&quot;
-        Test that DirectoryRecord.cacheToken is different for different records, and its value changes
-        as attributes on the record change.
-        &quot;&quot;&quot;
-
-        record1 = DirectoryRecord(self.service, &quot;users&quot;, str(uuid.uuid4()), shortNames=(&quot;testing1&quot;,))
-        record2 = DirectoryRecord(self.service, &quot;users&quot;, str(uuid.uuid4()), shortNames=(&quot;testing2&quot;,))
-        self.assertNotEquals(record1.cacheToken(), record2.cacheToken())
-
-        cache1 = record1.cacheToken()
-        record1.enabled = True
-        self.assertNotEquals(cache1, record1.cacheToken())
-
-        cache1 = record1.cacheToken()
-        record1.enabledForCalendaring = True
-        self.assertNotEquals(cache1, record1.cacheToken())
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_modifypy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_modify.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_modify.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_modify.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,159 +0,0 @@
</span><del>-##
-# Copyright (c) 2005-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.
-##
-
-import os
-from twistedcaldav.config import config
-from twistedcaldav.test.util import TestCase
-from calendarserver.tools.util import getDirectory
-from twext.python.filepath import CachingFilePath as FilePath
-from twistedcaldav.directory.directory import DirectoryError
-
-
-class ModificationTestCase(TestCase):
-
-    def setUp(self):
-        super(ModificationTestCase, self).setUp()
-
-        testRoot = os.path.join(os.path.dirname(__file__), &quot;modify&quot;)
-        #configFileName = os.path.join(testRoot, &quot;caldavd.plist&quot;)
-        #config.load(configFileName)
-
-        usersFile = os.path.join(testRoot, &quot;users-groups.xml&quot;)
-        config.DirectoryService.params.xmlFile = usersFile
-
-        # Copy xml file containing locations/resources to a temp file because
-        # we're going to be modifying it during testing
-
-        origResourcesFile = FilePath(os.path.join(os.path.dirname(__file__),
-            &quot;modify&quot;, &quot;resources-locations.xml&quot;))
-        copyResourcesFile = FilePath(self.mktemp())
-        origResourcesFile.copyTo(copyResourcesFile)
-        config.ResourceService.params.xmlFile = copyResourcesFile
-        config.ResourceService.Enabled = True
-
-        augmentsFile = os.path.join(testRoot, &quot;augments.xml&quot;)
-        config.AugmentService.params.xmlFiles = (augmentsFile,)
-
-
-    def test_createRecord(self):
-        directory = getDirectory()
-
-        record = directory.recordWithUID(&quot;resource01&quot;)
-        self.assertEquals(record, None)
-
-        directory.createRecord(&quot;resources&quot;, guid=&quot;resource01&quot;,
-            shortNames=(&quot;resource01&quot;,), uid=&quot;resource01&quot;,
-            emailAddresses=(&quot;res1@example.com&quot;, &quot;res2@example.com&quot;),
-            comment=&quot;Test Comment&quot;)
-
-        record = directory.recordWithUID(&quot;resource01&quot;)
-        self.assertNotEquals(record, None)
-
-        self.assertEquals(len(record.emailAddresses), 2)
-        self.assertEquals(record.extras['comment'], &quot;Test Comment&quot;)
-
-        directory.createRecord(&quot;resources&quot;, guid=&quot;resource02&quot;, shortNames=(&quot;resource02&quot;,), uid=&quot;resource02&quot;)
-
-        record = directory.recordWithUID(&quot;resource02&quot;)
-        self.assertNotEquals(record, None)
-
-        # Make sure old records are still there:
-        record = directory.recordWithUID(&quot;resource01&quot;)
-        self.assertNotEquals(record, None)
-        record = directory.recordWithUID(&quot;location01&quot;)
-        self.assertNotEquals(record, None)
-
-
-    def test_destroyRecord(self):
-        directory = getDirectory()
-
-        record = directory.recordWithUID(&quot;resource01&quot;)
-        self.assertEquals(record, None)
-
-        directory.createRecord(&quot;resources&quot;, guid=&quot;resource01&quot;, shortNames=(&quot;resource01&quot;,), uid=&quot;resource01&quot;)
-
-        record = directory.recordWithUID(&quot;resource01&quot;)
-        self.assertNotEquals(record, None)
-
-        directory.destroyRecord(&quot;resources&quot;, guid=&quot;resource01&quot;)
-
-        record = directory.recordWithUID(&quot;resource01&quot;)
-        self.assertEquals(record, None)
-
-        # Make sure old records are still there:
-        record = directory.recordWithUID(&quot;location01&quot;)
-        self.assertNotEquals(record, None)
-
-
-    def test_updateRecord(self):
-        directory = getDirectory()
-
-        directory.createRecord(&quot;resources&quot;, guid=&quot;resource01&quot;,
-            shortNames=(&quot;resource01&quot;,), uid=&quot;resource01&quot;,
-            fullName=&quot;Resource number 1&quot;)
-
-        record = directory.recordWithUID(&quot;resource01&quot;)
-        self.assertEquals(record.fullName, &quot;Resource number 1&quot;)
-
-        directory.updateRecord(&quot;resources&quot;, guid=&quot;resource01&quot;,
-            shortNames=(&quot;resource01&quot;, &quot;r01&quot;), uid=&quot;resource01&quot;,
-            fullName=&quot;Resource #1&quot;, firstName=&quot;First&quot;, lastName=&quot;Last&quot;,
-            emailAddresses=(&quot;resource01@example.com&quot;, &quot;r01@example.com&quot;),
-            comment=&quot;Test Comment&quot;)
-
-        record = directory.recordWithUID(&quot;resource01&quot;)
-        self.assertEquals(record.fullName, &quot;Resource #1&quot;)
-        self.assertEquals(record.firstName, &quot;First&quot;)
-        self.assertEquals(record.lastName, &quot;Last&quot;)
-        self.assertEquals(set(record.shortNames), set([&quot;resource01&quot;, &quot;r01&quot;]))
-        self.assertEquals(record.emailAddresses,
-            set([&quot;resource01@example.com&quot;, &quot;r01@example.com&quot;]))
-        self.assertEquals(record.extras['comment'], &quot;Test Comment&quot;)
-
-        # Make sure old records are still there:
-        record = directory.recordWithUID(&quot;location01&quot;)
-        self.assertNotEquals(record, None)
-
-
-    def test_createDuplicateRecord(self):
-        directory = getDirectory()
-
-        directory.createRecord(&quot;resources&quot;, guid=&quot;resource01&quot;, shortNames=(&quot;resource01&quot;,), uid=&quot;resource01&quot;)
-        self.assertRaises(DirectoryError, directory.createRecord, &quot;resources&quot;, guid=&quot;resource01&quot;, shortNames=(&quot;resource01&quot;,), uid=&quot;resource01&quot;)
-
-
-    def test_missingShortNames(self):
-        directory = getDirectory()
-
-        directory.createRecord(&quot;resources&quot;, guid=&quot;resource01&quot;)
-
-        record = directory.recordWithUID(&quot;resource01&quot;)
-        self.assertEquals(record.shortNames[0], &quot;resource01&quot;)
-
-        directory.updateRecord(&quot;resources&quot;, guid=&quot;resource01&quot;,
-            fullName=&quot;Resource #1&quot;)
-
-        record = directory.recordWithUID(&quot;resource01&quot;)
-        self.assertEquals(record.shortNames[0], &quot;resource01&quot;)
-        self.assertEquals(record.fullName, &quot;Resource #1&quot;)
-
-
-    def test_missingGUID(self):
-        directory = getDirectory()
-
-        record = directory.createRecord(&quot;resources&quot;)
-
-        self.assertEquals(record.shortNames[0], record.guid)
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_principalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_principal.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_principal.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_principal.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -16,68 +16,63 @@
</span><span class="cx"> from __future__ import print_function
</span><span class="cx"> 
</span><span class="cx"> import os
</span><ins>+from urllib import quote
</ins><span class="cx"> 
</span><span class="cx"> from twisted.cred.credentials import UsernamePassword
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks
</span><del>-from txdav.xml import element as davxml
-from txweb2.dav.fileop import rmdir
-from txweb2.dav.resource import AccessDeniedError
-from txweb2.http import HTTPError
-from txweb2.test.test_server import SimpleRequest
-
</del><ins>+from twistedcaldav import carddavxml
</ins><span class="cx"> from twistedcaldav.cache import DisabledCacheNotifier
</span><span class="cx"> from twistedcaldav.caldavxml import caldav_namespace
</span><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from twistedcaldav.customxml import calendarserver_namespace
</span><del>-from twistedcaldav.directory import augment, calendaruserproxy
</del><span class="cx"> from twistedcaldav.directory.addressbook import DirectoryAddressBookHomeProvisioningResource
</span><span class="cx"> from twistedcaldav.directory.calendar import DirectoryCalendarHomeProvisioningResource
</span><del>-from twistedcaldav.directory.directory import DirectoryService
-from twistedcaldav.directory.xmlfile import XMLDirectoryService
-from twistedcaldav.directory.test.test_xmlfile import xmlFile, augmentsFile
</del><ins>+from twistedcaldav.directory.principal import DirectoryCalendarPrincipalResource
</ins><span class="cx"> from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource
</span><del>-from twistedcaldav.directory.principal import DirectoryPrincipalTypeProvisioningResource
</del><span class="cx"> from twistedcaldav.directory.principal import DirectoryPrincipalResource
</span><del>-from twistedcaldav.directory.principal import DirectoryCalendarPrincipalResource
-from twistedcaldav import carddavxml
-import twistedcaldav.test.util
-
</del><ins>+from twistedcaldav.directory.principal import DirectoryPrincipalTypeProvisioningResource
+from twistedcaldav.test.util import StoreTestCase
</ins><span class="cx"> from txdav.common.datastore.file import CommonDataStore
</span><del>-from urllib import quote
</del><ins>+from txdav.xml import element as davxml
+from txweb2.dav.fileop import rmdir
+from txweb2.dav.resource import AccessDeniedError
+from txweb2.http import HTTPError
+from txweb2.test.test_server import SimpleRequest
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class ProvisionedPrincipals (twistedcaldav.test.util.TestCase):
</del><ins>+
+class ProvisionedPrincipals(StoreTestCase):  # twistedcaldav.test.util.TestCase):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Directory service provisioned principals.
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    def setUp(self):
-        super(ProvisionedPrincipals, self).setUp()
</del><ins>+    # def setUp(self):
+    #     super(ProvisionedPrincipals, self).setUp()
</ins><span class="cx"> 
</span><del>-        self.directoryServices = (
-            XMLDirectoryService(
-                {
-                    'xmlFile' : xmlFile,
-                    'augmentService' :
-                        augment.AugmentXMLDB(xmlFiles=(augmentsFile.path,)),
-                }
-            ),
-        )
</del><ins>+    #     self.directoryServices = (
+    #         XMLDirectoryService(
+    #             {
+    #                 'xmlFile' : xmlFile,
+    #                 'augmentService' :
+    #                     augment.AugmentXMLDB(xmlFiles=(augmentsFile.path,)),
+    #             }
+    #         ),
+    #     )
</ins><span class="cx"> 
</span><del>-        # Set up a principals hierarchy for each service we're testing with
-        self.principalRootResources = {}
-        for directory in self.directoryServices:
-            name = directory.__class__.__name__
-            url = &quot;/&quot; + name + &quot;/&quot;
</del><ins>+    #     # Set up a principals hierarchy for each service we're testing with
+    #     self.principalRootResources = {}
+    #     for directory in self.directoryServices:
+    #         name = directory.__class__.__name__
+    #         url = &quot;/&quot; + name + &quot;/&quot;
</ins><span class="cx"> 
</span><del>-            provisioningResource = DirectoryPrincipalProvisioningResource(url, directory)
-            directory.setPrincipalCollection(provisioningResource)
</del><ins>+    #         provisioningResource = DirectoryPrincipalProvisioningResource(url, directory)
+    #         directory.setPrincipalCollection(provisioningResource)
</ins><span class="cx"> 
</span><del>-            self.site.resource.putChild(name, provisioningResource)
</del><ins>+    #         self.site.resource.putChild(name, provisioningResource)
</ins><span class="cx"> 
</span><del>-            self.principalRootResources[directory.__class__.__name__] = provisioningResource
</del><ins>+    #         self.principalRootResources[directory.__class__.__name__] = provisioningResource
</ins><span class="cx"> 
</span><del>-        calendaruserproxy.ProxyDBService = calendaruserproxy.ProxySqliteDB(os.path.abspath(self.mktemp()))
</del><ins>+    #     calendaruserproxy.ProxyDBService = calendaruserproxy.ProxySqliteDB(os.path.abspath(self.mktemp()))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -95,7 +90,8 @@
</span><span class="cx"> 
</span><span class="cx">         DirectoryPrincipalResource.principalURL(),
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        for directory in self.directoryServices:
</del><ins>+        directory = self.directory
+        if True:
</ins><span class="cx">             #print(&quot;\n -&gt; %s&quot; % (directory.__class__.__name__,))
</span><span class="cx">             provisioningResource = self.principalRootResources[directory.__class__.__name__]
</span><span class="cx"> 
</span><span class="lines">@@ -170,33 +166,33 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DirectoryPrincipalProvisioningResource.principalForUser()
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        for directory in self.directoryServices:
-            provisioningResource = self.principalRootResources[directory.__class__.__name__]
</del><ins>+        directory = self.directory
+        provisioningResource = self.principalRootResources[directory.__class__.__name__]
</ins><span class="cx"> 
</span><del>-            for user in directory.listRecords(DirectoryService.recordType_users):
-                userResource = provisioningResource.principalForUser(user.shortNames[0])
-                if user.enabled:
-                    self.failIf(userResource is None)
-                    self.assertEquals(user, userResource.record)
-                else:
-                    self.failIf(userResource is not None)
</del><ins>+        for user in directory.listRecords(DirectoryService.recordType_users):
+            userResource = provisioningResource.principalForUser(user.shortNames[0])
+            if user.enabled:
+                self.failIf(userResource is None)
+                self.assertEquals(user, userResource.record)
+            else:
+                self.failIf(userResource is not None)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_principalForAuthID(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DirectoryPrincipalProvisioningResource.principalForAuthID()
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        for directory in self.directoryServices:
-            provisioningResource = self.principalRootResources[directory.__class__.__name__]
</del><ins>+        directory = self.directory
+        provisioningResource = self.principalRootResources[directory.__class__.__name__]
</ins><span class="cx"> 
</span><del>-            for user in directory.listRecords(DirectoryService.recordType_users):
-                creds = UsernamePassword(user.shortNames[0], &quot;bogus&quot;)
-                userResource = provisioningResource.principalForAuthID(creds)
-                if user.enabled:
-                    self.failIf(userResource is None)
-                    self.assertEquals(user, userResource.record)
-                else:
-                    self.failIf(userResource is not None)
</del><ins>+        for user in directory.listRecords(DirectoryService.recordType_users):
+            creds = UsernamePassword(user.shortNames[0], &quot;bogus&quot;)
+            userResource = provisioningResource.principalForAuthID(creds)
+            if user.enabled:
+                self.failIf(userResource is None)
+                self.assertEquals(user, userResource.record)
+            else:
+                self.failIf(userResource is not None)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_principalForUID(self):
</span><span class="lines">@@ -465,23 +461,23 @@
</span><span class="cx">         # Need to create a addressbook home provisioner for each service.
</span><span class="cx">         addressBookRootResources = {}
</span><span class="cx"> 
</span><del>-        for directory in self.directoryServices:
-            path = os.path.join(self.docroot, directory.__class__.__name__)
</del><ins>+        directory = self.directory
+        path = os.path.join(self.docroot, directory.__class__.__name__)
</ins><span class="cx"> 
</span><del>-            if os.path.exists(path):
-                rmdir(path)
-            os.mkdir(path)
</del><ins>+        if os.path.exists(path):
+            rmdir(path)
+        os.mkdir(path)
</ins><span class="cx"> 
</span><del>-            # Need a data store
-            _newStore = CommonDataStore(path, None, None, True, False)
</del><ins>+        # need a data store
+        _newstore = commondatastore(path, none, none, true, false)
</ins><span class="cx"> 
</span><del>-            provisioningResource = DirectoryAddressBookHomeProvisioningResource(
-                directory,
-                &quot;/addressbooks/&quot;,
-                _newStore
-            )
</del><ins>+        provisioningresource = directoryaddressbookhomeprovisioningresource(
+            directory,
+            &quot;/addressbooks/&quot;,
+            _newstore
+        )
</ins><span class="cx"> 
</span><del>-            addressBookRootResources[directory.__class__.__name__] = provisioningResource
</del><ins>+        addressbookrootresources[directory.__class__.__name__] = provisioningResource
</ins><span class="cx"> 
</span><span class="cx">         # AddressBook home provisioners should result in addressBook homes.
</span><span class="cx">         for provisioningResource, _ignore_recordType, recordResource, record in self._allRecords():
</span><span class="lines">@@ -517,23 +513,23 @@
</span><span class="cx">         # Need to create a calendar home provisioner for each service.
</span><span class="cx">         calendarRootResources = {}
</span><span class="cx"> 
</span><del>-        for directory in self.directoryServices:
-            path = os.path.join(self.docroot, directory.__class__.__name__)
</del><ins>+        directory = self.directory
+        path = os.path.join(self.docroot, directory.__class__.__name__)
</ins><span class="cx"> 
</span><del>-            if os.path.exists(path):
-                rmdir(path)
-            os.mkdir(path)
</del><ins>+        if os.path.exists(path):
+            rmdir(path)
+        os.mkdir(path)
</ins><span class="cx"> 
</span><del>-            # Need a data store
-            _newStore = CommonDataStore(path, None, None, True, False)
</del><ins>+        # Need a data store
+        _newStore = CommonDataStore(path, None, None, True, False)
</ins><span class="cx"> 
</span><del>-            provisioningResource = DirectoryCalendarHomeProvisioningResource(
-                directory,
-                &quot;/calendars/&quot;,
-                _newStore
-            )
</del><ins>+        provisioningResource = DirectoryCalendarHomeProvisioningResource(
+            directory,
+            &quot;/calendars/&quot;,
+            _newStore
+        )
</ins><span class="cx"> 
</span><del>-            calendarRootResources[directory.__class__.__name__] = provisioningResource
</del><ins>+        calendarRootResources[directory.__class__.__name__] = provisioningResource
</ins><span class="cx"> 
</span><span class="cx">         # Calendar home provisioners should result in calendar homes.
</span><span class="cx">         for provisioningResource, _ignore_recordType, recordResource, record in self._allRecords():
</span><span class="lines">@@ -643,19 +639,19 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Default access controls for principal provisioning resources.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        for directory in self.directoryServices:
-            #print(&quot;\n -&gt; %s&quot; % (directory.__class__.__name__,))
-            provisioningResource = self.principalRootResources[directory.__class__.__name__]
</del><ins>+        directory = self.directory
+        #print(&quot;\n -&gt; %s&quot; % (directory.__class__.__name__,))
+        provisioningResource = self.principalRootResources[directory.__class__.__name__]
</ins><span class="cx"> 
</span><del>-            for args in _authReadOnlyPrivileges(self, provisioningResource, provisioningResource.principalCollectionURL()):
-                yield self._checkPrivileges(*args)
</del><ins>+        for args in _authReadOnlyPrivileges(self, provisioningResource, provisioningResource.principalCollectionURL()):
+            yield self._checkPrivileges(*args)
</ins><span class="cx"> 
</span><del>-            for recordType in (yield provisioningResource.listChildren()):
-                #print(&quot;   -&gt; %s&quot; % (recordType,))
-                typeResource = provisioningResource.getChild(recordType)
</del><ins>+        for recordType in (yield provisioningResource.listChildren()):
+            #print(&quot;   -&gt; %s&quot; % (recordType,))
+            typeResource = provisioningResource.getChild(recordType)
</ins><span class="cx"> 
</span><del>-                for args in _authReadOnlyPrivileges(self, typeResource, typeResource.principalCollectionURL()):
-                    yield self._checkPrivileges(*args)
</del><ins>+            for args in _authReadOnlyPrivileges(self, typeResource, typeResource.principalCollectionURL()):
+                yield self._checkPrivileges(*args)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_propertyToField(self):
</span><span class="lines">@@ -705,14 +701,14 @@
</span><span class="cx">             C{record} is the directory service record
</span><span class="cx">             for each record in each directory in C{directoryServices}.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        for directory in self.directoryServices:
-            provisioningResource = self.principalRootResources[
-                directory.__class__.__name__
-            ]
-            for recordType in directory.recordTypes():
-                for record in directory.listRecords(recordType):
-                    recordResource = provisioningResource.principalForRecord(record)
-                    yield provisioningResource, recordType, recordResource, record
</del><ins>+        directory = self.directory
+        provisioningResource = self.principalRootResources[
+            directory.__class__.__name__
+        ]
+        for recordType in directory.recordTypes():
+            for record in directory.listRecords(recordType):
+                recordResource = provisioningResource.principalForRecord(record)
+                yield provisioningResource, recordType, recordResource, record
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def _checkPrivileges(self, resource, url, principal, privilege, allowed):
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_proxyprincipalmemberspy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_proxyprincipalmembers.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_proxyprincipalmembers.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_proxyprincipalmembers.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,506 +0,0 @@
</span><del>-##
-# Copyright (c) 2005-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.internet.defer import DeferredList, inlineCallbacks, succeed
-from txdav.xml import element as davxml
-
-from twistedcaldav.directory.directory import DirectoryService
-from twistedcaldav.test.util import xmlFile, augmentsFile, proxiesFile
-from twistedcaldav.directory.principal import DirectoryPrincipalProvisioningResource, \
-    DirectoryPrincipalResource
-from twistedcaldav.directory.xmlfile import XMLDirectoryService
-
-import twistedcaldav.test.util
-from twistedcaldav.directory import augment, calendaruserproxy
-from twistedcaldav.directory.calendaruserproxyloader import XMLCalendarUserProxyLoader
-
-
-class ProxyPrincipals (twistedcaldav.test.util.TestCase):
-    &quot;&quot;&quot;
-    Directory service provisioned principals.
-    &quot;&quot;&quot;
-
-    @inlineCallbacks
-    def setUp(self):
-        super(ProxyPrincipals, self).setUp()
-
-        self.directoryFixture.addDirectoryService(XMLDirectoryService(
-            {
-                'xmlFile' : xmlFile,
-                'augmentService' :
-                    augment.AugmentXMLDB(xmlFiles=(augmentsFile.path,)),
-            }
-        ))
-        calendaruserproxy.ProxyDBService = calendaruserproxy.ProxySqliteDB(&quot;proxies.sqlite&quot;)
-
-        # Set up a principals hierarchy for each service we're testing with
-        self.principalRootResources = {}
-        name = self.directoryService.__class__.__name__
-        url = &quot;/&quot; + name + &quot;/&quot;
-
-        provisioningResource = DirectoryPrincipalProvisioningResource(url, self.directoryService)
-
-        self.site.resource.putChild(name, provisioningResource)
-
-        self.principalRootResources[self.directoryService.__class__.__name__] = provisioningResource
-
-        yield XMLCalendarUserProxyLoader(proxiesFile.path).updateProxyDB()
-
-
-    def tearDown(self):
-        &quot;&quot;&quot; Empty the proxy db between tests &quot;&quot;&quot;
-        return calendaruserproxy.ProxyDBService.clean() #@UndefinedVariable
-
-
-    def _getPrincipalByShortName(self, type, name):
-        provisioningResource = self.principalRootResources[self.directoryService.__class__.__name__]
-        return provisioningResource.principalForShortName(type, name)
-
-
-    def _groupMembersTest(self, recordType, recordName, subPrincipalName, expectedMembers):
-        def gotMembers(members):
-            memberNames = set([p.displayName() for p in members])
-            self.assertEquals(memberNames, set(expectedMembers))
-
-        principal = self._getPrincipalByShortName(recordType, recordName)
-        if subPrincipalName is not None:
-            principal = principal.getChild(subPrincipalName)
-
-        d = principal.expandedGroupMembers()
-        d.addCallback(gotMembers)
-        return d
-
-
-    def _groupMembershipsTest(self, recordType, recordName, subPrincipalName, expectedMemberships):
-        def gotMemberships(memberships):
-            uids = set([p.principalUID() for p in memberships])
-            self.assertEquals(uids, set(expectedMemberships))
-
-        principal = self._getPrincipalByShortName(recordType, recordName)
-        if subPrincipalName is not None:
-            principal = principal.getChild(subPrincipalName)
-
-        d = principal.groupMemberships()
-        d.addCallback(gotMemberships)
-        return d
-
-
-    @inlineCallbacks
-    def _addProxy(self, principal, subPrincipalName, proxyPrincipal):
-
-        if isinstance(principal, tuple):
-            principal = self._getPrincipalByShortName(principal[0], principal[1])
-        principal = principal.getChild(subPrincipalName)
-        members = (yield principal.groupMembers())
-
-        if isinstance(proxyPrincipal, tuple):
-            proxyPrincipal = self._getPrincipalByShortName(proxyPrincipal[0], proxyPrincipal[1])
-        members.add(proxyPrincipal)
-
-        yield principal.setGroupMemberSetPrincipals(members)
-
-
-    @inlineCallbacks
-    def _removeProxy(self, recordType, recordName, subPrincipalName, proxyRecordType, proxyRecordName):
-
-        principal = self._getPrincipalByShortName(recordType, recordName)
-        principal = principal.getChild(subPrincipalName)
-        members = (yield principal.groupMembers())
-
-        proxyPrincipal = self._getPrincipalByShortName(proxyRecordType, proxyRecordName)
-        for p in members:
-            if p.principalUID() == proxyPrincipal.principalUID():
-                members.remove(p)
-                break
-
-        yield principal.setGroupMemberSetPrincipals(members)
-
-
-    @inlineCallbacks
-    def _clearProxy(self, principal, subPrincipalName):
-
-        if isinstance(principal, tuple):
-            principal = self._getPrincipalByShortName(principal[0], principal[1])
-        principal = principal.getChild(subPrincipalName)
-        yield principal.setGroupMemberSetPrincipals(set())
-
-
-    @inlineCallbacks
-    def _proxyForTest(self, recordType, recordName, expectedProxies, read_write):
-        principal = self._getPrincipalByShortName(recordType, recordName)
-        proxies = (yield principal.proxyFor(read_write))
-        proxies = sorted([_principal.displayName() for _principal in proxies])
-        self.assertEquals(proxies, sorted(expectedProxies))
-
-
-    @inlineCallbacks
-    def test_multipleProxyAssignmentsAtOnce(self):
-        yield self._proxyForTest(
-            DirectoryService.recordType_users, &quot;userb&quot;,
-            ('a',),
-            True
-        )
-        yield self._proxyForTest(
-            DirectoryService.recordType_users, &quot;userc&quot;,
-            ('a',),
-            True
-        )
-
-
-    def test_groupMembersRegular(self):
-        &quot;&quot;&quot;
-        DirectoryPrincipalResource.expandedGroupMembers()
-        &quot;&quot;&quot;
-        return self._groupMembersTest(
-            DirectoryService.recordType_groups, &quot;both_coasts&quot;, None,
-            (&quot;Chris Lecroy&quot;, &quot;David Reid&quot;, &quot;Wilfredo Sanchez&quot;, &quot;West Coast&quot;, &quot;East Coast&quot;, &quot;Cyrus Daboo&quot;,),
-        )
-
-
-    def test_groupMembersRecursive(self):
-        &quot;&quot;&quot;
-        DirectoryPrincipalResource.expandedGroupMembers()
-        &quot;&quot;&quot;
-        return self._groupMembersTest(
-            DirectoryService.recordType_groups, &quot;recursive1_coasts&quot;, None,
-            (&quot;Wilfredo Sanchez&quot;, &quot;Recursive2 Coasts&quot;, &quot;Cyrus Daboo&quot;,),
-        )
-
-
-    def test_groupMembersProxySingleUser(self):
-        &quot;&quot;&quot;
-        DirectoryPrincipalResource.expandedGroupMembers()
-        &quot;&quot;&quot;
-        return self._groupMembersTest(
-            DirectoryService.recordType_locations, &quot;gemini&quot;, &quot;calendar-proxy-write&quot;,
-            (&quot;Wilfredo Sanchez&quot;,),
-        )
-
-
-    def test_groupMembersProxySingleGroup(self):
-        &quot;&quot;&quot;
-        DirectoryPrincipalResource.expandedGroupMembers()
-        &quot;&quot;&quot;
-        return self._groupMembersTest(
-            DirectoryService.recordType_locations, &quot;mercury&quot;, &quot;calendar-proxy-write&quot;,
-            (&quot;Chris Lecroy&quot;, &quot;David Reid&quot;, &quot;Wilfredo Sanchez&quot;, &quot;West Coast&quot;,),
-        )
-
-
-    def test_groupMembersProxySingleGroupWithNestedGroups(self):
-        &quot;&quot;&quot;
-        DirectoryPrincipalResource.expandedGroupMembers()
-        &quot;&quot;&quot;
-        return self._groupMembersTest(
-            DirectoryService.recordType_locations, &quot;apollo&quot;, &quot;calendar-proxy-write&quot;,
-            (&quot;Chris Lecroy&quot;, &quot;David Reid&quot;, &quot;Wilfredo Sanchez&quot;, &quot;West Coast&quot;, &quot;East Coast&quot;, &quot;Cyrus Daboo&quot;, &quot;Both Coasts&quot;,),
-        )
-
-
-    def test_groupMembersProxySingleGroupWithNestedRecursiveGroups(self):
-        &quot;&quot;&quot;
-        DirectoryPrincipalResource.expandedGroupMembers()
-        &quot;&quot;&quot;
-        return self._groupMembersTest(
-            DirectoryService.recordType_locations, &quot;orion&quot;, &quot;calendar-proxy-write&quot;,
-            (&quot;Wilfredo Sanchez&quot;, &quot;Cyrus Daboo&quot;, &quot;Recursive1 Coasts&quot;, &quot;Recursive2 Coasts&quot;,),
-        )
-
-
-    def test_groupMembersProxySingleGroupWithNonCalendarGroup(self):
-        &quot;&quot;&quot;
-        DirectoryPrincipalResource.expandedGroupMembers()
-        &quot;&quot;&quot;
-        ds = []
-
-        ds.append(self._groupMembersTest(
-            DirectoryService.recordType_resources, &quot;non_calendar_proxy&quot;, &quot;calendar-proxy-write&quot;,
-            (&quot;Chris Lecroy&quot;, &quot;Cyrus Daboo&quot;, &quot;Non-calendar group&quot;),
-        ))
-
-        ds.append(self._groupMembershipsTest(
-            DirectoryService.recordType_groups, &quot;non_calendar_group&quot;, None,
-            (&quot;non_calendar_proxy#calendar-proxy-write&quot;,),
-        ))
-
-        return DeferredList(ds)
-
-
-    def test_groupMembersProxyMissingUser(self):
-        &quot;&quot;&quot;
-        DirectoryPrincipalResource.expandedGroupMembers()
-        &quot;&quot;&quot;
-        proxy = self._getPrincipalByShortName(DirectoryService.recordType_users, &quot;cdaboo&quot;)
-        proxyGroup = proxy.getChild(&quot;calendar-proxy-write&quot;)
-
-        def gotMembers(members):
-            members.add(&quot;12345&quot;)
-            return proxyGroup._index().setGroupMembers(&quot;%s#calendar-proxy-write&quot; % (proxy.principalUID(),), members)
-
-        def check(_):
-            return self._groupMembersTest(
-                DirectoryService.recordType_users, &quot;cdaboo&quot;, &quot;calendar-proxy-write&quot;,
-                (),
-            )
-
-        # Setup the fake entry in the DB
-        d = proxyGroup._index().getMembers(&quot;%s#calendar-proxy-write&quot; % (proxy.principalUID(),))
-        d.addCallback(gotMembers)
-        d.addCallback(check)
-        return d
-
-
-    def test_groupMembershipsMissingUser(self):
-        &quot;&quot;&quot;
-        DirectoryPrincipalResource.expandedGroupMembers()
-        &quot;&quot;&quot;
-        # Setup the fake entry in the DB
-        fake_uid = &quot;12345&quot;
-        proxy = self._getPrincipalByShortName(DirectoryService.recordType_users, &quot;cdaboo&quot;)
-        proxyGroup = proxy.getChild(&quot;calendar-proxy-write&quot;)
-
-        def gotMembers(members):
-            members.add(&quot;%s#calendar-proxy-write&quot; % (proxy.principalUID(),))
-            return proxyGroup._index().setGroupMembers(&quot;%s#calendar-proxy-write&quot; % (fake_uid,), members)
-
-        def check(_):
-            return self._groupMembershipsTest(
-                DirectoryService.recordType_users, &quot;cdaboo&quot;, &quot;calendar-proxy-write&quot;,
-                (),
-            )
-
-        d = proxyGroup._index().getMembers(&quot;%s#calendar-proxy-write&quot; % (fake_uid,))
-        d.addCallback(gotMembers)
-        d.addCallback(check)
-        return d
-
-
-    @inlineCallbacks
-    def test_setGroupMemberSet(self):
-        class StubMemberDB(object):
-            def __init__(self):
-                self.members = set()
-
-            def setGroupMembers(self, uid, members):
-                self.members = members
-                return succeed(None)
-
-            def getMembers(self, uid):
-                return succeed(self.members)
-
-        user = self._getPrincipalByShortName(self.directoryService.recordType_users,
-                                           &quot;cdaboo&quot;)
-
-        proxyGroup = user.getChild(&quot;calendar-proxy-write&quot;)
-
-        memberdb = StubMemberDB()
-
-        proxyGroup._index = (lambda: memberdb)
-
-        new_members = davxml.GroupMemberSet(
-            davxml.HRef.fromString(
-                &quot;/XMLDirectoryService/__uids__/8B4288F6-CC82-491D-8EF9-642EF4F3E7D0/&quot;),
-            davxml.HRef.fromString(
-                &quot;/XMLDirectoryService/__uids__/5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1/&quot;))
-
-        yield proxyGroup.setGroupMemberSet(new_members, None)
-
-        self.assertEquals(
-            set([str(p) for p in memberdb.members]),
-            set([&quot;5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1&quot;,
-                 &quot;8B4288F6-CC82-491D-8EF9-642EF4F3E7D0&quot;]))
-
-
-    @inlineCallbacks
-    def test_setGroupMemberSetNotifiesPrincipalCaches(self):
-        class StubCacheNotifier(object):
-            changedCount = 0
-            def changed(self):
-                self.changedCount += 1
-                return succeed(None)
-
-        user = self._getPrincipalByShortName(self.directoryService.recordType_users, &quot;cdaboo&quot;)
-
-        proxyGroup = user.getChild(&quot;calendar-proxy-write&quot;)
-
-        notifier = StubCacheNotifier()
-
-        oldCacheNotifier = DirectoryPrincipalResource.cacheNotifierFactory
-
-        try:
-            DirectoryPrincipalResource.cacheNotifierFactory = (lambda _1, _2, **kwargs: notifier)
-
-            self.assertEquals(notifier.changedCount, 0)
-
-            yield proxyGroup.setGroupMemberSet(
-                davxml.GroupMemberSet(
-                    davxml.HRef.fromString(
-                        &quot;/XMLDirectoryService/__uids__/5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1/&quot;)),
-                None)
-
-            self.assertEquals(notifier.changedCount, 1)
-        finally:
-            DirectoryPrincipalResource.cacheNotifierFactory = oldCacheNotifier
-
-
-    def test_proxyFor(self):
-
-        return self._proxyForTest(
-            DirectoryService.recordType_users, &quot;wsanchez&quot;,
-            (&quot;Mercury Seven&quot;, &quot;Gemini Twelve&quot;, &quot;Apollo Eleven&quot;, &quot;Orion&quot;,),
-            True
-        )
-
-
-    @inlineCallbacks
-    def test_proxyForDuplicates(self):
-
-        yield self._addProxy(
-            (DirectoryService.recordType_locations, &quot;gemini&quot;,),
-            &quot;calendar-proxy-write&quot;,
-            (DirectoryService.recordType_groups, &quot;grunts&quot;,),
-        )
-
-        yield self._proxyForTest(
-            DirectoryService.recordType_users, &quot;wsanchez&quot;,
-            (&quot;Mercury Seven&quot;, &quot;Gemini Twelve&quot;, &quot;Apollo Eleven&quot;, &quot;Orion&quot;,),
-            True
-        )
-
-
-    def test_readOnlyProxyFor(self):
-
-        return self._proxyForTest(
-            DirectoryService.recordType_users, &quot;wsanchez&quot;,
-            (&quot;Non-calendar proxy&quot;,),
-            False
-        )
-
-
-    @inlineCallbacks
-    def test_UserProxy(self):
-
-        for proxyType in (&quot;calendar-proxy-read&quot;, &quot;calendar-proxy-write&quot;):
-
-            yield self._addProxy(
-                (DirectoryService.recordType_users, &quot;wsanchez&quot;,),
-                proxyType,
-                (DirectoryService.recordType_users, &quot;cdaboo&quot;,),
-            )
-
-            yield self._groupMembersTest(
-                DirectoryService.recordType_users, &quot;wsanchez&quot;,
-                proxyType,
-                (&quot;Cyrus Daboo&quot;,),
-            )
-
-            yield self._addProxy(
-                (DirectoryService.recordType_users, &quot;wsanchez&quot;,),
-                proxyType,
-                (DirectoryService.recordType_users, &quot;lecroy&quot;,),
-            )
-
-            yield self._groupMembersTest(
-                DirectoryService.recordType_users, &quot;wsanchez&quot;,
-                proxyType,
-                (&quot;Cyrus Daboo&quot;, &quot;Chris Lecroy&quot;,),
-            )
-
-            yield self._removeProxy(
-                DirectoryService.recordType_users, &quot;wsanchez&quot;,
-                proxyType,
-                DirectoryService.recordType_users, &quot;cdaboo&quot;,
-            )
-
-            yield self._groupMembersTest(
-                DirectoryService.recordType_users, &quot;wsanchez&quot;,
-                proxyType,
-                (&quot;Chris Lecroy&quot;,),
-            )
-
-
-    @inlineCallbacks
-    def test_NonAsciiProxy(self):
-        &quot;&quot;&quot;
-        Ensure that principalURLs with non-ascii don't cause problems
-        within CalendarUserProxyPrincipalResource
-        &quot;&quot;&quot;
-
-        recordType = DirectoryService.recordType_users
-        proxyType = &quot;calendar-proxy-read&quot;
-
-        record = self.directoryService.recordWithGUID(&quot;320B73A1-46E2-4180-9563-782DFDBE1F63&quot;)
-        provisioningResource = self.principalRootResources[self.directoryService.__class__.__name__]
-        principal = provisioningResource.principalForRecord(record)
-        proxyPrincipal = provisioningResource.principalForShortName(recordType,
-            &quot;wsanchez&quot;)
-
-        yield self._addProxy(principal, proxyType, proxyPrincipal)
-        memberships = yield proxyPrincipal._calendar_user_proxy_index().getMemberships(proxyPrincipal.principalUID())
-        for uid in memberships:
-            provisioningResource.principalForUID(uid)
-
-
-    @inlineCallbacks
-    def test_getAllMembers(self):
-        &quot;&quot;&quot;
-        getAllMembers( ) returns the unique set of guids that have been
-        delegated-to directly
-        &quot;&quot;&quot;
-        self.assertEquals(
-            set((yield calendaruserproxy.ProxyDBService.getAllMembers())), #@UndefinedVariable
-            set([
-                u'00599DAF-3E75-42DD-9DB7-52617E79943F',
-                u'6423F94A-6B76-4A3A-815B-D52CFD77935D',
-                u'8A985493-EE2C-4665-94CF-4DFEA3A89500',
-                u'9FF60DAD-0BDE-4508-8C77-15F0CA5C8DD2',
-                u'both_coasts',
-                u'left_coast',
-                u'non_calendar_group',
-                u'recursive1_coasts',
-                u'recursive2_coasts',
-                u'EC465590-E9E9-4746-ACE8-6C756A49FE4D'])
-        )
-
-
-    @inlineCallbacks
-    def test_hideDisabledDelegates(self):
-        &quot;&quot;&quot;
-        Delegates who are not enabledForLogin are &quot;hidden&quot; from the delegate lists
-        (but groups *are* allowed)
-        &quot;&quot;&quot;
-
-        record = self.directoryService.recordWithGUID(&quot;EC465590-E9E9-4746-ACE8-6C756A49FE4D&quot;)
-
-        record.enabledForLogin = True
-        yield self._groupMembersTest(
-            DirectoryService.recordType_users, &quot;delegator&quot;, &quot;calendar-proxy-write&quot;,
-            (&quot;Occasional Delegate&quot;, &quot;Delegate Via Group&quot;, &quot;Delegate Group&quot;),
-        )
-
-        # Login disabled -- no longer shown as a delegate
-        record.enabledForLogin = False
-        yield self._groupMembersTest(
-            DirectoryService.recordType_users, &quot;delegator&quot;, &quot;calendar-proxy-write&quot;,
-            (&quot;Delegate Via Group&quot;, &quot;Delegate Group&quot;),
-        )
-
-        # Login re-enabled -- once again a delegate (it wasn't not removed from proxydb)
-        record.enabledForLogin = True
-        yield self._groupMembersTest(
-            DirectoryService.recordType_users, &quot;delegator&quot;, &quot;calendar-proxy-write&quot;,
-            (&quot;Occasional Delegate&quot;, &quot;Delegate Via Group&quot;, &quot;Delegate Group&quot;),
-        )
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_resourcespy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_resources.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_resources.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_resources.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,80 +0,0 @@
</span><del>-##
-# Copyright (c) 2005-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.
-##
-
-import os
-from twistedcaldav.config import config
-from twistedcaldav.test.util import TestCase
-from calendarserver.tools.util import getDirectory
-
-class ResourcesTestCase(TestCase):
-
-    def setUp(self):
-        super(ResourcesTestCase, self).setUp()
-
-        testRoot = os.path.join(&quot;.&quot;, os.path.dirname(__file__), &quot;resources&quot;)
-
-        xmlFile = os.path.join(testRoot, &quot;users-groups.xml&quot;)
-        config.DirectoryService.params.xmlFile = xmlFile
-
-        xmlFile = os.path.join(testRoot, &quot;resources-locations.xml&quot;)
-        config.ResourceService.params.xmlFile = xmlFile
-        config.ResourceService.Enabled = True
-
-        xmlFile = os.path.join(testRoot, &quot;augments.xml&quot;)
-        config.AugmentService.type = &quot;twistedcaldav.directory.augment.AugmentXMLDB&quot;
-        config.AugmentService.params.xmlFiles = (xmlFile,)
-
-# Uh, what's this testing?
-#    def test_loadConfig(self):
-#        directory = getDirectory()
-
-
-    def test_recordInPrimaryDirectory(self):
-        directory = getDirectory()
-
-        # Look up a user, which comes out of primary directory service
-        record = directory.recordWithUID(&quot;user01&quot;)
-        self.assertNotEquals(record, None)
-
-
-    def test_recordInSupplementalDirectory(self):
-        directory = getDirectory()
-
-        # Look up a resource, which comes out of locations/resources service
-        record = directory.recordWithUID(&quot;resource01&quot;)
-        self.assertNotEquals(record, None)
-
-
-    def test_augments(self):
-        directory = getDirectory()
-
-        # Primary directory
-        record = directory.recordWithUID(&quot;user01&quot;)
-        self.assertEquals(record.enabled, True)
-        self.assertEquals(record.enabledForCalendaring, True)
-        record = directory.recordWithUID(&quot;user02&quot;)
-        self.assertEquals(record.enabled, False)
-        self.assertEquals(record.enabledForCalendaring, False)
-
-        # Supplemental directory
-        record = directory.recordWithUID(&quot;resource01&quot;)
-        self.assertEquals(record.enabled, True)
-        self.assertEquals(record.enabledForCalendaring, True)
-        self.assertEquals(record.autoSchedule, True)
-        record = directory.recordWithUID(&quot;resource02&quot;)
-        self.assertEquals(record.enabled, False)
-        self.assertEquals(record.enabledForCalendaring, False)
-        self.assertEquals(record.autoSchedule, False)
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytesttest_xmlfilepy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_xmlfile.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_xmlfile.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/test_xmlfile.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,375 +0,0 @@
</span><del>-##
-# Copyright (c) 2005-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.python.filepath import CachingFilePath as FilePath
-
-from twistedcaldav.directory import augment
-from twistedcaldav.directory.directory import DirectoryService
-import twistedcaldav.directory.test.util
-from twistedcaldav.directory.xmlfile import XMLDirectoryService
-from twistedcaldav.test.util import TestCase, xmlFile, augmentsFile
-
-# FIXME: Add tests for GUID hooey, once we figure out what that means here
-
-class XMLFileBase(object):
-    &quot;&quot;&quot;
-    L{XMLFileBase} is a base/mix-in object for testing L{XMLDirectoryService}
-    (or things that depend on L{IDirectoryService} and need a simple
-    implementation to use).
-    &quot;&quot;&quot;
-    recordTypes = set((
-        DirectoryService.recordType_users,
-        DirectoryService.recordType_groups,
-        DirectoryService.recordType_locations,
-        DirectoryService.recordType_resources,
-        DirectoryService.recordType_addresses,
-    ))
-
-    users = {
-        &quot;admin&quot;      : {&quot;password&quot;: &quot;nimda&quot;, &quot;guid&quot;: &quot;D11F03A0-97EA-48AF-9A6C-FAC7F3975766&quot;, &quot;addresses&quot;: ()},
-        &quot;wsanchez&quot;   : {&quot;password&quot;: &quot;zehcnasw&quot;, &quot;guid&quot;: &quot;6423F94A-6B76-4A3A-815B-D52CFD77935D&quot;, &quot;addresses&quot;: (&quot;mailto:wsanchez@example.com&quot;,)},
-        &quot;cdaboo&quot;     : {&quot;password&quot;: &quot;oobadc&quot;, &quot;guid&quot;: &quot;5A985493-EE2C-4665-94CF-4DFEA3A89500&quot;, &quot;addresses&quot;: (&quot;mailto:cdaboo@example.com&quot;,)  },
-        &quot;lecroy&quot;     : {&quot;password&quot;: &quot;yorcel&quot;, &quot;guid&quot;: &quot;8B4288F6-CC82-491D-8EF9-642EF4F3E7D0&quot;, &quot;addresses&quot;: (&quot;mailto:lecroy@example.com&quot;,)  },
-        &quot;dreid&quot;      : {&quot;password&quot;: &quot;dierd&quot;, &quot;guid&quot;: &quot;5FF60DAD-0BDE-4508-8C77-15F0CA5C8DD1&quot;, &quot;addresses&quot;: (&quot;mailto:dreid@example.com&quot;,)   },
-        &quot;nocalendar&quot; : {&quot;password&quot;: &quot;radnelacon&quot;, &quot;guid&quot;: &quot;543D28BA-F74F-4D5F-9243-B3E3A61171E5&quot;, &quot;addresses&quot;: ()},
-        &quot;user01&quot;     : {&quot;password&quot;: &quot;01user&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (&quot;mailto:c4ca4238a0@example.com&quot;,)},
-        &quot;user02&quot;     : {&quot;password&quot;: &quot;02user&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (&quot;mailto:c81e728d9d@example.com&quot;,)},
-   }
-
-    groups = {
-        &quot;admin&quot;      : {&quot;password&quot;: &quot;admin&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (), &quot;members&quot;: ((DirectoryService.recordType_groups, &quot;managers&quot;),)},
-        &quot;managers&quot;   : {&quot;password&quot;: &quot;managers&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (), &quot;members&quot;: ((DirectoryService.recordType_users , &quot;lecroy&quot;),)},
-        &quot;grunts&quot;     : {&quot;password&quot;: &quot;grunts&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (), &quot;members&quot;: ((DirectoryService.recordType_users , &quot;wsanchez&quot;),
-                                                                                               (DirectoryService.recordType_users , &quot;cdaboo&quot;),
-                                                                                               (DirectoryService.recordType_users , &quot;dreid&quot;))},
-        &quot;right_coast&quot;: {&quot;password&quot;: &quot;right_coast&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (), &quot;members&quot;: ((DirectoryService.recordType_users , &quot;cdaboo&quot;),)},
-        &quot;left_coast&quot; : {&quot;password&quot;: &quot;left_coast&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (), &quot;members&quot;: ((DirectoryService.recordType_users , &quot;wsanchez&quot;),
-                                                                                               (DirectoryService.recordType_users , &quot;dreid&quot;),
-                                                                                               (DirectoryService.recordType_users , &quot;lecroy&quot;))},
-        &quot;both_coasts&quot;: {&quot;password&quot;: &quot;both_coasts&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (), &quot;members&quot;: ((DirectoryService.recordType_groups, &quot;right_coast&quot;),
-                                                                                               (DirectoryService.recordType_groups, &quot;left_coast&quot;))},
-        &quot;recursive1_coasts&quot;: {&quot;password&quot;: &quot;recursive1_coasts&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (), &quot;members&quot;: ((DirectoryService.recordType_groups, &quot;recursive2_coasts&quot;),
-                                                                                               (DirectoryService.recordType_users, &quot;wsanchez&quot;))},
-        &quot;recursive2_coasts&quot;: {&quot;password&quot;: &quot;recursive2_coasts&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (), &quot;members&quot;: ((DirectoryService.recordType_groups, &quot;recursive1_coasts&quot;),
-                                                                                               (DirectoryService.recordType_users, &quot;cdaboo&quot;))},
-        &quot;non_calendar_group&quot;: {&quot;password&quot;: &quot;non_calendar_group&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (), &quot;members&quot;: ((DirectoryService.recordType_users , &quot;cdaboo&quot;),
-                                                                                               (DirectoryService.recordType_users , &quot;lecroy&quot;))},
-   }
-
-    locations = {
-        &quot;mercury&quot;: {&quot;password&quot;: &quot;mercury&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (&quot;mailto:mercury@example.com&quot;,)},
-        &quot;gemini&quot; : {&quot;password&quot;: &quot;gemini&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (&quot;mailto:gemini@example.com&quot;,)},
-        &quot;apollo&quot; : {&quot;password&quot;: &quot;apollo&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (&quot;mailto:apollo@example.com&quot;,)},
-        &quot;orion&quot;  : {&quot;password&quot;: &quot;orion&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (&quot;mailto:orion@example.com&quot;,)},
-   }
-
-    resources = {
-        &quot;transporter&quot;        : {&quot;password&quot;: &quot;transporter&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (&quot;mailto:transporter@example.com&quot;,)       },
-        &quot;ftlcpu&quot;             : {&quot;password&quot;: &quot;ftlcpu&quot;, &quot;guid&quot;: None, &quot;addresses&quot;: (&quot;mailto:ftlcpu@example.com&quot;,)            },
-        &quot;non_calendar_proxy&quot; : {&quot;password&quot;: &quot;non_calendar_proxy&quot;, &quot;guid&quot;: &quot;non_calendar_proxy&quot;, &quot;addresses&quot;: (&quot;mailto:non_calendar_proxy@example.com&quot;,)},
-   }
-
-
-    def xmlFile(self):
-        &quot;&quot;&quot;
-        Create a L{FilePath} that points to a temporary file containing a copy
-        of C{twistedcaldav/directory/test/accounts.xml}.
-
-        @see: L{xmlFile}
-
-        @rtype: L{FilePath}
-        &quot;&quot;&quot;
-        if not hasattr(self, &quot;_xmlFile&quot;):
-            self._xmlFile = FilePath(self.mktemp())
-            xmlFile.copyTo(self._xmlFile)
-        return self._xmlFile
-
-
-    def augmentsFile(self):
-        &quot;&quot;&quot;
-        Create a L{FilePath} that points to a temporary file containing a copy
-        of C{twistedcaldav/directory/test/augments.xml}.
-
-        @see: L{augmentsFile}
-
-        @rtype: L{FilePath}
-        &quot;&quot;&quot;
-        if not hasattr(self, &quot;_augmentsFile&quot;):
-            self._augmentsFile = FilePath(self.mktemp())
-            augmentsFile.copyTo(self._augmentsFile)
-        return self._augmentsFile
-
-
-    def service(self):
-        &quot;&quot;&quot;
-        Create an L{XMLDirectoryService} based on the contents of the paths
-        returned by L{XMLFileBase.augmentsFile} and L{XMLFileBase.xmlFile}.
-
-        @rtype: L{XMLDirectoryService}
-        &quot;&quot;&quot;
-        return XMLDirectoryService(
-            {
-                'xmlFile': self.xmlFile(),
-                'augmentService':
-                    augment.AugmentXMLDB(xmlFiles=(self.augmentsFile().path,)),
-            },
-            alwaysStat=True
-        )
-
-
-
-class XMLFile (
-    XMLFileBase,
-    twistedcaldav.directory.test.util.BasicTestCase,
-    twistedcaldav.directory.test.util.DigestTestCase
-):
-    &quot;&quot;&quot;
-    Test XML file based directory implementation.
-    &quot;&quot;&quot;
-
-    def test_changedXML(self):
-        service = self.service()
-
-        self.xmlFile().open(&quot;w&quot;).write(
-&quot;&quot;&quot;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
-&lt;!DOCTYPE accounts SYSTEM &quot;accounts.dtd&quot;&gt;
-&lt;accounts realm=&quot;Test Realm&quot;&gt;
-  &lt;user&gt;
-    &lt;uid&gt;admin&lt;/uid&gt;
-    &lt;guid&gt;admin&lt;/guid&gt;
-    &lt;password&gt;nimda&lt;/password&gt;
-    &lt;name&gt;Super User&lt;/name&gt;
-  &lt;/user&gt;
-&lt;/accounts&gt;
-&quot;&quot;&quot;
-        )
-        for recordType, expectedRecords in (
-            (DirectoryService.recordType_users     , (&quot;admin&quot;,)),
-            (DirectoryService.recordType_groups    , ()),
-            (DirectoryService.recordType_locations , ()),
-            (DirectoryService.recordType_resources , ()),
-        ):
-            # Fault records in
-            for name in expectedRecords:
-                service.recordWithShortName(recordType, name)
-
-            self.assertEquals(
-                set(r.shortNames[0] for r in service.listRecords(recordType)),
-                set(expectedRecords)
-            )
-
-
-    def test_okAutoSchedule(self):
-        service = self.service()
-
-        self.xmlFile().open(&quot;w&quot;).write(
-&quot;&quot;&quot;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
-&lt;!DOCTYPE accounts SYSTEM &quot;accounts.dtd&quot;&gt;
-&lt;accounts realm=&quot;Test Realm&quot;&gt;
-  &lt;location&gt;
-    &lt;uid&gt;my office&lt;/uid&gt;
-    &lt;guid&gt;myoffice&lt;/guid&gt;
-    &lt;password&gt;nimda&lt;/password&gt;
-    &lt;name&gt;Super User&lt;/name&gt;
-  &lt;/location&gt;
-&lt;/accounts&gt;
-&quot;&quot;&quot;
-        )
-        self.augmentsFile().open(&quot;w&quot;).write(
-&quot;&quot;&quot;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
-&lt;!DOCTYPE accounts SYSTEM &quot;accounts.dtd&quot;&gt;
-&lt;augments&gt;
-  &lt;record&gt;
-    &lt;uid&gt;myoffice&lt;/uid&gt;
-    &lt;enable&gt;true&lt;/enable&gt;
-    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
-    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
-  &lt;/record&gt;
-&lt;/augments&gt;
-&quot;&quot;&quot;
-        )
-        service.augmentService.refresh()
-
-        for recordType, expectedRecords in (
-            (DirectoryService.recordType_users     , ()),
-            (DirectoryService.recordType_groups    , ()),
-            (DirectoryService.recordType_locations , (&quot;my office&quot;,)),
-            (DirectoryService.recordType_resources , ()),
-        ):
-            # Fault records in
-            for name in expectedRecords:
-                service.recordWithShortName(recordType, name)
-
-            self.assertEquals(
-                set(r.shortNames[0] for r in service.listRecords(recordType)),
-                set(expectedRecords)
-            )
-        self.assertTrue(service.recordWithShortName(DirectoryService.recordType_locations, &quot;my office&quot;).autoSchedule)
-
-
-    def test_okDisableCalendar(self):
-        service = self.service()
-
-        self.xmlFile().open(&quot;w&quot;).write(
-&quot;&quot;&quot;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
-&lt;!DOCTYPE accounts SYSTEM &quot;accounts.dtd&quot;&gt;
-&lt;accounts realm=&quot;Test Realm&quot;&gt;
-  &lt;group&gt;
-    &lt;uid&gt;enabled&lt;/uid&gt;
-    &lt;guid&gt;enabled&lt;/guid&gt;
-    &lt;password&gt;enabled&lt;/password&gt;
-    &lt;name&gt;Enabled&lt;/name&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
-    &lt;uid&gt;disabled&lt;/uid&gt;
-    &lt;guid&gt;disabled&lt;/guid&gt;
-    &lt;password&gt;disabled&lt;/password&gt;
-    &lt;name&gt;Disabled&lt;/name&gt;
-  &lt;/group&gt;
-&lt;/accounts&gt;
-&quot;&quot;&quot;
-        )
-
-        for recordType, expectedRecords in (
-            (DirectoryService.recordType_users     , ()),
-            (DirectoryService.recordType_groups    , (&quot;enabled&quot;, &quot;disabled&quot;)),
-            (DirectoryService.recordType_locations , ()),
-            (DirectoryService.recordType_resources , ()),
-        ):
-            # Fault records in
-            for name in expectedRecords:
-                service.recordWithShortName(recordType, name)
-
-            self.assertEquals(
-                set(r.shortNames[0] for r in service.listRecords(recordType)),
-                set(expectedRecords)
-            )
-
-        # All groups are disabled
-        self.assertFalse(service.recordWithShortName(DirectoryService.recordType_groups, &quot;enabled&quot;).enabledForCalendaring)
-        self.assertFalse(service.recordWithShortName(DirectoryService.recordType_groups, &quot;disabled&quot;).enabledForCalendaring)
-
-
-    def test_readExtras(self):
-        service = self.service()
-
-        self.xmlFile().open(&quot;w&quot;).write(
-&quot;&quot;&quot;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
-&lt;!DOCTYPE accounts SYSTEM &quot;accounts.dtd&quot;&gt;
-&lt;accounts realm=&quot;Test Realm&quot;&gt;
-  &lt;location&gt;
-    &lt;uid&gt;my office&lt;/uid&gt;
-    &lt;guid&gt;myoffice&lt;/guid&gt;
-    &lt;name&gt;My Office&lt;/name&gt;
-    &lt;extras&gt;
-        &lt;comment&gt;This is the comment&lt;/comment&gt;
-        &lt;capacity&gt;40&lt;/capacity&gt;
-    &lt;/extras&gt;
-  &lt;/location&gt;
-&lt;/accounts&gt;
-&quot;&quot;&quot;
-        )
-
-        record = service.recordWithShortName(
-            DirectoryService.recordType_locations, &quot;my office&quot;)
-        self.assertEquals(record.guid, &quot;myoffice&quot;)
-        self.assertEquals(record.extras[&quot;comment&quot;], &quot;This is the comment&quot;)
-        self.assertEquals(record.extras[&quot;capacity&quot;], &quot;40&quot;)
-
-
-    def test_writeExtras(self):
-        service = self.service()
-
-        service.createRecord(DirectoryService.recordType_locations, &quot;newguid&quot;,
-            shortNames=(&quot;New office&quot;,),
-            fullName=&quot;My New Office&quot;,
-            address=&quot;1 Infinite Loop, Cupertino, CA&quot;,
-            capacity=&quot;10&quot;,
-            comment=&quot;Test comment&quot;,
-        )
-
-        record = service.recordWithShortName(
-            DirectoryService.recordType_locations, &quot;New office&quot;)
-        self.assertEquals(record.extras[&quot;comment&quot;], &quot;Test comment&quot;)
-        self.assertEquals(record.extras[&quot;capacity&quot;], &quot;10&quot;)
-
-        service.updateRecord(DirectoryService.recordType_locations, &quot;newguid&quot;,
-            shortNames=(&quot;New office&quot;,),
-            fullName=&quot;My Newer Office&quot;,
-            address=&quot;2 Infinite Loop, Cupertino, CA&quot;,
-            capacity=&quot;20&quot;,
-            comment=&quot;Test comment updated&quot;,
-        )
-
-        record = service.recordWithShortName(
-            DirectoryService.recordType_locations, &quot;New office&quot;)
-        self.assertEquals(record.fullName, &quot;My Newer Office&quot;)
-        self.assertEquals(record.extras[&quot;address&quot;], &quot;2 Infinite Loop, Cupertino, CA&quot;)
-        self.assertEquals(record.extras[&quot;comment&quot;], &quot;Test comment updated&quot;)
-        self.assertEquals(record.extras[&quot;capacity&quot;], &quot;20&quot;)
-
-        service.destroyRecord(DirectoryService.recordType_locations, &quot;newguid&quot;)
-
-        record = service.recordWithShortName(
-            DirectoryService.recordType_locations, &quot;New office&quot;)
-        self.assertEquals(record, None)
-
-
-    def test_indexing(self):
-        service = self.service()
-        self.assertNotEquals(None, service._lookupInIndex(service.recordType_users, service.INDEX_TYPE_SHORTNAME, &quot;usera&quot;))
-        self.assertNotEquals(None, service._lookupInIndex(service.recordType_users, service.INDEX_TYPE_CUA, &quot;mailto:wsanchez@example.com&quot;))
-        self.assertNotEquals(None, service._lookupInIndex(service.recordType_users, service.INDEX_TYPE_GUID, &quot;9FF60DAD-0BDE-4508-8C77-15F0CA5C8DD2&quot;))
-        self.assertNotEquals(None, service._lookupInIndex(service.recordType_locations, service.INDEX_TYPE_SHORTNAME, &quot;orion&quot;))
-        self.assertEquals(None, service._lookupInIndex(service.recordType_users, service.INDEX_TYPE_CUA, &quot;mailto:nobody@example.com&quot;))
-
-
-    def test_repeat(self):
-        service = self.service()
-        record = service.recordWithShortName(
-            DirectoryService.recordType_users, &quot;user01&quot;)
-        self.assertEquals(record.fullName, &quot;c4ca4238a0b923820dcc509a6f75849bc4c User 01&quot;)
-        self.assertEquals(record.firstName, &quot;c4ca4&quot;)
-        self.assertEquals(record.lastName, &quot;c4ca4238a User 01&quot;)
-        self.assertEquals(record.emailAddresses, set(['c4ca4238a0@example.com']))
-
-
-
-class XMLFileSubset (XMLFileBase, TestCase):
-    &quot;&quot;&quot;
-    Test the recordTypes subset feature of XMLFile service.
-    &quot;&quot;&quot;
-    recordTypes = set((
-        DirectoryService.recordType_users,
-        DirectoryService.recordType_groups,
-    ))
-
-
-    def test_recordTypesSubset(self):
-        directory = XMLDirectoryService(
-            {
-                'xmlFile' : self.xmlFile(),
-                'augmentService' :
-                    augment.AugmentXMLDB(xmlFiles=(self.augmentsFile().path,)),
-                'recordTypes' :
-                    (
-                        DirectoryService.recordType_users,
-                        DirectoryService.recordType_groups
-                    ),
-            },
-            alwaysStat=True
-        )
-        self.assertEquals(set((&quot;users&quot;, &quot;groups&quot;)), set(directory.recordTypes()))
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectoryutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/util.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/util.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/util.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -34,7 +34,10 @@
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><span class="cx"> from txdav.xml import element as davxml
</span><span class="cx"> from uuid import UUID, uuid5
</span><ins>+from twisted.python.failure import Failure
+from twisted.web.template import tags
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><span class="cx"> def uuidFromName(namespace, name):
</span><span class="lines">@@ -148,3 +151,76 @@
</span><span class="cx">         else:
</span><span class="cx">             response = StatusResponse(responsecode.NOT_FOUND, &quot;Resource not found&quot;)
</span><span class="cx">             returnValue(response)
</span><ins>+
+
+
+
+def formatLink(url):
+    &quot;&quot;&quot;
+    Convert a URL string into some twisted.web.template DOM objects for
+    rendering as a link to itself.
+    &quot;&quot;&quot;
+    return tags.a(href=url)(url)
+
+
+
+def formatLinks(urls):
+    &quot;&quot;&quot;
+    Format a list of URL strings as a list of twisted.web.template DOM links.
+    &quot;&quot;&quot;
+    return formatList(formatLink(link) for link in urls)
+
+
+def formatPrincipals(principals):
+    &quot;&quot;&quot;
+    Format a list of principals into some twisted.web.template DOM objects.
+    &quot;&quot;&quot;
+    def recordKey(principal):
+        try:
+            record = principal.record
+        except AttributeError:
+            try:
+                record = principal.parent.record
+            except:
+                return None
+        return (record.recordType, record.shortNames[0])
+
+
+    def describe(principal):
+        if hasattr(principal, &quot;record&quot;):
+            return &quot; - %s&quot; % (principal.record.displayName,)
+        else:
+            return &quot;&quot;
+
+    return formatList(
+        tags.a(href=principal.principalURL())(
+            str(principal), describe(principal)
+        )
+        for principal in sorted(principals, key=recordKey)
+    )
+
+
+
+def formatList(iterable):
+    &quot;&quot;&quot;
+    Format a list of stuff as an interable.
+    &quot;&quot;&quot;
+    thereAreAny = False
+    try:
+        item = None
+        for item in iterable:
+            thereAreAny = True
+            yield &quot; -&gt; &quot;
+            if item is None:
+                yield &quot;None&quot;
+            else:
+                yield item
+            yield &quot;\n&quot;
+    except Exception, e:
+        log.error(&quot;Exception while rendering: %s&quot; % (e,))
+        Failure().printTraceback()
+        yield &quot;  ** %s **: %s\n&quot; % (e.__class__.__name__, e)
+    if not thereAreAny:
+        yield &quot; '()\n&quot;
+
+
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorywikipy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/wiki.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/wiki.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/wiki.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -19,32 +19,32 @@
</span><span class="cx"> as other principals.
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-__all__ = [
-    &quot;WikiDirectoryService&quot;,
-]
</del><span class="cx"> 
</span><ins>+from twisted.internet.defer import inlineCallbacks, returnValue, succeed
+from twistedcaldav.config import config
+from twisted.web.xmlrpc import Proxy, Fault
</ins><span class="cx"> from calendarserver.platform.darwin.wiki import accessForUserToWiki
</span><ins>+from twext.python.log import Logger
</ins><span class="cx"> 
</span><span class="cx"> from twext.internet.gaiendpoint import MultiFailure
</span><del>-from twext.python.log import Logger
</del><span class="cx"> from txweb2 import responsecode
</span><del>-from txweb2.auth.wrapper import UnauthorizedResponse
-from txweb2.dav.resource import TwistedACLInheritable
</del><ins>+# from txweb2.auth.wrapper import UnauthorizedResponse
+# from txweb2.dav.resource import TwistedACLInheritable
</ins><span class="cx"> from txweb2.http import HTTPError, StatusResponse
</span><span class="cx"> 
</span><del>-from twisted.internet.defer import inlineCallbacks, returnValue
</del><span class="cx"> from twisted.web.error import Error as WebError
</span><del>-from twisted.web.xmlrpc import Proxy, Fault
</del><span class="cx"> 
</span><del>-from twistedcaldav.config import config
-from twistedcaldav.directory.directory import DirectoryService, \
-    DirectoryRecord, UnknownRecordTypeError
</del><ins>+# from twistedcaldav.directory.directory import DirectoryService, \
+#     DirectoryRecord, UnknownRecordTypeError
</ins><span class="cx"> 
</span><del>-from txdav.xml import element as davxml
</del><ins>+# from txdav.xml import element as davxml
</ins><span class="cx"> 
</span><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><del>-class WikiDirectoryService(DirectoryService):
</del><ins>+# class WikiDirectoryService(DirectoryService):
+
+
+class WikiDirectoryService(object):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     L{IDirectoryService} implementation for Wikis.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="lines">@@ -57,81 +57,81 @@
</span><span class="cx">     UIDPrefix = &quot;wiki-&quot;
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def __repr__(self):
-        return &quot;&lt;%s %r&gt;&quot; % (self.__class__.__name__, self.realmName)
</del><ins>+#     def __repr__(self):
+#         return &quot;&lt;%s %r&gt;&quot; % (self.__class__.__name__, self.realmName)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def __init__(self):
-        super(WikiDirectoryService, self).__init__()
-        self.byUID = {}
-        self.byShortName = {}
</del><ins>+#     def __init__(self):
+#         super(WikiDirectoryService, self).__init__()
+#         self.byUID = {}
+#         self.byShortName = {}
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def recordTypes(self):
-        return (WikiDirectoryService.recordType_wikis,)
</del><ins>+#     def recordTypes(self):
+#         return (WikiDirectoryService.recordType_wikis,)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def listRecords(self, recordType):
-        return ()
</del><ins>+#     def listRecords(self, recordType):
+#         return ()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def recordWithShortName(self, recordType, shortName):
-        if recordType != WikiDirectoryService.recordType_wikis:
-            raise UnknownRecordTypeError(recordType)
</del><ins>+#     def recordWithShortName(self, recordType, shortName):
+#         if recordType != WikiDirectoryService.recordType_wikis:
+#             raise UnknownRecordTypeError(recordType)
</ins><span class="cx"> 
</span><del>-        if shortName in self.byShortName:
-            record = self.byShortName[shortName]
-            return record
</del><ins>+#         if shortName in self.byShortName:
+#             record = self.byShortName[shortName]
+#             return record
</ins><span class="cx"> 
</span><del>-        record = self._addRecord(shortName)
-        return record
</del><ins>+#         record = self._addRecord(shortName)
+#         return record
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def recordWithUID(self, uid):
</del><ins>+#     def recordWithUID(self, uid):
</ins><span class="cx"> 
</span><del>-        if uid in self.byUID:
-            record = self.byUID[uid]
-            return record
</del><ins>+#         if uid in self.byUID:
+#             record = self.byUID[uid]
+#             return record
</ins><span class="cx"> 
</span><del>-        if uid.startswith(self.UIDPrefix):
-            shortName = uid[len(self.UIDPrefix):]
-            record = self._addRecord(shortName)
-            return record
-        else:
-            return None
</del><ins>+#         if uid.startswith(self.UIDPrefix):
+#             shortName = uid[len(self.UIDPrefix):]
+#             record = self._addRecord(shortName)
+#             return record
+#         else:
+#             return None
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def _addRecord(self, shortName):
</del><ins>+#     def _addRecord(self, shortName):
</ins><span class="cx"> 
</span><del>-        record = WikiDirectoryRecord(
-            self,
-            WikiDirectoryService.recordType_wikis,
-            shortName,
-            None
-        )
-        self.byUID[record.uid] = record
-        self.byShortName[shortName] = record
-        return record
</del><ins>+#         record = WikiDirectoryRecord(
+#             self,
+#             WikiDirectoryService.recordType_wikis,
+#             shortName,
+#             None
+#         )
+#         self.byUID[record.uid] = record
+#         self.byShortName[shortName] = record
+#         return record
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class WikiDirectoryRecord(DirectoryRecord):
-    &quot;&quot;&quot;
-    L{DirectoryRecord} implementation for Wikis.
-    &quot;&quot;&quot;
</del><ins>+# class WikiDirectoryRecord(DirectoryRecord):
+#     &quot;&quot;&quot;
+#     L{DirectoryRecord} implementation for Wikis.
+#     &quot;&quot;&quot;
</ins><span class="cx"> 
</span><del>-    def __init__(self, service, recordType, shortName, entry):
-        super(WikiDirectoryRecord, self).__init__(
-            service=service,
-            recordType=recordType,
-            guid=None,
-            shortNames=(shortName,),
-            fullName=shortName,
-            enabledForCalendaring=True,
-            uid=&quot;%s%s&quot; % (WikiDirectoryService.UIDPrefix, shortName),
-        )
-        # Wiki enabling doesn't come from augments db, so enable here...
-        self.enabled = True
</del><ins>+#     def __init__(self, service, recordType, shortName, entry):
+#         super(WikiDirectoryRecord, self).__init__(
+#             service=service,
+#             recordType=recordType,
+#             guid=None,
+#             shortNames=(shortName,),
+#             fullName=shortName,
+#             enabledForCalendaring=True,
+#             uid=&quot;%s%s&quot; % (WikiDirectoryService.UIDPrefix, shortName),
+#         )
+#         # Wiki enabling doesn't come from augments db, so enable here...
+#         self.enabled = True
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -250,118 +250,120 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-@inlineCallbacks
</del><span class="cx"> def getWikiACL(resource, request):
</span><del>-    &quot;&quot;&quot;
-    Ask the wiki server we're paired with what level of access the authnUser has.
</del><ins>+    return succeed(None)
+# @inlineCallbacks
+# def getWikiACL(resource, request):
+#     &quot;&quot;&quot;
+#     Ask the wiki server we're paired with what level of access the authnUser has.
</ins><span class="cx"> 
</span><del>-    Returns an ACL.
</del><ins>+#     Returns an ACL.
</ins><span class="cx"> 
</span><del>-    Wiki authentication is a bit tricky because the end-user accessing a group
-    calendar may not actually be enabled for calendaring.  Therefore in that
-    situation, the authzUser will have been replaced with the wiki principal
-    in locateChild( ), so that any changes the user makes will have the wiki
-    as the originator.  The authnUser will always be the end-user.
-    &quot;&quot;&quot;
-    from twistedcaldav.directory.principal import DirectoryPrincipalResource
</del><ins>+#     Wiki authentication is a bit tricky because the end-user accessing a group
+#     calendar may not actually be enabled for calendaring.  Therefore in that
+#     situation, the authzUser will have been replaced with the wiki principal
+#     in locateChild( ), so that any changes the user makes will have the wiki
+#     as the originator.  The authnUser will always be the end-user.
+#     &quot;&quot;&quot;
+#     from twistedcaldav.directory.principal import DirectoryPrincipalResource
</ins><span class="cx"> 
</span><del>-    if (not hasattr(resource, &quot;record&quot;) or
-        resource.record.recordType != WikiDirectoryService.recordType_wikis):
-        returnValue(None)
</del><ins>+#     if (not hasattr(resource, &quot;record&quot;) or
+#         resource.record.recordType != WikiDirectoryService.recordType_wikis):
+#         returnValue(None)
</ins><span class="cx"> 
</span><del>-    if hasattr(request, 'wikiACL'):
-        returnValue(request.wikiACL)
</del><ins>+#     if hasattr(request, 'wikiACL'):
+#         returnValue(request.wikiACL)
</ins><span class="cx"> 
</span><del>-    userID = &quot;unauthenticated&quot;
-    wikiID = resource.record.shortNames[0]
</del><ins>+#     userID = &quot;unauthenticated&quot;
+#     wikiID = resource.record.shortNames[0]
</ins><span class="cx"> 
</span><del>-    try:
-        url = str(request.authnUser.children[0])
-        principal = (yield request.locateResource(url))
-        if isinstance(principal, DirectoryPrincipalResource):
-            userID = principal.record.guid
-    except:
-        # TODO: better error handling
-        pass
</del><ins>+#     try:
+#         url = str(request.authnUser.children[0])
+#         principal = (yield request.locateResource(url))
+#         if isinstance(principal, DirectoryPrincipalResource):
+#             userID = principal.record.guid
+#     except:
+#         # TODO: better error handling
+#         pass
</ins><span class="cx"> 
</span><del>-    try:
-        access = (yield getWikiAccess(userID, wikiID))
</del><ins>+#     try:
+#         access = (yield getWikiAccess(userID, wikiID))
</ins><span class="cx"> 
</span><del>-        # The ACL we returns has ACEs for the end-user and the wiki principal
-        # in case authzUser is the wiki principal.
-        if access == &quot;read&quot;:
-            request.wikiACL = davxml.ACL(
-                davxml.ACE(
-                    request.authnUser,
-                    davxml.Grant(
-                        davxml.Privilege(davxml.Read()),
-                        davxml.Privilege(davxml.ReadCurrentUserPrivilegeSet()),
</del><ins>+#         # The ACL we returns has ACEs for the end-user and the wiki principal
+#         # in case authzUser is the wiki principal.
+#         if access == &quot;read&quot;:
+#             request.wikiACL = davxml.ACL(
+#                 davxml.ACE(
+#                     request.authnUser,
+#                     davxml.Grant(
+#                         davxml.Privilege(davxml.Read()),
+#                         davxml.Privilege(davxml.ReadCurrentUserPrivilegeSet()),
</ins><span class="cx"> 
</span><del>-                        # We allow write-properties so that direct sharees can change
-                        # e.g. calendar color properties
-                        davxml.Privilege(davxml.WriteProperties()),
-                    ),
-                    TwistedACLInheritable(),
-                ),
-                davxml.ACE(
-                    davxml.Principal(
-                        davxml.HRef.fromString(&quot;/principals/wikis/%s/&quot; % (wikiID,))
-                    ),
-                    davxml.Grant(
-                        davxml.Privilege(davxml.Read()),
-                        davxml.Privilege(davxml.ReadCurrentUserPrivilegeSet()),
-                    ),
-                    TwistedACLInheritable(),
-                )
-            )
-            returnValue(request.wikiACL)
</del><ins>+#                         # We allow write-properties so that direct sharees can change
+#                         # e.g. calendar color properties
+#                         davxml.Privilege(davxml.WriteProperties()),
+#                     ),
+#                     TwistedACLInheritable(),
+#                 ),
+#                 davxml.ACE(
+#                     davxml.Principal(
+#                         davxml.HRef.fromString(&quot;/principals/wikis/%s/&quot; % (wikiID,))
+#                     ),
+#                     davxml.Grant(
+#                         davxml.Privilege(davxml.Read()),
+#                         davxml.Privilege(davxml.ReadCurrentUserPrivilegeSet()),
+#                     ),
+#                     TwistedACLInheritable(),
+#                 )
+#             )
+#             returnValue(request.wikiACL)
</ins><span class="cx"> 
</span><del>-        elif access in (&quot;write&quot;, &quot;admin&quot;):
-            request.wikiACL = davxml.ACL(
-                davxml.ACE(
-                    request.authnUser,
-                    davxml.Grant(
-                        davxml.Privilege(davxml.Read()),
-                        davxml.Privilege(davxml.ReadCurrentUserPrivilegeSet()),
-                        davxml.Privilege(davxml.Write()),
-                    ),
-                    TwistedACLInheritable(),
-                ),
-                davxml.ACE(
-                    davxml.Principal(
-                        davxml.HRef.fromString(&quot;/principals/wikis/%s/&quot; % (wikiID,))
-                    ),
-                    davxml.Grant(
-                        davxml.Privilege(davxml.Read()),
-                        davxml.Privilege(davxml.ReadCurrentUserPrivilegeSet()),
-                        davxml.Privilege(davxml.Write()),
-                    ),
-                    TwistedACLInheritable(),
-                )
-            )
-            returnValue(request.wikiACL)
</del><ins>+#         elif access in (&quot;write&quot;, &quot;admin&quot;):
+#             request.wikiACL = davxml.ACL(
+#                 davxml.ACE(
+#                     request.authnUser,
+#                     davxml.Grant(
+#                         davxml.Privilege(davxml.Read()),
+#                         davxml.Privilege(davxml.ReadCurrentUserPrivilegeSet()),
+#                         davxml.Privilege(davxml.Write()),
+#                     ),
+#                     TwistedACLInheritable(),
+#                 ),
+#                 davxml.ACE(
+#                     davxml.Principal(
+#                         davxml.HRef.fromString(&quot;/principals/wikis/%s/&quot; % (wikiID,))
+#                     ),
+#                     davxml.Grant(
+#                         davxml.Privilege(davxml.Read()),
+#                         davxml.Privilege(davxml.ReadCurrentUserPrivilegeSet()),
+#                         davxml.Privilege(davxml.Write()),
+#                     ),
+#                     TwistedACLInheritable(),
+#                 )
+#             )
+#             returnValue(request.wikiACL)
</ins><span class="cx"> 
</span><del>-        else: # &quot;no-access&quot;:
</del><ins>+#         else: # &quot;no-access&quot;:
</ins><span class="cx"> 
</span><del>-            if userID == &quot;unauthenticated&quot;:
-                # Return a 401 so they have an opportunity to log in
-                response = (yield UnauthorizedResponse.makeResponse(
-                    request.credentialFactories,
-                    request.remoteAddr,
-                ))
-                raise HTTPError(response)
</del><ins>+#             if userID == &quot;unauthenticated&quot;:
+#                 # Return a 401 so they have an opportunity to log in
+#                 response = (yield UnauthorizedResponse.makeResponse(
+#                     request.credentialFactories,
+#                     request.remoteAddr,
+#                 ))
+#                 raise HTTPError(response)
</ins><span class="cx"> 
</span><del>-            raise HTTPError(
-                StatusResponse(
-                    responsecode.FORBIDDEN,
-                    &quot;You are not allowed to access this wiki&quot;
-                )
-            )
</del><ins>+#             raise HTTPError(
+#                 StatusResponse(
+#                     responsecode.FORBIDDEN,
+#                     &quot;You are not allowed to access this wiki&quot;
+#                 )
+#             )
</ins><span class="cx"> 
</span><del>-    except HTTPError:
-        # pass through the HTTPError we might have raised above
-        raise
</del><ins>+#     except HTTPError:
+#         # pass through the HTTPError we might have raised above
+#         raise
</ins><span class="cx"> 
</span><del>-    except Exception, e:
-        log.error(&quot;Wiki ACL lookup failed: %s&quot; % (e,))
-        raise HTTPError(StatusResponse(responsecode.SERVICE_UNAVAILABLE, &quot;Wiki ACL lookup failed&quot;))
</del><ins>+#     except Exception, e:
+#         log.error(&quot;Wiki ACL lookup failed: %s&quot; % (e,))
+#         raise HTTPError(StatusResponse(responsecode.SERVICE_UNAVAILABLE, &quot;Wiki ACL lookup failed&quot;))
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorybackedaddressbookpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directorybackedaddressbook.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directorybackedaddressbook.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directorybackedaddressbook.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -112,16 +112,18 @@
</span><span class="cx">             # DAV:Read for all authenticated principals (does not include anonymous)
</span><span class="cx">             accessPrincipal = davxml.Authenticated()
</span><span class="cx"> 
</span><del>-        return davxml.ACL(
-            davxml.ACE(
-                davxml.Principal(accessPrincipal),
-                davxml.Grant(
-                    davxml.Privilege(davxml.Read()),
-                    davxml.Privilege(davxml.ReadCurrentUserPrivilegeSet())
-                                ),
-                davxml.Protected(),
-                TwistedACLInheritable(),
-           ),
</del><ins>+        return succeed(
+            davxml.ACL(
+                davxml.ACE(
+                    davxml.Principal(accessPrincipal),
+                    davxml.Grant(
+                        davxml.Privilege(davxml.Read()),
+                        davxml.Privilege(davxml.ReadCurrentUserPrivilegeSet())
+                                    ),
+                    davxml.Protected(),
+                    TwistedACLInheritable(),
+               ),
+            )
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -160,7 +162,7 @@
</span><span class="cx"> 
</span><span class="cx">     def accessControlList(self, request, inheritance=True, expanding=False, inherited_aces=None):
</span><span class="cx">         # Permissions here are fixed, and are not subject to inheritance rules, etc.
</span><del>-        return succeed(self.defaultAccessControlList())
</del><ins>+        return self.defaultAccessControlList()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavextensionspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/extensions.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/extensions.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/extensions.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -66,8 +66,8 @@
</span><span class="cx"> from twistedcaldav.method.report import http_REPORT
</span><span class="cx"> 
</span><span class="cx"> from twistedcaldav.config import config
</span><ins>+from twext.who.expression import Operand, MatchType, MatchFlags
</ins><span class="cx"> 
</span><del>-
</del><span class="cx"> thisModule = getModule(__name__)
</span><span class="cx"> 
</span><span class="cx"> log = Logger()
</span><span class="lines">@@ -95,7 +95,7 @@
</span><span class="cx">             msg = &quot;Bad XML: unknown value for test attribute: %s&quot; % (testMode,)
</span><span class="cx">             log.warn(msg)
</span><span class="cx">             raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, msg))
</span><del>-        operand = &quot;and&quot; if testMode == &quot;allof&quot; else &quot;or&quot;
</del><ins>+        operand = Operand.AND if testMode == &quot;allof&quot; else Operand.OR
</ins><span class="cx"> 
</span><span class="cx">         # Are we narrowing results down to a single CUTYPE?
</span><span class="cx">         cuType = principal_property_search.attributes.get(&quot;type&quot;, None)
</span><span class="lines">@@ -144,10 +144,18 @@
</span><span class="cx">                     log.warn(msg)
</span><span class="cx">                     raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, msg))
</span><span class="cx"> 
</span><ins>+                # Convert to twext.who.expression form
+                matchType = {
+                    &quot;starts-with&quot;: MatchType.startsWith,
+                    &quot;contains&quot;: MatchType.contains,
+                    &quot;equals&quot;: MatchType.equals
+                }.get(matchType)
+                matchFlags = MatchFlags.caseInsensitive if caseless else MatchFlags.none
+
</ins><span class="cx">                 # Ignore any query strings under three letters
</span><del>-                matchText = str(match)
</del><ins>+                matchText = match.toString()  # gives us unicode
</ins><span class="cx">                 if len(matchText) &gt;= 3:
</span><del>-                    propertySearches.append((props.children, matchText, caseless, matchType))
</del><ins>+                    propertySearches.append((props.children, matchText, matchFlags, matchType))
</ins><span class="cx"> 
</span><span class="cx">             elif child.qname() == (calendarserver_namespace, &quot;limit&quot;):
</span><span class="cx">                 try:
</span><span class="lines">@@ -182,7 +190,7 @@
</span><span class="cx">         # See if we can take advantage of the directory
</span><span class="cx">         fields = []
</span><span class="cx">         nonDirectorySearches = []
</span><del>-        for props, match, caseless, matchType in propertySearches:
</del><ins>+        for props, match, matchFlags, matchType in propertySearches:
</ins><span class="cx">             nonDirectoryProps = []
</span><span class="cx">             for prop in props:
</span><span class="cx">                 try:
</span><span class="lines">@@ -191,12 +199,12 @@
</span><span class="cx">                 except ValueError, e:
</span><span class="cx">                     raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
</span><span class="cx">                 if fieldName:
</span><del>-                    fields.append((fieldName, match, caseless, matchType))
</del><ins>+                    fields.append((fieldName, match, matchFlags, matchType))
</ins><span class="cx">                 else:
</span><span class="cx">                     nonDirectoryProps.append(prop)
</span><span class="cx">             if nonDirectoryProps:
</span><span class="cx">                 nonDirectorySearches.append((nonDirectoryProps, match,
</span><del>-                    caseless, matchType))
</del><ins>+                    matchFlags, matchType))
</ins><span class="cx"> 
</span><span class="cx">         matchingResources = []
</span><span class="cx">         matchcount = 0
</span><span class="lines">@@ -208,7 +216,7 @@
</span><span class="cx">                 operand=operand, cuType=cuType))
</span><span class="cx"> 
</span><span class="cx">             for record in records:
</span><del>-                resource = principalCollection.principalForRecord(record)
</del><ins>+                resource = yield principalCollection.principalForRecord(record)
</ins><span class="cx">                 if resource:
</span><span class="cx">                     matchingResources.append(resource)
</span><span class="cx"> 
</span><span class="lines">@@ -299,7 +307,7 @@
</span><span class="cx">         records = (yield dir.recordsMatchingTokens(tokens, context=context))
</span><span class="cx"> 
</span><span class="cx">         for record in records:
</span><del>-            resource = principalCollection.principalForRecord(record)
</del><ins>+            resource = yield principalCollection.principalForRecord(record)
</ins><span class="cx">             if resource:
</span><span class="cx">                 matchingResources.append(resource)
</span><span class="cx"> 
</span><span class="lines">@@ -420,9 +428,9 @@
</span><span class="cx">                 f.trap(HTTPError)
</span><span class="cx">                 code = f.value.response.code
</span><span class="cx">                 if code == responsecode.NOT_FOUND:
</span><del>-                    log.error(&quot;Property %s was returned by listProperties() &quot;
-                              &quot;but does not exist for resource %s.&quot;
-                              % (name, self.resource))
</del><ins>+                    log.error(&quot;Property {p} was returned by listProperties() &quot;
+                              &quot;but does not exist for resource {r}.&quot;,
+                              p=name, r=self.resource)
</ins><span class="cx">                     return (name, None)
</span><span class="cx">                 if code == responsecode.UNAUTHORIZED:
</span><span class="cx">                     return (name, accessDeniedValue)
</span><span class="lines">@@ -721,7 +729,13 @@
</span><span class="cx"> 
</span><span class="cx">             elif name == &quot;record-type&quot;:
</span><span class="cx">                 if hasattr(self, &quot;record&quot;):
</span><del>-                    returnValue(customxml.RecordType(self.record.recordType))
</del><ins>+                    returnValue(
+                        customxml.RecordType(
+                            self.record.service.recordTypeToOldName(
+                                self.record.recordType
+                            )
+                        )
+                    )
</ins><span class="cx">                 else:
</span><span class="cx">                     raise HTTPError(StatusResponse(
</span><span class="cx">                         responsecode.NOT_FOUND,
</span><span class="lines">@@ -848,7 +862,7 @@
</span><span class="cx">     ):
</span><span class="cx">         # Permissions here are fixed, and are not subject to
</span><span class="cx">         # inheritance rules, etc.
</span><del>-        return succeed(self.defaultAccessControlList())
</del><ins>+        return self.defaultAccessControlList()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavfreebusyurlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/freebusyurl.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/freebusyurl.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/freebusyurl.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -102,7 +102,7 @@
</span><span class="cx">                     davxml.Protected(),
</span><span class="cx">                 ),
</span><span class="cx">             )
</span><del>-        return davxml.ACL(*aces)
</del><ins>+        return succeed(davxml.ACL(*aces))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def resourceType(self):
</span><span class="lines">@@ -243,7 +243,7 @@
</span><span class="cx">         # TODO: We should probably verify that the actual time-range is within sensible bounds (e.g. not too far in the past or future and not too long)
</span><span class="cx"> 
</span><span class="cx">         # Now lookup the principal details for the targeted user
</span><del>-        principal = self.parent.principalForRecord()
</del><ins>+        principal = (yield self.parent.principalForRecord())
</ins><span class="cx"> 
</span><span class="cx">         # Pick the first mailto cu address or the first other type
</span><span class="cx">         cuaddr = None
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavicalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/ical.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/ical.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/ical.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> import itertools
</span><span class="cx"> import uuid
</span><span class="cx"> 
</span><ins>+from twisted.internet.defer import inlineCallbacks, returnValue
</ins><span class="cx"> from twext.python.log import Logger
</span><span class="cx"> from txweb2.stream import IStream
</span><span class="cx"> from txweb2.dav.util import allDataFromStream
</span><span class="lines">@@ -3239,6 +3240,7 @@
</span><span class="cx">                         self.removeProperty(attachment)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def normalizeCalendarUserAddresses(self, lookupFunction, principalFunction,
</span><span class="cx">         toUUID=True):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -3259,7 +3261,7 @@
</span><span class="cx">                 # Check that we can lookup this calendar user address - if not
</span><span class="cx">                 # we cannot do anything with it
</span><span class="cx">                 cuaddr = normalizeCUAddr(prop.value())
</span><del>-                name, guid, cuaddrs = lookupFunction(cuaddr, principalFunction, config)
</del><ins>+                name, guid, cuaddrs = yield lookupFunction(cuaddr, principalFunction, config)
</ins><span class="cx">                 if guid is None:
</span><span class="cx">                     continue
</span><span class="cx"> 
</span><span class="lines">@@ -3275,7 +3277,9 @@
</span><span class="cx"> 
</span><span class="cx">                 if toUUID:
</span><span class="cx">                     # Always re-write value to urn:uuid
</span><del>-                    prop.setValue(&quot;urn:uuid:%s&quot; % (guid,))
</del><ins>+                    if isinstance(guid, uuid.UUID):
+                        guid = unicode(guid).upper()
+                    prop.setValue(&quot;urn:uuid:{guid}&quot;.format(guid=guid))
</ins><span class="cx"> 
</span><span class="cx">                 # If it is already a non-UUID address leave it be
</span><span class="cx">                 elif cuaddr.startswith(&quot;urn:uuid:&quot;):
</span><span class="lines">@@ -3353,7 +3357,7 @@
</span><span class="cx"> 
</span><span class="cx">             # For VPOLL also do immediate children
</span><span class="cx">             if component.name() == &quot;VPOLL&quot;:
</span><del>-                component.normalizeCalendarUserAddresses(lookupFunction, principalFunction, toUUID)
</del><ins>+                yield component.normalizeCalendarUserAddresses(lookupFunction, principalFunction, toUUID)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def allPerUserUIDs(self):
</span><span class="lines">@@ -3563,15 +3567,16 @@
</span><span class="cx"> # Utilities
</span><span class="cx"> # #
</span><span class="cx"> 
</span><ins>+@inlineCallbacks
</ins><span class="cx"> def normalizeCUAddress(cuaddr, lookupFunction, principalFunction, toUUID=True):
</span><span class="cx">     # Check that we can lookup this calendar user address - if not
</span><span class="cx">     # we cannot do anything with it
</span><del>-    _ignore_name, guid, cuaddrs = lookupFunction(normalizeCUAddr(cuaddr), principalFunction, config)
</del><ins>+    _ignore_name, guid, cuaddrs = (yield lookupFunction(normalizeCUAddr(cuaddr), principalFunction, config))
</ins><span class="cx"> 
</span><span class="cx">     if toUUID:
</span><span class="cx">         # Always re-write value to urn:uuid
</span><span class="cx">         if guid:
</span><del>-            return &quot;urn:uuid:%s&quot; % (guid,)
</del><ins>+            returnValue(&quot;urn:uuid:%s&quot; % (guid,))
</ins><span class="cx"> 
</span><span class="cx">     # If it is already a non-UUID address leave it be
</span><span class="cx">     elif cuaddr.startswith(&quot;urn:uuid:&quot;):
</span><span class="lines">@@ -3610,9 +3615,9 @@
</span><span class="cx"> 
</span><span class="cx">         # Make the change
</span><span class="cx">         if newaddr:
</span><del>-            return newaddr
</del><ins>+            returnValue(newaddr)
</ins><span class="cx"> 
</span><del>-    return cuaddr
</del><ins>+    returnValue(cuaddr)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavresourcepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/resource.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/resource.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/resource.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -863,7 +863,8 @@
</span><span class="cx">                 home = self._newStoreObject.parentCollection().ownerHome()
</span><span class="cx">             else:
</span><span class="cx">                 home = self._newStoreObject.ownerHome()
</span><del>-            returnValue(element.HRef(self.principalForUID(home.uid()).principalURL()))
</del><ins>+            principal = (yield self.principalForUID(home.uid()))
+            returnValue(element.HRef(principal.principalURL()))
</ins><span class="cx">         else:
</span><span class="cx">             parent = (yield self.locateParent(request, request.urlForResource(self)))
</span><span class="cx">         if parent and isinstance(parent, CalDAVResource):
</span><span class="lines">@@ -883,7 +884,7 @@
</span><span class="cx">                 home = self._newStoreObject.parentCollection().ownerHome()
</span><span class="cx">             else:
</span><span class="cx">                 home = self._newStoreObject.ownerHome()
</span><del>-            returnValue(self.principalForUID(home.uid()))
</del><ins>+            returnValue((yield self.principalForUID(home.uid())))
</ins><span class="cx">         else:
</span><span class="cx">             parent = (yield self.locateParent(request, request.urlForResource(self)))
</span><span class="cx">         if parent and isinstance(parent, CalDAVResource):
</span><span class="lines">@@ -933,8 +934,8 @@
</span><span class="cx">             return None
</span><span class="cx"> 
</span><span class="cx">         if 'record' in dir(self):
</span><del>-            if self.record.fullName:
-                return self.record.fullName
</del><ins>+            if self.record.fullNames:
+                return self.record.fullNames[0]
</ins><span class="cx">             elif self.record.shortNames:
</span><span class="cx">                 return self.record.shortNames[0]
</span><span class="cx">             else:
</span><span class="lines">@@ -1063,6 +1064,7 @@
</span><span class="cx">         returnValue(PerUserDataFilter(accessUID).filter(caldata))
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    # MOVE2WHO returns Deferred
</ins><span class="cx">     def iCalendarAddressDoNormalization(self, ical):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Normalize calendar user addresses in the supplied iCalendar object into their
</span><span class="lines">@@ -1071,24 +1073,26 @@
</span><span class="cx">         @param ical: calendar object to normalize.
</span><span class="cx">         @type ical: L{Component}
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        ical.normalizeCalendarUserAddresses(normalizationLookup,
</del><ins>+        return ical.normalizeCalendarUserAddresses(normalizationLookup,
</ins><span class="cx">             self.principalForCalendarUserAddress)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def principalForCalendarUserAddress(self, address):
</span><span class="cx">         for principalCollection in self.principalCollections():
</span><del>-            principal = principalCollection.principalForCalendarUserAddress(address)
</del><ins>+            principal = (yield principalCollection.principalForCalendarUserAddress(address))
</ins><span class="cx">             if principal is not None:
</span><del>-                return principal
-        return None
</del><ins>+                returnValue(principal)
+        returnValue(None)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def principalForUID(self, principalUID):
</span><span class="cx">         for principalCollection in self.principalCollections():
</span><del>-            principal = principalCollection.principalForUID(principalUID)
</del><ins>+            principal = (yield principalCollection.principalForUID(principalUID))
</ins><span class="cx">             if principal is not None:
</span><del>-                return principal
-        return None
</del><ins>+                returnValue(principal)
+        returnValue(None)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -1874,7 +1878,7 @@
</span><span class="cx"> 
</span><span class="cx">             elif name == &quot;auto-schedule-mode&quot; and self.calendarsEnabled():
</span><span class="cx">                 autoScheduleMode = self.getAutoScheduleMode()
</span><del>-                returnValue(customxml.AutoScheduleMode(autoScheduleMode if autoScheduleMode else &quot;default&quot;))
</del><ins>+                returnValue(customxml.AutoScheduleMode(autoScheduleMode.description if autoScheduleMode else &quot;default&quot;))
</ins><span class="cx"> 
</span><span class="cx">         elif namespace == carddav_namespace and self.addressBooksEnabled():
</span><span class="cx">             if name == &quot;addressbook-home-set&quot;:
</span><span class="lines">@@ -2302,20 +2306,23 @@
</span><span class="cx">     # ACL
</span><span class="cx">     ##
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def owner(self, request):
</span><del>-        return succeed(element.HRef(self.principalForRecord().principalURL()))
</del><ins>+        principal = yield self.principalForRecord()
+        returnValue(element.HRef(principal.principalURL()))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def ownerPrincipal(self, request):
</span><del>-        return succeed(self.principalForRecord())
</del><ins>+        return self.principalForRecord()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def resourceOwnerPrincipal(self, request):
</span><del>-        return succeed(self.principalForRecord())
</del><ins>+        return self.principalForRecord()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def defaultAccessControlList(self):
</span><del>-        myPrincipal = self.principalForRecord()
</del><ins>+        myPrincipal = yield self.principalForRecord()
</ins><span class="cx"> 
</span><span class="cx">         # Server may be read only
</span><span class="cx">         if config.EnableReadOnlyServer:
</span><span class="lines">@@ -2342,12 +2349,12 @@
</span><span class="cx">         # Give all access to config.AdminPrincipals
</span><span class="cx">         aces += config.AdminACEs
</span><span class="cx"> 
</span><del>-        return element.ACL(*aces)
</del><ins>+        returnValue(element.ACL(*aces))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def accessControlList(self, request, inheritance=True, expanding=False, inherited_aces=None):
</span><span class="cx">         # Permissions here are fixed, and are not subject to inheritance rules, etc.
</span><del>-        return succeed(self.defaultAccessControlList())
</del><ins>+        return self.defaultAccessControlList()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def principalCollections(self):
</span><span class="lines">@@ -2555,9 +2562,10 @@
</span><span class="cx">         return config.Sharing.Enabled and config.Sharing.Calendars.Enabled and self.exists()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def _otherPrincipalHomeURL(self, otherUID):
</span><del>-        ownerPrincipal = self.principalForUID(otherUID)
-        return ownerPrincipal.calendarHomeURLs()[0]
</del><ins>+        ownerPrincipal = (yield self.principalForUID(otherUID))
+        returnValue(ownerPrincipal.calendarHomeURLs()[0])
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -2584,8 +2592,9 @@
</span><span class="cx">         return self._newStoreHome.hasCalendarResourceUIDSomewhereElse(uid, ok_object._newStoreObject, mode)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def defaultAccessControlList(self):
</span><del>-        myPrincipal = self.principalForRecord()
</del><ins>+        myPrincipal = yield self.principalForRecord()
</ins><span class="cx"> 
</span><span class="cx">         # Server may be read only
</span><span class="cx">         if config.EnableReadOnlyServer:
</span><span class="lines">@@ -2652,7 +2661,7 @@
</span><span class="cx">                 ),
</span><span class="cx">             )
</span><span class="cx"> 
</span><del>-        return element.ACL(*aces)
</del><ins>+        returnValue(element.ACL(*aces))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -2808,9 +2817,10 @@
</span><span class="cx">         return config.Sharing.Enabled and config.Sharing.AddressBooks.Enabled and self.exists()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def _otherPrincipalHomeURL(self, otherUID):
</span><del>-        ownerPrincipal = self.principalForUID(otherUID)
-        return ownerPrincipal.addressBookHomeURLs()[0]
</del><ins>+        ownerPrincipal = (yield self.principalForUID(otherUID))
+        returnValue(ownerPrincipal.addressBookHomeURLs()[0])
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavscheduling_storecaldavresourcepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/scheduling_store/caldav/resource.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/scheduling_store/caldav/resource.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/scheduling_store/caldav/resource.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -373,12 +373,14 @@
</span><span class="cx">         if config.Scheduling.CalDAV.OldDraftCompatibility:
</span><span class="cx">             privs += (davxml.Privilege(caldavxml.Schedule()),)
</span><span class="cx"> 
</span><del>-        return davxml.ACL(
-            # CalDAV:schedule-deliver for any authenticated user
-            davxml.ACE(
-                davxml.Principal(davxml.Authenticated()),
-                davxml.Grant(*privs),
-            ),
</del><ins>+        return succeed(
+            davxml.ACL(
+                # CalDAV:schedule-deliver for any authenticated user
+                davxml.ACE(
+                    davxml.Principal(davxml.Authenticated()),
+                    davxml.Grant(*privs),
+                ),
+            )
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -532,9 +534,10 @@
</span><span class="cx">         return succeed(sendSchedulePrivilegeSet)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def defaultAccessControlList(self):
</span><span class="cx">         if config.EnableProxyPrincipals:
</span><del>-            myPrincipal = self.parent.principalForRecord()
</del><ins>+            myPrincipal = yield self.parent.principalForRecord()
</ins><span class="cx"> 
</span><span class="cx">             privs = (
</span><span class="cx">                 davxml.Privilege(caldavxml.ScheduleSend()),
</span><span class="lines">@@ -542,16 +545,18 @@
</span><span class="cx">             if config.Scheduling.CalDAV.OldDraftCompatibility:
</span><span class="cx">                 privs += (davxml.Privilege(caldavxml.Schedule()),)
</span><span class="cx"> 
</span><del>-            return davxml.ACL(
-                # CalDAV:schedule for associated write proxies
-                davxml.ACE(
-                    davxml.Principal(davxml.HRef(joinURL(myPrincipal.principalURL(), &quot;calendar-proxy-write&quot;))),
-                    davxml.Grant(*privs),
-                    davxml.Protected(),
-                ),
</del><ins>+            returnValue(
+                davxml.ACL(
+                    # CalDAV:schedule for associated write proxies
+                    davxml.ACE(
+                        davxml.Principal(davxml.HRef(joinURL(myPrincipal.principalURL(), &quot;calendar-proxy-write&quot;))),
+                        davxml.Grant(*privs),
+                        davxml.Protected(),
+                    ),
+                )
</ins><span class="cx">             )
</span><span class="cx">         else:
</span><del>-            return super(ScheduleOutboxResource, self).defaultAccessControlList()
</del><ins>+            returnValue(super(ScheduleOutboxResource, self).defaultAccessControlList())
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def report_urn_ietf_params_xml_ns_caldav_calendar_query(self, request, calendar_query):
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavsharingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/sharing.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/sharing.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/sharing.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -792,7 +792,7 @@
</span><span class="cx">         Set shared state and check access control.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if child._newStoreObject is not None and not child._newStoreObject.owned():
</span><del>-            ownerHomeURL = self._otherPrincipalHomeURL(child._newStoreObject.ownerHome().uid())
</del><ins>+            ownerHomeURL = (yield self._otherPrincipalHomeURL(child._newStoreObject.ownerHome().uid()))
</ins><span class="cx">             ownerView = yield child._newStoreObject.ownerView()
</span><span class="cx">             child.setShare(joinURL(ownerHomeURL, ownerView.name()))
</span><span class="cx">             access = yield child._checkAccessControl()
</span><span class="lines">@@ -802,6 +802,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def _otherPrincipalHomeURL(self, otherUID):
</span><ins>+        # Is this only meant to be overridden?
</ins><span class="cx">         pass
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavstdconfigpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/stdconfig.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/stdconfig.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/stdconfig.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -374,10 +374,13 @@
</span><span class="cx">     #    users, groups, locations and resources) to the server.
</span><span class="cx">     #
</span><span class="cx">     &quot;DirectoryService&quot;: {
</span><ins>+        &quot;Enabled&quot;: True,
</ins><span class="cx">         &quot;type&quot;: &quot;twistedcaldav.directory.xmlfile.XMLDirectoryService&quot;,
</span><span class="cx">         &quot;params&quot;: DEFAULT_SERVICE_PARAMS[&quot;twistedcaldav.directory.xmlfile.XMLDirectoryService&quot;],
</span><span class="cx">     },
</span><span class="cx"> 
</span><ins>+    &quot;DirectoryRealmName&quot;: &quot;&quot;,
+
</ins><span class="cx">     #
</span><span class="cx">     # Locations and Resources service
</span><span class="cx">     #
</span><span class="lines">@@ -385,7 +388,7 @@
</span><span class="cx">     #    and resources.
</span><span class="cx">     #
</span><span class="cx">     &quot;ResourceService&quot;: {
</span><del>-        &quot;Enabled&quot; : True,
</del><ins>+        &quot;Enabled&quot;: True,
</ins><span class="cx">         &quot;type&quot;: &quot;twistedcaldav.directory.xmlfile.XMLDirectoryService&quot;,
</span><span class="cx">         &quot;params&quot;: DEFAULT_RESOURCE_PARAMS[&quot;twistedcaldav.directory.xmlfile.XMLDirectoryService&quot;],
</span><span class="cx">     },
</span><span class="lines">@@ -1016,8 +1019,6 @@
</span><span class="cx">         &quot;Enabled&quot;: True,
</span><span class="cx">         &quot;MemcachedPool&quot; : &quot;Default&quot;,
</span><span class="cx">         &quot;UpdateSeconds&quot; : 300,
</span><del>-        &quot;ExpireSeconds&quot; : 86400,
-        &quot;LockSeconds&quot;   : 600,
</del><span class="cx">         &quot;EnableUpdater&quot; : True,
</span><span class="cx">         &quot;UseExternalProxies&quot; : False,
</span><span class="cx">     },
</span><span class="lines">@@ -1254,8 +1255,12 @@
</span><span class="cx">             hostname = &quot;localhost&quot;
</span><span class="cx">         configDict.ServerHostName = hostname
</span><span class="cx"> 
</span><ins>+    # Default DirectoryRealmName from ServerHostName
+    if not configDict.DirectoryRealmName:
+        configDict.DirectoryRealmName = configDict.ServerHostName
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> def _updateMultiProcess(configDict, reloading=False):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Dynamically compute ProcessCount if it's set to 0.  Always compute
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavstorebridgepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/storebridge.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/storebridge.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/storebridge.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1763,11 +1763,12 @@
</span><span class="cx">         return succeed(davPrivilegeSet)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def defaultAccessControlList(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Only read privileges allowed for managed attachments.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        myPrincipal = self.parent.principalForRecord()
</del><ins>+        myPrincipal = yield self.parent.principalForRecord()
</ins><span class="cx"> 
</span><span class="cx">         read_privs = (
</span><span class="cx">             davxml.Privilege(davxml.Read()),
</span><span class="lines">@@ -1808,12 +1809,12 @@
</span><span class="cx">                 ),
</span><span class="cx">             )
</span><span class="cx"> 
</span><del>-        return davxml.ACL(*aces)
</del><ins>+        returnValue(davxml.ACL(*aces))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def accessControlList(self, request, inheritance=True, expanding=False, inherited_aces=None):
</span><span class="cx">         # Permissions here are fixed, and are not subject to inheritance rules, etc.
</span><del>-        return succeed(self.defaultAccessControlList())
</del><ins>+        return self.defaultAccessControlList()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -1988,7 +1989,7 @@
</span><span class="cx">                 # Access level comes from what the wiki has granted to the
</span><span class="cx">                 # sharee
</span><span class="cx">                 sharee = self.principalForUID(shareeUID)
</span><del>-                userID = sharee.record.guid
</del><ins>+                userID = sharee.record.uid
</ins><span class="cx">                 wikiID = owner.record.shortNames[0]
</span><span class="cx">                 access = (yield getWikiAccess(userID, wikiID))
</span><span class="cx">                 if access == &quot;read&quot;:
</span><span class="lines">@@ -2865,7 +2866,7 @@
</span><span class="cx">                 principalURL = str(authz_principal)
</span><span class="cx">                 if principalURL:
</span><span class="cx">                     authz = (yield request.locateResource(principalURL))
</span><del>-                    self._parentResource._newStoreObject._txn._authz_uid = authz.record.guid
</del><ins>+                    self._parentResource._newStoreObject._txn._authz_uid = authz.record.uid
</ins><span class="cx"> 
</span><span class="cx">             try:
</span><span class="cx">                 response = (yield self.storeComponent(component, smart_merge=schedule_tag_match))
</span><span class="lines">@@ -3586,7 +3587,7 @@
</span><span class="cx">                 principalURL = str(authz_principal)
</span><span class="cx">                 if principalURL:
</span><span class="cx">                     authz = (yield request.locateResource(principalURL))
</span><del>-                    self._parentResource._newStoreObject._txn._authz_uid = authz.record.guid
</del><ins>+                    self._parentResource._newStoreObject._txn._authz_uid = authz.record.uid
</ins><span class="cx"> 
</span><span class="cx">             try:
</span><span class="cx">                 response = (yield self.storeComponent(component))
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_addressbookmultigetpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_addressbookmultiget.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_addressbookmultiget.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_addressbookmultiget.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -31,7 +31,10 @@
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><span class="cx"> 
</span><span class="cx"> from txdav.xml import element as davxml
</span><ins>+from twext.who.idirectory import RecordType
</ins><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class AddressBookMultiget (StoreTestCase):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     addressbook-multiget REPORT
</span><span class="lines">@@ -39,6 +42,13 @@
</span><span class="cx">     data_dir = os.path.join(os.path.dirname(__file__), &quot;data&quot;)
</span><span class="cx">     vcards_dir = os.path.join(data_dir, &quot;vCards&quot;)
</span><span class="cx"> 
</span><ins>+
+    @inlineCallbacks
+    def setUp(self):
+        yield StoreTestCase.setUp(self)
+        self.authRecord = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
+
+
</ins><span class="cx">     def test_multiget_some_vcards(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         All vcards.
</span><span class="lines">@@ -207,7 +217,7 @@
</span><span class="cx"> &lt;/D:set&gt;
</span><span class="cx"> &lt;/D:mkcol&gt;
</span><span class="cx"> &quot;&quot;&quot;
</span><del>-            response = yield self.send(SimpleStoreRequest(self, &quot;MKCOL&quot;, addressbook_uri, content=mkcol, authid=&quot;wsanchez&quot;))
</del><ins>+            response = yield self.send(SimpleStoreRequest(self, &quot;MKCOL&quot;, addressbook_uri, content=mkcol, authRecord=self.authRecord))
</ins><span class="cx"> 
</span><span class="cx">             response = IResponse(response)
</span><span class="cx"> 
</span><span class="lines">@@ -221,7 +231,7 @@
</span><span class="cx">                         &quot;PUT&quot;,
</span><span class="cx">                         joinURL(addressbook_uri, filename + &quot;.vcf&quot;),
</span><span class="cx">                         headers=Headers({&quot;content-type&quot;: MimeType.fromString(&quot;text/vcard&quot;)}),
</span><del>-                        authid=&quot;wsanchez&quot;
</del><ins>+                        authRecord=self.authRecord
</ins><span class="cx">                     )
</span><span class="cx">                     request.stream = MemoryStream(icaldata)
</span><span class="cx">                     yield self.send(request)
</span><span class="lines">@@ -235,12 +245,12 @@
</span><span class="cx">                         &quot;PUT&quot;,
</span><span class="cx">                         joinURL(addressbook_uri, child.basename()),
</span><span class="cx">                         headers=Headers({&quot;content-type&quot;: MimeType.fromString(&quot;text/vcard&quot;)}),
</span><del>-                        authid=&quot;wsanchez&quot;
</del><ins>+                        authRecord=self.authRecord
</ins><span class="cx">                     )
</span><span class="cx">                     request.stream = MemoryStream(child.getContent())
</span><span class="cx">                     yield self.send(request)
</span><span class="cx"> 
</span><del>-        request = SimpleStoreRequest(self, &quot;REPORT&quot;, addressbook_uri, authid=&quot;wsanchez&quot;)
</del><ins>+        request = SimpleStoreRequest(self, &quot;REPORT&quot;, addressbook_uri, authRecord=self.authRecord)
</ins><span class="cx">         request.stream = MemoryStream(query.toxml())
</span><span class="cx">         response = yield self.send(request)
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_addressbookquerypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_addressbookquery.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_addressbookquery.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_addressbookquery.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -27,7 +27,10 @@
</span><span class="cx"> from twistedcaldav.test.util import StoreTestCase, SimpleStoreRequest
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><span class="cx"> from twisted.python.filepath import FilePath
</span><ins>+from twext.who.idirectory import RecordType
</ins><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class AddressBookQuery(StoreTestCase):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     addressbook-query REPORT
</span><span class="lines">@@ -67,6 +70,7 @@
</span><span class="cx"> 
</span><span class="cx">         oldValue = config.MaxQueryWithDataResults
</span><span class="cx">         config.MaxQueryWithDataResults = 1
</span><ins>+
</ins><span class="cx">         def _restoreValueOK(f):
</span><span class="cx">             config.MaxQueryWithDataResults = oldValue
</span><span class="cx">             return None
</span><span class="lines">@@ -89,6 +93,7 @@
</span><span class="cx"> 
</span><span class="cx">         oldValue = config.MaxQueryWithDataResults
</span><span class="cx">         config.MaxQueryWithDataResults = 1
</span><ins>+
</ins><span class="cx">         def _restoreValueOK(f):
</span><span class="cx">             config.MaxQueryWithDataResults = oldValue
</span><span class="cx">             return None
</span><span class="lines">@@ -191,15 +196,16 @@
</span><span class="cx">         if response.code != responsecode.CREATED:
</span><span class="cx">             self.fail(&quot;MKCOL failed: %s&quot; % (response.code,))
</span><span class="cx">         '''
</span><ins>+        authRecord = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
</ins><span class="cx">         # Add vCards to addressbook
</span><span class="cx">         for child in FilePath(self.vcards_dir).children():
</span><span class="cx">             if os.path.splitext(child.basename())[1] != &quot;.vcf&quot;:
</span><span class="cx">                 continue
</span><del>-            request = SimpleStoreRequest(self, &quot;PUT&quot;, joinURL(addressbook_uri, child.basename()), authid=&quot;wsanchez&quot;)
</del><ins>+            request = SimpleStoreRequest(self, &quot;PUT&quot;, joinURL(addressbook_uri, child.basename()), authRecord=authRecord)
</ins><span class="cx">             request.stream = MemoryStream(child.getContent())
</span><span class="cx">             yield self.send(request)
</span><span class="cx"> 
</span><del>-        request = SimpleStoreRequest(self, &quot;REPORT&quot;, addressbook_uri, authid=&quot;wsanchez&quot;)
</del><ins>+        request = SimpleStoreRequest(self, &quot;REPORT&quot;, addressbook_uri, authRecord=authRecord)
</ins><span class="cx">         request.stream = MemoryStream(query.toxml())
</span><span class="cx">         response = yield self.send(request)
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_calendarquerypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_calendarquery.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_calendarquery.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_calendarquery.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -34,8 +34,8 @@
</span><span class="cx"> from pycalendar.datetime import DateTime
</span><span class="cx"> from twistedcaldav.ical import Component
</span><span class="cx"> from txdav.caldav.icalendarstore import ComponentUpdateState
</span><del>-from twistedcaldav.directory.directory import DirectoryService
</del><span class="cx"> from txdav.caldav.datastore.query.filter import TimeRange
</span><ins>+from twext.who.idirectory import RecordType
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> @inlineCallbacks
</span><span class="lines">@@ -79,7 +79,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Put the contents of the Holidays directory into the store.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        record = self.directory.recordWithShortName(DirectoryService.recordType_users, &quot;wsanchez&quot;)
</del><ins>+        record = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
</ins><span class="cx">         yield self.transactionUnderTest().calendarHomeWithUID(record.uid, create=True)
</span><span class="cx">         calendar = yield self.calendarUnderTest(name=&quot;calendar&quot;, home=record.uid)
</span><span class="cx">         for f in os.listdir(self.holidays_dir):
</span><span class="lines">@@ -248,6 +248,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         self.patch(config, &quot;MaxQueryWithDataResults&quot;, 1)
</span><ins>+
</ins><span class="cx">         def _restoreValueOK(f):
</span><span class="cx">             self.fail(&quot;REPORT must fail with 403&quot;)
</span><span class="cx"> 
</span><span class="lines">@@ -268,6 +269,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         self.patch(config, &quot;MaxQueryWithDataResults&quot;, 1)
</span><ins>+
</ins><span class="cx">         def _restoreValueError(f):
</span><span class="cx">             self.fail(&quot;REPORT must not fail with 403&quot;)
</span><span class="cx"> 
</span><span class="lines">@@ -343,7 +345,8 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def calendar_query(self, query, got_xml):
</span><span class="cx"> 
</span><del>-        request = SimpleStoreRequest(self, &quot;REPORT&quot;, &quot;/calendars/users/wsanchez/calendar/&quot;, authid=&quot;wsanchez&quot;)
</del><ins>+        authRecord = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
+        request = SimpleStoreRequest(self, &quot;REPORT&quot;, &quot;/calendars/users/wsanchez/calendar/&quot;, authRecord=authRecord)
</ins><span class="cx">         request.stream = MemoryStream(query.toxml())
</span><span class="cx">         response = yield self.send(request)
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_collectioncontentspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_collectioncontents.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_collectioncontents.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_collectioncontents.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -14,22 +14,22 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><span class="cx"> 
</span><del>-from twisted.internet.defer import inlineCallbacks
</del><span class="cx"> from twext.python.filepath import CachingFilePath as FilePath
</span><del>-from txweb2 import responsecode
-from txweb2.iweb import IResponse
-from txweb2.stream import MemoryStream, FileStream
-from txweb2.http_headers import MimeType
-
</del><ins>+from twext.who.idirectory import RecordType
+from twisted.internet.defer import inlineCallbacks
</ins><span class="cx"> from twistedcaldav.ical import Component
</span><span class="cx"> from twistedcaldav.memcachelock import MemcacheLock
</span><span class="cx"> from twistedcaldav.memcacher import Memcacher
</span><del>-
-
</del><span class="cx"> from twistedcaldav.test.util import StoreTestCase, SimpleStoreRequest
</span><del>-from txweb2.dav.util import joinURL
</del><span class="cx"> from txdav.caldav.datastore.sql import CalendarObject
</span><ins>+from txweb2 import responsecode
+from txweb2.dav.util import joinURL
+from txweb2.http_headers import MimeType
+from txweb2.iweb import IResponse
+from txweb2.stream import MemoryStream, FileStream
</ins><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class CollectionContents(StoreTestCase):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     PUT request
</span><span class="lines">@@ -52,7 +52,7 @@
</span><span class="cx">         def _fakeDoImplicitScheduling(self, component, inserting, internal_state):
</span><span class="cx">             return False, None, False, None
</span><span class="cx"> 
</span><del>-        self.patch(CalendarObject , &quot;doImplicitScheduling&quot;,
</del><ins>+        self.patch(CalendarObject, &quot;doImplicitScheduling&quot;,
</ins><span class="cx">                    _fakeDoImplicitScheduling)
</span><span class="cx"> 
</span><span class="cx">         # Tests in this suite assume that the root resource is a calendar home.
</span><span class="lines">@@ -61,31 +61,27 @@
</span><span class="cx">         return super(CollectionContents, self).setUp()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def test_collection_in_calendar(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Make (regular) collection in calendar
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         calendar_uri = &quot;/calendars/users/wsanchez/collection_in_calendar/&quot;
</span><span class="cx"> 
</span><del>-        def mkcalendar_cb(response):
-            response = IResponse(response)
-
-            if response.code != responsecode.CREATED:
-                self.fail(&quot;MKCALENDAR failed: %s&quot; % (response.code,))
-
-            def mkcol_cb(response):
-                response = IResponse(response)
-
-                if response.code != responsecode.FORBIDDEN:
-                    self.fail(&quot;Incorrect response to nested MKCOL: %s&quot; % (response.code,))
-
</del><ins>+        authRecord = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
+        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, calendar_uri, authRecord=authRecord)
+        response = yield self.send(request)
+        response = IResponse(response)
+        if response.code != responsecode.CREATED:
+            self.fail(&quot;MKCALENDAR failed: %s&quot; % (response.code,))
</ins><span class="cx">             nested_uri = joinURL(calendar_uri, &quot;nested&quot;)
</span><span class="cx"> 
</span><del>-            request = SimpleStoreRequest(self, &quot;MKCOL&quot;, nested_uri, authid=&quot;wsanchez&quot;)
-            return self.send(request, mkcol_cb)
</del><ins>+            request = SimpleStoreRequest(self, &quot;MKCOL&quot;, nested_uri, authRecord=authRecord)
+            response = yield self.send(request)
+            response = IResponse(response)
</ins><span class="cx"> 
</span><del>-        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, calendar_uri, authid=&quot;wsanchez&quot;)
-        return self.send(request, mkcalendar_cb)
</del><ins>+            if response.code != responsecode.FORBIDDEN:
+                self.fail(&quot;Incorrect response to nested MKCOL: %s&quot; % (response.code,))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def test_bogus_file(self):
</span><span class="lines">@@ -163,6 +159,7 @@
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def _test_file_in_calendar(self, what, *work):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Creates a calendar collection, then PUTs a resource into that collection
</span><span class="lines">@@ -171,68 +168,58 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         calendar_uri = &quot;/calendars/users/wsanchez/testing_calendar/&quot;
</span><span class="cx"> 
</span><ins>+        authRecord = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
+        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, calendar_uri, authRecord=authRecord)
+        response = yield self.send(request)
+        response = IResponse(response)
+        if response.code != responsecode.CREATED:
+            self.fail(&quot;MKCALENDAR failed: %s&quot; % (response.code,))
</ins><span class="cx"> 
</span><del>-        @inlineCallbacks
-        def mkcalendar_cb(response):
</del><ins>+        c = 0
+        for stream, response_code in work:
+            dst_uri = joinURL(calendar_uri, &quot;dst%d.ics&quot; % (c,))
+            request = SimpleStoreRequest(self, &quot;PUT&quot;, dst_uri, authRecord=authRecord)
+            request.headers.setHeader(&quot;if-none-match&quot;, &quot;*&quot;)
+            request.headers.setHeader(&quot;content-type&quot;, MimeType(&quot;text&quot;, &quot;calendar&quot;))
+            request.stream = stream
+            response = yield self.send(request)
</ins><span class="cx">             response = IResponse(response)
</span><span class="cx"> 
</span><del>-            if response.code != responsecode.CREATED:
-                self.fail(&quot;MKCALENDAR failed: %s&quot; % (response.code,))
</del><ins>+            if response.code != response_code:
+                self.fail(&quot;Incorrect response to %s: %s (!= %s)&quot; % (what, response.code, response_code))
</ins><span class="cx"> 
</span><del>-            c = 0
</del><ins>+            c += 1
</ins><span class="cx"> 
</span><del>-            for stream, response_code in work:
</del><span class="cx"> 
</span><del>-                dst_uri = joinURL(calendar_uri, &quot;dst%d.ics&quot; % (c,))
-                request = SimpleStoreRequest(self, &quot;PUT&quot;, dst_uri, authid=&quot;wsanchez&quot;)
-                request.headers.setHeader(&quot;if-none-match&quot;, &quot;*&quot;)
-                request.headers.setHeader(&quot;content-type&quot;, MimeType(&quot;text&quot;, &quot;calendar&quot;))
-                request.stream = stream
-                response = yield self.send(request)
-                response = IResponse(response)
</del><span class="cx"> 
</span><del>-                if response.code != response_code:
-                    self.fail(&quot;Incorrect response to %s: %s (!= %s)&quot; % (what, response.code, response_code))
-
-                c += 1
-
-        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, calendar_uri, authid=&quot;wsanchez&quot;)
-        return self.send(request, mkcalendar_cb)
-
-
</del><ins>+    @inlineCallbacks
</ins><span class="cx">     def test_fail_dot_file_put_in_calendar(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Make (regular) collection in calendar
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         calendar_uri = &quot;/calendars/users/wsanchez/dot_file_in_calendar/&quot;
</span><ins>+        authRecord = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
+        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, calendar_uri, authRecord=authRecord)
+        response = yield self.send(request)
+        response = IResponse(response)
+        if response.code != responsecode.CREATED:
+            self.fail(&quot;MKCALENDAR failed: %s&quot; % (response.code,))
</ins><span class="cx"> 
</span><del>-        def mkcalendar_cb(response):
-            response = IResponse(response)
</del><ins>+        stream = self.dataPath.child(
+            &quot;Holidays&quot;).child(
+            &quot;C318AA54-1ED0-11D9-A5E0-000A958A3252.ics&quot;
+        ).open()
+        try:
+            calendar = str(Component.fromStream(stream))
+        finally:
+            stream.close()
</ins><span class="cx"> 
</span><del>-            if response.code != responsecode.CREATED:
-                self.fail(&quot;MKCALENDAR failed: %s&quot; % (response.code,))
</del><ins>+        event_uri = &quot;/&quot;.join([calendar_uri, &quot;.event.ics&quot;])
</ins><span class="cx"> 
</span><del>-            def put_cb(response):
-                response = IResponse(response)
-
-                if response.code != responsecode.FORBIDDEN:
-                    self.fail(&quot;Incorrect response to dot file PUT: %s&quot; % (response.code,))
-
-            stream = self.dataPath.child(
-                &quot;Holidays&quot;).child(
-                &quot;C318AA54-1ED0-11D9-A5E0-000A958A3252.ics&quot;
-            ).open()
-            try:
-                calendar = str(Component.fromStream(stream))
-            finally:
-                stream.close()
-
-            event_uri = &quot;/&quot;.join([calendar_uri, &quot;.event.ics&quot;])
-
-            request = SimpleStoreRequest(self, &quot;PUT&quot;, event_uri, authid=&quot;wsanchez&quot;)
-            request.headers.setHeader(&quot;content-type&quot;, MimeType(&quot;text&quot;, &quot;calendar&quot;))
-            request.stream = MemoryStream(calendar)
-            return self.send(request, put_cb)
-
-        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, calendar_uri, authid=&quot;wsanchez&quot;)
-        return self.send(request, mkcalendar_cb)
</del><ins>+        request = SimpleStoreRequest(self, &quot;PUT&quot;, event_uri, authRecord=authRecord)
+        request.headers.setHeader(&quot;content-type&quot;, MimeType(&quot;text&quot;, &quot;calendar&quot;))
+        request.stream = MemoryStream(calendar)
+        response = yield self.send(request)
+        response = IResponse(response)
+        if response.code != responsecode.FORBIDDEN:
+            self.fail(&quot;Incorrect response to dot file PUT: %s&quot; % (response.code,))
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_icalendarpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_icalendar.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_icalendar.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_icalendar.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -19,6 +19,7 @@
</span><span class="cx"> import itertools
</span><span class="cx"> 
</span><span class="cx"> from twisted.trial.unittest import SkipTest
</span><ins>+from twisted.internet.defer import inlineCallbacks, succeed
</ins><span class="cx"> 
</span><span class="cx"> from twistedcaldav.ical import Component, Property, InvalidICalendarDataError, \
</span><span class="cx">     normalizeCUAddress, normalize_iCalStr
</span><span class="lines">@@ -32,6 +33,8 @@
</span><span class="cx"> from twistedcaldav.dateops import normalizeForExpand
</span><span class="cx"> from pycalendar.value import Value
</span><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class iCalendar (twistedcaldav.test.util.TestCase):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     iCalendar support tests
</span><span class="lines">@@ -7497,6 +7500,7 @@
</span><span class="cx">             self.assertEquals(expected, ical.hasInstancesAfter(cutoff))
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def test_normalizeCalendarUserAddressesFromUUID(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Ensure mailto is preferred, followed by path form, then http form.
</span><span class="lines">@@ -7520,25 +7524,27 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         def lookupFunction(cuaddr, ignored1, ignored2):
</span><del>-            return {
-                &quot;urn:uuid:foo&quot; : (
-                    &quot;Foo&quot;,
-                    &quot;foo&quot;,
-                    (&quot;urn:uuid:foo&quot;, &quot;http://example.com/foo&quot;, &quot;/foo&quot;)
-                ),
-                &quot;urn:uuid:bar&quot; : (
-                    &quot;Bar&quot;,
-                    &quot;bar&quot;,
-                    (&quot;urn:uuid:bar&quot;, &quot;mailto:bar@example.com&quot;, &quot;http://example.com/bar&quot;, &quot;/bar&quot;)
-                ),
-                &quot;urn:uuid:baz&quot; : (
-                    &quot;Baz&quot;,
-                    &quot;baz&quot;,
-                    (&quot;urn:uuid:baz&quot;, &quot;http://example.com/baz&quot;)
-                ),
-            }[cuaddr]
</del><ins>+            return succeed(
+                {
+                    &quot;urn:uuid:foo&quot; : (
+                        &quot;Foo&quot;,
+                        &quot;foo&quot;,
+                        (&quot;urn:uuid:foo&quot;, &quot;http://example.com/foo&quot;, &quot;/foo&quot;)
+                    ),
+                    &quot;urn:uuid:bar&quot; : (
+                        &quot;Bar&quot;,
+                        &quot;bar&quot;,
+                        (&quot;urn:uuid:bar&quot;, &quot;mailto:bar@example.com&quot;, &quot;http://example.com/bar&quot;, &quot;/bar&quot;)
+                    ),
+                    &quot;urn:uuid:baz&quot; : (
+                        &quot;Baz&quot;,
+                        &quot;baz&quot;,
+                        (&quot;urn:uuid:baz&quot;, &quot;http://example.com/baz&quot;)
+                    ),
+                }[cuaddr]
+            )
</ins><span class="cx"> 
</span><del>-        component.normalizeCalendarUserAddresses(lookupFunction, None, toUUID=False)
</del><ins>+        yield component.normalizeCalendarUserAddresses(lookupFunction, None, toUUID=False)
</ins><span class="cx"> 
</span><span class="cx">         self.assertEquals(&quot;mailto:bar@example.com&quot;,
</span><span class="cx">             component.getAttendeeProperty((&quot;mailto:bar@example.com&quot;,)).value())
</span><span class="lines">@@ -7548,6 +7554,7 @@
</span><span class="cx">             component.getAttendeeProperty((&quot;http://example.com/baz&quot;,)).value())
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def test_normalizeCalendarUserAddressesAndLocationChange(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Ensure http(s) and /path CUA values are tucked away into the property
</span><span class="lines">@@ -7573,25 +7580,27 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         def lookupFunction(cuaddr, ignored1, ignored2):
</span><del>-            return {
-                &quot;/principals/users/foo&quot; : (
-                    &quot;Foo&quot;,
-                    &quot;foo&quot;,
-                    (&quot;urn:uuid:foo&quot;,)
-                ),
-                &quot;http://example.com/principals/users/bar&quot; : (
-                    &quot;Bar&quot;,
-                    &quot;bar&quot;,
-                    (&quot;urn:uuid:bar&quot;,)
-                ),
-                &quot;http://example.com/principals/locations/buzz&quot; : (
-                    &quot;{Restricted} Buzz&quot;,
-                    &quot;buzz&quot;,
-                    (&quot;urn:uuid:buzz&quot;,)
-                ),
-            }[cuaddr]
</del><ins>+            return succeed(
+                {
+                    &quot;/principals/users/foo&quot; : (
+                        &quot;Foo&quot;,
+                        &quot;foo&quot;,
+                        (&quot;urn:uuid:foo&quot;,)
+                    ),
+                    &quot;http://example.com/principals/users/bar&quot; : (
+                        &quot;Bar&quot;,
+                        &quot;bar&quot;,
+                        (&quot;urn:uuid:bar&quot;,)
+                    ),
+                    &quot;http://example.com/principals/locations/buzz&quot; : (
+                        &quot;{Restricted} Buzz&quot;,
+                        &quot;buzz&quot;,
+                        (&quot;urn:uuid:buzz&quot;,)
+                    ),
+                }[cuaddr]
+            )
</ins><span class="cx"> 
</span><del>-        component.normalizeCalendarUserAddresses(lookupFunction, None, toUUID=True)
</del><ins>+        yield component.normalizeCalendarUserAddresses(lookupFunction, None, toUUID=True)
</ins><span class="cx"> 
</span><span class="cx">         # Location value changed
</span><span class="cx">         prop = component.mainComponent().getProperty(&quot;LOCATION&quot;)
</span><span class="lines">@@ -7601,6 +7610,7 @@
</span><span class="cx">         self.assertEquals(prop.parameterValue(&quot;CN&quot;), &quot;{Restricted} Buzz&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def test_normalizeCalendarUserAddressesAndLocationNoChange(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Ensure http(s) and /path CUA values are tucked away into the property
</span><span class="lines">@@ -7626,25 +7636,27 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         def lookupFunction(cuaddr, ignored1, ignored2):
</span><del>-            return {
-                &quot;/principals/users/foo&quot; : (
-                    &quot;Foo&quot;,
-                    &quot;foo&quot;,
-                    (&quot;urn:uuid:foo&quot;,)
-                ),
-                &quot;http://example.com/principals/users/bar&quot; : (
-                    &quot;Bar&quot;,
-                    &quot;bar&quot;,
-                    (&quot;urn:uuid:bar&quot;,)
-                ),
-                &quot;http://example.com/principals/locations/buzz&quot; : (
-                    &quot;{Restricted} Buzz&quot;,
-                    &quot;buzz&quot;,
-                    (&quot;urn:uuid:buzz&quot;,)
-                ),
-            }[cuaddr]
</del><ins>+            return succeed(
+                {
+                    &quot;/principals/users/foo&quot; : (
+                        &quot;Foo&quot;,
+                        &quot;foo&quot;,
+                        (&quot;urn:uuid:foo&quot;,)
+                    ),
+                    &quot;http://example.com/principals/users/bar&quot; : (
+                        &quot;Bar&quot;,
+                        &quot;bar&quot;,
+                        (&quot;urn:uuid:bar&quot;,)
+                    ),
+                    &quot;http://example.com/principals/locations/buzz&quot; : (
+                        &quot;{Restricted} Buzz&quot;,
+                        &quot;buzz&quot;,
+                        (&quot;urn:uuid:buzz&quot;,)
+                    ),
+                }[cuaddr]
+            )
</ins><span class="cx"> 
</span><del>-        component.normalizeCalendarUserAddresses(lookupFunction, None, toUUID=True)
</del><ins>+        yield component.normalizeCalendarUserAddresses(lookupFunction, None, toUUID=True)
</ins><span class="cx"> 
</span><span class="cx">         # Location value changed
</span><span class="cx">         prop = component.mainComponent().getProperty(&quot;LOCATION&quot;)
</span><span class="lines">@@ -7654,6 +7666,7 @@
</span><span class="cx">         self.assertEquals(prop.parameterValue(&quot;CN&quot;), &quot;{Restricted} Buzz&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def test_normalizeCalendarUserAddressesAndLocationNoChangeOtherCUType(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Ensure http(s) and /path CUA values are tucked away into the property
</span><span class="lines">@@ -7679,25 +7692,27 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         def lookupFunction(cuaddr, ignored1, ignored2):
</span><del>-            return {
-                &quot;/principals/users/foo&quot; : (
-                    &quot;Foo&quot;,
-                    &quot;foo&quot;,
-                    (&quot;urn:uuid:foo&quot;,)
-                ),
-                &quot;http://example.com/principals/users/bar&quot; : (
-                    &quot;Bar&quot;,
-                    &quot;bar&quot;,
-                    (&quot;urn:uuid:bar&quot;,)
-                ),
-                &quot;http://example.com/principals/locations/buzz&quot; : (
-                    &quot;{Restricted} Buzz&quot;,
-                    &quot;buzz&quot;,
-                    (&quot;urn:uuid:buzz&quot;,)
-                ),
-            }[cuaddr]
</del><ins>+            return succeed(
+                {
+                    &quot;/principals/users/foo&quot; : (
+                        &quot;Foo&quot;,
+                        &quot;foo&quot;,
+                        (&quot;urn:uuid:foo&quot;,)
+                    ),
+                    &quot;http://example.com/principals/users/bar&quot; : (
+                        &quot;Bar&quot;,
+                        &quot;bar&quot;,
+                        (&quot;urn:uuid:bar&quot;,)
+                    ),
+                    &quot;http://example.com/principals/locations/buzz&quot; : (
+                        &quot;{Restricted} Buzz&quot;,
+                        &quot;buzz&quot;,
+                        (&quot;urn:uuid:buzz&quot;,)
+                    ),
+                }[cuaddr]
+            )
</ins><span class="cx"> 
</span><del>-        component.normalizeCalendarUserAddresses(lookupFunction, None, toUUID=True)
</del><ins>+        yield component.normalizeCalendarUserAddresses(lookupFunction, None, toUUID=True)
</ins><span class="cx"> 
</span><span class="cx">         # Location value changed
</span><span class="cx">         prop = component.mainComponent().getProperty(&quot;LOCATION&quot;)
</span><span class="lines">@@ -8404,6 +8419,7 @@
</span><span class="cx">             self.assertEqual(changed, result_changed)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def test_normalizeCUAddressFromUUID(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Ensure mailto is preferred, followed by path form, then http form.
</span><span class="lines">@@ -8418,34 +8434,37 @@
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx">         def lookupFunction(cuaddr, ignored1, ignored2):
</span><del>-            return {
-                &quot;urn:uuid:foo&quot; : (
-                    &quot;Foo&quot;,
-                    &quot;foo&quot;,
-                    (&quot;urn:uuid:foo&quot;, &quot;http://example.com/foo&quot;, &quot;/foo&quot;)
-                ),
-                &quot;urn:uuid:bar&quot; : (
-                    &quot;Bar&quot;,
-                    &quot;bar&quot;,
-                    (&quot;urn:uuid:bar&quot;, &quot;mailto:bar@example.com&quot;, &quot;http://example.com/bar&quot;, &quot;/bar&quot;)
-                ),
-                &quot;urn:uuid:baz&quot; : (
-                    &quot;Baz&quot;,
-                    &quot;baz&quot;,
-                    (&quot;urn:uuid:baz&quot;, &quot;http://example.com/baz&quot;)
-                ),
-                &quot;urn:uuid:buz&quot; : (
-                    &quot;Buz&quot;,
-                    &quot;buz&quot;,
-                    (&quot;urn:uuid:buz&quot;,)
-                ),
-            }[cuaddr]
</del><ins>+            return succeed(
+                {
+                    &quot;urn:uuid:foo&quot; : (
+                        &quot;Foo&quot;,
+                        &quot;foo&quot;,
+                        (&quot;urn:uuid:foo&quot;, &quot;http://example.com/foo&quot;, &quot;/foo&quot;)
+                    ),
+                    &quot;urn:uuid:bar&quot; : (
+                        &quot;Bar&quot;,
+                        &quot;bar&quot;,
+                        (&quot;urn:uuid:bar&quot;, &quot;mailto:bar@example.com&quot;, &quot;http://example.com/bar&quot;, &quot;/bar&quot;)
+                    ),
+                    &quot;urn:uuid:baz&quot; : (
+                        &quot;Baz&quot;,
+                        &quot;baz&quot;,
+                        (&quot;urn:uuid:baz&quot;, &quot;http://example.com/baz&quot;)
+                    ),
+                    &quot;urn:uuid:buz&quot; : (
+                        &quot;Buz&quot;,
+                        &quot;buz&quot;,
+                        (&quot;urn:uuid:buz&quot;,)
+                    ),
+                }[cuaddr]
+            )
</ins><span class="cx"> 
</span><span class="cx">         for cuaddr, result in data:
</span><del>-            new_cuaddr = normalizeCUAddress(cuaddr, lookupFunction, None, toUUID=False)
</del><ins>+            new_cuaddr = yield normalizeCUAddress(cuaddr, lookupFunction, None, toUUID=False)
</ins><span class="cx">             self.assertEquals(new_cuaddr, result)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def test_normalizeCUAddressToUUID(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Ensure http(s) and /path CUA values are tucked away into the property
</span><span class="lines">@@ -8459,21 +8478,23 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         def lookupFunction(cuaddr, ignored1, ignored2):
</span><del>-            return {
-                &quot;/principals/users/foo&quot; : (
-                    &quot;Foo&quot;,
-                    &quot;foo&quot;,
-                    (&quot;urn:uuid:foo&quot;,)
-                ),
-                &quot;http://example.com/principals/users/buz&quot; : (
-                    &quot;Buz&quot;,
-                    &quot;buz&quot;,
-                    (&quot;urn:uuid:buz&quot;,)
-                ),
-            }[cuaddr]
</del><ins>+            return succeed(
+                {
+                    &quot;/principals/users/foo&quot; : (
+                        &quot;Foo&quot;,
+                        &quot;foo&quot;,
+                        (&quot;urn:uuid:foo&quot;,)
+                    ),
+                    &quot;http://example.com/principals/users/buz&quot; : (
+                        &quot;Buz&quot;,
+                        &quot;buz&quot;,
+                        (&quot;urn:uuid:buz&quot;,)
+                    ),
+                }[cuaddr]
+            )
</ins><span class="cx"> 
</span><span class="cx">         for cuaddr, result in data:
</span><del>-            new_cuaddr = normalizeCUAddress(cuaddr, lookupFunction, None, toUUID=True)
</del><ins>+            new_cuaddr = yield normalizeCUAddress(cuaddr, lookupFunction, None, toUUID=True)
</ins><span class="cx">             self.assertEquals(new_cuaddr, result)
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_mkcalendarpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_mkcalendar.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_mkcalendar.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_mkcalendar.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -27,6 +27,10 @@
</span><span class="cx"> from twistedcaldav import caldavxml
</span><span class="cx"> from twistedcaldav.test.util import StoreTestCase, SimpleStoreRequest
</span><span class="cx"> 
</span><ins>+from twext.who.idirectory import RecordType
+
+
+
</ins><span class="cx"> class MKCALENDAR (StoreTestCase):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     MKCALENDAR request
</span><span class="lines">@@ -35,6 +39,12 @@
</span><span class="cx">     # Try nesting calendars (should fail)
</span><span class="cx">     # HEAD request on calendar: resourcetype = (collection, calendar)
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
+    def setUp(self):
+        yield StoreTestCase.setUp(self)
+        self.authRecord = yield self.directory.recordWithShortName(RecordType.user, u&quot;user01&quot;)
+
+
</ins><span class="cx">     def test_make_calendar(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Make calendar
</span><span class="lines">@@ -45,7 +55,7 @@
</span><span class="cx">         if os.path.exists(path):
</span><span class="cx">             rmdir(path)
</span><span class="cx"> 
</span><del>-        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, uri, authid=&quot;user01&quot;)
</del><ins>+        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, uri, authRecord=self.authRecord)
</ins><span class="cx"> 
</span><span class="cx">         @inlineCallbacks
</span><span class="cx">         def do_test(response):
</span><span class="lines">@@ -146,7 +156,7 @@
</span><span class="cx">             )
</span><span class="cx">         )
</span><span class="cx"> 
</span><del>-        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, uri, authid=&quot;user01&quot;)
</del><ins>+        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, uri, authRecord=self.authRecord)
</ins><span class="cx">         request.stream = MemoryStream(mk.toxml())
</span><span class="cx">         return self.send(request, do_test)
</span><span class="cx"> 
</span><span class="lines">@@ -165,7 +175,7 @@
</span><span class="cx"> 
</span><span class="cx">             # FIXME: Check for DAV:resource-must-be-null element
</span><span class="cx"> 
</span><del>-        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, uri, authid=&quot;user01&quot;)
</del><ins>+        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, uri, authRecord=self.authRecord)
</ins><span class="cx">         return self.send(request, do_test)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -190,8 +200,8 @@
</span><span class="cx"> 
</span><span class="cx">             nested_uri = os.path.join(first_uri, &quot;nested&quot;)
</span><span class="cx"> 
</span><del>-            request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, nested_uri, authid=&quot;user01&quot;)
</del><ins>+            request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, nested_uri, authRecord=self.authRecord)
</ins><span class="cx">             yield self.send(request, do_test)
</span><span class="cx"> 
</span><del>-        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, first_uri, authid=&quot;user01&quot;)
</del><ins>+        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, first_uri, authRecord=self.authRecord)
</ins><span class="cx">         return self.send(request, next)
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_multigetpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_multiget.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_multiget.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_multiget.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -14,6 +14,7 @@
</span><span class="cx"> ##
</span><span class="cx"> 
</span><span class="cx"> from twext.python.filepath import CachingFilePath as FilePath
</span><ins>+from twext.who.idirectory import RecordType
</ins><span class="cx"> from txweb2 import responsecode
</span><span class="cx"> from txweb2.dav.util import davXMLFromStream, joinURL
</span><span class="cx"> from txweb2.http_headers import Headers, MimeType
</span><span class="lines">@@ -38,6 +39,12 @@
</span><span class="cx">     data_dir = os.path.join(os.path.dirname(__file__), &quot;data&quot;)
</span><span class="cx">     holidays_dir = os.path.join(data_dir, &quot;Holidays&quot;)
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
+    def setUp(self):
+        yield StoreTestCase.setUp(self)
+        self.authRecord = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
+
+
</ins><span class="cx">     def test_multiget_some_events(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         All events.
</span><span class="lines">@@ -262,7 +269,7 @@
</span><span class="cx">     def calendar_query(self, calendar_uri, query, got_xml, data, no_init):
</span><span class="cx"> 
</span><span class="cx">         if not no_init:
</span><del>-            response = yield self.send(SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, calendar_uri, authid=&quot;wsanchez&quot;))
</del><ins>+            response = yield self.send(SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, calendar_uri, authRecord=self.authRecord))
</ins><span class="cx">             response = IResponse(response)
</span><span class="cx">             if response.code != responsecode.CREATED:
</span><span class="cx">                 self.fail(&quot;MKCALENDAR failed: %s&quot; % (response.code,))
</span><span class="lines">@@ -274,7 +281,7 @@
</span><span class="cx">                         &quot;PUT&quot;,
</span><span class="cx">                         joinURL(calendar_uri, filename + &quot;.ics&quot;),
</span><span class="cx">                         headers=Headers({&quot;content-type&quot;: MimeType.fromString(&quot;text/calendar&quot;)}),
</span><del>-                        authid=&quot;wsanchez&quot;
</del><ins>+                        authRecord=self.authRecord
</ins><span class="cx">                     )
</span><span class="cx">                     request.stream = MemoryStream(icaldata)
</span><span class="cx">                     yield self.send(request)
</span><span class="lines">@@ -288,12 +295,12 @@
</span><span class="cx">                         &quot;PUT&quot;,
</span><span class="cx">                         joinURL(calendar_uri, child.basename()),
</span><span class="cx">                         headers=Headers({&quot;content-type&quot;: MimeType.fromString(&quot;text/calendar&quot;)}),
</span><del>-                        authid=&quot;wsanchez&quot;
</del><ins>+                        authRecord=self.authRecord
</ins><span class="cx">                     )
</span><span class="cx">                     request.stream = MemoryStream(child.getContent())
</span><span class="cx">                     yield self.send(request)
</span><span class="cx"> 
</span><del>-        request = SimpleStoreRequest(self, &quot;REPORT&quot;, calendar_uri, authid=&quot;wsanchez&quot;)
</del><ins>+        request = SimpleStoreRequest(self, &quot;REPORT&quot;, calendar_uri, authRecord=self.authRecord)
</ins><span class="cx">         request.stream = MemoryStream(query.toxml())
</span><span class="cx">         response = yield self.send(request)
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_propspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_props.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_props.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_props.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -19,21 +19,35 @@
</span><span class="cx"> from txweb2.iweb import IResponse
</span><span class="cx"> from txweb2.stream import MemoryStream
</span><span class="cx"> 
</span><ins>+from twisted.internet.defer import inlineCallbacks
+
</ins><span class="cx"> from twistedcaldav import caldavxml
</span><span class="cx"> from twistedcaldav.test.util import StoreTestCase, SimpleStoreRequest
</span><span class="cx"> 
</span><span class="cx"> from txdav.xml import element as davxml
</span><span class="cx"> 
</span><ins>+from twext.who.idirectory import RecordType
+
+
+
</ins><span class="cx"> class Properties(StoreTestCase):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     CalDAV properties
</span><span class="cx">     &quot;&quot;&quot;
</span><ins>+
+    @inlineCallbacks
+    def setUp(self):
+        yield StoreTestCase.setUp(self)
+        self.authRecord = yield self.directory.recordWithShortName(RecordType.user, u&quot;user01&quot;)
+
+
</ins><span class="cx">     def test_live_props(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Live CalDAV properties
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         calendar_uri = &quot;/calendars/users/user01/test/&quot;
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx">         def mkcalendar_cb(response):
</span><span class="cx">             response = IResponse(response)
</span><span class="cx"> 
</span><span class="lines">@@ -123,24 +137,24 @@
</span><span class="cx">                 return davXMLFromStream(response.stream).addCallback(got_xml)
</span><span class="cx"> 
</span><span class="cx">             query = davxml.PropertyFind(
</span><del>-                        davxml.PropertyContainer(
-                            caldavxml.SupportedCalendarData(),
-                            caldavxml.SupportedCalendarComponentSet(),
-                            davxml.SupportedReportSet(),
-                        ),
-                    )
</del><ins>+                davxml.PropertyContainer(
+                    caldavxml.SupportedCalendarData(),
+                    caldavxml.SupportedCalendarComponentSet(),
+                    davxml.SupportedReportSet(),
+                ),
+            )
</ins><span class="cx"> 
</span><span class="cx">             request = SimpleStoreRequest(
</span><span class="cx">                 self,
</span><span class="cx">                 &quot;PROPFIND&quot;,
</span><span class="cx">                 calendar_uri,
</span><span class="cx">                 headers=http_headers.Headers({&quot;Depth&quot;: &quot;0&quot;}),
</span><del>-                authid=&quot;user01&quot;,
</del><ins>+                authRecord=self.authRecord,
</ins><span class="cx">             )
</span><span class="cx">             request.stream = MemoryStream(query.toxml())
</span><span class="cx">             return self.send(request, propfind_cb)
</span><span class="cx"> 
</span><del>-        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, calendar_uri, authid=&quot;user01&quot;)
</del><ins>+        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, calendar_uri, authRecord=self.authRecord)
</ins><span class="cx">         return self.send(request, mkcalendar_cb)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -207,10 +221,10 @@
</span><span class="cx">                 &quot;PROPFIND&quot;,
</span><span class="cx">                 calendar_uri,
</span><span class="cx">                 headers=http_headers.Headers({&quot;Depth&quot;: &quot;0&quot;}),
</span><del>-                authid=&quot;user01&quot;,
</del><ins>+                authRecord=self.authRecord,
</ins><span class="cx">             )
</span><span class="cx">             request.stream = MemoryStream(query.toxml())
</span><span class="cx">             return self.send(request, propfind_cb)
</span><span class="cx"> 
</span><del>-        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, calendar_uri, authid=&quot;user01&quot;)
</del><ins>+        request = SimpleStoreRequest(self, &quot;MKCALENDAR&quot;, calendar_uri, authRecord=self.authRecord)
</ins><span class="cx">         return self.send(request, mkcalendar_cb)
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_resourcepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_resource.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_resource.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_resource.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -14,22 +14,25 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><span class="cx"> 
</span><ins>+from twext.who.idirectory import RecordType
+from twisted.internet.defer import inlineCallbacks
+from twistedcaldav import carddavxml
+from twistedcaldav.config import config
+from twistedcaldav.notifications import NotificationCollectionResource
+from twistedcaldav.resource import (
+    CalDAVResource, CommonHomeResource,
+    CalendarHomeResource, AddressBookHomeResource
+)
+from twistedcaldav.test.util import (
+    InMemoryPropertyStore, StoreTestCase, SimpleStoreRequest
+)
+from twistedcaldav.test.util import TestCase
</ins><span class="cx"> from txdav.xml.element import HRef, Principal, Unauthenticated
</span><span class="cx"> from txweb2.http import HTTPError
</span><span class="cx"> from txweb2.test.test_server import SimpleRequest
</span><span class="cx"> 
</span><del>-from twisted.internet.defer import inlineCallbacks
</del><span class="cx"> 
</span><del>-from twistedcaldav import carddavxml
-from twistedcaldav.config import config
-from twistedcaldav.resource import CalDAVResource, CommonHomeResource, \
- CalendarHomeResource, AddressBookHomeResource
-from twistedcaldav.test.util import InMemoryPropertyStore, StoreTestCase, \
-    SimpleStoreRequest
-from twistedcaldav.test.util import TestCase
-from twistedcaldav.notifications import NotificationCollectionResource
</del><span class="cx"> 
</span><del>-
</del><span class="cx"> class StubProperty(object):
</span><span class="cx">     def qname(self):
</span><span class="cx">         return &quot;StubQnamespace&quot;, &quot;StubQname&quot;
</span><span class="lines">@@ -185,13 +188,20 @@
</span><span class="cx"> 
</span><span class="cx"> class DefaultAddressBook (StoreTestCase):
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx">     @inlineCallbacks
</span><ins>+    def setUp(self):
+        yield StoreTestCase.setUp(self)
+        self.authRecord = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
+
+
+    @inlineCallbacks
</ins><span class="cx">     def test_pick_default_addressbook(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Get adbk
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        request = SimpleStoreRequest(self, &quot;GET&quot;, &quot;/addressbooks/users/wsanchez/&quot;, authid=&quot;wsanchez&quot;)
</del><ins>+        request = SimpleStoreRequest(self, &quot;GET&quot;, &quot;/addressbooks/users/wsanchez/&quot;, authRecord=self.authRecord)
</ins><span class="cx">         home = yield request.locateResource(&quot;/addressbooks/users/wsanchez&quot;)
</span><span class="cx"> 
</span><span class="cx">         # default property initially not present
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_sharingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_sharing.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_sharing.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_sharing.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -185,7 +185,8 @@
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def _doPOST(self, body, resultcode=responsecode.OK):
</span><del>-        request = SimpleStoreRequest(self, &quot;POST&quot;, &quot;/calendars/__uids__/user01/calendar/&quot;, content=body, authid=&quot;user01&quot;)
</del><ins>+        authRecord = yield self.directory.recordWithUID(u&quot;user01&quot;)
+        request = SimpleStoreRequest(self, &quot;POST&quot;, &quot;/calendars/__uids__/user01/calendar/&quot;, content=body, authRecord=authRecord)
</ins><span class="cx">         request.headers.setHeader(&quot;content-type&quot;, MimeType(&quot;text&quot;, &quot;xml&quot;))
</span><span class="cx">         response = yield self.send(request)
</span><span class="cx">         response = IResponse(response)
</span><span class="lines">@@ -210,7 +211,8 @@
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def _doPOSTSharerAccept(self, body, resultcode=responsecode.OK):
</span><del>-        request = SimpleStoreRequest(self, &quot;POST&quot;, &quot;/calendars/__uids__/user02/&quot;, content=body, authid=&quot;user02&quot;)
</del><ins>+        authRecord = yield self.directory.recordWithUID(u&quot;user02&quot;)
+        request = SimpleStoreRequest(self, &quot;POST&quot;, &quot;/calendars/__uids__/user02/&quot;, content=body, authRecord=authRecord)
</ins><span class="cx">         request.headers.setHeader(&quot;content-type&quot;, MimeType(&quot;text&quot;, &quot;xml&quot;))
</span><span class="cx">         response = yield self.send(request)
</span><span class="cx">         response = IResponse(response)
</span><span class="lines">@@ -732,6 +734,7 @@
</span><span class="cx">         self.assertEquals(propInvite, None)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    # MOVE2WHO Fix wiki
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def wikiSetup(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -798,7 +801,8 @@
</span><span class="cx">         self.patch(sharing, &quot;getWikiAccess&quot;, stubWikiAccessMethod)
</span><span class="cx">         @inlineCallbacks
</span><span class="cx">         def listChildrenViaPropfind():
</span><del>-            request = SimpleStoreRequest(self, &quot;PROPFIND&quot;, &quot;/calendars/__uids__/user01/&quot;, authid=&quot;user01&quot;)
</del><ins>+            authRecord = yield self.directory.recordWithUID(u&quot;user01&quot;)
+            request = SimpleStoreRequest(self, &quot;PROPFIND&quot;, &quot;/calendars/__uids__/user01/&quot;, authRecord=authRecord)
</ins><span class="cx">             request.headers.setHeader(&quot;depth&quot;, &quot;1&quot;)
</span><span class="cx">             response = yield self.send(request)
</span><span class="cx">             response = IResponse(response)
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_upgradepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_upgrade.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_upgrade.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_upgrade.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1536,6 +1536,7 @@
</span><span class="cx">         self.assertFalse(changed)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def test_normalizeCUAddrs(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Ensure that calendar user addresses (CUAs) are cached so we can
</span><span class="lines">@@ -1577,8 +1578,8 @@
</span><span class="cx"> 
</span><span class="cx">         directory = StubDirectory()
</span><span class="cx">         cuaCache = {}
</span><del>-        normalizeCUAddrs(normalizeEvent, directory, cuaCache)
-        normalizeCUAddrs(normalizeEvent, directory, cuaCache)
</del><ins>+        yield normalizeCUAddrs(normalizeEvent, directory, cuaCache)
+        yield normalizeCUAddrs(normalizeEvent, directory, cuaCache)
</ins><span class="cx"> 
</span><span class="cx">         # Ensure we only called principalForCalendarUserAddress 3 times.  It
</span><span class="cx">         # would have been 8 times without the cuaCache.
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtesttest_wrappingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_wrapping.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_wrapping.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/test_wrapping.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -28,11 +28,12 @@
</span><span class="cx"> from txweb2.responsecode import UNAUTHORIZED
</span><span class="cx"> from txweb2.stream import MemoryStream
</span><span class="cx"> 
</span><ins>+from twext.who.idirectory import RecordType
+
</ins><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><span class="cx"> from twisted.internet.defer import maybeDeferred
</span><span class="cx"> 
</span><span class="cx"> from twistedcaldav.config import config
</span><del>-from twistedcaldav.directory.test.test_xmlfile import XMLFileBase
</del><span class="cx"> from twistedcaldav.ical import Component as VComponent
</span><span class="cx"> from twistedcaldav.storebridge import DropboxCollection, \
</span><span class="cx">     CalendarCollectionResource
</span><span class="lines">@@ -51,11 +52,14 @@
</span><span class="cx"> 
</span><span class="cx"> import hashlib
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> def _todo(f, why):
</span><span class="cx">     f.todo = why
</span><span class="cx">     return f
</span><span class="cx"> rewriteOrRemove = lambda f: _todo(f, &quot;Rewrite or remove&quot;)
</span><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class FakeChanRequest(object):
</span><span class="cx">     code = 'request-not-finished'
</span><span class="cx"> 
</span><span class="lines">@@ -113,7 +117,7 @@
</span><span class="cx">         @param objectText: Some iCalendar text to populate it with.
</span><span class="cx">         @type objectText: str
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        record = self.directory.recordWithShortName(&quot;users&quot;, &quot;wsanchez&quot;)
</del><ins>+        record = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
</ins><span class="cx">         uid = record.uid
</span><span class="cx">         txn = self.transactionUnderTest()
</span><span class="cx">         home = yield txn.calendarHomeWithUID(uid, True)
</span><span class="lines">@@ -132,7 +136,7 @@
</span><span class="cx">         @param objectText: Some iVcard text to populate it with.
</span><span class="cx">         @type objectText: str
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        record = self.directory.recordWithShortName(&quot;users&quot;, &quot;wsanchez&quot;)
</del><ins>+        record = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
</ins><span class="cx">         uid = record.uid
</span><span class="cx">         txn = self.transactionUnderTest()
</span><span class="cx">         home = yield txn.addressbookHomeWithUID(uid, True)
</span><span class="lines">@@ -171,9 +175,10 @@
</span><span class="cx">             &quot;http://localhost:8008/&quot; + path
</span><span class="cx">         )
</span><span class="cx">         if user is not None:
</span><del>-            guid = XMLFileBase.users[user][&quot;guid&quot;]
</del><ins>+            record = yield self.directory.recordWithShortName(RecordType.user, user)
+            uid = record.uid
</ins><span class="cx">             req.authnUser = req.authzUser = (
</span><del>-                davxml.Principal(davxml.HRef('/principals/__uids__/' + guid + '/'))
</del><ins>+                davxml.Principal(davxml.HRef('/principals/__uids__/' + uid + '/'))
</ins><span class="cx">             )
</span><span class="cx">         returnValue(aResource)
</span><span class="cx"> 
</span><span class="lines">@@ -271,7 +276,7 @@
</span><span class="cx">         )
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertIsInstance(dropBoxResource, DropboxCollection)
</span><del>-        dropboxHomeType = davxml.ResourceType.dropboxhome #@UndefinedVariable
</del><ins>+        dropboxHomeType = davxml.ResourceType.dropboxhome  # @UndefinedVariable
</ins><span class="cx">         self.assertEquals(dropBoxResource.resourceType(),
</span><span class="cx">                           dropboxHomeType)
</span><span class="cx"> 
</span><span class="lines">@@ -285,7 +290,7 @@
</span><span class="cx">         C{CalendarHome.calendarWithName}.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         calDavFile = yield self.getResource(&quot;calendars/users/wsanchez/calendar&quot;)
</span><del>-        regularCalendarType = davxml.ResourceType.calendar #@UndefinedVariable
</del><ins>+        regularCalendarType = davxml.ResourceType.calendar  # @UndefinedVariable
</ins><span class="cx">         self.assertEquals(calDavFile.resourceType(),
</span><span class="cx">                           regularCalendarType)
</span><span class="cx">         yield self.commit()
</span><span class="lines">@@ -344,8 +349,11 @@
</span><span class="cx">             self.assertIdentical(
</span><span class="cx">                 homeChild._associatedTransaction,
</span><span class="cx">                 homeTransaction,
</span><del>-                &quot;transaction mismatch on %s; %r is not %r &quot; %
-                    (name, homeChild._associatedTransaction, homeTransaction))
</del><ins>+                &quot;transaction mismatch on {n}; {at} is not {ht} &quot;.format(
+                    n=name, at=homeChild._associatedTransaction,
+                    ht=homeTransaction
+                )
+            )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -575,12 +583,13 @@
</span><span class="cx">         yield NamedLock.acquire(txn, &quot;ImplicitUIDLock:%s&quot; % (hashlib.md5(&quot;uid1&quot;).hexdigest(),))
</span><span class="cx"> 
</span><span class="cx">         # PUT fails
</span><ins>+        authRecord = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
</ins><span class="cx">         request = SimpleStoreRequest(
</span><span class="cx">             self,
</span><span class="cx">             &quot;PUT&quot;,
</span><span class="cx">             &quot;/calendars/users/wsanchez/calendar/1.ics&quot;,
</span><span class="cx">             headers=Headers({&quot;content-type&quot;: MimeType.fromString(&quot;text/calendar&quot;)}),
</span><del>-            authid=&quot;wsanchez&quot;
</del><ins>+            authRecord=authRecord
</ins><span class="cx">         )
</span><span class="cx">         request.stream = MemoryStream(&quot;&quot;&quot;BEGIN:VCALENDAR
</span><span class="cx"> CALSCALE:GREGORIAN
</span><span class="lines">@@ -606,12 +615,13 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         # PUT works
</span><ins>+        authRecord = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
</ins><span class="cx">         request = SimpleStoreRequest(
</span><span class="cx">             self,
</span><span class="cx">             &quot;PUT&quot;,
</span><span class="cx">             &quot;/calendars/users/wsanchez/calendar/1.ics&quot;,
</span><span class="cx">             headers=Headers({&quot;content-type&quot;: MimeType.fromString(&quot;text/calendar&quot;)}),
</span><del>-            authid=&quot;wsanchez&quot;
</del><ins>+            authRecord=authRecord
</ins><span class="cx">         )
</span><span class="cx">         request.stream = MemoryStream(&quot;&quot;&quot;BEGIN:VCALENDAR
</span><span class="cx"> CALSCALE:GREGORIAN
</span><span class="lines">@@ -635,11 +645,12 @@
</span><span class="cx">         txn = self.transactionUnderTest()
</span><span class="cx">         yield NamedLock.acquire(txn, &quot;ImplicitUIDLock:%s&quot; % (hashlib.md5(&quot;uid1&quot;).hexdigest(),))
</span><span class="cx"> 
</span><ins>+        authRecord = yield self.directory.recordWithShortName(RecordType.user, u&quot;wsanchez&quot;)
</ins><span class="cx">         request = SimpleStoreRequest(
</span><span class="cx">             self,
</span><span class="cx">             &quot;DELETE&quot;,
</span><span class="cx">             &quot;/calendars/users/wsanchez/calendar/1.ics&quot;,
</span><del>-            authid=&quot;wsanchez&quot;
</del><ins>+            authRecord=authRecord
</ins><span class="cx">         )
</span><span class="cx">         response = yield self.send(request)
</span><span class="cx">         self.assertEqual(response.code, responsecode.SERVICE_UNAVAILABLE)
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtestutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/util.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/util.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/test/util.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -17,45 +17,37 @@
</span><span class="cx"> from __future__ import with_statement
</span><span class="cx"> 
</span><span class="cx"> import os
</span><del>-import xattr
</del><span class="cx"> 
</span><del>-from twistedcaldav.stdconfig import config
-
-from twisted.python.failure import Failure
</del><ins>+from calendarserver.provision.root import RootResource
+from calendarserver.tap.util import getRootResource
+from twext.python.filepath import CachingFilePath as FilePath
+from twext.python.log import Logger
</ins><span class="cx"> from twisted.internet.base import DelayedCall
</span><span class="cx"> from twisted.internet.defer import succeed, fail, inlineCallbacks, returnValue
</span><span class="cx"> from twisted.internet.protocol import ProcessProtocol
</span><del>-
-from twext.python.filepath import CachingFilePath as FilePath
-import txweb2.dav.test.util
-from txdav.xml import element as davxml, element
-from txweb2.http import HTTPError, StatusResponse
-
</del><ins>+from twisted.python.failure import Failure
</ins><span class="cx"> from twistedcaldav import memcacher
</span><del>-from twistedcaldav.memcacheclient import ClientFactory
</del><span class="cx"> from twistedcaldav.bind import doBind
</span><del>-from twistedcaldav.directory import augment
</del><span class="cx"> from twistedcaldav.directory.addressbook import DirectoryAddressBookHomeProvisioningResource
</span><span class="cx"> from twistedcaldav.directory.calendar import (
</span><span class="cx">     DirectoryCalendarHomeProvisioningResource
</span><span class="cx"> )
</span><span class="cx"> from twistedcaldav.directory.principal import (
</span><span class="cx">     DirectoryPrincipalProvisioningResource)
</span><del>-from twistedcaldav.directory.aggregate import AggregateDirectoryService
-from twistedcaldav.directory.xmlfile import XMLDirectoryService
-
-from txdav.common.datastore.test.util import deriveQuota, CommonCommonTests
-from txdav.common.datastore.file import CommonDataStore
-
-from calendarserver.provision.root import RootResource
-
-from twext.python.log import Logger
</del><ins>+from twistedcaldav.directory.util import transactionFromRequest
+from twistedcaldav.memcacheclient import ClientFactory
+from twistedcaldav.stdconfig import config
</ins><span class="cx"> from txdav.caldav.datastore.test.util import buildCalendarStore
</span><del>-from calendarserver.tap.util import getRootResource, directoryFromConfig
</del><ins>+from txdav.common.datastore.file import CommonDataStore
+from txdav.common.datastore.test.util import deriveQuota, CommonCommonTests
+from txdav.who.util import directoryFromConfig
+from txdav.xml import element as davxml, element
</ins><span class="cx"> from txweb2.dav.test.util import SimpleRequest
</span><del>-from twistedcaldav.directory.util import transactionFromRequest
-from twistedcaldav.directory.directory import DirectoryService
</del><ins>+import txweb2.dav.test.util
+from txweb2.http import HTTPError, StatusResponse
+import xattr
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -67,10 +59,12 @@
</span><span class="cx"> ]
</span><span class="cx"> DelayedCall.debug = True
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> def _todo(f, why):
</span><span class="cx">     f.todo = why
</span><span class="cx">     return f
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> featureUnimplemented = lambda f: _todo(f, &quot;Feature unimplemented&quot;)
</span><span class="cx"> testUnimplemented = lambda f: _todo(f, &quot;Test unimplemented&quot;)
</span><span class="cx"> todo = lambda why: lambda f: _todo(f, why)
</span><span class="lines">@@ -83,92 +77,21 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class DirectoryFixture(object):
-    &quot;&quot;&quot;
-    Test fixture for creating various parts of the resource hierarchy related
-    to directories.
-    &quot;&quot;&quot;
</del><span class="cx"> 
</span><del>-    def __init__(self):
-        def _setUpPrincipals(ds):
-            # FIXME: see FIXME in
-            # DirectoryPrincipalProvisioningResource.__init__; this performs a
-            # necessary modification to any directory service object for it to
-            # be fully functional.
-            self.principalsResource = DirectoryPrincipalProvisioningResource(
-                &quot;/principals/&quot;, ds
-            )
-        self._directoryChangeHooks = [_setUpPrincipals]
</del><span class="cx"> 
</span><del>-    directoryService = None
-    principalsResource = None
-
-    def addDirectoryService(self, newService):
-        &quot;&quot;&quot;
-        Add an L{IDirectoryService} to this test case.
-
-        If this test case does not have a directory service yet, create it and
-        assign C{directoryService} and C{principalsResource} attributes to this
-        test case.
-
-        If the test case already has a directory service, create an
-        L{AggregateDirectoryService} and re-assign the C{self.directoryService}
-        attribute to point at it instead, while setting the C{realmName} of the
-        new service to match the old one.
-
-        If the test already has an L{AggregateDirectoryService}, create a
-        I{new} L{AggregateDirectoryService} with the same list of services,
-        after adjusting the new service's realm to match the existing ones.
-        &quot;&quot;&quot;
-
-        if self.directoryService is None:
-            directoryService = newService
-        else:
-            newService.realmName = self.directoryService.realmName
-            if isinstance(self.directoryService, AggregateDirectoryService):
-                directories = set(self.directoryService._recordTypes.items())
-                directories.add(newService)
-            else:
-                directories = [newService, self.directoryService]
-            directoryService = AggregateDirectoryService(directories, None)
-
-        self.directoryService = directoryService
-        # FIXME: see FIXME in DirectoryPrincipalProvisioningResource.__init__;
-        # this performs a necessary modification to the directory service object
-        # for it to be fully functional.
-        for hook in self._directoryChangeHooks:
-            hook(directoryService)
-
-
-    def whenDirectoryServiceChanges(self, callback):
-        &quot;&quot;&quot;
-        When the C{directoryService} attribute is changed by
-        L{TestCase.addDirectoryService}, call the given callback in order to
-        update any state which relies upon that service.
-
-        If there's already a directory, invoke the callback immediately.
-        &quot;&quot;&quot;
-        self._directoryChangeHooks.append(callback)
-        if self.directoryService is not None:
-            callback(self.directoryService)
-
-
-
</del><span class="cx"> class SimpleStoreRequest(SimpleRequest):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     A SimpleRequest that automatically grabs the proper transaction for a test.
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    def __init__(self, test, method, uri, headers=None, content=None, authid=None):
</del><ins>+    def __init__(self, test, method, uri, headers=None, content=None, authRecord=None):
</ins><span class="cx">         super(SimpleStoreRequest, self).__init__(test.site, method, uri, headers, content)
</span><span class="cx">         self._test = test
</span><span class="cx">         self._newStoreTransaction = test.transactionUnderTest(txn=transactionFromRequest(self, test.storeUnderTest()))
</span><span class="cx">         self.credentialFactories = {}
</span><span class="cx"> 
</span><span class="cx">         # Fake credentials if auth needed
</span><del>-        if authid is not None:
-            record = self._test.directory.recordWithShortName(DirectoryService.recordType_users, authid)
-            if record:
-                self.authzUser = self.authnUser = element.Principal(element.HRef(&quot;/principals/__uids__/%s/&quot; % (record.uid,)))
</del><ins>+        if authRecord is not None:
+            self.authzUser = self.authnUser = element.Principal(element.HRef(&quot;/principals/__uids__/%s/&quot; % (authRecord.uid,)))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -198,9 +121,13 @@
</span><span class="cx"> 
</span><span class="cx">         self.configure()
</span><span class="cx"> 
</span><del>-        self._sqlCalendarStore = yield buildCalendarStore(self, self.notifierFactory, directoryFromConfig(config))
</del><ins>+        self._sqlCalendarStore = yield buildCalendarStore(
+            self, self.notifierFactory, None
+        )
+        self.directory = directoryFromConfig(config, self._sqlCalendarStore)
+        self._sqlCalendarStore.setDirectoryService(self.directory)
+
</ins><span class="cx">         self.rootResource = getRootResource(config, self._sqlCalendarStore)
</span><del>-        self.directory = self._sqlCalendarStore.directoryService()
</del><span class="cx"> 
</span><span class="cx">         self.principalsResource = DirectoryPrincipalProvisioningResource(&quot;/principals/&quot;, self.directory)
</span><span class="cx">         self.site.resource.putChild(&quot;principals&quot;, self.principalsResource)
</span><span class="lines">@@ -259,16 +186,7 @@
</span><span class="cx">         accounts.setContent(xmlFile.getContent())
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    @property
-    def directoryService(self):
-        &quot;&quot;&quot;
-        Read-only alias for L{DirectoryFixture.directoryService} for
-        compatibility with older tests.  TODO: remove this.
-        &quot;&quot;&quot;
-        return self.directory
</del><span class="cx"> 
</span><del>-
-
</del><span class="cx"> class TestCase(txweb2.dav.test.util.TestCase):
</span><span class="cx">     resource_class = RootResource
</span><span class="cx"> 
</span><span class="lines">@@ -282,19 +200,6 @@
</span><span class="cx">                                quota=deriveQuota(self))
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def createStockDirectoryService(self):
-        &quot;&quot;&quot;
-        Create a stock C{directoryService} attribute and assign it.
-        &quot;&quot;&quot;
-        self.xmlFile = FilePath(config.DataRoot).child(&quot;accounts.xml&quot;)
-        self.xmlFile.setContent(xmlFile.getContent())
-        self.directoryFixture.addDirectoryService(XMLDirectoryService({
-            &quot;xmlFile&quot;: &quot;accounts.xml&quot;,
-            &quot;augmentService&quot;:
-                augment.AugmentXMLDB(xmlFiles=(augmentsFile.path,)),
-        }))
-
-
</del><span class="cx">     def setupCalendars(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         When a directory service exists, set up the resources at C{/calendars}
</span><span class="lines">@@ -308,6 +213,8 @@
</span><span class="cx">         L{TestCase.directoryFixture.addDirectoryService}.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         newStore = self.createDataStore()
</span><ins>+
+
</ins><span class="cx">         @self.directoryFixture.whenDirectoryServiceChanges
</span><span class="cx">         def putAllChildren(ds):
</span><span class="cx">             self.calendarCollection = (
</span><span class="lines">@@ -343,20 +250,10 @@
</span><span class="cx">         config.UsePackageTimezones = True
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    @property
-    def directoryService(self):
-        &quot;&quot;&quot;
-        Read-only alias for L{DirectoryFixture.directoryService} for
-        compatibility with older tests.  TODO: remove this.
-        &quot;&quot;&quot;
-        return self.directoryFixture.directoryService
</del><span class="cx"> 
</span><del>-
</del><span class="cx">     def setUp(self):
</span><span class="cx">         super(TestCase, self).setUp()
</span><span class="cx"> 
</span><del>-        self.directoryFixture = DirectoryFixture()
-
</del><span class="cx">         # FIXME: this is only here to workaround circular imports
</span><span class="cx">         doBind()
</span><span class="cx"> 
</span><span class="lines">@@ -506,7 +403,7 @@
</span><span class="cx">                                     print(&quot;Xattr mismatch:&quot;, childPath, attr)
</span><span class="cx">                                     print((xattr.getxattr(childPath, attr), &quot; != &quot;, value))
</span><span class="cx">                                     return False
</span><del>-                            else: # method
</del><ins>+                            else:  # method
</ins><span class="cx">                                 if not value(xattr.getxattr(childPath, attr)):
</span><span class="cx">                                     return False
</span><span class="cx"> 
</span><span class="lines">@@ -555,7 +452,8 @@
</span><span class="cx">         that stores the data for that L{CalendarHomeResource}.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         super(HomeTestCase, self).setUp()
</span><del>-        self.createStockDirectoryService()
</del><ins>+
+
</ins><span class="cx">         @self.directoryFixture.whenDirectoryServiceChanges
</span><span class="cx">         def addHomeProvisioner(ds):
</span><span class="cx">             self.homeProvisioner = DirectoryCalendarHomeProvisioningResource(
</span><span class="lines">@@ -639,7 +537,8 @@
</span><span class="cx">         file.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         super(AddressBookHomeTestCase, self).setUp()
</span><del>-        self.createStockDirectoryService()
</del><ins>+
+
</ins><span class="cx">         @self.directoryFixture.whenDirectoryServiceChanges
</span><span class="cx">         def addHomeProvisioner(ds):
</span><span class="cx">             self.homeProvisioner = DirectoryAddressBookHomeProvisioningResource(
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtimezoneservicepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/timezoneservice.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/timezoneservice.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/timezoneservice.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -86,15 +86,17 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def defaultAccessControlList(self):
</span><del>-        return davxml.ACL(
-            # DAV:Read for all principals (includes anonymous)
-            davxml.ACE(
-                davxml.Principal(davxml.All()),
-                davxml.Grant(
-                    davxml.Privilege(davxml.Read()),
</del><ins>+        return succeed(
+            davxml.ACL(
+                # DAV:Read for all principals (includes anonymous)
+                davxml.ACE(
+                    davxml.Principal(davxml.All()),
+                    davxml.Grant(
+                        davxml.Privilege(davxml.Read()),
+                    ),
+                    davxml.Protected(),
</ins><span class="cx">                 ),
</span><del>-                davxml.Protected(),
-            ),
</del><ins>+            )
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavtimezonestdservicepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/timezonestdservice.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/timezonestdservice.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/timezonestdservice.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -146,15 +146,17 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def defaultAccessControlList(self):
</span><del>-        return davxml.ACL(
-            # DAV:Read for all principals (includes anonymous)
-            davxml.ACE(
-                davxml.Principal(davxml.All()),
-                davxml.Grant(
-                    davxml.Privilege(davxml.Read()),
</del><ins>+        return succeed(
+            davxml.ACL(
+                # DAV:Read for all principals (includes anonymous)
+                davxml.ACE(
+                    davxml.Principal(davxml.All()),
+                    davxml.Grant(
+                        davxml.Privilege(davxml.Read()),
+                    ),
+                    davxml.Protected(),
</ins><span class="cx">                 ),
</span><del>-                davxml.Protected(),
-            ),
</del><ins>+            )
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavupgradepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/upgrade.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/upgrade.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/upgrade.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -39,11 +39,8 @@
</span><span class="cx"> from twistedcaldav import caldavxml
</span><span class="cx"> from twistedcaldav.directory import calendaruserproxy
</span><span class="cx"> from twistedcaldav.directory.calendaruserproxyloader import XMLCalendarUserProxyLoader
</span><del>-from twistedcaldav.directory.directory import DirectoryService
-from twistedcaldav.directory.directory import GroupMembershipCacheUpdater
</del><span class="cx"> from twistedcaldav.directory.principal import DirectoryCalendarPrincipalResource
</span><span class="cx"> from twistedcaldav.directory.resourceinfo import ResourceInfoDatabase
</span><del>-from twistedcaldav.directory.xmlfile import XMLDirectoryService
</del><span class="cx"> from twistedcaldav.ical import Component
</span><span class="cx"> from txdav.caldav.datastore.scheduling.cuaddress import LocalCalendarUser
</span><span class="cx"> from txdav.caldav.datastore.scheduling.imip.mailgateway import MailGatewayTokensDatabase
</span><span class="lines">@@ -60,8 +57,7 @@
</span><span class="cx"> 
</span><span class="cx"> from twisted.protocols.amp import AMP, Command, String, Boolean
</span><span class="cx"> 
</span><del>-from calendarserver.tap.util import getRootResource, FakeRequest, directoryFromConfig
-from calendarserver.tools.util import getDirectory
</del><ins>+from calendarserver.tap.util import getRootResource, FakeRequest
</ins><span class="cx"> 
</span><span class="cx"> from txdav.caldav.datastore.scheduling.imip.mailgateway import migrateTokensToStore
</span><span class="cx"> 
</span><span class="lines">@@ -121,6 +117,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+@inlineCallbacks
</ins><span class="cx"> def upgradeCalendarCollection(calPath, directory, cuaCache):
</span><span class="cx">     errorOccurred = False
</span><span class="cx">     collectionUpdated = False
</span><span class="lines">@@ -164,7 +161,7 @@
</span><span class="cx">                 continue
</span><span class="cx"> 
</span><span class="cx">             try:
</span><del>-                data, fixed = normalizeCUAddrs(data, directory, cuaCache)
</del><ins>+                data, fixed = (yield normalizeCUAddrs(data, directory, cuaCache))
</ins><span class="cx">                 if fixed:
</span><span class="cx">                     log.debug(&quot;Normalized CUAddrs in %s&quot; % (resPath,))
</span><span class="cx">                     needsRewrite = True
</span><span class="lines">@@ -207,10 +204,11 @@
</span><span class="cx">         except:
</span><span class="cx">             raise
</span><span class="cx"> 
</span><del>-    return errorOccurred
</del><ins>+    returnValue(errorOccurred)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+@inlineCallbacks
</ins><span class="cx"> def upgradeCalendarHome(homePath, directory, cuaCache):
</span><span class="cx"> 
</span><span class="cx">     errorOccurred = False
</span><span class="lines">@@ -229,7 +227,7 @@
</span><span class="cx">                 rmdir(calPath)
</span><span class="cx">                 continue
</span><span class="cx">             log.debug(&quot;Upgrading calendar: %s&quot; % (calPath,))
</span><del>-            if not upgradeCalendarCollection(calPath, directory, cuaCache):
</del><ins>+            if not (yield upgradeCalendarCollection(calPath, directory, cuaCache)):
</ins><span class="cx">                 errorOccurred = True
</span><span class="cx"> 
</span><span class="cx">             # Change the calendar-free-busy-set xattrs of the inbox to the
</span><span class="lines">@@ -254,7 +252,7 @@
</span><span class="cx">         log.error(&quot;Failed to upgrade calendar home %s: %s&quot; % (homePath, e))
</span><span class="cx">         raise
</span><span class="cx"> 
</span><del>-    return errorOccurred
</del><ins>+    returnValue(errorOccurred)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -288,9 +286,10 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @UpgradeOneHome.responder
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def upgradeOne(self, path):
</span><del>-        result = upgradeCalendarHome(path, self.directory, self.cuaCache)
-        return dict(succeeded=result)
</del><ins>+        result = yield upgradeCalendarHome(path, self.directory, self.cuaCache)
+        returnValue(dict(succeeded=result))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -543,9 +542,9 @@
</span><span class="cx">                                         # Skip non-directories
</span><span class="cx">                                         continue
</span><span class="cx"> 
</span><del>-                                    if not upgradeCalendarHome(
</del><ins>+                                    if not (yield upgradeCalendarHome(
</ins><span class="cx">                                         homePath, directory, cuaCache
</span><del>-                                    ):
</del><ins>+                                    )):
</ins><span class="cx">                                         setError()
</span><span class="cx"> 
</span><span class="cx">                                     count += 1
</span><span class="lines">@@ -564,6 +563,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+@inlineCallbacks
</ins><span class="cx"> def normalizeCUAddrs(data, directory, cuaCache):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Normalize calendar user addresses to urn:uuid: form.
</span><span class="lines">@@ -583,23 +583,24 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     cal = Component.fromString(data)
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def lookupFunction(cuaddr, principalFunction, config):
</span><span class="cx"> 
</span><span class="cx">         # Return cached results, if any.
</span><span class="cx">         if cuaddr in cuaCache:
</span><del>-            return cuaCache[cuaddr]
</del><ins>+            returnValue(cuaCache[cuaddr])
</ins><span class="cx"> 
</span><del>-        result = normalizationLookup(cuaddr, principalFunction, config)
</del><ins>+        result = yield normalizationLookup(cuaddr, principalFunction, config)
</ins><span class="cx"> 
</span><span class="cx">         # Cache the result
</span><span class="cx">         cuaCache[cuaddr] = result
</span><del>-        return result
</del><ins>+        returnValue(result)
</ins><span class="cx"> 
</span><del>-    cal.normalizeCalendarUserAddresses(lookupFunction,
</del><ins>+    yield cal.normalizeCalendarUserAddresses(lookupFunction,
</ins><span class="cx">         directory.principalForCalendarUserAddress)
</span><span class="cx"> 
</span><span class="cx">     newData = str(cal)
</span><del>-    return newData, not newData == data
</del><ins>+    returnValue(newData, not newData == data)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -904,31 +905,31 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-# Deferred
-def migrateFromOD(config, directory):
-    #
-    # Migrates locations and resources from OD
-    #
-    try:
-        from twistedcaldav.directory.appleopendirectory import OpenDirectoryService
-        from calendarserver.tools.resources import migrateResources
-    except ImportError:
-        return succeed(None)
</del><ins>+# # Deferred
+# def migrateFromOD(config, directory):
+#     #
+#     # Migrates locations and resources from OD
+#     #
+#     try:
+#         from twistedcaldav.directory.appleopendirectory import OpenDirectoryService
+#         from calendarserver.tools.resources import migrateResources
+#     except ImportError:
+#         return succeed(None)
</ins><span class="cx"> 
</span><del>-    log.warn(&quot;Migrating locations and resources&quot;)
</del><ins>+#     log.warn(&quot;Migrating locations and resources&quot;)
</ins><span class="cx"> 
</span><del>-    userService = directory.serviceForRecordType(&quot;users&quot;)
-    resourceService = directory.serviceForRecordType(&quot;resources&quot;)
-    if (
-        not isinstance(userService, OpenDirectoryService) or
-        not isinstance(resourceService, XMLDirectoryService)
-    ):
-        # Configuration requires no migration
-        return succeed(None)
</del><ins>+#     userService = directory.serviceForRecordType(&quot;users&quot;)
+#     resourceService = directory.serviceForRecordType(&quot;resources&quot;)
+#     if (
+#         not isinstance(userService, OpenDirectoryService) or
+#         not isinstance(resourceService, XMLDirectoryService)
+#     ):
+#         # Configuration requires no migration
+#         return succeed(None)
</ins><span class="cx"> 
</span><del>-    # Create internal copies of resources and locations based on what is
-    # found in OD
-    return migrateResources(userService, resourceService)
</del><ins>+#     # Create internal copies of resources and locations based on what is
+#     # found in OD
+#     return migrateResources(userService, resourceService)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -997,7 +998,9 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Execute the step.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        return self.doUpgrade()
</del><ins>+        return succeed(None)
+        # MOVE2WHO
+        # return self.doUpgrade()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -1025,7 +1028,7 @@
</span><span class="cx">     def stepWithResult(self, result):
</span><span class="cx">         if self.doPostImport:
</span><span class="cx"> 
</span><del>-            directory = directoryFromConfig(self.config)
</del><ins>+            directory = self.store.directoryService()
</ins><span class="cx"> 
</span><span class="cx">             # Load proxy assignments from XML if specified
</span><span class="cx">             if self.config.ProxyLoadFromFile:
</span><span class="lines">@@ -1035,27 +1038,28 @@
</span><span class="cx">                 loader = XMLCalendarUserProxyLoader(self.config.ProxyLoadFromFile)
</span><span class="cx">                 yield loader.updateProxyDB()
</span><span class="cx"> 
</span><del>-            # Populate the group membership cache
-            if (self.config.GroupCaching.Enabled and
-                self.config.GroupCaching.EnableUpdater):
-                proxydb = calendaruserproxy.ProxyDBService
-                if proxydb is None:
-                    proxydbClass = namedClass(self.config.ProxyDBService.type)
-                    proxydb = proxydbClass(**self.config.ProxyDBService.params)
</del><ins>+            # # Populate the group membership cache
+            # if (self.config.GroupCaching.Enabled and
+            #     self.config.GroupCaching.EnableUpdater):
+            #     proxydb = calendaruserproxy.ProxyDBService
+            #     if proxydb is None:
+            #         proxydbClass = namedClass(self.config.ProxyDBService.type)
+            #         proxydb = proxydbClass(**self.config.ProxyDBService.params)
</ins><span class="cx"> 
</span><del>-                updater = GroupMembershipCacheUpdater(proxydb,
-                    directory,
-                    self.config.GroupCaching.UpdateSeconds,
-                    self.config.GroupCaching.ExpireSeconds,
-                    self.config.GroupCaching.LockSeconds,
-                    namespace=self.config.GroupCaching.MemcachedPool,
-                    useExternalProxies=self.config.GroupCaching.UseExternalProxies)
-                yield updater.updateCache(fast=True)
</del><ins>+            #     # MOVE2WHO FIXME: port to new group cacher
+            #     updater = GroupMembershipCacheUpdater(proxydb,
+            #         directory,
+            #         self.config.GroupCaching.UpdateSeconds,
+            #         self.config.GroupCaching.ExpireSeconds,
+            #         self.config.GroupCaching.LockSeconds,
+            #         namespace=self.config.GroupCaching.MemcachedPool,
+            #         useExternalProxies=self.config.GroupCaching.UseExternalProxies)
+            #     yield updater.updateCache(fast=True)
</ins><span class="cx"> 
</span><del>-                uid, gid = getCalendarServerIDs(self.config)
-                dbPath = os.path.join(self.config.DataRoot, &quot;proxies.sqlite&quot;)
-                if os.path.exists(dbPath):
-                    os.chown(dbPath, uid, gid)
</del><ins>+            uid, gid = getCalendarServerIDs(self.config)
+            dbPath = os.path.join(self.config.DataRoot, &quot;proxies.sqlite&quot;)
+            if os.path.exists(dbPath):
+                os.chown(dbPath, uid, gid)
</ins><span class="cx"> 
</span><span class="cx">             # Process old inbox items
</span><span class="cx">             self.store.setMigrating(True)
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/util.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/util.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/util.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -23,6 +23,7 @@
</span><span class="cx"> from hashlib import md5, sha1
</span><span class="cx"> 
</span><span class="cx"> from twisted.internet import ssl, reactor
</span><ins>+from twisted.internet.defer import inlineCallbacks, returnValue
</ins><span class="cx"> from twisted.web import client
</span><span class="cx"> from twisted.python import failure
</span><span class="cx"> from twext.python.log import Logger
</span><span class="lines">@@ -495,6 +496,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+@inlineCallbacks
</ins><span class="cx"> def normalizationLookup(cuaddr, principalFunction, config):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Lookup function to be passed to ical.normalizeCalendarUserAddresses.
</span><span class="lines">@@ -503,13 +505,13 @@
</span><span class="cx">     principal for the cuaddr.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     try:
</span><del>-        principal = principalFunction(cuaddr)
</del><ins>+        principal = yield principalFunction(cuaddr)
</ins><span class="cx">     except Exception, e:
</span><span class="cx">         log.debug(&quot;Lookup of %s failed: %s&quot; % (cuaddr, e))
</span><span class="cx">         principal = None
</span><span class="cx"> 
</span><span class="cx">     if principal is None:
</span><del>-        return (None, None, None)
</del><ins>+        returnValue((None, None, None))
</ins><span class="cx">     else:
</span><span class="cx">         rec = principal.record
</span><span class="cx"> 
</span><span class="lines">@@ -520,9 +522,9 @@
</span><span class="cx">         # to single-quotes.
</span><span class="cx">         fullName = rec.fullName.replace('&quot;', &quot;'&quot;)
</span><span class="cx"> 
</span><del>-        cuas = principal.record.calendarUserAddresses
</del><ins>+        cuas = principal.record.calendarUserAddresses()
</ins><span class="cx"> 
</span><del>-        return (fullName, rec.guid, cuas)
</del><ins>+        returnValue((fullName, rec.guid, cuas))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingcaldavschedulerpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/caldav/scheduler.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/caldav/scheduler.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/caldav/scheduler.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -85,13 +85,14 @@
</span><span class="cx">             ))
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def checkOriginator(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Check the validity of the Originator header. Extract the corresponding principal.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         # Verify that Originator is a valid calendar user
</span><del>-        originatorPrincipal = self.txn.directoryService().recordWithCalendarUserAddress(self.originator)
</del><ins>+        originatorPrincipal = yield self.txn.directoryService().recordWithCalendarUserAddress(self.originator)
</ins><span class="cx">         if originatorPrincipal is None:
</span><span class="cx">             # Local requests MUST have a principal.
</span><span class="cx">             log.error(&quot;Could not find principal for originator: %s&quot; % (self.originator,))
</span><span class="lines">@@ -122,7 +123,7 @@
</span><span class="cx">         results = []
</span><span class="cx">         for recipient in self.recipients:
</span><span class="cx">             # Get the principal resource for this recipient
</span><del>-            principal = self.txn.directoryService().recordWithCalendarUserAddress(recipient)
</del><ins>+            principal = yield self.txn.directoryService().recordWithCalendarUserAddress(recipient)
</ins><span class="cx"> 
</span><span class="cx">             # If no principal we may have a remote recipient but we should check whether
</span><span class="cx">             # the address is one that ought to be on our server and treat that as a missing
</span><span class="lines">@@ -161,7 +162,7 @@
</span><span class="cx">         # Verify that the ORGANIZER's cu address maps to a valid user
</span><span class="cx">         organizer = self.calendar.getOrganizer()
</span><span class="cx">         if organizer:
</span><del>-            organizerPrincipal = self.txn.directoryService().recordWithCalendarUserAddress(organizer)
</del><ins>+            organizerPrincipal = yield self.txn.directoryService().recordWithCalendarUserAddress(organizer)
</ins><span class="cx">             if organizerPrincipal:
</span><span class="cx">                 if organizerPrincipal.calendarsEnabled():
</span><span class="cx"> 
</span><span class="lines">@@ -225,6 +226,7 @@
</span><span class="cx">             ))
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def checkAttendeeAsOriginator(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Check the validity of the ATTENDEE value as this is the originator of the iTIP message.
</span><span class="lines">@@ -232,7 +234,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         # Attendee's Outbox MUST be the request URI
</span><del>-        attendeePrincipal = self.txn.directoryService().recordWithCalendarUserAddress(self.attendee)
</del><ins>+        attendeePrincipal = yield self.txn.directoryService().recordWithCalendarUserAddress(self.attendee)
</ins><span class="cx">         if attendeePrincipal:
</span><span class="cx">             if self.doingPOST is not None and attendeePrincipal.uid != self.originator_uid:
</span><span class="cx">                 log.error(&quot;ATTENDEE in calendar data does not match owner of Outbox: %s&quot; % (self.calendar,))
</span><span class="lines">@@ -257,11 +259,11 @@
</span><span class="cx"> 
</span><span class="cx">         # Prevent spoofing of ORGANIZER with specific METHODs when local
</span><span class="cx">         if self.isiTIPRequest:
</span><del>-            self.checkOrganizerAsOriginator()
</del><ins>+            return self.checkOrganizerAsOriginator()
</ins><span class="cx"> 
</span><span class="cx">         # Prevent spoofing when doing reply-like METHODs
</span><span class="cx">         else:
</span><del>-            self.checkAttendeeAsOriginator()
</del><ins>+            return self.checkAttendeeAsOriginator()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def finalChecks(self):
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingfreebusypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/freebusy.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/freebusy.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/freebusy.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -47,6 +47,8 @@
</span><span class="cx"> 
</span><span class="cx"> fbcacher = Memcacher(&quot;FBCache&quot;, pickle=True)
</span><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class FBCacheEntry(object):
</span><span class="cx"> 
</span><span class="cx">     CACHE_DAYS_FLOATING_ADJUST = 1
</span><span class="lines">@@ -212,12 +214,12 @@
</span><span class="cx">     # TODO: actually we by pass altogether by assuming anyone can check anyone else's freebusy
</span><span class="cx"> 
</span><span class="cx">     # May need organizer principal
</span><del>-    organizer_record = calresource.directoryService().recordWithCalendarUserAddress(organizer) if organizer else None
</del><ins>+    organizer_record = (yield calresource.directoryService().recordWithCalendarUserAddress(organizer)) if organizer else None
</ins><span class="cx">     organizer_uid = organizer_record.uid if organizer_record else &quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     # Free busy is per-user
</span><span class="cx">     attendee_uid = calresource.viewerHome().uid()
</span><del>-    attendee_record = calresource.directoryService().recordWithUID(attendee_uid)
</del><ins>+    attendee_record = yield calresource.directoryService().recordWithUID(attendee_uid.decode(&quot;utf-8&quot;))
</ins><span class="cx"> 
</span><span class="cx">     # Get the timezone property from the collection.
</span><span class="cx">     tz = calresource.getTimezone()
</span><span class="lines">@@ -237,7 +239,7 @@
</span><span class="cx">         authz_record = organizer_record
</span><span class="cx">         if hasattr(calresource._txn, &quot;_authz_uid&quot;) and calresource._txn._authz_uid != organizer_uid:
</span><span class="cx">             authz_uid = calresource._txn._authz_uid
</span><del>-            authz_record = calresource.directoryService().recordWithUID(authz_uid)
</del><ins>+            authz_record = yield calresource.directoryService().recordWithUID(authz_uid.decode(&quot;utf-8&quot;))
</ins><span class="cx"> 
</span><span class="cx">         # Check if attendee is also the organizer or the delegate doing the request
</span><span class="cx">         if attendee_uid in (organizer_uid, authz_uid):
</span><span class="lines">@@ -335,7 +337,7 @@
</span><span class="cx">                 if excludeuid:
</span><span class="cx">                     # See if we have a UID match
</span><span class="cx">                     if (excludeuid == uid):
</span><del>-                        test_record = calresource.directoryService().recordWithCalendarUserAddress(test_organizer) if test_organizer else None
</del><ins>+                        test_record = (yield calresource.directoryService().recordWithCalendarUserAddress(test_organizer)) if test_organizer else None
</ins><span class="cx">                         test_uid = test_record.uid if test_record else &quot;&quot;
</span><span class="cx"> 
</span><span class="cx">                         # Check that ORGANIZER's match (security requirement)
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingimipinboundpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/imip/inbound.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/imip/inbound.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/imip/inbound.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -329,9 +329,12 @@
</span><span class="cx">                 toAddr = organizer[7:]
</span><span class="cx">             elif organizer.startswith(&quot;urn:uuid:&quot;):
</span><span class="cx">                 guid = organizer[9:]
</span><del>-                record = self.directory.recordWithGUID(guid)
-                if record and record.emailAddresses:
-                    toAddr = list(record.emailAddresses)[0]
</del><ins>+                record = yield self.directory.recordWithGUID(guid)
+                try:
+                    if record and record.emailAddresses:
+                        toAddr = list(record.emailAddresses)[0]
+                except AttributeError:
+                    pass
</ins><span class="cx"> 
</span><span class="cx">             if toAddr is None:
</span><span class="cx">                 log.error(&quot;Don't have an email address for the organizer; &quot;
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingimplicitpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/implicit.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/implicit.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/implicit.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -297,7 +297,7 @@
</span><span class="cx">         organizer_scheduling = (yield self.isOrganizerScheduling())
</span><span class="cx">         if organizer_scheduling:
</span><span class="cx">             self.state = &quot;organizer&quot;
</span><del>-        elif self.isAttendeeScheduling():
</del><ins>+        elif (yield self.isAttendeeScheduling()):
</ins><span class="cx">             self.state = &quot;attendee&quot;
</span><span class="cx">         elif self.organizer:
</span><span class="cx">             # There is an ORGANIZER that is not this user but no ATTENDEE property for
</span><span class="lines">@@ -365,7 +365,7 @@
</span><span class="cx"> 
</span><span class="cx">         # Get some useful information from the calendar
</span><span class="cx">         yield self.extractCalendarData()
</span><del>-        self.organizerPrincipal = self.calendar_home.directoryService().recordWithCalendarUserAddress(self.organizer)
</del><ins>+        self.organizerPrincipal = yield self.calendar_home.directoryService().recordWithCalendarUserAddress(self.organizer)
</ins><span class="cx">         self.organizerAddress = (yield addressmapping.mapper.getCalendarUser(self.organizer, self.organizerPrincipal))
</span><span class="cx"> 
</span><span class="cx">         # Originator is the organizer in this case
</span><span class="lines">@@ -447,7 +447,7 @@
</span><span class="cx">             self.calendar = calendar_old
</span><span class="cx"> 
</span><span class="cx">         yield self.extractCalendarData()
</span><del>-        self.organizerPrincipal = self.calendar_home.directoryService().recordWithCalendarUserAddress(self.organizer)
</del><ins>+        self.organizerPrincipal = yield self.calendar_home.directoryService().recordWithCalendarUserAddress(self.organizer)
</ins><span class="cx">         self.organizerAddress = (yield addressmapping.mapper.getCalendarUser(self.organizer, self.organizerPrincipal))
</span><span class="cx"> 
</span><span class="cx">         # Originator is the organizer in this case
</span><span class="lines">@@ -479,7 +479,7 @@
</span><span class="cx">         # Get some useful information from the calendar
</span><span class="cx">         yield self.extractCalendarData()
</span><span class="cx"> 
</span><del>-        self.attendeePrincipal = self.calendar_home.directoryService().recordWithUID(self.calendar_home.uid())
</del><ins>+        self.attendeePrincipal = yield self.calendar_home.directoryService().recordWithUID(self.calendar_home.uid().decode(&quot;utf-8&quot;))
</ins><span class="cx">         self.originator = self.attendee = self.attendeePrincipal.canonicalCalendarUserAddress()
</span><span class="cx"> 
</span><span class="cx">         result = (yield self.scheduleWithOrganizer())
</span><span class="lines">@@ -491,7 +491,7 @@
</span><span class="cx">     def extractCalendarData(self):
</span><span class="cx"> 
</span><span class="cx">         # Get the originator who is the owner of the calendar resource being modified
</span><del>-        self.originatorPrincipal = self.calendar_home.directoryService().recordWithUID(self.calendar_home.uid())
</del><ins>+        self.originatorPrincipal = yield self.calendar_home.directoryService().recordWithUID(self.calendar_home.uid().decode(&quot;utf-8&quot;))
</ins><span class="cx"> 
</span><span class="cx">         # Pick the canonical CUA:
</span><span class="cx">         self.originator = self.originatorPrincipal.canonicalCalendarUserAddress()
</span><span class="lines">@@ -555,7 +555,7 @@
</span><span class="cx">             returnValue(False)
</span><span class="cx"> 
</span><span class="cx">         # Organizer must map to a valid principal
</span><del>-        self.organizerPrincipal = self.calendar_home.directoryService().recordWithCalendarUserAddress(self.organizer)
</del><ins>+        self.organizerPrincipal = yield self.calendar_home.directoryService().recordWithCalendarUserAddress(self.organizer)
</ins><span class="cx">         self.organizerAddress = (yield addressmapping.mapper.getCalendarUser(self.organizer, self.organizerPrincipal))
</span><span class="cx">         if not self.organizerPrincipal:
</span><span class="cx">             returnValue(False)
</span><span class="lines">@@ -567,21 +567,22 @@
</span><span class="cx">         returnValue(True)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def isAttendeeScheduling(self):
</span><span class="cx"> 
</span><span class="cx">         # First must have organizer property
</span><span class="cx">         if not self.organizer:
</span><del>-            return False
</del><ins>+            returnValue(False)
</ins><span class="cx"> 
</span><span class="cx">         # Check to see whether any attendee is the owner
</span><span class="cx">         for attendee in self.attendees:
</span><del>-            attendeePrincipal = self.calendar_home.directoryService().recordWithCalendarUserAddress(attendee)
</del><ins>+            attendeePrincipal = yield self.calendar_home.directoryService().recordWithCalendarUserAddress(attendee)
</ins><span class="cx">             if attendeePrincipal and attendeePrincipal.uid == self.calendar_home.uid():
</span><span class="cx">                 self.attendee = attendee
</span><span class="cx">                 self.attendeePrincipal = attendeePrincipal
</span><del>-                return True
</del><ins>+                returnValue(True)
</ins><span class="cx"> 
</span><del>-        return False
</del><ins>+        returnValue(False)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def makeScheduler(self):
</span><span class="lines">@@ -1033,7 +1034,7 @@
</span><span class="cx">             if attendee.parameterValue(&quot;SCHEDULE-AGENT&quot;, &quot;SERVER&quot;).upper() == &quot;CLIENT&quot;:
</span><span class="cx">                 cuaddr = attendee.value()
</span><span class="cx">                 if cuaddr not in coerced:
</span><del>-                    attendeePrincipal = self.calendar_home.directoryService().recordWithCalendarUserAddress(cuaddr)
</del><ins>+                    attendeePrincipal = yield self.calendar_home.directoryService().recordWithCalendarUserAddress(cuaddr)
</ins><span class="cx">                     attendeeAddress = (yield addressmapping.mapper.getCalendarUser(cuaddr, attendeePrincipal))
</span><span class="cx">                     local_attendee = type(attendeeAddress) in (LocalCalendarUser, OtherServerCalendarUser,)
</span><span class="cx">                     coerced[cuaddr] = local_attendee
</span><span class="lines">@@ -1096,7 +1097,7 @@
</span><span class="cx"> 
</span><span class="cx">             # Handle split by not scheduling local attendees
</span><span class="cx">             if self.split_details is not None:
</span><del>-                attendeePrincipal = self.calendar_home.directoryService().recordWithCalendarUserAddress(attendee)
</del><ins>+                attendeePrincipal = yield self.calendar_home.directoryService().recordWithCalendarUserAddress(attendee)
</ins><span class="cx">                 attendeeAddress = (yield addressmapping.mapper.getCalendarUser(attendee, attendeePrincipal))
</span><span class="cx">                 if type(attendeeAddress) is LocalCalendarUser:
</span><span class="cx">                     continue
</span><span class="lines">@@ -1153,7 +1154,7 @@
</span><span class="cx"> 
</span><span class="cx">             # Handle split by not scheduling local attendees
</span><span class="cx">             if self.split_details is not None:
</span><del>-                attendeePrincipal = self.calendar_home.directoryService().recordWithCalendarUserAddress(attendee)
</del><ins>+                attendeePrincipal = yield self.calendar_home.directoryService().recordWithCalendarUserAddress(attendee)
</ins><span class="cx">                 attendeeAddress = (yield addressmapping.mapper.getCalendarUser(attendee, attendeePrincipal))
</span><span class="cx">                 if type(attendeeAddress) is LocalCalendarUser:
</span><span class="cx">                     continue
</span><span class="lines">@@ -1213,7 +1214,7 @@
</span><span class="cx"> 
</span><span class="cx">             # Handle split by not scheduling local attendees
</span><span class="cx">             if self.split_details is not None:
</span><del>-                attendeePrincipal = self.calendar_home.directoryService().recordWithCalendarUserAddress(attendee)
</del><ins>+                attendeePrincipal = yield self.calendar_home.directoryService().recordWithCalendarUserAddress(attendee)
</ins><span class="cx">                 attendeeAddress = (yield addressmapping.mapper.getCalendarUser(attendee, attendeePrincipal))
</span><span class="cx">                 if type(attendeeAddress) is LocalCalendarUser:
</span><span class="cx">                     continue
</span><span class="lines">@@ -1278,7 +1279,7 @@
</span><span class="cx"> 
</span><span class="cx">             # Handle split by not scheduling local attendees
</span><span class="cx">             if self.split_details is not None:
</span><del>-                attendeePrincipal = self.calendar_home.directoryService().recordWithCalendarUserAddress(attendee)
</del><ins>+                attendeePrincipal = yield self.calendar_home.directoryService().recordWithCalendarUserAddress(attendee)
</ins><span class="cx">                 attendeeAddress = (yield addressmapping.mapper.getCalendarUser(attendee, attendeePrincipal))
</span><span class="cx">                 if type(attendeeAddress) is LocalCalendarUser:
</span><span class="cx">                     continue
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingischeduledeliverypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/ischedule/delivery.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/ischedule/delivery.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/ischedule/delivery.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -228,7 +228,7 @@
</span><span class="cx">             # Loop over at most 3 redirects
</span><span class="cx">             ssl, host, port, path = self.server.details()
</span><span class="cx">             for _ignore in xrange(3):
</span><del>-                self._prepareRequest(host, port)
</del><ins>+                yield self._prepareRequest(host, port)
</ins><span class="cx">                 response = (yield self._processRequest(ssl, host, port, path))
</span><span class="cx">                 if response.code not in (responsecode.MOVED_PERMANENTLY, responsecode.TEMPORARY_REDIRECT,):
</span><span class="cx">                     break
</span><span class="lines">@@ -334,16 +334,18 @@
</span><span class="cx">         returnValue(iostr.getvalue())
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def _prepareRequest(self, host, port):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Setup the request for sending. We might need to do this several times
</span><span class="cx">         whilst following redirects.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        component, method = self._prepareData()
-        self._prepareHeaders(host, port, component, method)
</del><ins>+        component, method = (yield self._prepareData())
+        yield self._prepareHeaders(host, port, component, method)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def _prepareHeaders(self, host, port, component, method):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Always generate a new set of headers because the Host may varying during redirects,
</span><span class="lines">@@ -357,7 +359,7 @@
</span><span class="cx">         # The Originator must be the ORGANIZER (for a request) or ATTENDEE (for a reply)
</span><span class="cx">         originator = self.scheduler.organizer.cuaddr if self.scheduler.isiTIPRequest else self.scheduler.attendee
</span><span class="cx">         if self.server.unNormalizeAddresses:
</span><del>-            originator = normalizeCUAddress(originator, normalizationLookup, self.scheduler.txn.directoryService().recordWithCalendarUserAddress, toUUID=False)
</del><ins>+            originator = yield normalizeCUAddress(originator, normalizationLookup, self.scheduler.txn.directoryService().recordWithCalendarUserAddress, toUUID=False)
</ins><span class="cx">         self.headers.addRawHeader(&quot;Originator&quot;, utf8String(originator))
</span><span class="cx">         self.sign_headers.append(&quot;Originator&quot;)
</span><span class="cx"> 
</span><span class="lines">@@ -399,6 +401,7 @@
</span><span class="cx">             self.sign_headers.append(&quot;Authorization&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def _prepareData(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Prepare data via normalization etc. Only need to do this once even when
</span><span class="lines">@@ -411,7 +414,7 @@
</span><span class="cx">             normalizedCalendar = self.scheduler.calendar.duplicate()
</span><span class="cx">             self.original_organizer = normalizedCalendar.getOrganizer()
</span><span class="cx">             if self.server.unNormalizeAddresses:
</span><del>-                normalizedCalendar.normalizeCalendarUserAddresses(
</del><ins>+                yield normalizedCalendar.normalizeCalendarUserAddresses(
</ins><span class="cx">                     normalizationLookup,
</span><span class="cx">                     self.scheduler.txn.directoryService().recordWithCalendarUserAddress,
</span><span class="cx">                     toUUID=False)
</span><span class="lines">@@ -423,12 +426,12 @@
</span><span class="cx">             component = normalizedCalendar.mainType()
</span><span class="cx">             method = normalizedCalendar.propertyValue(&quot;METHOD&quot;)
</span><span class="cx">             self.data = str(normalizedCalendar)
</span><del>-            return component, method
</del><ins>+            returnValue(component, method)
</ins><span class="cx">         else:
</span><span class="cx">             cal = Component.fromString(self.data)
</span><span class="cx">             component = cal.mainType()
</span><span class="cx">             method = cal.propertyValue(&quot;METHOD&quot;)
</span><del>-            return component, method
</del><ins>+            returnValue(component, method)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingischeduleresourcepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/ischedule/resource.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/ischedule/resource.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/ischedule/resource.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -353,11 +353,13 @@
</span><span class="cx">             davxml.Privilege(caldavxml.ScheduleDeliver()),
</span><span class="cx">         )
</span><span class="cx"> 
</span><del>-        return davxml.ACL(
-            # DAV:Read, CalDAV:schedule-deliver for all principals (includes anonymous)
-            davxml.ACE(
-                davxml.Principal(davxml.All()),
-                davxml.Grant(*privs),
-                davxml.Protected(),
-            ),
</del><ins>+        return succeed(
+            davxml.ACL(
+                # DAV:Read, CalDAV:schedule-deliver for all principals (includes anonymous)
+                davxml.ACE(
+                    davxml.Principal(davxml.All()),
+                    davxml.Grant(*privs),
+                    davxml.Protected(),
+                ),
+            )
</ins><span class="cx">         )
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingischeduleschedulerpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/ischedule/scheduler.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/ischedule/scheduler.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/ischedule/scheduler.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -186,7 +186,7 @@
</span><span class="cx">         # Normalize recipient addresses
</span><span class="cx">         results = []
</span><span class="cx">         for recipient in recipients:
</span><del>-            normalized = normalizeCUAddress(recipient, normalizationLookup, self.txn.directoryService().recordWithCalendarUserAddress)
</del><ins>+            normalized = yield normalizeCUAddress(recipient, normalizationLookup, self.txn.directoryService().recordWithCalendarUserAddress)
</ins><span class="cx">             self.recipientsNormalizationMap[normalized] = recipient
</span><span class="cx">             results.append(normalized)
</span><span class="cx">         recipients = results
</span><span class="lines">@@ -205,7 +205,7 @@
</span><span class="cx">         if not self.checkForFreeBusy():
</span><span class="cx">             # Need to normalize the calendar data and recipient values to keep those in sync,
</span><span class="cx">             # as we might later try to match them
</span><del>-            self.calendar.normalizeCalendarUserAddresses(normalizationLookup, self.txn.directoryService().recordWithCalendarUserAddress)
</del><ins>+            return self.calendar.normalizeCalendarUserAddresses(normalizationLookup, self.txn.directoryService().recordWithCalendarUserAddress)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def checkAuthorization(self):
</span><span class="lines">@@ -226,7 +226,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         # For remote requests we do not allow the originator to be a local user or one within our domain.
</span><del>-        originatorPrincipal = self.txn.directoryService().recordWithCalendarUserAddress(self.originator)
</del><ins>+        originatorPrincipal = (yield self.txn.directoryService().recordWithCalendarUserAddress(self.originator))
</ins><span class="cx">         localUser = (yield addressmapping.mapper.isCalendarUserInMyDomain(self.originator))
</span><span class="cx">         if originatorPrincipal or localUser:
</span><span class="cx">             if originatorPrincipal.thisServer():
</span><span class="lines">@@ -367,7 +367,7 @@
</span><span class="cx">         # Verify that the ORGANIZER's cu address does not map to a valid user
</span><span class="cx">         organizer = self.calendar.getOrganizer()
</span><span class="cx">         if organizer:
</span><del>-            organizerPrincipal = self.txn.directoryService().recordWithCalendarUserAddress(organizer)
</del><ins>+            organizerPrincipal = yield self.txn.directoryService().recordWithCalendarUserAddress(organizer)
</ins><span class="cx">             if organizerPrincipal:
</span><span class="cx">                 if organizerPrincipal.thisServer():
</span><span class="cx">                     log.error(&quot;Invalid ORGANIZER in calendar data: %s&quot; % (self.calendar,))
</span><span class="lines">@@ -408,7 +408,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         # Attendee cannot be local.
</span><del>-        attendeePrincipal = self.txn.directoryService().recordWithCalendarUserAddress(self.attendee)
</del><ins>+        attendeePrincipal = yield self.txn.directoryService().recordWithCalendarUserAddress(self.attendee)
</ins><span class="cx">         if attendeePrincipal:
</span><span class="cx">             if attendeePrincipal.thisServer():
</span><span class="cx">                 log.error(&quot;Invalid ATTENDEE in calendar data: %s&quot; % (self.calendar,))
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingprocessingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/processing.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/processing.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/processing.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> from txdav.caldav.datastore.scheduling.work import ScheduleRefreshWork, \
</span><span class="cx">     ScheduleAutoReplyWork
</span><span class="cx"> from txdav.caldav.icalendarstore import ComponentUpdateState, ComponentRemoveState
</span><ins>+from txdav.who.idirectory import AutoScheduleMode
</ins><span class="cx"> 
</span><span class="cx"> import collections
</span><span class="cx"> import hashlib
</span><span class="lines">@@ -58,6 +59,8 @@
</span><span class="cx"> 
</span><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class ImplicitProcessorException(Exception):
</span><span class="cx"> 
</span><span class="cx">     def __init__(self, msg):
</span><span class="lines">@@ -604,19 +607,28 @@
</span><span class="cx">         @param calendar: the iTIP message to process
</span><span class="cx">         @type calendar: L{Component}
</span><span class="cx">         @param automode: the auto-schedule mode for the recipient
</span><del>-        @type automode: C{str}
</del><ins>+        @type automode: L{txdav.who.idirectory.AutoScheduleMode}
</ins><span class="cx"> 
</span><span class="cx">         @return: C{tuple} of C{bool}, C{bool}, C{str} indicating whether changes were made, whether the inbox item
</span><span class="cx">             should be added, and the new PARTSTAT.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-
</del><span class="cx">         # First ignore the none mode
</span><del>-        if automode == &quot;none&quot;:
</del><ins>+        if automode == AutoScheduleMode.none:
</ins><span class="cx">             returnValue((False, True, &quot;&quot;,))
</span><del>-        elif not automode or automode == &quot;default&quot;:
-            automode = config.Scheduling.Options.AutoSchedule.DefaultMode
</del><ins>+        elif not automode:
+            automode = {
+                &quot;none&quot;: AutoScheduleMode.none,
+                &quot;accept-always&quot;: AutoScheduleMode.accept,
+                &quot;decline-always&quot;: AutoScheduleMode.decline,
+                &quot;accept-if-free&quot;: AutoScheduleMode.acceptIfFree,
+                &quot;decline-if-busy&quot;: AutoScheduleMode.declineIfBusy,
+                &quot;automatic&quot;: AutoScheduleMode.acceptIfFreeDeclineIfBusy,
+            }.get(
+                config.Scheduling.Options.AutoSchedule.DefaultMode,
+                &quot;automatic&quot;
+            )
</ins><span class="cx"> 
</span><del>-        log.debug(&quot;ImplicitProcessing - recipient '%s' processing UID: '%s' - checking for auto-reply with mode: %s&quot; % (self.recipient.cuaddr, self.uid, automode,))
</del><ins>+        log.debug(&quot;ImplicitProcessing - recipient '%s' processing UID: '%s' - checking for auto-reply with mode: %s&quot; % (self.recipient.cuaddr, self.uid, automode.name,))
</ins><span class="cx"> 
</span><span class="cx">         cuas = self.recipient.principal.calendarUserAddresses
</span><span class="cx"> 
</span><span class="lines">@@ -704,13 +716,19 @@
</span><span class="cx">         partstat_counts = collections.defaultdict(int)
</span><span class="cx">         for instance in instances.instances.itervalues():
</span><span class="cx">             if instance.partstat == &quot;NEEDS-ACTION&quot; and instance.active:
</span><del>-                if automode == &quot;accept-always&quot;:
</del><ins>+                if automode == AutoScheduleMode.accept:
</ins><span class="cx">                     freePartstat = busyPartstat = &quot;ACCEPTED&quot;
</span><del>-                elif automode == &quot;decline-always&quot;:
</del><ins>+                elif automode == AutoScheduleMode.decline:
</ins><span class="cx">                     freePartstat = busyPartstat = &quot;DECLINED&quot;
</span><span class="cx">                 else:
</span><del>-                    freePartstat = &quot;ACCEPTED&quot; if automode in (&quot;accept-if-free&quot;, &quot;automatic&quot;,) else &quot;NEEDS-ACTION&quot;
-                    busyPartstat = &quot;DECLINED&quot; if automode in (&quot;decline-if-busy&quot;, &quot;automatic&quot;,) else &quot;NEEDS-ACTION&quot;
</del><ins>+                    freePartstat = &quot;ACCEPTED&quot; if automode in (
+                        AutoScheduleMode.acceptIfFree,
+                        AutoScheduleMode.acceptIfFreeDeclineIfBusy,
+                    ) else &quot;NEEDS-ACTION&quot;
+                    busyPartstat = &quot;DECLINED&quot; if automode in (
+                        AutoScheduleMode.declineIfBusy,
+                        AutoScheduleMode.acceptIfFreeDeclineIfBusy,
+                    ) else &quot;NEEDS-ACTION&quot;
</ins><span class="cx">                 instance.partstat = freePartstat if instance.free else busyPartstat
</span><span class="cx">             partstat_counts[instance.partstat] += 1
</span><span class="cx"> 
</span><span class="lines">@@ -901,7 +919,7 @@
</span><span class="cx"> 
</span><span class="cx">         # We only need to fix data that already exists
</span><span class="cx">         if recipient_resource is not None:
</span><del>-            if originator_calendar.mainType() != None:
</del><ins>+            if originator_calendar.mainType() is not None:
</ins><span class="cx">                 yield self.writeCalendarResource(None, recipient_resource, originator_calendar)
</span><span class="cx">             else:
</span><span class="cx">                 yield self.deleteCalendarResource(recipient_resource)
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingschedulerpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/scheduler.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/scheduler.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/scheduler.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -162,7 +162,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         self.calendar = calendar
</span><del>-        self.preProcessCalendarData()
</del><ins>+        yield self.preProcessCalendarData()
</ins><span class="cx"> 
</span><span class="cx">         if self.logItems is not None:
</span><span class="cx">             self.logItems[&quot;recipients&quot;] = len(recipients)
</span><span class="lines">@@ -550,7 +550,7 @@
</span><span class="cx">         results = []
</span><span class="cx">         for recipient in self.recipients:
</span><span class="cx">             # Get the principal resource for this recipient
</span><del>-            principal = self.txn.directoryService().recordWithCalendarUserAddress(recipient)
</del><ins>+            principal = yield self.txn.directoryService().recordWithCalendarUserAddress(recipient)
</ins><span class="cx"> 
</span><span class="cx">             # If no principal we may have a remote recipient but we should check whether
</span><span class="cx">             # the address is one that ought to be on our server and treat that as a missing
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingworkpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/work.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/work.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/work.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -45,6 +45,8 @@
</span><span class="cx"> 
</span><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class ScheduleWorkMixin(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Base class for common schedule work item behavior.
</span><span class="lines">@@ -189,7 +191,7 @@
</span><span class="cx">         try:
</span><span class="cx">             home = (yield self.transaction.calendarHomeWithResourceID(self.homeResourceID))
</span><span class="cx">             resource = (yield home.objectResourceWithID(self.resourceID))
</span><del>-            organizerPrincipal = home.directoryService().recordWithUID(home.uid())
</del><ins>+            organizerPrincipal = yield home.directoryService().recordWithUID(home.uid().decode(&quot;utf-8&quot;))
</ins><span class="cx">             organizer = organizerPrincipal.canonicalCalendarUserAddress()
</span><span class="cx">             calendar_old = Component.fromString(self.icalendarTextOld) if self.icalendarTextOld else None
</span><span class="cx">             calendar_new = Component.fromString(self.icalendarTextNew) if self.icalendarTextNew else None
</span><span class="lines">@@ -311,7 +313,7 @@
</span><span class="cx">         try:
</span><span class="cx">             home = (yield self.transaction.calendarHomeWithResourceID(self.homeResourceID))
</span><span class="cx">             resource = (yield home.objectResourceWithID(self.resourceID))
</span><del>-            attendeePrincipal = home.directoryService().recordWithUID(home.uid())
</del><ins>+            attendeePrincipal = yield home.directoryService().recordWithUID(home.uid().decode(&quot;utf-8&quot;))
</ins><span class="cx">             attendee = attendeePrincipal.canonicalCalendarUserAddress()
</span><span class="cx">             calendar = (yield resource.componentForUser())
</span><span class="cx">             organizer = calendar.validOrganizerForScheduling()
</span><span class="lines">@@ -336,6 +338,7 @@
</span><span class="cx">             self._dequeued()
</span><span class="cx"> 
</span><span class="cx">         except Exception, e:
</span><ins>+            # FIXME: calendar may not be set here!
</ins><span class="cx">             log.debug(&quot;ScheduleReplyWork - exception ID: {id}, UID: '{uid}', {err}&quot;, id=self.workID, uid=calendar.resourceUID(), err=str(e))
</span><span class="cx">             raise
</span><span class="cx">         except:
</span><span class="lines">@@ -381,7 +384,7 @@
</span><span class="cx"> 
</span><span class="cx">         try:
</span><span class="cx">             home = (yield self.transaction.calendarHomeWithResourceID(self.homeResourceID))
</span><del>-            attendeePrincipal = home.directoryService().recordWithUID(home.uid())
</del><ins>+            attendeePrincipal = yield home.directoryService().recordWithUID(home.uid().decode(&quot;utf-8&quot;))
</ins><span class="cx">             attendee = attendeePrincipal.canonicalCalendarUserAddress()
</span><span class="cx">             calendar = Component.fromString(self.icalendarText)
</span><span class="cx">             organizer = calendar.validOrganizerForScheduling()
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/sql.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/sql.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/sql.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1915,14 +1915,14 @@
</span><span class="cx"> 
</span><span class="cx">             # Normalize the calendar user addresses once we know we have valid
</span><span class="cx">             # calendar data
</span><del>-            component.normalizeCalendarUserAddresses(normalizationLookup, self.directoryService().recordWithCalendarUserAddress)
</del><ins>+            yield component.normalizeCalendarUserAddresses(normalizationLookup, self.directoryService().recordWithCalendarUserAddress)
</ins><span class="cx"> 
</span><span class="cx">         # Possible timezone stripping
</span><span class="cx">         if config.EnableTimezonesByReference:
</span><span class="cx">             component.stripKnownTimezones()
</span><span class="cx"> 
</span><span class="cx">         # Check location/resource organizer requirement
</span><del>-        self.validLocationResourceOrganizer(component, inserting, internal_state)
</del><ins>+        yield self.validLocationResourceOrganizer(component, inserting, internal_state)
</ins><span class="cx"> 
</span><span class="cx">         # Check access
</span><span class="cx">         if config.EnablePrivateEvents:
</span><span class="lines">@@ -1986,13 +1986,14 @@
</span><span class="cx">                     raise TooManyAttendeesError(&quot;Attendee list size %d is larger than allowed limit %d&quot; % (attendeeListLength, config.MaxAttendeesPerInstance))
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def validLocationResourceOrganizer(self, component, inserting, internal_state):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         If the calendar owner is a location or resource, check whether an ORGANIZER property is required.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         if internal_state == ComponentUpdateState.NORMAL:
</span><del>-            originatorPrincipal = self.calendar().ownerHome().directoryRecord()
</del><ins>+            originatorPrincipal = yield self.calendar().ownerHome().directoryRecord()
</ins><span class="cx">             cutype = originatorPrincipal.getCUType() if originatorPrincipal is not None else &quot;INDIVIDUAL&quot;
</span><span class="cx">             organizer = component.getOrganizer()
</span><span class="cx"> 
</span><span class="lines">@@ -2009,10 +2010,10 @@
</span><span class="cx"> 
</span><span class="cx">                 # Find current principal and update modified by details
</span><span class="cx">                 if hasattr(self._txn, &quot;_authz_uid&quot;):
</span><del>-                    authz = self.directoryService().recordWithUID(self._txn._authz_uid)
</del><ins>+                    authz = yield self.directoryService().recordWithUID(self._txn._authz_uid.decode(&quot;utf-8&quot;))
</ins><span class="cx">                     prop = Property(&quot;X-CALENDARSERVER-MODIFIED-BY&quot;, authz.canonicalCalendarUserAddress())
</span><span class="cx">                     prop.setParameter(&quot;CN&quot;, authz.displayName())
</span><del>-                    for candidate in authz.calendarUserAddresses:
</del><ins>+                    for candidate in authz.calendarUserAddresses():
</ins><span class="cx">                         if candidate.startswith(&quot;mailto:&quot;):
</span><span class="cx">                             prop.setParameter(&quot;EMAIL&quot;, candidate[7:])
</span><span class="cx">                             break
</span><span class="lines">@@ -2108,7 +2109,7 @@
</span><span class="cx">                 log.debug(&quot;Organizer and attendee properties were entirely removed by the client. Restoring existing properties.&quot;)
</span><span class="cx"> 
</span><span class="cx">                 # Get the originator who is the owner of the calendar resource being modified
</span><del>-                originatorPrincipal = self.calendar().ownerHome().directoryRecord()
</del><ins>+                originatorPrincipal = yield self.calendar().ownerHome().directoryRecord()
</ins><span class="cx">                 originatorAddresses = originatorPrincipal.calendarUserAddresses
</span><span class="cx"> 
</span><span class="cx">                 for component in calendar.subcomponents():
</span><span class="lines">@@ -2145,7 +2146,7 @@
</span><span class="cx">                 log.debug(&quot;Sync COMPLETED property change.&quot;)
</span><span class="cx"> 
</span><span class="cx">                 # Get the originator who is the owner of the calendar resource being modified
</span><del>-                originatorPrincipal = self.calendar().ownerHome().directoryRecord()
</del><ins>+                originatorPrincipal = yield self.calendar().ownerHome().directoryRecord()
</ins><span class="cx">                 originatorAddresses = originatorPrincipal.calendarUserAddresses
</span><span class="cx"> 
</span><span class="cx">                 for component in calendar.subcomponents():
</span><span class="lines">@@ -2264,6 +2265,7 @@
</span><span class="cx">             self._componentChanged = True
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def addStructuredLocation(self, component):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Scan the component for ROOM attendees; if any are associated with an
</span><span class="lines">@@ -2277,12 +2279,12 @@
</span><span class="cx">                     value = attendee.value()
</span><span class="cx">                     if value.startswith(&quot;urn:uuid:&quot;):
</span><span class="cx">                         guid = value[9:]
</span><del>-                        loc = self.directoryService().recordWithGUID(guid)
</del><ins>+                        loc = yield self.directoryService().recordWithGUID(guid)
</ins><span class="cx">                         if loc is not None:
</span><span class="cx">                             guid = loc.extras.get(&quot;associatedAddress&quot;,
</span><span class="cx">                                 None)
</span><span class="cx">                             if guid is not None:
</span><del>-                                addr = self.directoryService().recordWithGUID(guid)
</del><ins>+                                addr = yield self.directoryService().recordWithGUID(guid)
</ins><span class="cx">                                 if addr is not None:
</span><span class="cx">                                     street = addr.extras.get(&quot;streetAddress&quot;, &quot;&quot;)
</span><span class="cx">                                     geo = addr.extras.get(&quot;geo&quot;, &quot;&quot;)
</span><span class="lines">@@ -2539,7 +2541,7 @@
</span><span class="cx">             self.processAlarms(component, inserting)
</span><span class="cx"> 
</span><span class="cx">             # Process structured location
</span><del>-            self.addStructuredLocation(component)
</del><ins>+            yield self.addStructuredLocation(component)
</ins><span class="cx"> 
</span><span class="cx">             # Do scheduling
</span><span class="cx">             implicit_result = (yield self.doImplicitScheduling(component, inserting, internal_state))
</span><span class="lines">@@ -3760,9 +3762,9 @@
</span><span class="cx">             raise InvalidSplit()
</span><span class="cx"> 
</span><span class="cx">         # Cannot be attendee
</span><del>-        ownerPrincipal = self.calendar().ownerHome().directoryRecord()
</del><ins>+        ownerPrincipal = yield self.calendar().ownerHome().directoryRecord()
</ins><span class="cx">         organizer = component.getOrganizer()
</span><del>-        organizerPrincipal = self.directoryService().recordWithCalendarUserAddress(organizer) if organizer else None
</del><ins>+        organizerPrincipal = (yield self.directoryService().recordWithCalendarUserAddress(organizer)) if organizer else None
</ins><span class="cx">         if organizer is not None and organizerPrincipal.uid != ownerPrincipal.uid:
</span><span class="cx">             raise InvalidSplit()
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoretestattachmentsaccountsxml"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/attachments/accounts.xml (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/attachments/accounts.xml        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/attachments/accounts.xml        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -18,19 +18,19 @@
</span><span class="cx"> 
</span><span class="cx"> &lt;!DOCTYPE accounts SYSTEM &quot;../../../conf/auth/accounts.dtd&quot;&gt;
</span><span class="cx"> 
</span><del>-&lt;accounts realm=&quot;/Search&quot;&gt;
-  &lt;user&gt;
</del><ins>+&lt;directory realm=&quot;/Search&quot;&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;home1&lt;/uid&gt;
</span><del>-    &lt;guid&gt;home1&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;home1&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;home1&lt;/password&gt;
</span><del>-    &lt;name&gt;Example User 1&lt;/name&gt;
-    &lt;email-address&gt;home1@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;Example User 1&lt;/full-name&gt;
+    &lt;email&gt;home1@example.com&lt;/email&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;home2&lt;/uid&gt;
</span><del>-    &lt;guid&gt;home2&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;home2&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;home2&lt;/password&gt;
</span><del>-    &lt;name&gt;Example User 2&lt;/name&gt;
-    &lt;email-address&gt;home2@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
-&lt;/accounts&gt;
</del><ins>+    &lt;full-name&gt;Example User 2&lt;/full-name&gt;
+    &lt;email&gt;home2@example.com&lt;/email&gt;
+  &lt;/record&gt;
+&lt;/directory&gt;
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoretesttest_attachmentspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/test_attachments.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/test_attachments.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/test_attachments.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -14,7 +14,7 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><span class="cx"> 
</span><del>-from calendarserver.tap.util import directoryFromConfig
</del><ins>+from txdav.who.util import directoryFromConfig
</ins><span class="cx"> 
</span><span class="cx"> from pycalendar.datetime import DateTime
</span><span class="cx"> from pycalendar.value import Value
</span><span class="lines">@@ -49,7 +49,7 @@
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx"> storePath = FilePath(__file__).parent().child(&quot;calendar_store&quot;)
</span><del>-homeRoot = storePath.child(&quot;ho&quot;).child(&quot;me&quot;).child(&quot;home1&quot;)
</del><ins>+homeRoot = storePath.child(&quot;ho&quot;).child(&quot;me&quot;).child(u&quot;home1&quot;)
</ins><span class="cx"> cal1Root = homeRoot.child(&quot;calendar_1&quot;)
</span><span class="cx"> 
</span><span class="cx"> calendar1_objectNames = [
</span><span class="lines">@@ -597,7 +597,7 @@
</span><span class="cx"> 
</span><span class="cx">         self.assertTrue(os.path.exists(apath))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertNotEqual(quota, 0)
</span><span class="lines">@@ -609,7 +609,7 @@
</span><span class="cx"> 
</span><span class="cx">         self.assertFalse(os.path.exists(apath))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertEqual(quota, 0)
</span><span class="lines">@@ -648,7 +648,7 @@
</span><span class="cx">         self.assertTrue(os.path.exists(apath1))
</span><span class="cx">         self.assertTrue(os.path.exists(apath2))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertNotEqual(quota, 0)
</span><span class="lines">@@ -661,7 +661,7 @@
</span><span class="cx">         self.assertFalse(os.path.exists(apath1))
</span><span class="cx">         self.assertFalse(os.path.exists(apath2))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertEqual(quota, 0)
</span><span class="lines">@@ -743,7 +743,7 @@
</span><span class="cx"> 
</span><span class="cx">         self.assertTrue(os.path.exists(apath))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertNotEqual(quota, 0)
</span><span class="lines">@@ -755,7 +755,7 @@
</span><span class="cx"> 
</span><span class="cx">         self.assertTrue(os.path.exists(apath))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertNotEqual(quota, 0)
</span><span class="lines">@@ -767,7 +767,7 @@
</span><span class="cx"> 
</span><span class="cx">         self.assertFalse(os.path.exists(apath))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertEqual(quota, 0)
</span><span class="lines">@@ -1131,7 +1131,7 @@
</span><span class="cx"> 
</span><span class="cx">         self.assertTrue(os.path.exists(apath))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertNotEqual(quota, 0)
</span><span class="lines">@@ -1143,7 +1143,7 @@
</span><span class="cx"> 
</span><span class="cx">         self.assertFalse(os.path.exists(apath))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertEqual(quota, 0)
</span><span class="lines">@@ -1178,7 +1178,7 @@
</span><span class="cx">         self.assertTrue(os.path.exists(apath1))
</span><span class="cx">         self.assertTrue(os.path.exists(apath2))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertNotEqual(quota, 0)
</span><span class="lines">@@ -1191,7 +1191,7 @@
</span><span class="cx">         self.assertFalse(os.path.exists(apath1))
</span><span class="cx">         self.assertFalse(os.path.exists(apath2))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertEqual(quota, 0)
</span><span class="lines">@@ -1218,7 +1218,7 @@
</span><span class="cx"> 
</span><span class="cx">         self.assertTrue(os.path.exists(apath))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertNotEqual(quota, 0)
</span><span class="lines">@@ -1230,7 +1230,7 @@
</span><span class="cx"> 
</span><span class="cx">         self.assertTrue(os.path.exists(apath))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertNotEqual(quota, 0)
</span><span class="lines">@@ -1242,7 +1242,7 @@
</span><span class="cx"> 
</span><span class="cx">         self.assertFalse(os.path.exists(apath))
</span><span class="cx"> 
</span><del>-        home = (yield self.transactionUnderTest().calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield self.transactionUnderTest().calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         quota = (yield home.quotaUsedBytes())
</span><span class="cx">         yield self.commit()
</span><span class="cx">         self.assertEqual(quota, 0)
</span><span class="lines">@@ -1363,7 +1363,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     requirements = {
</span><del>-        &quot;home1&quot; : {
</del><ins>+        u&quot;home1&quot; : {
</ins><span class="cx">             &quot;calendar1&quot; : {
</span><span class="cx">                 &quot;1.1.ics&quot; : (PLAIN_ICS % {&quot;year&quot;: now, &quot;uid&quot;: &quot;1.1&quot;, }, metadata,),
</span><span class="cx">                 &quot;1.2.ics&quot; : (ATTACHMENT_ICS % {&quot;year&quot;: now, &quot;uid&quot;: &quot;1.2&quot;, &quot;userid&quot;: &quot;user01&quot;, &quot;dropboxid&quot;: &quot;1.2&quot;}, metadata,),
</span><span class="lines">@@ -1372,7 +1372,7 @@
</span><span class="cx">                 &quot;1.5.ics&quot; : (ATTACHMENT_ICS % {&quot;year&quot;: now, &quot;uid&quot;: &quot;1.5&quot;, &quot;userid&quot;: &quot;user01&quot;, &quot;dropboxid&quot;: &quot;1.4&quot;}, metadata,),
</span><span class="cx">             }
</span><span class="cx">         },
</span><del>-        &quot;home2&quot; : {
</del><ins>+        u&quot;home2&quot; : {
</ins><span class="cx">             &quot;calendar2&quot; : {
</span><span class="cx">                 &quot;2-2.1.ics&quot; : (PLAIN_ICS % {&quot;year&quot;: now, &quot;uid&quot;: &quot;2-2.1&quot;, }, metadata,),
</span><span class="cx">                 &quot;2-2.2.ics&quot; : (ATTACHMENT_ICS % {&quot;year&quot;: now, &quot;uid&quot;: &quot;2-2.2&quot;, &quot;userid&quot;: &quot;user02&quot;, &quot;dropboxid&quot;: &quot;2.2&quot;}, metadata,),
</span><span class="lines">@@ -1488,16 +1488,16 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Add the full set of attachments to be used for testing.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        yield self._addAttachment(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, &quot;1.2&quot;, &quot;attach_1_2_1.txt&quot;)
-        yield self._addAttachment(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, &quot;1.2&quot;, &quot;attach_1_2_2.txt&quot;)
-        yield self._addAttachment(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.3.ics&quot;, &quot;1.3&quot;, &quot;attach_1_3.txt&quot;)
-        yield self._addAttachment(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.4.ics&quot;, &quot;1.4&quot;, &quot;attach_1_4.txt&quot;)
-        yield self._addAttachmentProperty(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.5.ics&quot;, &quot;1.4&quot;, &quot;home1&quot;, &quot;attach_1_4.txt&quot;)
</del><ins>+        yield self._addAttachment(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, &quot;1.2&quot;, &quot;attach_1_2_1.txt&quot;)
+        yield self._addAttachment(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, &quot;1.2&quot;, &quot;attach_1_2_2.txt&quot;)
+        yield self._addAttachment(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.3.ics&quot;, &quot;1.3&quot;, &quot;attach_1_3.txt&quot;)
+        yield self._addAttachment(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.4.ics&quot;, &quot;1.4&quot;, &quot;attach_1_4.txt&quot;)
+        yield self._addAttachmentProperty(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.5.ics&quot;, &quot;1.4&quot;, &quot;home1&quot;, &quot;attach_1_4.txt&quot;)
</ins><span class="cx"> 
</span><del>-        yield self._addAttachment(&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.2.ics&quot;, &quot;2.2&quot;, &quot;attach_2_2.txt&quot;)
-        yield self._addAttachmentProperty(&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.3.ics&quot;, &quot;1.3&quot;, &quot;home1&quot;, &quot;attach_1_3.txt&quot;)
-        yield self._addAttachmentProperty(&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.2.ics&quot;, &quot;1.4&quot;, &quot;home1&quot;, &quot;attach_1_4.txt&quot;)
-        yield self._addAttachmentProperty(&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.3.ics&quot;, &quot;1.4&quot;, &quot;home1&quot;, &quot;attach_1_4.txt&quot;)
</del><ins>+        yield self._addAttachment(u&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.2.ics&quot;, &quot;2.2&quot;, &quot;attach_2_2.txt&quot;)
+        yield self._addAttachmentProperty(u&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.3.ics&quot;, &quot;1.3&quot;, &quot;home1&quot;, &quot;attach_1_3.txt&quot;)
+        yield self._addAttachmentProperty(u&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.2.ics&quot;, &quot;1.4&quot;, &quot;home1&quot;, &quot;attach_1_4.txt&quot;)
+        yield self._addAttachmentProperty(u&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.3.ics&quot;, &quot;1.4&quot;, &quot;home1&quot;, &quot;attach_1_4.txt&quot;)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -1586,7 +1586,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Test L{txdav.caldav.datastore.sql.DropboxAttachment.convertToManaged} converts properly to a ManagedAttachment.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        yield self._addAttachment(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, &quot;1.2&quot;, &quot;attach_1_2.txt&quot;)
</del><ins>+        yield self._addAttachment(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, &quot;1.2&quot;, &quot;attach_1_2.txt&quot;)
</ins><span class="cx"> 
</span><span class="cx">         txn = self._sqlCalendarStore.newTransaction()
</span><span class="cx"> 
</span><span class="lines">@@ -1616,11 +1616,11 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Test L{txdav.caldav.datastore.sql.ManagedAttachment.newReference} creates a new managed attachment reference.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        yield self._addAttachment(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.4.ics&quot;, &quot;1.4&quot;, &quot;attach_1_4.txt&quot;)
</del><ins>+        yield self._addAttachment(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.4.ics&quot;, &quot;1.4&quot;, &quot;attach_1_4.txt&quot;)
</ins><span class="cx"> 
</span><span class="cx">         txn = self._sqlCalendarStore.newTransaction()
</span><span class="cx"> 
</span><del>-        home = (yield txn.calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield txn.calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         calendar = (yield home.calendarWithName(&quot;calendar1&quot;))
</span><span class="cx">         event4 = (yield calendar.calendarObjectWithName(&quot;1.4.ics&quot;))
</span><span class="cx">         event5 = (yield calendar.calendarObjectWithName(&quot;1.5.ics&quot;))
</span><span class="lines">@@ -1664,12 +1664,12 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Test L{txdav.caldav.datastore.sql.CalendarObject.convertAttachments} re-writes calendar data.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        yield self._addAttachment(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, &quot;1.2&quot;, &quot;attach_1_2_1.txt&quot;)
-        yield self._addAttachment(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, &quot;1.2&quot;, &quot;attach_1_2_2.txt&quot;)
</del><ins>+        yield self._addAttachment(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, &quot;1.2&quot;, &quot;attach_1_2_1.txt&quot;)
+        yield self._addAttachment(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, &quot;1.2&quot;, &quot;attach_1_2_2.txt&quot;)
</ins><span class="cx"> 
</span><span class="cx">         txn = self._sqlCalendarStore.newTransaction()
</span><span class="cx"> 
</span><del>-        home = (yield txn.calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield txn.calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         calendar = (yield home.calendarWithName(&quot;calendar1&quot;))
</span><span class="cx">         event = (yield calendar.calendarObjectWithName(&quot;1.2.ics&quot;))
</span><span class="cx"> 
</span><span class="lines">@@ -1688,7 +1688,7 @@
</span><span class="cx"> 
</span><span class="cx">         txn = self._sqlCalendarStore.newTransaction()
</span><span class="cx"> 
</span><del>-        home = (yield txn.calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield txn.calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         calendar = (yield home.calendarWithName(&quot;calendar1&quot;))
</span><span class="cx">         event = (yield calendar.calendarObjectWithName(&quot;1.2.ics&quot;))
</span><span class="cx"> 
</span><span class="lines">@@ -1712,7 +1712,7 @@
</span><span class="cx"> 
</span><span class="cx">         # Convert the second dropbox attachment
</span><span class="cx">         txn = self._sqlCalendarStore.newTransaction()
</span><del>-        home = (yield txn.calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield txn.calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         calendar = (yield home.calendarWithName(&quot;calendar1&quot;))
</span><span class="cx">         event = (yield calendar.calendarObjectWithName(&quot;1.2.ics&quot;))
</span><span class="cx">         dattachment = (yield DropBoxAttachment.load(txn, &quot;1.2.dropbox&quot;, &quot;attach_1_2_2.txt&quot;))
</span><span class="lines">@@ -1722,7 +1722,7 @@
</span><span class="cx">         yield txn.commit()
</span><span class="cx"> 
</span><span class="cx">         txn = self._sqlCalendarStore.newTransaction()
</span><del>-        home = (yield txn.calendarHomeWithUID(&quot;home1&quot;))
</del><ins>+        home = (yield txn.calendarHomeWithUID(u&quot;home1&quot;))
</ins><span class="cx">         calendar = (yield home.calendarWithName(&quot;calendar1&quot;))
</span><span class="cx">         event = (yield calendar.calendarObjectWithName(&quot;1.2.ics&quot;))
</span><span class="cx">         component = (yield event.componentForUser()).mainComponent()
</span><span class="lines">@@ -1760,14 +1760,14 @@
</span><span class="cx">         yield calstore._upgradeDropbox(txn, &quot;1.2.dropbox&quot;)
</span><span class="cx">         yield txn.commit()
</span><span class="cx"> 
</span><del>-        yield self._verifyConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, (&quot;attach_1_2_1.txt&quot;, &quot;attach_1_2_2.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.4.ics&quot;, (&quot;attach_1_4.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.5.ics&quot;, (&quot;attach_1_4.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.2.ics&quot;, (&quot;attach_2_2.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.2.ics&quot;, (&quot;attach_1_4.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.3.ics&quot;, (&quot;attach_1_4.txt&quot;,))
</del><ins>+        yield self._verifyConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, (&quot;attach_1_2_1.txt&quot;, &quot;attach_1_2_2.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.4.ics&quot;, (&quot;attach_1_4.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.5.ics&quot;, (&quot;attach_1_4.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.2.ics&quot;, (&quot;attach_2_2.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.2.ics&quot;, (&quot;attach_1_4.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.3.ics&quot;, (&quot;attach_1_4.txt&quot;,))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -1784,14 +1784,14 @@
</span><span class="cx">         yield calstore._upgradeDropbox(txn, &quot;1.3.dropbox&quot;)
</span><span class="cx">         yield txn.commit()
</span><span class="cx"> 
</span><del>-        yield self._verifyNoConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, (&quot;attach_1_2_1.txt&quot;, &quot;attach_1_2_2.txt&quot;,))
-        yield self._verifyConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.4.ics&quot;, (&quot;attach_1_4.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.5.ics&quot;, (&quot;attach_1_4.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.2.ics&quot;, (&quot;attach_2_2.txt&quot;,))
-        yield self._verifyConversion(&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.2.ics&quot;, (&quot;attach_1_4.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.3.ics&quot;, (&quot;attach_1_4.txt&quot;,))
</del><ins>+        yield self._verifyNoConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, (&quot;attach_1_2_1.txt&quot;, &quot;attach_1_2_2.txt&quot;,))
+        yield self._verifyConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.4.ics&quot;, (&quot;attach_1_4.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.5.ics&quot;, (&quot;attach_1_4.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.2.ics&quot;, (&quot;attach_2_2.txt&quot;,))
+        yield self._verifyConversion(u&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.2.ics&quot;, (&quot;attach_1_4.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.3.ics&quot;, (&quot;attach_1_4.txt&quot;,))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -1808,14 +1808,14 @@
</span><span class="cx">         yield calstore._upgradeDropbox(txn, &quot;1.4.dropbox&quot;)
</span><span class="cx">         yield txn.commit()
</span><span class="cx"> 
</span><del>-        yield self._verifyNoConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, (&quot;attach_1_2_1.txt&quot;, &quot;attach_1_2_2.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
-        yield self._verifyConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.4.ics&quot;, (&quot;attach_1_4.txt&quot;,))
-        yield self._verifyConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.5.ics&quot;, (&quot;attach_1_4.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.2.ics&quot;, (&quot;attach_2_2.txt&quot;,))
-        yield self._verifyNoConversion(&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
-        yield self._verifyConversion(&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.2.ics&quot;, (&quot;attach_1_4.txt&quot;,))
-        yield self._verifyConversion(&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.3.ics&quot;, (&quot;attach_1_4.txt&quot;,))
</del><ins>+        yield self._verifyNoConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, (&quot;attach_1_2_1.txt&quot;, &quot;attach_1_2_2.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
+        yield self._verifyConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.4.ics&quot;, (&quot;attach_1_4.txt&quot;,))
+        yield self._verifyConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.5.ics&quot;, (&quot;attach_1_4.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.2.ics&quot;, (&quot;attach_2_2.txt&quot;,))
+        yield self._verifyNoConversion(u&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
+        yield self._verifyConversion(u&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.2.ics&quot;, (&quot;attach_1_4.txt&quot;,))
+        yield self._verifyConversion(u&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.3.ics&quot;, (&quot;attach_1_4.txt&quot;,))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -1830,14 +1830,14 @@
</span><span class="cx">         calstore = CalendarStoreFeatures(self._sqlCalendarStore)
</span><span class="cx">         yield calstore.upgradeToManagedAttachments(2)
</span><span class="cx"> 
</span><del>-        yield self._verifyConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, (&quot;attach_1_2_1.txt&quot;, &quot;attach_1_2_2.txt&quot;,))
-        yield self._verifyConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
-        yield self._verifyConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.4.ics&quot;, (&quot;attach_1_4.txt&quot;,))
-        yield self._verifyConversion(&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.5.ics&quot;, (&quot;attach_1_4.txt&quot;,))
-        yield self._verifyConversion(&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.2.ics&quot;, (&quot;attach_2_2.txt&quot;,))
-        yield self._verifyConversion(&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
-        yield self._verifyConversion(&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.2.ics&quot;, (&quot;attach_1_4.txt&quot;,))
-        yield self._verifyConversion(&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.3.ics&quot;, (&quot;attach_1_4.txt&quot;,))
</del><ins>+        yield self._verifyConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.2.ics&quot;, (&quot;attach_1_2_1.txt&quot;, &quot;attach_1_2_2.txt&quot;,))
+        yield self._verifyConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
+        yield self._verifyConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.4.ics&quot;, (&quot;attach_1_4.txt&quot;,))
+        yield self._verifyConversion(u&quot;home1&quot;, &quot;calendar1&quot;, &quot;1.5.ics&quot;, (&quot;attach_1_4.txt&quot;,))
+        yield self._verifyConversion(u&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.2.ics&quot;, (&quot;attach_2_2.txt&quot;,))
+        yield self._verifyConversion(u&quot;home2&quot;, &quot;calendar2&quot;, &quot;2-2.3.ics&quot;, (&quot;attach_1_3.txt&quot;,))
+        yield self._verifyConversion(u&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.2.ics&quot;, (&quot;attach_1_4.txt&quot;,))
+        yield self._verifyConversion(u&quot;home2&quot;, &quot;calendar3&quot;, &quot;2-3.3.ics&quot;, (&quot;attach_1_4.txt&quot;,))
</ins><span class="cx"> 
</span><span class="cx">         # Paths do not exist
</span><span class="cx">         for path in self.paths.values():
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoretestutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/util.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/util.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/util.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -16,7 +16,7 @@
</span><span class="cx"> ##
</span><span class="cx"> from twisted.trial.unittest import TestCase
</span><span class="cx"> from twext.python.clsprop import classproperty
</span><del>-from twisted.internet.defer import inlineCallbacks
</del><ins>+from twisted.internet.defer import inlineCallbacks, succeed
</ins><span class="cx"> 
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> Store test utility functions
</span><span class="lines">@@ -40,7 +40,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def recordWithCalendarUserAddress(self, cuaddr):
</span><del>-        return self.recordsByCUA.get(cuaddr)
</del><ins>+        return succeed(self.recordsByCUA.get(cuaddr))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def addRecord(self, record):
</span><span class="lines">@@ -117,7 +117,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def isProxyFor(self, other):
</span><del>-        return False
</del><ins>+        return succeed(False)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/util.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/util.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/util.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -100,6 +100,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+@inlineCallbacks
</ins><span class="cx"> def normalizationLookup(cuaddr, recordFunction, config):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Lookup function to be passed to ical.normalizeCalendarUserAddresses.
</span><span class="lines">@@ -108,23 +109,25 @@
</span><span class="cx">     record for the cuaddr.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     try:
</span><del>-        record = recordFunction(cuaddr)
</del><ins>+        record = yield recordFunction(cuaddr)
</ins><span class="cx">     except Exception, e:
</span><span class="cx">         log.debug(&quot;Lookup of %s failed: %s&quot; % (cuaddr, e))
</span><span class="cx">         record = None
</span><span class="cx"> 
</span><span class="cx">     if record is None:
</span><del>-        return (None, None, None)
</del><ins>+        returnValue((None, None, None))
</ins><span class="cx">     else:
</span><span class="cx">         # RFC5545 syntax does not allow backslash escaping in
</span><span class="cx">         # parameter values. A double-quote is thus not allowed
</span><span class="cx">         # in a parameter value except as the start/end delimiters.
</span><span class="cx">         # Single quotes are allowed, so we convert any double-quotes
</span><span class="cx">         # to single-quotes.
</span><del>-        return (
-            record.fullName.replace('&quot;', &quot;'&quot;),
-            record.uid,
-            record.calendarUserAddresses,
</del><ins>+        returnValue(
+            (
+                record.displayName.replace('&quot;', &quot;'&quot;),
+                record.uid,
+                record.calendarUserAddresses,
+            )
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavicalendardirectoryservicepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/icalendardirectoryservice.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/icalendardirectoryservice.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/icalendardirectoryservice.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -37,8 +37,8 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Return the record for the specified calendar user address.
</span><span class="cx"> 
</span><del>-        @return: the record.
-        @rtype: L{ICalendarStoreDirectoryRecord}
</del><ins>+        @return: Deferred resulting in the record.
+        @rtype: L{Deferred} resulting in L{ICalendarStoreDirectoryRecord}
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcommondatastorefilepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/file.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/file.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/file.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -700,7 +700,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def directoryRecord(self):
</span><del>-        return self.directoryService().recordWithUID(self.uid())
</del><ins>+        return self.directoryService().recordWithUID(self.uid().decode(&quot;utf-8&quot;))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def retrieveOldShares(self):
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcommondatastorepoddingconduitpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/podding/conduit.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/podding/conduit.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/podding/conduit.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -76,32 +76,33 @@
</span><span class="cx">         self.store = store
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def validRequst(self, source_guid, destination_guid):
</del><ins>+    @inlineCallbacks
+    def validRequest(self, source_uid, destination_uid):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        Verify that the specified GUIDs are valid for the request and return the
</del><ins>+        Verify that the specified uids are valid for the request and return the
</ins><span class="cx">         matching directory records.
</span><span class="cx"> 
</span><del>-        @param source_guid: GUID for the user on whose behalf the request is being made
-        @type source_guid: C{str}
-        @param destination_guid: GUID for the user to whom the request is being sent
-        @type destination_guid: C{str}
</del><ins>+        @param source_uid: UID for the user on whose behalf the request is being made
+        @type source_uid: C{str}
+        @param destination_uid: UID for the user to whom the request is being sent
+        @type destination_uid: C{str}
</ins><span class="cx"> 
</span><del>-        @return: C{tuple} of L{IStoreDirectoryRecord}
</del><ins>+        @return: L{Deferred} resulting in C{tuple} of L{IStoreDirectoryRecord}
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        source = self.store.directoryService().recordWithUID(source_guid)
</del><ins>+        source = yield self.store.directoryService().recordWithUID(source_uid)
</ins><span class="cx">         if source is None:
</span><del>-            raise DirectoryRecordNotFoundError(&quot;Cross-pod source: {}&quot;.format(source_guid))
</del><ins>+            raise DirectoryRecordNotFoundError(&quot;Cross-pod source: {}&quot;.format(source_uid))
</ins><span class="cx">         if not source.thisServer():
</span><del>-            raise FailedCrossPodRequestError(&quot;Cross-pod source not on this server: {}&quot;.format(source_guid))
</del><ins>+            raise FailedCrossPodRequestError(&quot;Cross-pod source not on this server: {}&quot;.format(source_uid))
</ins><span class="cx"> 
</span><del>-        destination = self.store.directoryService().recordWithUID(destination_guid)
</del><ins>+        destination = yield self.store.directoryService().recordWithUID(destination_uid)
</ins><span class="cx">         if destination is None:
</span><del>-            raise DirectoryRecordNotFoundError(&quot;Cross-pod destination: {}&quot;.format(destination_guid))
</del><ins>+            raise DirectoryRecordNotFoundError(&quot;Cross-pod destination: {}&quot;.format(destination_uid))
</ins><span class="cx">         if destination.thisServer():
</span><del>-            raise FailedCrossPodRequestError(&quot;Cross-pod destination on this server: {}&quot;.format(destination_guid))
</del><ins>+            raise FailedCrossPodRequestError(&quot;Cross-pod destination on this server: {}&quot;.format(destination_uid))
</ins><span class="cx"> 
</span><del>-        return (source, destination,)
</del><ins>+        returnValue((source, destination,))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -166,13 +167,13 @@
</span><span class="cx"> 
</span><span class="cx">         @param homeType: Type of home being shared.
</span><span class="cx">         @type homeType: C{int}
</span><del>-        @param ownerUID: GUID of the sharer.
</del><ins>+        @param ownerUID: UID of the sharer.
</ins><span class="cx">         @type ownerUID: C{str}
</span><span class="cx">         @param ownerID: resource ID of the sharer calendar
</span><span class="cx">         @type ownerID: C{int}
</span><span class="cx">         @param ownerName: owner's name of the sharer calendar
</span><span class="cx">         @type ownerName: C{str}
</span><del>-        @param shareeUID: GUID of the sharee
</del><ins>+        @param shareeUID: UID of the sharee
</ins><span class="cx">         @type shareeUID: C{str}
</span><span class="cx">         @param shareUID: Resource/invite ID for sharee
</span><span class="cx">         @type shareUID: C{str}
</span><span class="lines">@@ -186,7 +187,7 @@
</span><span class="cx">         @type supported_components: C{str}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        _ignore_sender, recipient = self.validRequst(ownerUID, shareeUID)
</del><ins>+        _ignore_sender, recipient = yield self.validRequest(ownerUID, shareeUID)
</ins><span class="cx"> 
</span><span class="cx">         action = {
</span><span class="cx">             &quot;action&quot;: &quot;shareinvite&quot;,
</span><span class="lines">@@ -250,17 +251,17 @@
</span><span class="cx"> 
</span><span class="cx">         @param homeType: Type of home being shared.
</span><span class="cx">         @type homeType: C{int}
</span><del>-        @param ownerUID: GUID of the sharer.
</del><ins>+        @param ownerUID: UID of the sharer.
</ins><span class="cx">         @type ownerUID: C{str}
</span><span class="cx">         @param ownerID: resource ID of the sharer calendar
</span><span class="cx">         @type ownerID: C{int}
</span><del>-        @param shareeUID: GUID of the sharee
</del><ins>+        @param shareeUID: UID of the sharee
</ins><span class="cx">         @type shareeUID: C{str}
</span><span class="cx">         @param shareUID: Resource/invite ID for sharee
</span><span class="cx">         @type shareUID: C{str}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        _ignore_sender, recipient = self.validRequst(ownerUID, shareeUID)
</del><ins>+        _ignore_sender, recipient = yield self.validRequest(ownerUID, shareeUID)
</ins><span class="cx"> 
</span><span class="cx">         action = {
</span><span class="cx">             &quot;action&quot;: &quot;shareuninvite&quot;,
</span><span class="lines">@@ -313,9 +314,9 @@
</span><span class="cx"> 
</span><span class="cx">         @param homeType: Type of home being shared.
</span><span class="cx">         @type homeType: C{int}
</span><del>-        @param ownerUID: GUID of the sharer.
</del><ins>+        @param ownerUID: UID of the sharer.
</ins><span class="cx">         @type ownerUID: C{str}
</span><del>-        @param shareeUID: GUID of the recipient
</del><ins>+        @param shareeUID: UID of the recipient
</ins><span class="cx">         @type shareeUID: C{str}
</span><span class="cx">         @param shareUID: Resource/invite ID for recipient
</span><span class="cx">         @type shareUID: C{str}
</span><span class="lines">@@ -325,7 +326,7 @@
</span><span class="cx">         @type summary: C{str}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        _ignore_sender, recipient = self.validRequst(shareeUID, ownerUID)
</del><ins>+        _ignore_sender, recipient = yield self.validRequest(shareeUID, ownerUID)
</ins><span class="cx"> 
</span><span class="cx">         action = {
</span><span class="cx">             &quot;action&quot;: &quot;sharereply&quot;,
</span><span class="lines">@@ -398,7 +399,7 @@
</span><span class="cx"> 
</span><span class="cx">         actionName = &quot;add-attachment&quot;
</span><span class="cx">         shareeView = objectResource._parentCollection
</span><del>-        action, recipient = self._send(actionName, shareeView, objectResource)
</del><ins>+        action, recipient = yield self._send(actionName, shareeView, objectResource)
</ins><span class="cx">         action[&quot;rids&quot;] = rids
</span><span class="cx">         action[&quot;filename&quot;] = filename
</span><span class="cx">         result = yield self.sendRequest(shareeView._txn, recipient, action, stream, content_type)
</span><span class="lines">@@ -458,7 +459,7 @@
</span><span class="cx"> 
</span><span class="cx">         actionName = &quot;update-attachment&quot;
</span><span class="cx">         shareeView = objectResource._parentCollection
</span><del>-        action, recipient = self._send(actionName, shareeView, objectResource)
</del><ins>+        action, recipient = yield self._send(actionName, shareeView, objectResource)
</ins><span class="cx">         action[&quot;managedID&quot;] = managed_id
</span><span class="cx">         action[&quot;filename&quot;] = filename
</span><span class="cx">         result = yield self.sendRequest(shareeView._txn, recipient, action, stream, content_type)
</span><span class="lines">@@ -514,7 +515,7 @@
</span><span class="cx"> 
</span><span class="cx">         actionName = &quot;remove-attachment&quot;
</span><span class="cx">         shareeView = objectResource._parentCollection
</span><del>-        action, recipient = self._send(actionName, shareeView, objectResource)
</del><ins>+        action, recipient = yield self._send(actionName, shareeView, objectResource)
</ins><span class="cx">         action[&quot;rids&quot;] = rids
</span><span class="cx">         action[&quot;managedID&quot;] = managed_id
</span><span class="cx">         result = yield self.sendRequest(shareeView._txn, recipient, action)
</span><span class="lines">@@ -557,6 +558,7 @@
</span><span class="cx">     # Sharer data access related apis
</span><span class="cx">     #
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def _send(self, action, parent, child=None):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Base behavior for an operation on a L{CommonHomeChild}.
</span><span class="lines">@@ -570,7 +572,7 @@
</span><span class="cx">         ownerID = parent.external_id()
</span><span class="cx">         shareeUID = parent.viewerHome().uid()
</span><span class="cx"> 
</span><del>-        _ignore_sender, recipient = self.validRequst(shareeUID, ownerUID)
</del><ins>+        _ignore_sender, recipient = yield self.validRequest(shareeUID, ownerUID)
</ins><span class="cx"> 
</span><span class="cx">         result = {
</span><span class="cx">             &quot;action&quot;: action,
</span><span class="lines">@@ -581,7 +583,7 @@
</span><span class="cx">         }
</span><span class="cx">         if child is not None:
</span><span class="cx">             result[&quot;resource_id&quot;] = child.id()
</span><del>-        return result, recipient
</del><ins>+        returnValue((result, recipient))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -644,7 +646,7 @@
</span><span class="cx">         @type kwargs: C{dict}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        action, recipient = self._send(actionName, shareeView, objectResource)
</del><ins>+        action, recipient = yield self._send(actionName, shareeView, objectResource)
</ins><span class="cx">         if args is not None:
</span><span class="cx">             action[&quot;arguments&quot;] = args
</span><span class="cx">         if kwargs is not None:
</span><span class="lines">@@ -710,7 +712,7 @@
</span><span class="cx">         servertoserver,
</span><span class="cx">         event_details,
</span><span class="cx">     ):
</span><del>-        action, recipient = self._send(&quot;freebusy&quot;, calresource)
</del><ins>+        action, recipient = yield self._send(&quot;freebusy&quot;, calresource)
</ins><span class="cx">         action[&quot;timerange&quot;] = [timerange.start.getText(), timerange.end.getText()]
</span><span class="cx">         action[&quot;matchtotal&quot;] = matchtotal
</span><span class="cx">         action[&quot;excludeuid&quot;] = excludeuid
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcommondatastorepoddingresourcepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/podding/resource.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/podding/resource.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/podding/resource.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -179,11 +179,13 @@
</span><span class="cx">             davxml.Privilege(davxml.Read()),
</span><span class="cx">         )
</span><span class="cx"> 
</span><del>-        return davxml.ACL(
-            # DAV:Read for all principals (includes anonymous)
-            davxml.ACE(
-                davxml.Principal(davxml.All()),
-                davxml.Grant(*privs),
-                davxml.Protected(),
-            ),
</del><ins>+        return succeed(
+            davxml.ACL(
+                # DAV:Read for all principals (includes anonymous)
+                davxml.ACE(
+                    davxml.Principal(davxml.All()),
+                    davxml.Grant(*privs),
+                    davxml.Protected(),
+                ),
+            )
</ins><span class="cx">         )
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcommondatastorepoddingtesttest_conduitpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/podding/test/test_conduit.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/podding/test/test_conduit.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/podding/test/test_conduit.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -123,29 +123,41 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def test_validRequst(self):
</del><ins>+    @inlineCallbacks
+    def test_validRequest(self):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Cross-pod request fails when there is no shared secret header present.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         conduit = PoddingConduit(self.storeUnderTest())
</span><del>-        r1, r2 = conduit.validRequst(&quot;user01&quot;, &quot;puser02&quot;)
</del><ins>+        r1, r2 = yield conduit.validRequest(&quot;user01&quot;, &quot;puser02&quot;)
</ins><span class="cx">         self.assertTrue(r1 is not None)
</span><span class="cx">         self.assertTrue(r2 is not None)
</span><span class="cx"> 
</span><del>-        self.assertRaises(DirectoryRecordNotFoundError, conduit.validRequst, &quot;bogus01&quot;, &quot;user02&quot;)
-        self.assertRaises(DirectoryRecordNotFoundError, conduit.validRequst, &quot;user01&quot;, &quot;bogus02&quot;)
-        self.assertRaises(FailedCrossPodRequestError, conduit.validRequst, &quot;user01&quot;, &quot;user02&quot;)
</del><ins>+        self.assertFailure(
+            conduit.validRequest(&quot;bogus01&quot;, &quot;user02&quot;),
+            DirectoryRecordNotFoundError
+        )
</ins><span class="cx"> 
</span><ins>+        self.assertFailure(
+            conduit.validRequest(&quot;user01&quot;, &quot;bogus02&quot;),
+            DirectoryRecordNotFoundError
+        )
</ins><span class="cx"> 
</span><ins>+        self.assertFailure(
+            conduit.validRequest(&quot;user01&quot;, &quot;user02&quot;),
+            FailedCrossPodRequestError
+        )
</ins><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class TestConduitToConduit(MultiStoreConduitTest):
</span><span class="cx"> 
</span><span class="cx">     class FakeConduit(PoddingConduit):
</span><span class="cx"> 
</span><span class="cx">         @inlineCallbacks
</span><span class="cx">         def send_fake(self, txn, ownerUID, shareeUID):
</span><del>-            _ignore_owner, sharee = self.validRequst(ownerUID, shareeUID)
</del><ins>+            _ignore_owner, sharee = yield self.validRequest(ownerUID, shareeUID)
</ins><span class="cx">             action = {
</span><span class="cx">                 &quot;action&quot;: &quot;fake&quot;,
</span><span class="cx">                 &quot;echo&quot;: &quot;bravo&quot;
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcommondatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/sql.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/sql.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/sql.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -211,6 +211,10 @@
</span><span class="cx">         return self._directoryService
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def setDirectoryService(self, directoryService):
+        self._directoryService = directoryService
+
+
</ins><span class="cx">     def callWithNewTransactions(self, callback):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Registers a method to be called whenever a new transaction is
</span><span class="lines">@@ -922,102 +926,164 @@
</span><span class="cx">     @classproperty
</span><span class="cx">     def _addGroupQuery(cls):
</span><span class="cx">         gr = schema.GROUPS
</span><del>-        return Insert({gr.NAME: Parameter(&quot;name&quot;),
-                       gr.GROUP_GUID: Parameter(&quot;groupGUID&quot;),
-                       gr.MEMBERSHIP_HASH: Parameter(&quot;membershipHash&quot;)},
-                       Return=gr.GROUP_ID)
</del><ins>+        return Insert(
+            {
+                gr.NAME: Parameter(&quot;name&quot;),
+                gr.GROUP_GUID: Parameter(&quot;groupUID&quot;),
+                gr.MEMBERSHIP_HASH: Parameter(&quot;membershipHash&quot;)
+            },
+            Return=gr.GROUP_ID
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><span class="cx">     def _updateGroupQuery(cls):
</span><span class="cx">         gr = schema.GROUPS
</span><del>-        return Update({gr.MEMBERSHIP_HASH: Parameter(&quot;membershipHash&quot;),
-            gr.NAME: Parameter(&quot;name&quot;), gr.MODIFIED: Parameter(&quot;timestamp&quot;)},
-            Where=(gr.GROUP_GUID == Parameter(&quot;groupGUID&quot;)))
</del><ins>+        return Update(
+            {
+                gr.MEMBERSHIP_HASH: Parameter(&quot;membershipHash&quot;),
+                gr.NAME: Parameter(&quot;name&quot;),
+                gr.MODIFIED:
+                Parameter(&quot;timestamp&quot;)
+            },
+            Where=(gr.GROUP_GUID == Parameter(&quot;groupUID&quot;))
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _groupByGUID(cls):
</del><ins>+    def _groupByUID(cls):
</ins><span class="cx">         gr = schema.GROUPS
</span><del>-        return Select([gr.GROUP_ID, gr.NAME, gr.MEMBERSHIP_HASH], From=gr,
-                Where=(
-                    gr.GROUP_GUID == Parameter(&quot;groupGUID&quot;)
-                )
-            )
</del><ins>+        return Select(
+            [gr.GROUP_ID, gr.NAME, gr.MEMBERSHIP_HASH],
+            From=gr,
+            Where=(gr.GROUP_GUID == Parameter(&quot;groupUID&quot;))
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><span class="cx">     def _groupByID(cls):
</span><span class="cx">         gr = schema.GROUPS
</span><del>-        return Select([gr.GROUP_GUID, gr.NAME, gr.MEMBERSHIP_HASH], From=gr,
-                Where=(
-                    gr.GROUP_ID == Parameter(&quot;groupID&quot;)
-                )
-            )
</del><ins>+        return Select(
+            [gr.GROUP_GUID, gr.NAME, gr.MEMBERSHIP_HASH],
+            From=gr,
+            Where=(gr.GROUP_ID == Parameter(&quot;groupID&quot;))
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><span class="cx">     def _deleteGroup(cls):
</span><span class="cx">         gr = schema.GROUPS
</span><del>-        return Delete(From=gr,
-              Where=(gr.GROUP_ID == Parameter(&quot;groupID&quot;)))
</del><ins>+        return Delete(
+            From=gr,
+            Where=(gr.GROUP_ID == Parameter(&quot;groupID&quot;))
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def addGroup(self, groupGUID, name, membershipHash):
</del><ins>+    def addGroup(self, groupUID, name, membershipHash):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        @type groupGUID: C{UUID}
</del><ins>+        @type groupUID: C{unicode}
+        @type name: C{unicode}
+        @type membershipHash: C{str}
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        return self._addGroupQuery.on(self, name=name,
-            groupGUID=str(groupGUID), membershipHash=membershipHash)
</del><ins>+        return self._addGroupQuery.on(
+            self,
+            name=name.encode(&quot;utf-8&quot;),
+            groupUID=groupUID.encode(&quot;utf-8&quot;),
+            membershipHash=membershipHash
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def updateGroup(self, groupGUID, name, membershipHash):
</del><ins>+    def updateGroup(self, groupUID, name, membershipHash):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        @type groupGUID: C{UUID}
</del><ins>+        @type groupUID: C{unicode}
+        @type name: C{unicode}
+        @type membershipHash: C{str}
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         timestamp = datetime.datetime.utcnow()
</span><del>-        return self._updateGroupQuery.on(self, name=name,
-            groupGUID=str(groupGUID), timestamp=timestamp,
-            membershipHash=membershipHash)
</del><ins>+        return self._updateGroupQuery.on(
+            self,
+            name=name.encode(&quot;utf-8&quot;),
+            groupUID=groupUID.encode(&quot;utf-8&quot;),
+            timestamp=timestamp,
+            membershipHash=membershipHash
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def groupByGUID(self, groupGUID):
</del><ins>+    def groupByUID(self, groupUID):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        @type groupGUID: C{UUID}
</del><ins>+        Return or create a record for the group UID.
+
+        @type groupUID: C{unicode}
+
+        @return: Deferred firing with tuple of group ID C{str}, group name
+            C{unicode}, and membership hash C{str}
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        results = (yield self._groupByGUID.on(self, groupGUID=str(groupGUID)))
</del><ins>+        results = (
+            yield self._groupByUID.on(
+                self, groupUID=groupUID.encode(&quot;utf-8&quot;)
+            )
+        )
</ins><span class="cx">         if results:
</span><del>-            returnValue(results[0])
</del><ins>+            returnValue((
+                results[0][0],  # group id
+                results[0][1].decode(&quot;utf-8&quot;),  # name
+                results[0][2],  # membership hash
+            ))
</ins><span class="cx">         else:
</span><del>-            savepoint = SavepointAction(&quot;groupByGUID&quot;)
</del><ins>+            savepoint = SavepointAction(&quot;groupByUID&quot;)
</ins><span class="cx">             yield savepoint.acquire(self)
</span><span class="cx">             try:
</span><del>-                yield self.addGroup(groupGUID, &quot;&quot;, &quot;&quot;)
</del><ins>+                yield self.addGroup(groupUID, u&quot;&quot;, &quot;&quot;)
</ins><span class="cx">             except Exception:
</span><span class="cx">                 yield savepoint.rollback(self)
</span><del>-                results = (yield self._groupByGUID.on(self,
-                    groupGUID=str(groupGUID)))
</del><ins>+                results = (
+                    yield self._groupByUID.on(
+                        self, groupUID=groupUID.encode(&quot;utf-8&quot;)
+                    )
+                )
</ins><span class="cx">                 if results:
</span><del>-                    returnValue(results[0])
</del><ins>+                    returnValue((
+                        results[0][0],  # group id
+                        results[0][1].decode(&quot;utf-8&quot;),  # name
+                        results[0][2],  # membership hash
+                    ))
</ins><span class="cx">                 else:
</span><span class="cx">                     raise
</span><span class="cx">             else:
</span><span class="cx">                 yield savepoint.release(self)
</span><del>-                results = (yield self._groupByGUID.on(self,
-                    groupGUID=str(groupGUID)))
</del><ins>+                results = (
+                    yield self._groupByUID.on(
+                        self, groupUID=groupUID.encode(&quot;utf-8&quot;)
+                    )
+                )
</ins><span class="cx">                 if results:
</span><del>-                    returnValue(results[0])
</del><ins>+                    returnValue((
+                        results[0][0],  # group id
+                        results[0][1].decode(&quot;utf-8&quot;),  # name
+                        results[0][2],  # membership hash
+                    ))
</ins><span class="cx">                 else:
</span><span class="cx">                     raise
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def groupByID(self, groupID):
</span><ins>+        &quot;&quot;&quot;
+        Given a group ID, return the group UID, or raise NotFoundError
+
+        @type groupID: C{str}
+        @return: Deferred firing with a tuple of group UID C{unicode},
+            group name C{unicode}, and membership hash C{str}
+        &quot;&quot;&quot;
</ins><span class="cx">         try:
</span><span class="cx">             results = (yield self._groupByID.on(self, groupID=groupID))[0]
</span><span class="cx">             if results:
</span><del>-                results = [UUID(&quot;urn:uuid:&quot; + results[0])] + results[1:]
</del><ins>+                results = (
+                    results[0].decode(&quot;utf-8&quot;),
+                    results[1].decode(&quot;utf-8&quot;),
+                    results[2]
+                )
</ins><span class="cx">             returnValue(results)
</span><span class="cx">         except IndexError:
</span><span class="cx">             raise NotFoundError
</span><span class="lines">@@ -1037,7 +1103,7 @@
</span><span class="cx">         return Insert(
</span><span class="cx">             {
</span><span class="cx">                 gm.GROUP_ID: Parameter(&quot;groupID&quot;),
</span><del>-                gm.MEMBER_GUID: Parameter(&quot;memberGUID&quot;)
</del><ins>+                gm.MEMBER_GUID: Parameter(&quot;memberUID&quot;)
</ins><span class="cx">             }
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="lines">@@ -1050,7 +1116,7 @@
</span><span class="cx">             Where=(
</span><span class="cx">                 gm.GROUP_ID == Parameter(&quot;groupID&quot;)
</span><span class="cx">             ).And(
</span><del>-                gm.MEMBER_GUID == Parameter(&quot;memberGUID&quot;)
</del><ins>+                gm.MEMBER_GUID == Parameter(&quot;memberUID&quot;)
</ins><span class="cx">             )
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="lines">@@ -1069,25 +1135,35 @@
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><span class="cx">     def _selectGroupsForQuery(cls):
</span><ins>+        gr = schema.GROUPS
</ins><span class="cx">         gm = schema.GROUP_MEMBERSHIP
</span><ins>+
</ins><span class="cx">         return Select(
</span><del>-            [gm.GROUP_ID],
-            From=gm,
</del><ins>+            [gr.GROUP_GUID],
+            From=gr,
</ins><span class="cx">             Where=(
</span><del>-                gm.MEMBER_GUID == Parameter(&quot;guid&quot;)
</del><ins>+                gr.GROUP_ID.In(
+                    Select(
+                        [gm.GROUP_ID],
+                        From=gm,
+                        Where=(
+                            gm.MEMBER_GUID == Parameter(&quot;uid&quot;)
+                        )
+                    )
+                )
</ins><span class="cx">             )
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def addMemberToGroup(self, memberGUID, groupID):
</del><ins>+    def addMemberToGroup(self, memberUID, groupID):
</ins><span class="cx">         return self._addMemberToGroupQuery.on(
</span><del>-            self, groupID=groupID, memberGUID=str(memberGUID)
</del><ins>+            self, groupID=groupID, memberUID=memberUID.encode(&quot;utf-8&quot;)
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def removeMemberFromGroup(self, memberGUID, groupID):
</del><ins>+    def removeMemberFromGroup(self, memberUID, groupID):
</ins><span class="cx">         return self._removeMemberFromGroupQuery.on(
</span><del>-            self, groupID=groupID, memberGUID=str(memberGUID)
</del><ins>+            self, groupID=groupID, memberUID=memberUID.encode(&quot;utf-8&quot;)
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -1107,25 +1183,29 @@
</span><span class="cx">         members = set()
</span><span class="cx">         results = (yield self._selectGroupMembersQuery.on(self, groupID=groupID))
</span><span class="cx">         for row in results:
</span><del>-            members.add(UUID(&quot;urn:uuid:&quot; + row[0]))
</del><ins>+            members.add(row[0].decode(&quot;utf-8&quot;))
</ins><span class="cx">         returnValue(members)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def groupsFor(self, guid):
</del><ins>+    def groupsFor(self, uid):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        Returns the cached set of GUIDs for the groups this given guid is
</del><ins>+        Returns the cached set of UIDs for the groups this given uid is
</ins><span class="cx">         a member of.
</span><span class="cx"> 
</span><del>-        @param guid: the guid
-        @type guid: C{UUID}
</del><ins>+        @param uid: the uid
+        @type uid: C{unicode}
</ins><span class="cx">         @return: the set of group IDs
</span><span class="cx">         @rtype: a Deferred which fires with a set() of C{int} group IDs
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         groups = set()
</span><del>-        results = (yield self._selectGroupsForQuery.on(self, guid=str(guid)))
</del><ins>+        results = (
+            yield self._selectGroupsForQuery.on(
+                self, uid=uid.encode(&quot;utf-8&quot;)
+            )
+        )
</ins><span class="cx">         for row in results:
</span><del>-            groups.add(row[0])
</del><ins>+            groups.add(row[0].decode(&quot;utf-8&quot;))
</ins><span class="cx">         returnValue(groups)
</span><span class="cx"> 
</span><span class="cx">     # End of Group Members
</span><span class="lines">@@ -1168,6 +1248,19 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><ins>+    def _removeDelegatesQuery(cls):
+        de = schema.DELEGATES
+        return Delete(
+            From=de,
+            Where=(
+                de.DELEGATOR == Parameter(&quot;delegator&quot;)
+            ).And(
+                de.READ_WRITE == Parameter(&quot;readWrite&quot;)
+            )
+        )
+
+
+    @classproperty
</ins><span class="cx">     def _removeDelegateGroupQuery(cls):
</span><span class="cx">         ds = schema.DELEGATE_GROUPS
</span><span class="cx">         return Delete(
</span><span class="lines">@@ -1183,6 +1276,19 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><ins>+    def _removeDelegateGroupsQuery(cls):
+        ds = schema.DELEGATE_GROUPS
+        return Delete(
+            From=ds,
+            Where=(
+                ds.DELEGATOR == Parameter(&quot;delegator&quot;)
+            ).And(
+                ds.READ_WRITE == Parameter(&quot;readWrite&quot;)
+            )
+        )
+
+
+    @classproperty
</ins><span class="cx">     def _selectDelegatesQuery(cls):
</span><span class="cx">         de = schema.DELEGATES
</span><span class="cx">         return Select(
</span><span class="lines">@@ -1199,13 +1305,23 @@
</span><span class="cx">     @classproperty
</span><span class="cx">     def _selectDelegateGroupsQuery(cls):
</span><span class="cx">         ds = schema.DELEGATE_GROUPS
</span><ins>+        gr = schema.GROUPS
+
</ins><span class="cx">         return Select(
</span><del>-            [ds.GROUP_ID],
-            From=ds,
</del><ins>+            [gr.GROUP_GUID],
+            From=gr,
</ins><span class="cx">             Where=(
</span><del>-                ds.DELEGATOR == Parameter(&quot;delegator&quot;)
-            ).And(
-                ds.READ_WRITE == Parameter(&quot;readWrite&quot;)
</del><ins>+                gr.GROUP_ID.In(
+                    Select(
+                        [ds.GROUP_ID],
+                        From=ds,
+                        Where=(
+                            ds.DELEGATOR == Parameter(&quot;delegator&quot;)
+                        ).And(
+                            ds.READ_WRITE == Parameter(&quot;readWrite&quot;)
+                        )
+                    )
+                )
</ins><span class="cx">             )
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="lines">@@ -1317,18 +1433,18 @@
</span><span class="cx">         Adds a row to the DELEGATES table.  The delegate should not be a
</span><span class="cx">         group.  To delegate to a group, call addDelegateGroup() instead.
</span><span class="cx"> 
</span><del>-        @param delegator: the GUID of the delegator
-        @type delegator: C{UUID}
-        @param delegate: the GUID of the delegate
-        @type delegate: C{UUID}
</del><ins>+        @param delegator: the UID of the delegator
+        @type delegator: C{unicode}
+        @param delegate: the UID of the delegate
+        @type delegate: C{unicode}
</ins><span class="cx">         @param readWrite: grant read and write access if True, otherwise
</span><span class="cx">             read-only access
</span><span class="cx">         @type readWrite: C{boolean}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         return self._addDelegateQuery.on(
</span><span class="cx">             self,
</span><del>-            delegator=str(delegator),
-            delegate=str(delegate),
</del><ins>+            delegator=delegator.encode(&quot;utf-8&quot;),
+            delegate=delegate.encode(&quot;utf-8&quot;),
</ins><span class="cx">             readWrite=1 if readWrite else 0
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="lines">@@ -1339,8 +1455,8 @@
</span><span class="cx">         Adds a row to the DELEGATE_GROUPS table.  The delegate should be a
</span><span class="cx">         group.  To delegate to a person, call addDelegate() instead.
</span><span class="cx"> 
</span><del>-        @param delegator: the GUID of the delegator
-        @type delegator: C{UUID}
</del><ins>+        @param delegator: the UID of the delegator
+        @type delegator: C{unicode}
</ins><span class="cx">         @param delegateGroupID: the GROUP_ID of the delegate group
</span><span class="cx">         @type delegateGroupID: C{int}
</span><span class="cx">         @param readWrite: grant read and write access if True, otherwise
</span><span class="lines">@@ -1349,7 +1465,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         return self._addDelegateGroupQuery.on(
</span><span class="cx">             self,
</span><del>-            delegator=str(delegator),
</del><ins>+            delegator=delegator.encode(&quot;utf-8&quot;),
</ins><span class="cx">             groupID=delegateGroupID,
</span><span class="cx">             readWrite=1 if readWrite else 0,
</span><span class="cx">             isExternal=1 if isExternal else 0
</span><span class="lines">@@ -1361,29 +1477,47 @@
</span><span class="cx">         Removes a row from the DELEGATES table.  The delegate should not be a
</span><span class="cx">         group.  To remove a delegate group, call removeDelegateGroup() instead.
</span><span class="cx"> 
</span><del>-        @param delegator: the GUID of the delegator
-        @type delegator: C{UUID}
-        @param delegate: the GUID of the delegate
-        @type delegate: C{UUID}
</del><ins>+        @param delegator: the UID of the delegator
+        @type delegator: C{unicode}
+        @param delegate: the UID of the delegate
+        @type delegate: C{unicode}
</ins><span class="cx">         @param readWrite: remove read and write access if True, otherwise
</span><span class="cx">             read-only access
</span><span class="cx">         @type readWrite: C{boolean}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         return self._removeDelegateQuery.on(
</span><span class="cx">             self,
</span><del>-            delegator=str(delegator),
-            delegate=str(delegate),
</del><ins>+            delegator=delegator.encode(&quot;utf-8&quot;),
+            delegate=delegate.encode(&quot;utf-8&quot;),
</ins><span class="cx">             readWrite=1 if readWrite else 0
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def removeDelegates(self, delegator, readWrite):
+        &quot;&quot;&quot;
+        Removes all rows for this delegator/readWrite combination from the
+        DELEGATES table.
+
+        @param delegator: the UID of the delegator
+        @type delegator: C{unicode}
+        @param readWrite: remove read and write access if True, otherwise
+            read-only access
+        @type readWrite: C{boolean}
+        &quot;&quot;&quot;
+        return self._removeDelegatesQuery.on(
+            self,
+            delegator=delegator.encode(&quot;utf-8&quot;),
+            readWrite=1 if readWrite else 0
+        )
+
+
</ins><span class="cx">     def removeDelegateGroup(self, delegator, delegateGroupID, readWrite):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Removes a row from the DELEGATE_GROUPS table.  The delegate should be a
</span><span class="cx">         group.  To remove a delegate person, call removeDelegate() instead.
</span><span class="cx"> 
</span><del>-        @param delegator: the GUID of the delegator
-        @type delegator: C{UUID}
</del><ins>+        @param delegator: the UID of the delegator
+        @type delegator: C{unicode}
</ins><span class="cx">         @param delegateGroupID: the GROUP_ID of the delegate group
</span><span class="cx">         @type delegateGroupID: C{int}
</span><span class="cx">         @param readWrite: remove read and write access if True, otherwise
</span><span class="lines">@@ -1392,26 +1526,44 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         return self._removeDelegateGroupQuery.on(
</span><span class="cx">             self,
</span><del>-            delegator=str(delegator),
</del><ins>+            delegator=delegator.encode(&quot;utf-8&quot;),
</ins><span class="cx">             groupID=delegateGroupID,
</span><span class="cx">             readWrite=1 if readWrite else 0
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def removeDelegateGroups(self, delegator, readWrite):
+        &quot;&quot;&quot;
+        Removes all rows for this delegator/readWrite combination from the
+        DELEGATE_GROUPS table.
+
+        @param delegator: the UID of the delegator
+        @type delegator: C{unicode}
+        @param readWrite: remove read and write access if True, otherwise
+            read-only access
+        @type readWrite: C{boolean}
+        &quot;&quot;&quot;
+        return self._removeDelegateGroupsQuery.on(
+            self,
+            delegator=delegator.encode(&quot;utf-8&quot;),
+            readWrite=1 if readWrite else 0
+        )
+
+
</ins><span class="cx">     @inlineCallbacks
</span><del>-    def delegates(self, delegator, readWrite):
</del><ins>+    def delegates(self, delegator, readWrite, expanded=False):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        Returns the GUIDs of all delegates for the given delegator.  If
-        delegate access was granted to any groups, those groups' members
-        (flattened) will be included. No GUIDs of the groups themselves
-        will be returned.
</del><ins>+        Returns the UIDs of all delegates for the given delegator.  If
+        expanded is False, only the direct delegates (users and groups)
+        are returned.  If expanded is True, the expanded membmership is
+        returned, not including the groups themselves.
</ins><span class="cx"> 
</span><del>-        @param delegator: the GUID of the delegator
-        @type delegator: C{UUID}
</del><ins>+        @param delegator: the UID of the delegator
+        @type delegator: C{unicode}
</ins><span class="cx">         @param readWrite: the access-type to check for; read and write
</span><span class="cx">             access if True, otherwise read-only access
</span><span class="cx">         @type readWrite: C{boolean}
</span><del>-        @returns: the GUIDs of the delegates (for the specified access
</del><ins>+        @returns: the UIDs of the delegates (for the specified access
</ins><span class="cx">             type)
</span><span class="cx">         @rtype: a Deferred resulting in a set
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -1421,35 +1573,48 @@
</span><span class="cx">         results = (
</span><span class="cx">             yield self._selectDelegatesQuery.on(
</span><span class="cx">                 self,
</span><del>-                delegator=str(delegator),
</del><ins>+                delegator=delegator.encode(&quot;utf-8&quot;),
</ins><span class="cx">                 readWrite=1 if readWrite else 0
</span><span class="cx">             )
</span><span class="cx">         )
</span><span class="cx">         for row in results:
</span><del>-            delegates.add(UUID(&quot;urn:uuid:&quot; + row[0]))
</del><ins>+            delegates.add(row[0].decode(&quot;utf-8&quot;))
</ins><span class="cx"> 
</span><del>-        # Finally get those who are in groups which have been delegated to
-        results = (
-            yield self._selectIndirectDelegatesQuery.on(
-                self,
-                delegator=str(delegator),
-                readWrite=1 if readWrite else 0
</del><ins>+        if expanded:
+            # Get those who are in groups which have been delegated to
+            results = (
+                yield self._selectIndirectDelegatesQuery.on(
+                    self,
+                    delegator=delegator.encode(&quot;utf-8&quot;),
+                    readWrite=1 if readWrite else 0
+                )
</ins><span class="cx">             )
</span><del>-        )
-        for row in results:
-            delegates.add(UUID(&quot;urn:uuid:&quot; + row[0]))
</del><ins>+            for row in results:
+                delegates.add(row[0].decode(&quot;utf-8&quot;))
</ins><span class="cx"> 
</span><ins>+        else:
+            # Get the directly-delegated-to groups
+            results = (
+                yield self._selectDelegateGroupsQuery.on(
+                    self,
+                    delegator=delegator.encode(&quot;utf-8&quot;),
+                    readWrite=1 if readWrite else 0
+                )
+            )
+            for row in results:
+                delegates.add(row[0].decode(&quot;utf-8&quot;))
+
</ins><span class="cx">         returnValue(delegates)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def delegators(self, delegate, readWrite):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Returns the GUIDs of all delegators which have granted access to
</del><ins>+        Returns the UIDs of all delegators which have granted access to
</ins><span class="cx">         the given delegate, either directly or indirectly via groups.
</span><span class="cx"> 
</span><del>-        @param delegate: the GUID of the delegate
-        @type delegate: C{UUID}
</del><ins>+        @param delegate: the UID of the delegate
+        @type delegate: C{unicode}
</ins><span class="cx">         @param readWrite: the access-type to check for; read and write
</span><span class="cx">             access if True, otherwise read-only access
</span><span class="cx">         @type readWrite: C{boolean}
</span><span class="lines">@@ -1463,24 +1628,24 @@
</span><span class="cx">         results = (
</span><span class="cx">             yield self._selectDirectDelegatorsQuery.on(
</span><span class="cx">                 self,
</span><del>-                delegate=str(delegate),
</del><ins>+                delegate=delegate.encode(&quot;utf-8&quot;),
</ins><span class="cx">                 readWrite=1 if readWrite else 0
</span><span class="cx">             )
</span><span class="cx">         )
</span><span class="cx">         for row in results:
</span><del>-            delegators.add(UUID(&quot;urn:uuid:&quot; + row[0]))
</del><ins>+            delegators.add(row[0].decode(&quot;utf-8&quot;))
</ins><span class="cx"> 
</span><span class="cx">         # Finally get those who have delegated to groups the delegate
</span><span class="cx">         # is a member of
</span><span class="cx">         results = (
</span><span class="cx">             yield self._selectIndirectDelegatorsQuery.on(
</span><span class="cx">                 self,
</span><del>-                delegate=str(delegate),
</del><ins>+                delegate=delegate.encode(&quot;utf-8&quot;),
</ins><span class="cx">                 readWrite=1 if readWrite else 0
</span><span class="cx">             )
</span><span class="cx">         )
</span><span class="cx">         for row in results:
</span><del>-            delegators.add(UUID(&quot;urn:uuid:&quot; + row[0]))
</del><ins>+            delegators.add(row[0].decode(&quot;utf-8&quot;))
</ins><span class="cx"> 
</span><span class="cx">         returnValue(delegators)
</span><span class="cx"> 
</span><span class="lines">@@ -1488,11 +1653,11 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def allGroupDelegates(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Return the GUIDs of all groups which have been delegated to.  Useful
</del><ins>+        Return the UIDs of all groups which have been delegated to.  Useful
</ins><span class="cx">         for obtaining the set of groups which need to be synchronized from
</span><span class="cx">         the directory.
</span><span class="cx"> 
</span><del>-        @returns: the GUIDs of all delegated-to groups
</del><ins>+        @returns: the UIDs of all delegated-to groups
</ins><span class="cx">         @rtype: a Deferred resulting in a set
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         gr = schema.GROUPS
</span><span class="lines">@@ -1505,7 +1670,7 @@
</span><span class="cx">         ).on(self))
</span><span class="cx">         delegates = set()
</span><span class="cx">         for row in results:
</span><del>-            delegates.add(UUID(&quot;urn:uuid:&quot; + row[0]))
</del><ins>+            delegates.add(row[0].decode(&quot;utf-8&quot;))
</ins><span class="cx"> 
</span><span class="cx">         returnValue(delegates)
</span><span class="cx"> 
</span><span class="lines">@@ -1513,22 +1678,22 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def externalDelegates(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Returns a dictionary mapping delegate GUIDs to (read-group, write-group)
</del><ins>+        Returns a dictionary mapping delegate UIDs to (read-group, write-group)
</ins><span class="cx">         tuples, including only those assignments that originated from the
</span><span class="cx">         directory.
</span><span class="cx"> 
</span><del>-        @returns: dictionary mapping delegator guid to (readDelegateGUID,
-            writeDelegateGUID) tuples
</del><ins>+        @returns: dictionary mapping delegator uid to (readDelegateUID,
+            writeDelegateUID) tuples
</ins><span class="cx">         @rtype: a Deferred resulting in a dictionary
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         delegates = {}
</span><span class="cx"> 
</span><span class="cx">         # Get the externally managed delegates (which are all groups)
</span><span class="cx">         results = (yield self._selectExternalDelegateGroupsQuery.on(self))
</span><del>-        for delegator, readDelegateGUID, writeDelegateGUID in results:
-            delegates[UUID(delegator)] = (
-                UUID(readDelegateGUID) if readDelegateGUID else None,
-                UUID(writeDelegateGUID) if writeDelegateGUID else None
</del><ins>+        for delegator, readDelegateUID, writeDelegateUID in results:
+            delegates[delegator.encode(&quot;utf-8&quot;)] = (
+                readDelegateUID.encode(&quot;utf-8&quot;) if readDelegateUID else None,
+                writeDelegateUID.encode(&quot;utf-8&quot;) if writeDelegateUID else None
</ins><span class="cx">             )
</span><span class="cx"> 
</span><span class="cx">         returnValue(delegates)
</span><span class="lines">@@ -1537,7 +1702,7 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def assignExternalDelegates(
</span><span class="cx">         self, delegator, readDelegateGroupID, writeDelegateGroupID,
</span><del>-        readDelegateGUID, writeDelegateGUID
</del><ins>+        readDelegateUID, writeDelegateUID
</ins><span class="cx">     ):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Update the external delegate group table so we can quickly identify
</span><span class="lines">@@ -1560,12 +1725,12 @@
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx">         # Store new assignments in the external comparison table
</span><del>-        if readDelegateGUID or writeDelegateGUID:
</del><ins>+        if readDelegateUID or writeDelegateUID:
</ins><span class="cx">             readDelegateForDB = (
</span><del>-                str(readDelegateGUID) if readDelegateGUID else &quot;&quot;
</del><ins>+                readDelegateUID.encode(&quot;utf-8&quot;) if readDelegateUID else &quot;&quot;
</ins><span class="cx">             )
</span><span class="cx">             writeDelegateForDB = (
</span><del>-                str(writeDelegateGUID) if writeDelegateGUID else &quot;&quot;
</del><ins>+                writeDelegateUID.encode(&quot;utf-8&quot;) if writeDelegateUID else &quot;&quot;
</ins><span class="cx">             )
</span><span class="cx">             yield self._storeExternalDelegateGroupsPairQuery.on(
</span><span class="cx">                 self,
</span><span class="lines">@@ -2742,6 +2907,9 @@
</span><span class="cx">     @classmethod
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def homeWithUID(cls, txn, uid, create=False):
</span><ins>+        &quot;&quot;&quot;
+        @param uid: I'm going to assume uid is utf-8 encoded bytes
+        &quot;&quot;&quot;
</ins><span class="cx">         homeObject = yield cls.makeClass(txn, uid)
</span><span class="cx">         if homeObject is not None:
</span><span class="cx">             returnValue(homeObject)
</span><span class="lines">@@ -2750,7 +2918,7 @@
</span><span class="cx">                 returnValue(None)
</span><span class="cx"> 
</span><span class="cx">             # Determine if the user is local or external
</span><del>-            record = txn.directoryService().recordWithUID(uid)
</del><ins>+            record = yield txn.directoryService().recordWithUID(uid.decode(&quot;utf-8&quot;))
</ins><span class="cx">             if record is None:
</span><span class="cx">                 raise DirectoryRecordNotFoundError(&quot;Cannot create home for UID since no directory record exists: {}&quot;.format(uid))
</span><span class="cx"> 
</span><span class="lines">@@ -2844,7 +3012,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def directoryRecord(self):
</span><del>-        return self.directoryService().recordWithUID(self.uid())
</del><ins>+        return self.directoryService().recordWithUID(self.uid().decode(&quot;utf-8&quot;))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -6744,6 +6912,9 @@
</span><span class="cx">     @classmethod
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def notificationsWithUID(cls, txn, uid, create):
</span><ins>+        &quot;&quot;&quot;
+        @param uid: I'm going to assume uid is utf-8 encoded bytes
+        &quot;&quot;&quot;
</ins><span class="cx">         rows = yield cls._resourceIDFromUIDQuery.on(txn, uid=uid)
</span><span class="cx"> 
</span><span class="cx">         if rows:
</span><span class="lines">@@ -6751,7 +6922,7 @@
</span><span class="cx">             created = False
</span><span class="cx">         elif create:
</span><span class="cx">             # Determine if the user is local or external
</span><del>-            record = txn.directoryService().recordWithUID(uid)
</del><ins>+            record = yield txn.directoryService().recordWithUID(uid.decode(&quot;utf-8&quot;))
</ins><span class="cx">             if record is None:
</span><span class="cx">                 raise DirectoryRecordNotFoundError(&quot;Cannot create home for UID since no directory record exists: {}&quot;.format(uid))
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcommondatastoretestutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/test/util.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/test/util.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/common/datastore/test/util.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -46,7 +46,7 @@
</span><span class="cx"> from twisted.application.service import Service
</span><span class="cx"> from twisted.internet import reactor
</span><span class="cx"> from twisted.internet.defer import Deferred, inlineCallbacks
</span><del>-from twisted.internet.defer import returnValue
</del><ins>+from twisted.internet.defer import returnValue, succeed
</ins><span class="cx"> from twisted.internet.task import deferLater
</span><span class="cx"> from twisted.trial.unittest import TestCase
</span><span class="cx"> 
</span><span class="lines">@@ -110,14 +110,14 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def recordWithUID(self, uid):
</span><del>-        return self.records.get(uid)
</del><ins>+        return succeed(self.records.get(uid))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def recordWithGUID(self, guid):
</span><span class="cx">         for record in self.records.itervalues():
</span><span class="cx">             if record.guid == guid:
</span><del>-                return record
-        return None
</del><ins>+                return succeed(record)
+        return succeed(None)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def addRecord(self, record):
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavdpsclientpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/dps/client.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -15,53 +15,97 @@
</span><span class="cx"> ##
</span><span class="cx"> 
</span><span class="cx"> import cPickle as pickle
</span><ins>+import uuid
</ins><span class="cx"> 
</span><span class="cx"> from twext.python.log import Logger
</span><span class="cx"> from twext.who.directory import DirectoryRecord as BaseDirectoryRecord
</span><span class="cx"> from twext.who.directory import DirectoryService as BaseDirectoryService
</span><del>-from twext.who.idirectory import RecordType
</del><ins>+from twext.who.expression import Operand
+from twext.who.idirectory import RecordType, IDirectoryService
</ins><span class="cx"> import twext.who.idirectory
</span><span class="cx"> from twext.who.util import ConstantsContainer
</span><span class="cx"> from twisted.internet import reactor
</span><del>-from twisted.internet.defer import inlineCallbacks, returnValue
</del><ins>+from twisted.internet.defer import inlineCallbacks, returnValue, succeed
</ins><span class="cx"> from twisted.internet.protocol import ClientCreator
</span><span class="cx"> from twisted.protocols import amp
</span><ins>+from twisted.python.constants import Names, NamedConstant
+from txdav.caldav.icalendardirectoryservice import ICalendarStoreDirectoryRecord
+from txdav.common.idirectoryservice import IStoreDirectoryService
</ins><span class="cx"> from txdav.dps.commands import (
</span><span class="cx">     RecordWithShortNameCommand, RecordWithUIDCommand, RecordWithGUIDCommand,
</span><span class="cx">     RecordsWithRecordTypeCommand, RecordsWithEmailAddressCommand,
</span><ins>+    RecordsMatchingTokensCommand, RecordsMatchingFieldsCommand,
+    MembersCommand, GroupsCommand, SetMembersCommand,
</ins><span class="cx">     VerifyPlaintextPasswordCommand, VerifyHTTPDigestCommand
</span><span class="cx"> )
</span><ins>+from txdav.who.directory import (
+    CalendarDirectoryRecordMixin, CalendarDirectoryServiceMixin
+)
+import txdav.who.delegates
</ins><span class="cx"> import txdav.who.idirectory
</span><span class="cx"> from zope.interface import implementer
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> ##
</span><span class="cx"> ## Client implementation of Directory Proxy Service
</span><span class="cx"> ##
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-@implementer(twext.who.idirectory.IDirectoryService)
-class DirectoryService(BaseDirectoryService):
</del><ins>+
+## MOVE2WHO TODOs:
+## realm from primary/user directory service
+## SACLs
+## Wiki
+## LDAP
+## Tests from old twistedcaldav/directory
+## Cmd line tools
+## Store based directory service (records in the store, i.e. locations/resources)
+## Separate store for DPS (augments and delegates separate from calendar data)
+## calverify needs deferreds, including:
+##    component.normalizeCalendarUserAddresses
+
+@implementer(IDirectoryService, IStoreDirectoryService)
+class DirectoryService(BaseDirectoryService, CalendarDirectoryServiceMixin):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Client side of directory proxy
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     recordType = ConstantsContainer(
</span><span class="cx">         (twext.who.idirectory.RecordType,
</span><del>-         txdav.who.idirectory.RecordType)
</del><ins>+         txdav.who.idirectory.RecordType,
+         txdav.who.delegates.RecordType)
</ins><span class="cx">     )
</span><span class="cx"> 
</span><ins>+    fieldName = ConstantsContainer(
+        (twext.who.idirectory.FieldName,
+         txdav.who.idirectory.FieldName)
+    )
</ins><span class="cx"> 
</span><ins>+
+    # MOVE2WHO: we talked about passing these in instead:
+    # def __init__(self, fieldNames, recordTypes):
+    #     self.fieldName = fieldNames
+    #     self.recordType = recordTypes
+
+
+    # MOVE2WHO needed?
+    def getGroups(self, guids=None):
+        return succeed(set())
+    # END MOVE2WHO
+
+
+
</ins><span class="cx">     def _dictToRecord(self, serializedFields):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        This to be replaced by something awesome
</del><ins>+        Turn a dictionary of fields sent from the server into a directory
+        record
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if not serializedFields:
</span><span class="cx">             return None
</span><span class="cx"> 
</span><ins>+        # print(&quot;FIELDS&quot;, serializedFields)
+
</ins><span class="cx">         fields = {}
</span><span class="cx">         for fieldName, value in serializedFields.iteritems():
</span><span class="cx">             try:
</span><span class="lines">@@ -70,8 +114,21 @@
</span><span class="cx">                 # unknown field
</span><span class="cx">                 pass
</span><span class="cx">             else:
</span><del>-                fields[field] = value
-        fields[self.fieldName.recordType] = self.recordType.user
</del><ins>+                valueType = self.fieldName.valueType(field)
+                if valueType in (unicode, bool):
+                    fields[field] = value
+                elif valueType is uuid.UUID:
+                    fields[field] = uuid.UUID(value)
+                elif issubclass(valueType, Names):
+                    if value is not None:
+                        fields[field] = field.valueType.lookupByName(value)
+                    else:
+                        fields[field] = None
+                elif issubclass(valueType, NamedConstant):
+                    if fieldName == &quot;recordType&quot;:  # Is there a better way?
+                        fields[field] = self.recordType.lookupByName(value)
+
+        # print(&quot;AFTER:&quot;, fields)
</ins><span class="cx">         return DirectoryRecord(self, fields)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -127,15 +184,31 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def recordWithShortName(self, recordType, shortName):
</span><ins>+        # MOVE2WHO
+        # temporary hack until we can fix all callers not to pass strings:
+        if isinstance(recordType, (str, unicode)):
+            recordType = self.recordType.lookupByName(recordType)
+
+        # MOVE2WHO, REMOVE THIS HACK TOO:
+        if not isinstance(shortName, unicode):
+            log.warn(&quot;Need to change shortName to unicode&quot;)
+            shortName = shortName.decode(&quot;utf-8&quot;)
+
+
</ins><span class="cx">         return self._call(
</span><span class="cx">             RecordWithShortNameCommand,
</span><span class="cx">             self._processSingleRecord,
</span><del>-            recordType=recordType.description.encode(&quot;utf-8&quot;),
</del><ins>+            recordType=recordType.name.encode(&quot;utf-8&quot;),
</ins><span class="cx">             shortName=shortName.encode(&quot;utf-8&quot;)
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def recordWithUID(self, uid):
</span><ins>+        # MOVE2WHO, REMOVE THIS:
+        if not isinstance(uid, unicode):
+            log.warn(&quot;Need to change uid to unicode&quot;)
+            uid = uid.decode(&quot;utf-8&quot;)
+
</ins><span class="cx">         return self._call(
</span><span class="cx">             RecordWithUIDCommand,
</span><span class="cx">             self._processSingleRecord,
</span><span class="lines">@@ -147,7 +220,7 @@
</span><span class="cx">         return self._call(
</span><span class="cx">             RecordWithGUIDCommand,
</span><span class="cx">             self._processSingleRecord,
</span><del>-            guid=guid.encode(&quot;utf-8&quot;)
</del><ins>+            guid=str(guid)
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -155,10 +228,12 @@
</span><span class="cx">         return self._call(
</span><span class="cx">             RecordsWithRecordTypeCommand,
</span><span class="cx">             self._processMultipleRecords,
</span><del>-            recordType=recordType.description.encode(&quot;utf-8&quot;)
</del><ins>+            recordType=recordType.name.encode(&quot;utf-8&quot;)
</ins><span class="cx">         )
</span><span class="cx"> 
</span><ins>+    listRecords = recordsWithRecordType
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx">     def recordsWithEmailAddress(self, emailAddress):
</span><span class="cx">         return self._call(
</span><span class="cx">             RecordsWithEmailAddressCommand,
</span><span class="lines">@@ -167,9 +242,47 @@
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def recordsMatchingTokens(self, tokens, context=None, limitResults=50,
+                              timeoutSeconds=10):
+        return self._call(
+            RecordsMatchingTokensCommand,
+            self._processMultipleRecords,
+            tokens=[t.encode(&quot;utf-8&quot;) for t in tokens],
+            context=context
+        )
</ins><span class="cx"> 
</span><del>-class DirectoryRecord(BaseDirectoryRecord):
</del><span class="cx"> 
</span><ins>+    def recordsMatchingFields(self, fields, operand=Operand.OR, recordType=None):
+
+        newFields = []
+        for fieldName, searchTerm, matchFlags, matchType in fields:
+            newFields.append(
+                (
+                    fieldName.encode(&quot;utf-8&quot;),
+                    searchTerm.encode(&quot;utf-8&quot;),
+                    matchFlags.name.encode(&quot;utf-8&quot;),
+                    matchType.name.encode(&quot;utf-8&quot;)
+                )
+            )
+        if recordType is not None:
+            recordType = recordType.name.encode(&quot;utf-8&quot;)
+
+        return self._call(
+            RecordsMatchingFieldsCommand,
+            self._processMultipleRecords,
+            fields=newFields,
+            operand=operand.name.encode(&quot;utf-8&quot;),
+            recordType=recordType
+        )
+
+
+
+
+
+@implementer(ICalendarStoreDirectoryRecord)
+class DirectoryRecord(BaseDirectoryRecord, CalendarDirectoryRecordMixin):
+
+
</ins><span class="cx">     def verifyPlaintextPassword(self, password):
</span><span class="cx">         return self.service._call(
</span><span class="cx">             VerifyPlaintextPasswordCommand,
</span><span class="lines">@@ -201,6 +314,50 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def members(self):
+        return self.service._call(
+            MembersCommand,
+            self.service._processMultipleRecords,
+            uid=self.uid.encode(&quot;utf-8&quot;)
+        )
+
+
+    def groups(self):
+        return self.service._call(
+            GroupsCommand,
+            self.service._processMultipleRecords,
+            uid=self.uid.encode(&quot;utf-8&quot;)
+        )
+
+
+    def setMembers(self, members):
+        log.debug(&quot;DPS Client setMembers&quot;)
+        memberUIDs = [m.uid.encode(&quot;utf-8&quot;) for m in members]
+        return self.service._call(
+            SetMembersCommand,
+            lambda x: x['success'],
+            uid=self.uid.encode(&quot;utf-8&quot;),
+            memberUIDs=memberUIDs
+        )
+
+
+    # For scheduling/freebusy
+    # FIXME: doesn't this need to happen in the DPS?
+    @inlineCallbacks
+    def isProxyFor(self, other):
+        for recordType in (
+            txdav.who.delegates.RecordType.readDelegatorGroup,
+            txdav.who.delegates.RecordType.writeDelegatorGroup,
+        ):
+            delegatorGroup = yield self.service.recordWithShortName(
+                recordType, self.uid
+            )
+            if delegatorGroup:
+                if other in (yield delegatorGroup.members()):
+                    returnValue(True)
+
+
+
</ins><span class="cx"> # Test client:
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavdpscommandspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/dps/commands.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/dps/commands.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/dps/commands.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -67,7 +67,27 @@
</span><span class="cx">     ]
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class RecordsMatchingTokensCommand(amp.Command):
+    arguments = [
+        ('tokens', amp.ListOf(amp.String())),
+        ('context', amp.String(optional=True)),
+    ]
+    response = [
+        ('fieldsList', amp.String()),
+    ]
</ins><span class="cx"> 
</span><ins>+
+class RecordsMatchingFieldsCommand(amp.Command):
+    arguments = [
+        ('fields', amp.ListOf(amp.ListOf(amp.String()))),
+        ('operand', amp.String()),
+        ('recordType', amp.String(optional=True)),
+    ]
+    response = [
+        ('fieldsList', amp.String()),
+    ]
+
+
</ins><span class="cx"> class UpdateRecordsCommand(amp.Command):
</span><span class="cx">     arguments = [
</span><span class="cx">         ('fieldsList', amp.String()),
</span><span class="lines">@@ -89,6 +109,37 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class MembersCommand(amp.Command):
+    arguments = [
+        ('uid', amp.String()),
+    ]
+    response = [
+        ('fieldsList', amp.String()),
+    ]
+
+
+
+class GroupsCommand(amp.Command):
+    arguments = [
+        ('uid', amp.String()),
+    ]
+    response = [
+        ('fieldsList', amp.String()),
+    ]
+
+
+
+class SetMembersCommand(amp.Command):
+    arguments = [
+        ('uid', amp.String()),
+        ('memberUIDs', amp.ListOf(amp.String())),
+    ]
+    response = [
+        ('success', amp.Boolean()),
+    ]
+
+
+
</ins><span class="cx"> class VerifyPlaintextPasswordCommand(amp.Command):
</span><span class="cx">     arguments = [
</span><span class="cx">         ('uid', amp.String()),
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavdpsserverpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/dps/server.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/dps/server.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/dps/server.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -15,10 +15,10 @@
</span><span class="cx"> ##
</span><span class="cx"> 
</span><span class="cx"> import cPickle as pickle
</span><del>-import os
</del><span class="cx"> import uuid
</span><span class="cx"> 
</span><span class="cx"> from twext.python.log import Logger
</span><ins>+from twext.who.expression import MatchType, MatchFlags, Operand
</ins><span class="cx"> from twext.who.idirectory import RecordType
</span><span class="cx"> from twisted.application import service
</span><span class="cx"> from twisted.application.strports import service as strPortsService
</span><span class="lines">@@ -26,21 +26,22 @@
</span><span class="cx"> from twisted.internet.protocol import Factory
</span><span class="cx"> from twisted.plugin import IPlugin
</span><span class="cx"> from twisted.protocols import amp
</span><del>-from twisted.python.filepath import FilePath
</del><ins>+from twisted.python.constants import Names, NamedConstant
</ins><span class="cx"> from twisted.python.usage import Options, UsageError
</span><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from twistedcaldav.stdconfig import DEFAULT_CONFIG, DEFAULT_CONFIG_FILE
</span><span class="cx"> from txdav.dps.commands import (
</span><span class="cx">     RecordWithShortNameCommand, RecordWithUIDCommand, RecordWithGUIDCommand,
</span><span class="cx">     RecordsWithRecordTypeCommand, RecordsWithEmailAddressCommand,
</span><ins>+    RecordsMatchingTokensCommand, RecordsMatchingFieldsCommand,
+    MembersCommand, GroupsCommand, SetMembersCommand,
</ins><span class="cx">     VerifyPlaintextPasswordCommand, VerifyHTTPDigestCommand,
</span><span class="cx">     # UpdateRecordsCommand, RemoveRecordsCommand
</span><span class="cx"> )
</span><del>-from twext.who.ldap import DirectoryService as LDAPDirectoryService
-from txdav.who.xml import DirectoryService as XMLDirectoryService
</del><ins>+from txdav.who.util import directoryFromConfig
</ins><span class="cx"> from zope.interface import implementer
</span><del>-from twisted.cred.credentials import UsernamePassword
</del><span class="cx"> 
</span><ins>+
</ins><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -63,15 +64,21 @@
</span><span class="cx"> 
</span><span class="cx">     def recordToDict(self, record):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        This to be replaced by something awesome
</del><ins>+        Turn a record in a dictionary of fields which can be reconstituted
+        within the client
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         fields = {}
</span><span class="cx">         if record is not None:
</span><span class="cx">             for field, value in record.fields.iteritems():
</span><del>-                # print(&quot;%s: %s&quot; % (field.name, value))
-                valueType = self._directory.fieldName.valueType(field)
-                if valueType is unicode:
</del><ins>+                valueType = record.service.fieldName.valueType(field)
+                # print(&quot;%s: %s (%s)&quot; % (field.name, value, valueType))
+                if valueType in (unicode, bool):
</ins><span class="cx">                     fields[field.name] = value
</span><ins>+                elif valueType is uuid.UUID:
+                    fields[field.name] = str(value)
+                elif issubclass(valueType, (Names, NamedConstant)):
+                    fields[field.name] = value.name if value else None
+        # print(&quot;Server side fields&quot;, fields)
</ins><span class="cx">         return fields
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -82,7 +89,7 @@
</span><span class="cx">         shortName = shortName.decode(&quot;utf-8&quot;)
</span><span class="cx">         log.debug(&quot;RecordWithShortName: {r} {n}&quot;, r=recordType, n=shortName)
</span><span class="cx">         record = (yield self._directory.recordWithShortName(
</span><del>-            RecordType.lookupByName(recordType), shortName)
</del><ins>+            self._directory.recordType.lookupByName(recordType), shortName)
</ins><span class="cx">         )
</span><span class="cx">         fields = self.recordToDict(record)
</span><span class="cx">         response = {
</span><span class="lines">@@ -130,7 +137,7 @@
</span><span class="cx">         recordType = recordType  # as bytes
</span><span class="cx">         log.debug(&quot;RecordsWithRecordType: {r}&quot;, r=recordType)
</span><span class="cx">         records = (yield self._directory.recordsWithRecordType(
</span><del>-            RecordType.lookupByName(recordType))
</del><ins>+            self._directory.recordType.lookupByName(recordType))
</ins><span class="cx">         )
</span><span class="cx">         fieldsList = []
</span><span class="cx">         for record in records:
</span><span class="lines">@@ -158,6 +165,124 @@
</span><span class="cx">         returnValue(response)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @RecordsMatchingTokensCommand.responder
+    @inlineCallbacks
+    def recordsMatchingTokens(self, tokens, context=None):
+        tokens = [t.decode(&quot;utf-8&quot;) for t in tokens]
+        log.debug(&quot;RecordsMatchingTokens: {t}&quot;, t=(&quot;, &quot;.join(tokens)))
+        records = yield self._directory.recordsMatchingTokens(
+            tokens, context=context
+        )
+        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)
+
+
+    @RecordsMatchingFieldsCommand.responder
+    @inlineCallbacks
+    def recordsMatchingFields(self, fields, operand=&quot;OR&quot;, recordType=None):
+        log.debug(&quot;RecordsMatchingFields&quot;)
+        newFields = []
+        for fieldName, searchTerm, matchFlags, matchType in fields:
+            fieldName = fieldName.decode(&quot;utf-8&quot;)
+            searchTerm = searchTerm.decode(&quot;utf-8&quot;)
+            matchFlags = MatchFlags.lookupByName(matchFlags.decode(&quot;utf-8&quot;))
+            matchType = MatchType.lookupByName(matchType.decode(&quot;utf-8&quot;))
+            newFields.append((fieldName, searchTerm, matchFlags, matchType))
+        operand = Operand.lookupByName(operand)
+        if recordType:
+            recordType = self._directory.recordType.lookupByName(recordType)
+        records = yield self._directory.recordsMatchingFields(
+            newFields, operand=operand, recordType=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)
+
+
+    @MembersCommand.responder
+    @inlineCallbacks
+    def members(self, uid):
+        uid = uid.decode(&quot;utf-8&quot;)
+        log.debug(&quot;Members: {u}&quot;, u=uid)
+        try:
+            record = (yield self._directory.recordWithUID(uid))
+        except Exception as e:
+            log.error(&quot;Failed in members&quot;, error=e)
+            record = None
+
+        fieldsList = []
+        if record is not None:
+            for member in (yield record.members()):
+                fieldsList.append(self.recordToDict(member))
+        response = {
+            &quot;fieldsList&quot;: pickle.dumps(fieldsList),
+        }
+        log.debug(&quot;Responding with: {response}&quot;, response=response)
+        returnValue(response)
+
+
+    @SetMembersCommand.responder
+    @inlineCallbacks
+    def setMembers(self, uid, memberUIDs):
+        uid = uid.decode(&quot;utf-8&quot;)
+        memberUIDs = [m.decode(&quot;utf-8&quot;) for m in memberUIDs]
+        log.debug(&quot;Set Members: {u} -&gt; {m}&quot;, u=uid, m=memberUIDs)
+        try:
+            record = (yield self._directory.recordWithUID(uid))
+        except Exception as e:
+            log.error(&quot;Failed in setMembers&quot;, error=e)
+            record = None
+
+        if record is not None:
+            memberRecords = []
+            for memberUID in memberUIDs:
+                memberRecord = yield self._directory.recordWithUID(memberUID)
+                if memberRecord is not None:
+                    memberRecords.append(memberRecord)
+            yield record.setMembers(memberRecords)
+            success = True
+        else:
+            success = False
+
+        response = {
+            &quot;success&quot;: success,
+        }
+        log.debug(&quot;Responding with: {response}&quot;, response=response)
+        returnValue(response)
+
+
+    @GroupsCommand.responder
+    @inlineCallbacks
+    def groups(self, uid):
+        uid = uid.decode(&quot;utf-8&quot;)
+        log.debug(&quot;Groups: {u}&quot;, u=uid)
+        try:
+            record = (yield self._directory.recordWithUID(uid))
+        except Exception as e:
+            log.error(&quot;Failed in groups&quot;, error=e)
+            record = None
+
+        fieldsList = []
+        for group in (yield record.groups()):
+            fieldsList.append(self.recordToDict(group))
+        response = {
+            &quot;fieldsList&quot;: pickle.dumps(fieldsList),
+        }
+        log.debug(&quot;Responding with: {response}&quot;, response=response)
+        returnValue(response)
+
+
</ins><span class="cx">     @VerifyPlaintextPasswordCommand.responder
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def verifyPlaintextPassword(self, uid, password):
</span><span class="lines">@@ -333,36 +458,17 @@
</span><span class="cx">         else:
</span><span class="cx">             setproctitle(&quot;CalendarServer Directory Proxy Service&quot;)
</span><span class="cx"> 
</span><del>-        directoryType = config.DirectoryProxy.DirectoryType
-        args = config.DirectoryProxy.Arguments
-        kwds = config.DirectoryProxy.Keywords
</del><ins>+        try:
+            directory = directoryFromConfig(config)
+        except Exception as e:
+            log.error(&quot;Failed to create directory service&quot;, error=e)
+            raise
</ins><span class="cx"> 
</span><del>-        if directoryType == &quot;OD&quot;:
-            from twext.who.opendirectory import DirectoryService as ODDirectoryService
-            directory = ODDirectoryService(*args, **kwds)
</del><ins>+        log.info(&quot;Created directory service&quot;)
</ins><span class="cx"> 
</span><del>-        elif directoryType == &quot;LDAP&quot;:
-            authDN = kwds.pop(&quot;authDN&quot;, &quot;&quot;)
-            password = kwds.pop(&quot;password&quot;, &quot;&quot;)
-            if authDN and password:
-                creds = UsernamePassword(authDN, password)
-            else:
-                creds = None
-            kwds[&quot;credentials&quot;] = creds
-            debug = kwds.pop(&quot;debug&quot;, &quot;&quot;)
-            directory = LDAPDirectoryService(*args, _debug=debug, **kwds)
-
-        elif directoryType == &quot;XML&quot;:
-            path = kwds.pop(&quot;path&quot;, &quot;&quot;)
-            if not path or not os.path.exists(path):
-                log.error(&quot;Path not found for XML directory: {p}&quot;, p=path)
-            fp = FilePath(path)
-            directory = XMLDirectoryService(fp, *args, **kwds)
-
-        else:
-            log.error(&quot;Invalid DirectoryType: {dt}&quot;, dt=directoryType)
-
-        desc = &quot;unix:{path}:mode=660&quot;.format(
-            path=config.DirectoryProxy.SocketPath
</del><ins>+        return strPortsService(
+            &quot;unix:{path}:mode=660&quot;.format(
+                path=config.DirectoryProxy.SocketPath
+            ),
+            DirectoryProxyAMPFactory(directory)
</ins><span class="cx">         )
</span><del>-        return strPortsService(desc, DirectoryProxyAMPFactory(directory))
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavdpstesttestxml"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test.xml (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test.xml        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test.xml        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -23,6 +23,7 @@
</span><span class="cx"> 
</span><span class="cx">   &lt;record type=&quot;user&quot;&gt;
</span><span class="cx">     &lt;uid&gt;__sagen__&lt;/uid&gt;
</span><ins>+    &lt;guid&gt;B3B1158F-0564-4F5B-81E4-A89EA5FF81B0&lt;/guid&gt;
</ins><span class="cx">     &lt;short-name&gt;sagen&lt;/short-name&gt;
</span><span class="cx">     &lt;full-name&gt;Morgen Sagen&lt;/full-name&gt;
</span><span class="cx">     &lt;password&gt;negas&lt;/password&gt;
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavdpstesttest_clientpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/dps/test/test_client.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -25,17 +25,34 @@
</span><span class="cx"> from twisted.trial import unittest
</span><span class="cx"> from txdav.dps.client import DirectoryService
</span><span class="cx"> from txdav.dps.server import DirectoryProxyAMPProtocol
</span><ins>+from txdav.who.directory import CalendarDirectoryServiceMixin
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> testMode = &quot;xml&quot;  # &quot;xml&quot; or &quot;od&quot;
</span><span class="cx"> if testMode == &quot;xml&quot;:
</span><span class="cx">     from txdav.who.xml import DirectoryService as XMLDirectoryService
</span><ins>+
+    # Mix in the calendar-specific service methods
+    class CalendarXMLDirectorySerivce(
+        XMLDirectoryService,
+        CalendarDirectoryServiceMixin
+    ):
+        pass
+
</ins><span class="cx"> elif testMode == &quot;od&quot;:
</span><span class="cx">     odpw = &quot;secret&quot;
</span><span class="cx">     from twext.who.opendirectory import DirectoryService as OpenDirectoryService
</span><span class="cx"> 
</span><ins>+    # Mix in the calendar-specific service methods
+    class CalendarODDirectorySerivce(
+        OpenDirectoryService,
+        CalendarDirectoryServiceMixin
+    ):
+        pass
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class DPSClientTest(unittest.TestCase):
</span><span class="cx"> 
</span><span class="cx">     def setUp(self):
</span><span class="lines">@@ -46,9 +63,9 @@
</span><span class="cx">         # The &quot;remote&quot; directory service
</span><span class="cx">         if testMode == &quot;xml&quot;:
</span><span class="cx">             path = os.path.join(os.path.dirname(__file__), &quot;test.xml&quot;)
</span><del>-            remoteDirectory = XMLDirectoryService(FilePath(path))
</del><ins>+            remoteDirectory = CalendarXMLDirectorySerivce(FilePath(path))
</ins><span class="cx">         elif testMode == &quot;od&quot;:
</span><del>-            remoteDirectory = OpenDirectoryService()
</del><ins>+            remoteDirectory = CalendarODDirectorySerivce()
</ins><span class="cx"> 
</span><span class="cx">         # Connect the two services directly via an IOPump
</span><span class="cx">         client = AMP()
</span><span class="lines">@@ -112,6 +129,18 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><ins>+    def test_recordsMatchingTokens(self):
+        records = (yield self.directory.recordsMatchingTokens(
+            [u&quot;anche&quot;]
+        ))
+        self.assertEquals(len(records), 2)
+        self.assertEquals(
+            set([u&quot;__dre__&quot;, u&quot;__wsanchez__&quot;]),
+            set([r.uid for r in records])
+        )
+
+
+    @inlineCallbacks
</ins><span class="cx">     def test_verifyPlaintextPassword(self):
</span><span class="cx">         if testMode == &quot;xml&quot;:
</span><span class="cx">             expectations = (
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhoaugmentpyfromrev12913CalendarServerbranchesuserssagenmove2who3txdavwhoaugmentpy"></a>
<div class="copfile"><h4>Copied: CalendarServer/branches/users/sagen/move2who-4/txdav/who/augment.py (from rev 12913, CalendarServer/branches/users/sagen/move2who-3/txdav/who/augment.py) (0 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/augment.py                                (rev 0)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/augment.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -0,0 +1,289 @@
</span><ins>+# -*- test-case-name: txdav.who.test.test_augment -*-
+##
+# Copyright (c) 2013 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.
+##
+
+&quot;&quot;&quot;
+Augmenting Directory Service
+&quot;&quot;&quot;
+
+from twext.python.log import Logger
+from twext.who.directory import DirectoryRecord
+from twext.who.directory import DirectoryService as BaseDirectoryService
+from twext.who.idirectory import IDirectoryService, RecordType
+from twext.who.util import ConstantsContainer
+from twisted.internet.defer import inlineCallbacks, returnValue
+from txdav.common.idirectoryservice import IStoreDirectoryService
+from txdav.who.directory import (
+    CalendarDirectoryRecordMixin, CalendarDirectoryServiceMixin
+)
+from txdav.who.idirectory import AutoScheduleMode, FieldName
+from zope.interface import implementer
+
+
+log = Logger()
+
+
+class AugmentedDirectoryRecord(DirectoryRecord, CalendarDirectoryRecordMixin):
+
+    def __init__(self, service, baseRecord, augmentedFields):
+        DirectoryRecord.__init__(self, service, augmentedFields)
+        self._baseRecord = baseRecord
+
+
+    @inlineCallbacks
+    def members(self):
+        augmented = []
+        records = yield self._baseRecord.members()
+        for record in records:
+            augmented.append((yield self.service.augment(record)))
+        returnValue(augmented)
+
+
+    @inlineCallbacks
+    def groups(self):
+        augmented = []
+        txn = self.service._store.newTransaction()
+        groupUIDs = yield txn.groupsFor(self.uid)
+        for groupUID in groupUIDs:
+            groupRecord = yield self.service.recordWithShortName(
+                RecordType.group, groupUID
+            )
+            if groupRecord:
+                augmented.append((yield self.service.augment(groupRecord)))
+        returnValue(augmented)
+
+
+@implementer(IDirectoryService, IStoreDirectoryService)
+class AugmentedDirectoryService(BaseDirectoryService,
+                                CalendarDirectoryServiceMixin):
+
+    fieldName = ConstantsContainer((
+        BaseDirectoryService.fieldName,
+        FieldName,
+    ))
+
+
+    @property
+    def recordType(self):
+        &quot;&quot;&quot;
+        Defer to the directory service we're augmenting
+        &quot;&quot;&quot;
+        return self._directory.recordType
+
+
+    def __init__(self, directory, store, augmentDB):
+        BaseDirectoryService.__init__(self, directory.realmName)
+        self._directory = directory
+        self._store = store
+        self._augmentDB = augmentDB
+
+
+    def recordTypes(self):
+        return self._directory.recordTypes()
+
+
+    @inlineCallbacks
+    def recordsFromExpression(self, expression):
+        records = yield self._directory.recordsFromExpression(expression)
+        augmented = []
+        for record in records:
+            record = yield self.augment(record)
+            augmented.append(record)
+        returnValue(augmented)
+
+
+    @inlineCallbacks
+    def recordsWithFieldValue(self, fieldName, value):
+        records = yield self._directory.recordsWithFieldValue(
+            fieldName, value
+        )
+        augmented = []
+        for record in records:
+            record = yield self.augment(record)
+            augmented.append(record)
+        returnValue(augmented)
+
+
+    @inlineCallbacks
+    def recordWithUID(self, uid):
+        # MOVE2WHO, REMOVE THIS:
+        if not isinstance(uid, unicode):
+            log.warn(&quot;Need to change uid to unicode&quot;)
+            uid = uid.decode(&quot;utf-8&quot;)
+
+        record = yield self._directory.recordWithUID(uid)
+        record = yield self.augment(record)
+        returnValue(record)
+
+
+    @inlineCallbacks
+    def recordWithGUID(self, guid):
+        record = yield self._directory.recordWithGUID(guid)
+        record = yield self.augment(record)
+        returnValue(record)
+
+
+    @inlineCallbacks
+    def recordsWithRecordType(self, recordType):
+        records = yield self._directory.recordsWithRecordType(recordType)
+        augmented = []
+        for record in records:
+            record = yield self.augment(record)
+            augmented.append(record)
+        returnValue(augmented)
+
+
+    @inlineCallbacks
+    def recordWithShortName(self, recordType, shortName):
+        # log.debug(
+        #     &quot;Augment - recordWithShortName {rt}, {n}&quot;,
+        #     rt=recordType.name,
+        #     n=shortName
+        # )
+        # MOVE2WHO, REMOVE THIS:
+        if not isinstance(shortName, unicode):
+            log.warn(&quot;Need to change shortName to unicode&quot;)
+            shortName = shortName.decode(&quot;utf-8&quot;)
+
+        record = yield self._directory.recordWithShortName(recordType, shortName)
+        record = yield self.augment(record)
+        # log.debug(
+        #     &quot;Augment - recordWithShortName {rt}, {n} returned {r}, {u}&quot;,
+        #     rt=recordType.name,
+        #     n=shortName,
+        #     r=record.recordType.name,
+        #     u=record.uid
+        # )
+        returnValue(record)
+
+
+    @inlineCallbacks
+    def recordsWithEmailAddress(self, emailAddress):
+        # MOVE2WHO, REMOVE THIS:
+        if not isinstance(emailAddress, unicode):
+            log.warn(&quot;Need to change emailAddress to unicode&quot;)
+            emailAddress = emailAddress.decode(&quot;utf-8&quot;)
+
+        records = yield self._directory.recordsWithEmailAddress(emailAddress)
+        augmented = []
+        for record in records:
+            record = yield self.augment(record)
+            augmented.append(record)
+        returnValue(augmented)
+
+
+    @inlineCallbacks
+    def listRecords(self, recordType):
+        records = yield self._directory.listRecords(recordType)
+        augmented = []
+        for record in records:
+            record = yield self.augment(record)
+            augmented.append(record)
+        returnValue(augmented)
+
+
+    @inlineCallbacks
+    def updateRecords(self, records, create=False):
+        return self._directory.updateRecords(records, create=create)
+
+
+    @inlineCallbacks
+    def removeRecords(self, uids):
+        return self._directory.removeRecords(uids)
+
+
+    def assignToField(self, fields, name, value):
+        field = self.fieldName.lookupByName(name)
+        fields[field] = value
+
+
+    @inlineCallbacks
+    def augment(self, record):
+        if record is None:
+            returnValue(None)
+
+        try:
+            augmentRecord = yield self._augmentDB.getAugmentRecord(
+                record.uid,
+                self.recordTypeToOldName(record.recordType)
+            )
+        except KeyError:
+            # Augments does not know about this record type, so return
+            # the original record
+            returnValue(record)
+
+        fields = record.fields.copy()
+
+        # print(&quot;Got augment record&quot;, augmentRecord)
+
+        if augmentRecord:
+            # record.enabled = augmentRecord.enabled
+            # record.serverID = augmentRecord.serverID
+            self.assignToField(
+                fields, &quot;hasCalendars&quot;,
+                augmentRecord.enabledForCalendaring
+            )
+            self.assignToField(
+                fields, &quot;hasContacts&quot;,
+                augmentRecord.enabledForAddressBooks
+            )
+            autoScheduleMode = {
+                &quot;none&quot;: AutoScheduleMode.none,
+                &quot;accept-always&quot;: AutoScheduleMode.accept,
+                &quot;decline-always&quot;: AutoScheduleMode.decline,
+                &quot;accept-if-free&quot;: AutoScheduleMode.acceptIfFree,
+                &quot;decline-if-busy&quot;: AutoScheduleMode.declineIfBusy,
+                &quot;automatic&quot;: AutoScheduleMode.acceptIfFreeDeclineIfBusy,
+            }.get(augmentRecord.autoScheduleMode, None)
+            self.assignToField(
+                fields, &quot;autoScheduleMode&quot;,
+                autoScheduleMode
+            )
+            self.assignToField(
+                fields, &quot;autoAcceptGroup&quot;,
+                unicode(augmentRecord.autoAcceptGroup)
+            )
+            self.assignToField(
+                fields, &quot;loginAllowed&quot;,
+                augmentRecord.enabledForLogin
+            )
+
+            if (
+                (
+                    fields.get(self.fieldName.lookupByName(&quot;hasCalendars&quot;), False) or
+                    fields.get(self.fieldName.lookupByName(&quot;hasContacts&quot;), False)
+                ) and record.recordType == RecordType.group
+            ):
+                self.assignToField(fields, &quot;hasCalendars&quot;, False)
+                self.assignToField(fields, &quot;hasContacts&quot;, False)
+
+                # For augment records cloned from the Default augment record,
+                # don't emit this message:
+                if not augmentRecord.clonedFromDefault:
+                    log.error(&quot;Group '%s(%s)' cannot be enabled for calendaring or address books&quot; % (record.guid, record.shortNames[0],))
+
+        else:
+            # Groups are by default always enabled
+            # record.enabled = (record.recordType == record.service.recordType_groups)
+            # record.serverID = &quot;&quot;
+            self.assignToField(fields, &quot;hasCalendars&quot;, False)
+            self.assignToField(fields, &quot;hasContacts&quot;, False)
+            self.assignToField(fields, &quot;loginAllowed&quot;, False)
+
+        # print(&quot;Augmented fields&quot;, fields)
+
+        # Clone to a new record with the augmented fields
+        returnValue(AugmentedDirectoryRecord(self, record, fields))
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhodelegatespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/delegates.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/delegates.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/delegates.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><del>-# -*- test-case-name: twext.who.test.test_delegates -*-
</del><ins>+# -*- test-case-name: txdav.who.test.test_delegates -*-
</ins><span class="cx"> ##
</span><span class="cx"> # Copyright (c) 2013 Apple Inc. All rights reserved.
</span><span class="cx"> #
</span><span class="lines">@@ -19,13 +19,201 @@
</span><span class="cx"> Delegate assignments
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-from twisted.internet.defer import inlineCallbacks, returnValue
-from twext.who.idirectory import RecordType
</del><ins>+from twext.python.log import Logger
+from twext.who.directory import (
+    DirectoryService as BaseDirectoryService,
+    DirectoryRecord as BaseDirectoryRecord
+)
+from twext.who.expression import MatchExpression, MatchType
+from twext.who.idirectory import (
+    RecordType as BaseRecordType, FieldName, NotAllowedError
+)
+from twisted.internet.defer import inlineCallbacks, returnValue, succeed
+from twisted.python.constants import Names, NamedConstant
</ins><span class="cx"> 
</span><del>-from twext.python.log import Logger
</del><ins>+
</ins><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+
+class RecordType(Names):
+    &quot;&quot;&quot;
+    Constants for read-only delegates and read-write delegate groups
+    &quot;&quot;&quot;
+
+    readDelegateGroup = NamedConstant()
+    readDelegateGroup.description = u&quot;read-delegate-group&quot;
+
+    writeDelegateGroup = NamedConstant()
+    writeDelegateGroup.description = u&quot;write-delegate-group&quot;
+
+    readDelegatorGroup = NamedConstant()
+    readDelegatorGroup.description = u&quot;read-delegator-group&quot;
+
+    writeDelegatorGroup = NamedConstant()
+    writeDelegatorGroup.description = u&quot;write-delegator-group&quot;
+
+
+class DirectoryRecord(BaseDirectoryRecord):
+
+
+    @inlineCallbacks
+    def members(self, expanded=False):
+        &quot;&quot;&quot;
+        If this is a readDelegateGroup or writeDelegateGroup, the members
+        will consist of the records who are delegates *of* this record.
+        If this is a readDelegatorGroup or writeDelegatorGroup,
+        the members will consist of the records who have delegated *to*
+        this record.
+        &quot;&quot;&quot;
+        parentUID, proxyType = self.uid.split(&quot;#&quot;)
+
+        txn = self.service._store.newTransaction()
+
+        if self.recordType in (
+            RecordType.readDelegateGroup, RecordType.writeDelegateGroup
+        ):  # Members are delegates of this record
+            readWrite = (self.recordType is RecordType.writeDelegateGroup)
+            delegateUIDs = (
+                yield txn.delegates(parentUID, readWrite, expanded=expanded)
+            )
+
+        else:  # Members have delegated to this record
+            readWrite = (self.recordType is RecordType.writeDelegatorGroup)
+            delegateUIDs = (
+                yield txn.delegators(parentUID, readWrite)
+            )
+
+        records = []
+        for uid in delegateUIDs:
+            if uid != parentUID:
+                record = (yield self.service._masterDirectory.recordWithUID(uid))
+                if record is not None:
+                    records.append(record)
+        yield txn.commit()
+
+        returnValue(records)
+
+
+
+    @inlineCallbacks
+    def setMembers(self, memberRecords):
+        &quot;&quot;&quot;
+        Replace the members of this group with the new members.
+
+        @param memberRecords: The new members of the group
+        @type memberRecords: iterable of L{iDirectoryRecord}s
+        &quot;&quot;&quot;
+        if self.recordType not in (
+            RecordType.readDelegateGroup, RecordType.writeDelegateGroup
+        ):
+            raise NotAllowedError(&quot;Setting members not supported&quot;)
+
+        parentUID, proxyType = self.uid.split(&quot;#&quot;)
+        readWrite = (self.recordType is RecordType.writeDelegateGroup)
+
+        log.debug(
+            &quot;Setting delegate assignments for {u} ({rw}) to {m}&quot;.format(
+                u=parentUID, rw=(&quot;write&quot; if readWrite else &quot;read&quot;),
+                m=[r.uid for r in memberRecords]
+            )
+        )
+
+        txn = self.service._store.newTransaction()
+
+        yield txn.removeDelegates(parentUID, readWrite)
+        yield txn.removeDelegateGroups(parentUID, readWrite)
+
+        delegator = yield self.service._masterDirectory.recordWithUID(parentUID)
+
+        for delegate in memberRecords:
+            yield addDelegate(txn, delegator, delegate, readWrite)
+
+        yield txn.commit()
+
+
+
+def recordTypeToProxyType(recordType):
+    return {
+        RecordType.readDelegateGroup: &quot;calendar-proxy-read&quot;,
+        RecordType.writeDelegateGroup: &quot;calendar-proxy-write&quot;,
+        RecordType.readDelegatorGroup: &quot;calendar-proxy-read-for&quot;,
+        RecordType.writeDelegatorGroup: &quot;calendar-proxy-write-for&quot;,
+    }.get(recordType, None)
+
+
+def proxyTypeToRecordType(proxyType):
+    return {
+        &quot;calendar-proxy-read&quot;: RecordType.readDelegateGroup,
+        &quot;calendar-proxy-write&quot;: RecordType.writeDelegateGroup,
+        &quot;calendar-proxy-read-for&quot;: RecordType.readDelegatorGroup,
+        &quot;calendar-proxy-write-for&quot;: RecordType.writeDelegatorGroup,
+    }.get(proxyType, None)
+
+
+
+class DirectoryService(BaseDirectoryService):
+    &quot;&quot;&quot;
+    Delegate directory service
+    &quot;&quot;&quot;
+
+    recordType = RecordType
+
+
+    def __init__(self, realmName, store):
+        BaseDirectoryService.__init__(self, realmName)
+        self._store = store
+        self._masterDirectory = None
+
+
+    def setMasterDirectory(self, masterDirectory):
+        self._masterDirectory = masterDirectory
+
+
+    def recordWithShortName(self, recordType, shortName):
+        uid = shortName + &quot;#&quot; + recordTypeToProxyType(recordType)
+
+        record = DirectoryRecord(self, {
+            FieldName.uid: uid,
+            FieldName.recordType: recordType,
+            FieldName.shortNames: (uid,),
+        })
+        return succeed(record)
+
+
+    def recordWithUID(self, uid):
+        if &quot;#&quot; not in uid:  # Not a delegate group uid
+            return succeed(None)
+        uid, proxyType = uid.split(&quot;#&quot;)
+        recordType = proxyTypeToRecordType(proxyType)
+        if recordType is None:
+            return succeed(None)
+        return self.recordWithShortName(recordType, uid)
+
+
+    @inlineCallbacks
+    def recordsFromExpression(self, expression, records=None):
+        &quot;&quot;&quot;
+        It's only ever appropriate to look up delegate group record by
+        shortName or uid.  When wrapped by an aggregate directory, looking up
+        by shortName will already go directly to recordWithShortName.  However
+        when looking up by UID, it won't.  Inspect the expression to see if
+        it's one we can handle.
+        &quot;&quot;&quot;
+        if isinstance(expression, MatchExpression):
+            if(
+                (expression.fieldName is FieldName.uid) and
+                (expression.matchType is MatchType.equals) and
+                (&quot;#&quot; in expression.fieldValue)
+            ):
+                record = yield self.recordWithUID(expression.fieldValue)
+                if record is not None:
+                    returnValue((record,))
+
+        returnValue(())
+
+
+
</ins><span class="cx"> @inlineCallbacks
</span><span class="cx"> def addDelegate(txn, delegator, delegate, readWrite):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="lines">@@ -39,12 +227,12 @@
</span><span class="cx">     @param readWrite: if True, read and write access is granted; read-only
</span><span class="cx">         access otherwise
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    if delegate.recordType == RecordType.group:
</del><ins>+    if delegate.recordType == BaseRecordType.group:
</ins><span class="cx">         # find the groupID
</span><del>-        groupID, name, membershipHash = (yield txn.groupByGUID(delegate.guid))
-        yield txn.addDelegateGroup(delegator.guid, groupID, readWrite)
</del><ins>+        groupID, name, membershipHash = (yield txn.groupByUID(delegate.uid))
+        yield txn.addDelegateGroup(delegator.uid, groupID, readWrite)
</ins><span class="cx">     else:
</span><del>-        yield txn.addDelegate(delegator.guid, delegate.guid, readWrite)
</del><ins>+        yield txn.addDelegate(delegator.uid, delegate.uid, readWrite)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> @inlineCallbacks
</span><span class="lines">@@ -60,16 +248,16 @@
</span><span class="cx">     @param readWrite: if True, read and write access is revoked; read-only
</span><span class="cx">         access otherwise
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    if delegate.recordType == RecordType.group:
</del><ins>+    if delegate.recordType == BaseRecordType.group:
</ins><span class="cx">         # find the groupID
</span><del>-        groupID, name, membershipHash = (yield txn.groupByGUID(delegate.guid))
-        yield txn.removeDelegateGroup(delegator.guid, groupID, readWrite)
</del><ins>+        groupID, name, membershipHash = (yield txn.groupByUID(delegate.uid))
+        yield txn.removeDelegateGroup(delegator.uid, groupID, readWrite)
</ins><span class="cx">     else:
</span><del>-        yield txn.removeDelegate(delegator.guid, delegate.guid, readWrite)
</del><ins>+        yield txn.removeDelegate(delegator.uid, delegate.uid, readWrite)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> @inlineCallbacks
</span><del>-def delegatesOf(txn, delegator, readWrite):
</del><ins>+def delegatesOf(txn, delegator, readWrite, expanded=False):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Return the records of the delegates of &quot;delegator&quot;.  The type of access
</span><span class="cx">     is specified by the &quot;readWrite&quot; parameter.
</span><span class="lines">@@ -83,10 +271,12 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     records = []
</span><span class="cx">     directory = delegator.service
</span><del>-    delegateGUIDs = (yield txn.delegates(delegator.guid, readWrite))
-    for guid in delegateGUIDs:
-        if guid != delegator.guid:
-            record = (yield directory.recordWithGUID(guid))
</del><ins>+    delegateUIDs = (
+        yield txn.delegates(delegator.uid, readWrite, expanded=expanded)
+    )
+    for uid in delegateUIDs:
+        if uid != delegator.uid:
+            record = (yield directory.recordWithUID(uid))
</ins><span class="cx">             if record is not None:
</span><span class="cx">                 records.append(record)
</span><span class="cx">     returnValue(records)
</span><span class="lines">@@ -107,18 +297,10 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     records = []
</span><span class="cx">     directory = delegate.service
</span><del>-    delegatorGUIDs = (yield txn.delegators(delegate.guid, readWrite))
-    for guid in delegatorGUIDs:
-        if guid != delegate.guid:
-            record = (yield directory.recordWithGUID(guid))
</del><ins>+    delegatorUIDs = (yield txn.delegators(delegate.uid, readWrite))
+    for uid in delegatorUIDs:
+        if uid != delegate.uid:
+            record = (yield directory.recordWithUID(uid))
</ins><span class="cx">             if record is not None:
</span><span class="cx">                 records.append(record)
</span><span class="cx">     returnValue(records)
</span><del>-
-
-def allGroupDelegates(txn):
-    &quot;&quot;&quot;
-    @return: the GUIDs of all groups which are currently delegated to
-    @rtype: a Deferred which fires with a set() of GUID strings
-    &quot;&quot;&quot;
-    return txn.allGroupDelegates()
</del></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhodirectorypyfromrev12913CalendarServerbranchesuserssagenmove2who3txdavwhodirectorypy"></a>
<div class="copfile"><h4>Copied: CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py (from rev 12913, CalendarServer/branches/users/sagen/move2who-3/txdav/who/directory.py) (0 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py                                (rev 0)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -0,0 +1,359 @@
</span><ins>+##
+# Copyright (c) 2006-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.
+##
+
+&quot;&quot;&quot;
+Calendar/Contacts specific methods for DirectoryRecord
+&quot;&quot;&quot;
+
+
+import uuid
+
+from twext.python.log import Logger
+from twext.who.expression import (
+    MatchType, Operand, MatchExpression, CompoundExpression, MatchFlags
+)
+from twext.who.idirectory import RecordType as BaseRecordType
+from twisted.cred.credentials import UsernamePassword
+from twisted.internet.defer import inlineCallbacks, returnValue
+from txdav.who.idirectory import RecordType as DAVRecordType
+from txweb2.auth.digest import DigestedCredentials
+
+log = Logger()
+
+
+__all__ = [
+    &quot;CalendarDirectoryRecordMixin&quot;,
+    &quot;CalendarDirectoryServiceMixin&quot;,
+]
+
+
+
+class CalendarDirectoryServiceMixin(object):
+
+    guid = &quot;1332A615-4D3A-41FE-B636-FBE25BFB982E&quot;
+
+    # Must maintain the hack for a bit longer:
+    def setPrincipalCollection(self, principalCollection):
+        &quot;&quot;&quot;
+        Set the principal service that the directory relies on for doing proxy tests.
+
+        @param principalService: the principal service.
+        @type principalService: L{DirectoryProvisioningResource}
+        &quot;&quot;&quot;
+        self.principalCollection = principalCollection
+
+
+    @inlineCallbacks
+    def recordWithCalendarUserAddress(self, address):
+        # FIXME: moved this here to avoid circular import problems
+        from txdav.caldav.datastore.scheduling.cuaddress import normalizeCUAddr
+        address = normalizeCUAddr(address)
+        record = None
+        if address.startswith(&quot;urn:uuid:&quot;):
+            guid = address[9:]
+            record = yield self.recordWithGUID(uuid.UUID(guid))
+        elif address.startswith(&quot;mailto:&quot;):
+            records = yield self.recordsWithEmailAddress(address[7:])
+            if records:
+                returnValue(records[0])
+            else:
+                returnValue(None)
+        elif address.startswith(&quot;/principals/&quot;):
+            parts = address.split(&quot;/&quot;)
+            if len(parts) == 4:
+                if parts[2] == &quot;__uids__&quot;:
+                    uid = parts[3]
+                    record = yield self.recordWithUID(uid)
+                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 = [
+            (&quot;fullNames&quot;, MatchType.contains),
+            (&quot;emailAddresses&quot;, 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)
+
+
+    def recordsMatchingFieldsWithCUType(self, fields, operand=Operand.OR,
+                                        cuType=None):
+        if cuType:
+            recordType = CalendarDirectoryRecordMixin.fromCUType(cuType)
+        else:
+            recordType = None
+
+        return self.recordsMatchingFields(
+            fields, operand=operand, recordType=recordType
+        )
+
+
+    def recordsMatchingFields(self, fields, operand=Operand.OR, recordType=None):
+        &quot;&quot;&quot;
+        @param fields: a iterable of tuples, each tuple consisting of:
+            directory field name (C{unicode})
+            search term (C{unicode})
+            match flags (L{twext.who.expression.MatchFlags})
+            match type (L{twext.who.expression.MatchType})
+        &quot;&quot;&quot;
+        subExpressions = []
+        for fieldName, searchTerm, matchFlags, matchType in fields:
+            subExpression = MatchExpression(
+                self.fieldName.lookupByName(fieldName),
+                searchTerm,
+                matchType,
+                matchFlags
+            )
+            subExpressions.append(subExpression)
+
+        expression = CompoundExpression(subExpressions, operand)
+        return self.recordsFromExpression(expression)
+
+
+    _oldRecordTypeNames = {
+        &quot;address&quot;: &quot;addresses&quot;,
+        &quot;group&quot;: &quot;groups&quot;,
+        &quot;location&quot;: &quot;locations&quot;,
+        &quot;resource&quot;: &quot;resources&quot;,
+        &quot;user&quot;: &quot;users&quot;,
+        &quot;readDelegateGroup&quot;: &quot;readDelegateGroups&quot;,
+        &quot;writeDelegateGroup&quot;: &quot;writeDelegateGroups&quot;,
+        &quot;readDelegatorGroup&quot;: &quot;readDelegatorGroups&quot;,
+        &quot;writeDelegatorGroup&quot;: &quot;writeDelegatorGroups&quot;,
+    }
+
+    # 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 &quot;users&quot;, &quot;locations&quot;
+    def recordTypeToOldName(self, recordType):
+        return self._oldRecordTypeNames[recordType.name]
+
+    def oldNameToRecordType(self, oldName):
+        for name, value in self._oldRecordTypeNames.iteritems():
+            if oldName == value:
+                return self.recordType.lookupByName(name)
+        return None
+
+
+
+class CalendarDirectoryRecordMixin(object):
+
+
+    @inlineCallbacks
+    def verifyCredentials(self, credentials):
+
+        # XYZZY REMOVE THIS, it bypasses all authentication!:
+        returnValue(True)
+
+        if isinstance(credentials, UsernamePassword):
+            log.debug(&quot;UsernamePassword&quot;)
+            returnValue(
+                (yield self.verifyPlaintextPassword(credentials.password))
+            )
+
+        elif isinstance(credentials, DigestedCredentials):
+            log.debug(&quot;DigestedCredentials&quot;)
+            returnValue(
+                (yield self.verifyHTTPDigest(
+                    self.shortNames[0],
+                    self.service.realmName,
+                    credentials.fields[&quot;uri&quot;],
+                    credentials.fields[&quot;nonce&quot;],
+                    credentials.fields.get(&quot;cnonce&quot;, &quot;&quot;),
+                    credentials.fields[&quot;algorithm&quot;],
+                    credentials.fields.get(&quot;nc&quot;, &quot;&quot;),
+                    credentials.fields.get(&quot;qop&quot;, &quot;&quot;),
+                    credentials.fields[&quot;response&quot;],
+                    credentials.method
+                ))
+            )
+
+
+    @property
+    def calendarUserAddresses(self):
+        if not self.hasCalendars:
+            return frozenset()
+
+        try:
+            cuas = set(
+                [&quot;mailto:%s&quot; % (emailAddress,)
+                 for emailAddress in self.emailAddresses]
+            )
+        except AttributeError:
+            cuas = set()
+
+        try:
+            if self.guid:
+                if isinstance(self.guid, uuid.UUID):
+                    guid = unicode(self.guid).upper()
+                else:
+                    guid = self.guid
+                cuas.add(&quot;urn:uuid:{guid}&quot;.format(guid=guid))
+        except AttributeError:
+            # No guid
+            pass
+        cuas.add(&quot;/principals/__uids__/{uid}/&quot;.format(uid=self.uid))
+        for shortName in self.shortNames:
+            cuas.add(&quot;/principals/{rt}/{sn}/&quot;.format(
+                rt=self.service.recordTypeToOldName(self.recordType),
+                sn=shortName)
+            )
+        return frozenset(cuas)
+
+
+    # Mapping from directory record.recordType to RFC2445 CUTYPE values
+    _cuTypes = {
+        BaseRecordType.user: 'INDIVIDUAL',
+        BaseRecordType.group: 'GROUP',
+        DAVRecordType.resource: 'RESOURCE',
+        DAVRecordType.location: 'ROOM',
+    }
+
+
+    def getCUType(self):
+        return self._cuTypes.get(self.recordType, &quot;UNKNOWN&quot;)
+
+
+    @classmethod
+    def fromCUType(cls, cuType):
+        for key, val in cls._cuTypes.iteritems():
+            if val == cuType:
+                return key
+        return None
+
+
+    def applySACLs(self):
+        &quot;&quot;&quot;
+        Disable calendaring and addressbooks as dictated by SACLs
+        &quot;&quot;&quot;
+
+        # FIXME: need to re-implement SACLs
+        # if config.EnableSACLs and self.CheckSACL:
+        #     username = self.shortNames[0]
+        #     if self.CheckSACL(username, &quot;calendar&quot;) != 0:
+        #         self.log.debug(&quot;%s is not enabled for calendaring due to SACL&quot;
+        #                        % (username,))
+        #         self.enabledForCalendaring = False
+        #     if self.CheckSACL(username, &quot;addressbook&quot;) != 0:
+        #         self.log.debug(&quot;%s is not enabled for addressbooks due to SACL&quot;
+        #                        % (username,))
+        #         self.enabledForAddressBooks = False
+
+
+    @property
+    def displayName(self):
+        return self.fullNames[0]
+
+
+    def cacheToken(self):
+        &quot;&quot;&quot;
+        Generate a token that can be uniquely used to identify the state of this record for use
+        in a cache.
+        &quot;&quot;&quot;
+        return hash((
+            self.__class__.__name__,
+            self.service.realmName,
+            self.recordType.name,
+            self.shortNames,
+            self.uid,
+            self.hasCalendars,
+        ))
+
+
+    def canonicalCalendarUserAddress(self):
+        &quot;&quot;&quot;
+            Return a CUA for this record, preferring in this order:
+            urn:uuid: form
+            mailto: form
+            first in calendarUserAddresses list
+        &quot;&quot;&quot;
+
+        cua = &quot;&quot;
+        for candidate in self.calendarUserAddresses:
+            # Pick the first one, but urn:uuid: and mailto: can override
+            if not cua:
+                cua = candidate
+            # But always immediately choose the urn:uuid: form
+            if candidate.startswith(&quot;urn:uuid:&quot;):
+                cua = candidate
+                break
+            # Prefer mailto: if no urn:uuid:
+            elif candidate.startswith(&quot;mailto:&quot;):
+                cua = candidate
+        return cua
+
+
+    def enabledAsOrganizer(self):
+        # MOVE2WHO FIXME TO LOOK AT CONFIG
+        if self.recordType == self.service.recordType.user:
+            return True
+        elif self.recordType == self.service.recordType.group:
+            return False  # config.Scheduling.Options.AllowGroupAsOrganizer
+        elif self.recordType == self.service.recordType.location:
+            return False  # config.Scheduling.Options.AllowLocationAsOrganizer
+        elif self.recordType == self.service.recordType.resource:
+            return False  # config.Scheduling.Options.AllowResourceAsOrganizer
+        else:
+            return False
+
+
+    #MOVE2WHO
+    def thisServer(self):
+        return True
+
+
+    def isLoginEnabled(self):
+        return self.loginAllowed
+
+
+    #MOVE2WHO
+    def calendarsEnabled(self):
+        # In the old world, this *also* looked at config:
+        # return config.EnableCalDAV and self.enabledForCalendaring
+        return self.hasCalendars
+
+
+    def getAutoScheduleMode(self, organizer):
+        # MOVE2WHO Fix this to take organizer into account:
+        return self.autoScheduleMode
+
+
+    def canAutoSchedule(self, organizer=None):
+        # MOVE2WHO Fix this:
+        return True
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhogroupspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/groups.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/groups.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/groups.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><del>-# -*- test-case-name: twext.who.test.test_groups -*-
</del><ins>+# -*- test-case-name: txdav.who.test.test_groups -*-
</ins><span class="cx"> ##
</span><span class="cx"> # Copyright (c) 2013 Apple Inc. All rights reserved.
</span><span class="cx"> #
</span><span class="lines">@@ -22,7 +22,6 @@
</span><span class="cx"> from twext.enterprise.dal.record import fromTable
</span><span class="cx"> from twext.enterprise.dal.syntax import Delete, Select
</span><span class="cx"> from twext.enterprise.jobqueue import WorkItem, PeerConnectionPool
</span><del>-from txdav.who.delegates import allGroupDelegates
</del><span class="cx"> from twext.who.idirectory import RecordType
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue
</span><span class="cx"> from txdav.common.datastore.sql_tables import schema
</span><span class="lines">@@ -46,17 +45,14 @@
</span><span class="cx">         # Delete all other work items
</span><span class="cx">         yield Delete(From=self.table, Where=None).on(self.transaction)
</span><span class="cx"> 
</span><del>-        oldGroupCacher = getattr(self.transaction, &quot;_groupCacher&quot;, None)
-        newGroupCacher = getattr(self.transaction, &quot;_newGroupCacher&quot;, None)
-        if oldGroupCacher is not None or newGroupCacher is not None:
</del><ins>+        groupCacher = getattr(self.transaction, &quot;_groupCacher&quot;, None)
+        if groupCacher is not None:
</ins><span class="cx"> 
</span><span class="cx">             # Schedule next update
</span><span class="cx"> 
</span><del>-            # TODO: Be sure to move updateSeconds to the new cacher
-            # implementation
</del><span class="cx">             notBefore = (
</span><span class="cx">                 datetime.datetime.utcnow() +
</span><del>-                datetime.timedelta(seconds=oldGroupCacher.updateSeconds)
</del><ins>+                datetime.timedelta(seconds=groupCacher.updateSeconds)
</ins><span class="cx">             )
</span><span class="cx">             log.debug(
</span><span class="cx">                 &quot;Scheduling next group cacher update: {when}&quot;, when=notBefore
</span><span class="lines">@@ -68,22 +64,13 @@
</span><span class="cx"> 
</span><span class="cx">             # New implmementation
</span><span class="cx">             try:
</span><del>-                newGroupCacher.update(self.transaction)
</del><ins>+                yield groupCacher.update(self.transaction)
</ins><span class="cx">             except Exception, e:
</span><span class="cx">                 log.error(
</span><span class="cx">                     &quot;Failed to update new group membership cache ({error})&quot;,
</span><span class="cx">                     error=e
</span><span class="cx">                 )
</span><span class="cx"> 
</span><del>-            # Old implmementation
-            try:
-                oldGroupCacher.updateCache()
-            except Exception, e:
-                log.error(
-                    &quot;Failed to update old group membership cache ({error})&quot;,
-                    error=e
-                )
-
</del><span class="cx">         else:
</span><span class="cx">             notBefore = (
</span><span class="cx">                 datetime.datetime.utcnow() +
</span><span class="lines">@@ -126,25 +113,28 @@
</span><span class="cx"> 
</span><span class="cx"> class GroupRefreshWork(WorkItem, fromTable(schema.GROUP_REFRESH_WORK)):
</span><span class="cx"> 
</span><del>-    group = property(lambda self: self.groupGUID)
</del><ins>+    # Note, the schema has &quot;groupGuid&quot;, but really it's a UID.  At some point
+    # we should change the column name.
+    group = property(lambda self: self.groupGuid)
</ins><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def doWork(self):
</span><del>-
</del><span class="cx">         # Delete all other work items for this group
</span><span class="cx">         yield Delete(
</span><del>-            From=self.table, Where=(self.table.GROUP_GUID == self.groupGUID)
</del><ins>+            From=self.table, Where=(self.table.GROUP_GUID == self.groupGuid)
</ins><span class="cx">         ).on(self.transaction)
</span><span class="cx"> 
</span><span class="cx">         groupCacher = getattr(self.transaction, &quot;_groupCacher&quot;, None)
</span><span class="cx">         if groupCacher is not None:
</span><span class="cx"> 
</span><span class="cx">             try:
</span><del>-                groupCacher.refreshGroup(self.transaction, self.groupGUID)
</del><ins>+                yield groupCacher.refreshGroup(
+                    self.transaction, self.groupGuid.decode(&quot;utf-8&quot;)
+                )
</ins><span class="cx">             except Exception, e:
</span><span class="cx">                 log.error(
</span><span class="cx">                     &quot;Failed to refresh group {group} {err}&quot;,
</span><del>-                    group=self.groupGUID, err=e
</del><ins>+                    group=self.groupGuid, err=e
</ins><span class="cx">                 )
</span><span class="cx"> 
</span><span class="cx">         else:
</span><span class="lines">@@ -154,11 +144,11 @@
</span><span class="cx">             )
</span><span class="cx">             log.debug(
</span><span class="cx">                 &quot;Rescheduling group refresh for {group}: {when}&quot;,
</span><del>-                group=self.groupGUID, when=notBefore
</del><ins>+                group=self.groupGuid, when=notBefore
</ins><span class="cx">             )
</span><span class="cx">             yield self.transaction.enqueue(
</span><span class="cx">                 GroupRefreshWork,
</span><del>-                groupGUID=self.groupGUID, notBefore=notBefore
</del><ins>+                groupGuid=self.groupGuid, notBefore=notBefore
</ins><span class="cx">             )
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -182,6 +172,7 @@
</span><span class="cx">             )
</span><span class="cx">         ).on(self.transaction)
</span><span class="cx"> 
</span><ins>+    # MOVE2WHO
</ins><span class="cx">     # TODO: Pull this over from groupcacher branch
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -201,6 +192,7 @@
</span><span class="cx">         records.add(record)
</span><span class="cx">         for member in (yield record.members()):
</span><span class="cx">             if member not in records:
</span><ins>+                #MOVE2WHO
</ins><span class="cx">                 #TODO:  HACK for old-style XML. FIX
</span><span class="cx">                 if (
</span><span class="cx">                     member.recordType != RecordType.group and
</span><span class="lines">@@ -219,14 +211,14 @@
</span><span class="cx">     of two lists -- one for added/updated assignments, and one for removed
</span><span class="cx">     assignments.
</span><span class="cx"> 
</span><del>-    @param old: dictionary of delegator: (readGroupGUID, writeGroupGUID)
</del><ins>+    @param old: dictionary of delegator: (readGroupUID, writeGroupUID)
</ins><span class="cx">     @type old: C{dict}
</span><span class="cx"> 
</span><del>-    @param new: dictionary of delegator: (readGroupGUID, writeGroupGUID)
</del><ins>+    @param new: dictionary of delegator: (readGroupUID, writeGroupUID)
</ins><span class="cx">     @type new: C{dict}
</span><span class="cx"> 
</span><span class="cx">     @return: Tuple of two lists; the first list contains tuples of (delegator,
</span><del>-        (readGroupGUID, writeGroupGUID)), and represents all the new or updated
</del><ins>+        (readGroupUID, writeGroupUID)), and represents all the new or updated
</ins><span class="cx">         assignments.  The second list contains all the delegators which used to
</span><span class="cx">         have a delegate but don't anymore.
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="lines">@@ -251,13 +243,16 @@
</span><span class="cx"> 
</span><span class="cx">     def __init__(
</span><span class="cx">         self, directory,
</span><del>-        useExternalProxies=False, externalProxiesSource=None
</del><ins>+        updateSeconds=600,
+        useExternalProxies=False,
+        externalProxiesSource=None
</ins><span class="cx">     ):
</span><span class="cx">         self.directory = directory
</span><span class="cx">         self.useExternalProxies = useExternalProxies
</span><span class="cx">         if useExternalProxies and externalProxiesSource is None:
</span><span class="cx">             externalProxiesSource = self.directory.getExternalProxyAssignments
</span><span class="cx">         self.externalProxiesSource = externalProxiesSource
</span><ins>+        self.updateSeconds = updateSeconds
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -269,19 +264,21 @@
</span><span class="cx">         # yield self.applyExternalAssignments(txn, externalAssignments)
</span><span class="cx"> 
</span><span class="cx">         # Figure out which groups matter
</span><del>-        groupGUIDs = yield self.groupsToRefresh(txn)
</del><ins>+        groupUIDs = yield self.groupsToRefresh(txn)
</ins><span class="cx">         self.log.debug(
</span><del>-            &quot;Number of groups to refresh: {num}&quot;, num=len(groupGUIDs)
</del><ins>+            &quot;Number of groups to refresh: {num}&quot;, num=len(groupUIDs)
</ins><span class="cx">         )
</span><span class="cx">         # For each of those groups, create a per-group refresh work item
</span><del>-        for groupGUID in groupGUIDs:
</del><ins>+        for groupUID in groupUIDs:
</ins><span class="cx">             notBefore = (
</span><span class="cx">                 datetime.datetime.utcnow() +
</span><span class="cx">                 datetime.timedelta(seconds=1)
</span><span class="cx">             )
</span><ins>+            self.log.debug(&quot;Enqueuing group refresh for {u}&quot;, u=groupUID)
</ins><span class="cx">             yield txn.enqueue(
</span><del>-                GroupRefreshWork, groupGUID=groupGUID, notBefore=notBefore
</del><ins>+                GroupRefreshWork, groupGuid=groupUID, notBefore=notBefore
</ins><span class="cx">             )
</span><ins>+            self.log.debug(&quot;Enqueued group refresh for {u}&quot;, u=groupUID)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -290,84 +287,91 @@
</span><span class="cx">         oldAssignments = (yield txn.externalDelegates())
</span><span class="cx"> 
</span><span class="cx">         # external assignments is of the form:
</span><del>-        # { delegatorGUID: (readDelegateGroupGUID, writeDelegateGroupGUID),
</del><ins>+        # { delegatorUID: (readDelegateGroupUID, writeDelegateGroupUID),
</ins><span class="cx">         # }
</span><span class="cx"> 
</span><span class="cx">         changed, removed = diffAssignments(oldAssignments, newAssignments)
</span><span class="cx">         if changed:
</span><span class="cx">             for (
</span><del>-                delegatorGUID, (readDelegateGUID, writeDelegateGUID)
</del><ins>+                delegatorUID, (readDelegateUID, writeDelegateUID)
</ins><span class="cx">             ) in changed:
</span><span class="cx">                 readDelegateGroupID = writeDelegateGroupID = None
</span><del>-                if readDelegateGUID:
</del><ins>+                if readDelegateUID:
</ins><span class="cx">                     readDelegateGroupID, _ignore_name, hash = (
</span><del>-                        yield txn.groupByGUID(readDelegateGUID)
</del><ins>+                        yield txn.groupByUID(readDelegateUID)
</ins><span class="cx">                     )
</span><del>-                if writeDelegateGUID:
</del><ins>+                if writeDelegateUID:
</ins><span class="cx">                     writeDelegateGroupID, _ignore_name, hash = (
</span><del>-                        yield txn.groupByGUID(writeDelegateGUID)
</del><ins>+                        yield txn.groupByUID(writeDelegateUID)
</ins><span class="cx">                     )
</span><span class="cx">                 yield txn.assignExternalDelegates(
</span><del>-                    delegatorGUID, readDelegateGroupID, writeDelegateGroupID,
-                    readDelegateGUID, writeDelegateGUID
</del><ins>+                    delegatorUID, readDelegateGroupID, writeDelegateGroupID,
+                    readDelegateUID, writeDelegateUID
</ins><span class="cx">                 )
</span><span class="cx">         if removed:
</span><del>-            for delegatorGUID in removed:
</del><ins>+            for delegatorUID in removed:
</ins><span class="cx">                 yield txn.assignExternalDelegates(
</span><del>-                    delegatorGUID, None, None, None, None
</del><ins>+                    delegatorUID, None, None, None, None
</ins><span class="cx">                 )
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def refreshGroup(self, txn, groupGUID):
</del><ins>+    def refreshGroup(self, txn, groupUID):
</ins><span class="cx">         # Does the work of a per-group refresh work item
</span><del>-        # Faults in the flattened membership of a group, as GUIDs
</del><ins>+        # Faults in the flattened membership of a group, as UIDs
</ins><span class="cx">         # and updates the GROUP_MEMBERSHIP table
</span><del>-        record = (yield self.directory.recordWithGUID(groupGUID))
-        membershipHashContent = hashlib.md5()
-        members = (yield expandedMembers(record))
-        members = list(members)
-        members.sort(cmp=lambda x, y: cmp(x.guid, y.guid))
-        for member in members:
-            membershipHashContent.update(str(member.guid))
-        membershipHash = membershipHashContent.hexdigest()
-        groupID, _ignore_cachedName, cachedMembershipHash = (
-            yield txn.groupByGUID(groupGUID)
-        )
-
-        if cachedMembershipHash != membershipHash:
-            membershipChanged = True
-            self.log.debug(
-                &quot;Group '{group}' changed&quot;, group=record.fullNames[0]
</del><ins>+        self.log.debug(&quot;Faulting in group: {g}&quot;, g=groupUID)
+        record = (yield self.directory.recordWithUID(groupUID))
+        if record is None:
+            # FIXME: the group has disappeared from the directory.
+            # How do we want to handle this?
+            self.log.info(&quot;Group has disappeared: {g}&quot;, g=groupUID)
+        else:
+            self.log.debug(&quot;Got group record: {u}&quot;, u=record.uid)
+            membershipHashContent = hashlib.md5()
+            members = (yield expandedMembers(record))
+            members = list(members)
+            members.sort(cmp=lambda x, y: cmp(x.uid, y.uid))
+            for member in members:
+                membershipHashContent.update(str(member.uid))
+            membershipHash = membershipHashContent.hexdigest()
+            groupID, _ignore_cachedName, cachedMembershipHash = (
+                yield txn.groupByUID(groupUID)
</ins><span class="cx">             )
</span><del>-        else:
-            membershipChanged = False
</del><span class="cx"> 
</span><del>-        yield txn.updateGroup(groupGUID, record.fullNames[0], membershipHash)
</del><ins>+            if cachedMembershipHash != membershipHash:
+                membershipChanged = True
+                self.log.debug(
+                    &quot;Group '{group}' changed&quot;, group=record.fullNames[0]
+                )
+            else:
+                membershipChanged = False
</ins><span class="cx"> 
</span><del>-        if membershipChanged:
-            newMemberGUIDs = set()
-            for member in members:
-                newMemberGUIDs.add(member.guid)
-            yield self.synchronizeMembers(txn, groupID, newMemberGUIDs)
</del><ins>+            yield txn.updateGroup(groupUID, record.fullNames[0], membershipHash)
</ins><span class="cx"> 
</span><del>-        yield self.scheduleEventReconciliations(txn, groupID, groupGUID)
</del><ins>+            if membershipChanged:
+                newMemberUIDs = set()
+                for member in members:
+                    newMemberUIDs.add(member.uid)
+                yield self.synchronizeMembers(txn, groupID, newMemberUIDs)
</ins><span class="cx"> 
</span><ins>+            yield self.scheduleEventReconciliations(txn, groupID, groupUID)
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx">     @inlineCallbacks
</span><del>-    def synchronizeMembers(self, txn, groupID, newMemberGUIDs):
</del><ins>+    def synchronizeMembers(self, txn, groupID, newMemberUIDs):
</ins><span class="cx">         numRemoved = numAdded = 0
</span><del>-        cachedMemberGUIDs = (yield txn.membersOfGroup(groupID))
</del><ins>+        cachedMemberUIDs = (yield txn.membersOfGroup(groupID))
</ins><span class="cx"> 
</span><del>-        for memberGUID in cachedMemberGUIDs:
-            if memberGUID not in newMemberGUIDs:
</del><ins>+        for memberUID in cachedMemberUIDs:
+            if memberUID not in newMemberUIDs:
</ins><span class="cx">                 numRemoved += 1
</span><del>-                yield txn.removeMemberFromGroup(memberGUID, groupID)
</del><ins>+                yield txn.removeMemberFromGroup(memberUID, groupID)
</ins><span class="cx"> 
</span><del>-        for memberGUID in newMemberGUIDs:
-            if memberGUID not in cachedMemberGUIDs:
</del><ins>+        for memberUID in newMemberUIDs:
+            if memberUID not in cachedMemberUIDs:
</ins><span class="cx">                 numAdded += 1
</span><del>-                yield txn.addMemberToGroup(memberGUID, groupID)
</del><ins>+                yield txn.addMemberToGroup(memberUID, groupID)
</ins><span class="cx"> 
</span><span class="cx">         returnValue((numAdded, numRemoved))
</span><span class="cx"> 
</span><span class="lines">@@ -378,23 +382,23 @@
</span><span class="cx">         The members of the given group as recorded in the db
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         members = set()
</span><del>-        memberGUIDs = (yield txn.membersOfGroup(groupID))
-        for guid in memberGUIDs:
-            record = (yield self.directory.recordWithGUID(guid))
</del><ins>+        memberUIDs = (yield txn.membersOfGroup(groupID))
+        for uid in memberUIDs:
+            record = (yield self.directory.recordWithUID(uid))
</ins><span class="cx">             if record is not None:
</span><span class="cx">                 members.add(record)
</span><span class="cx">         returnValue(members)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def cachedGroupsFor(self, txn, guid):
</del><ins>+    def cachedGroupsFor(self, txn, uid):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        The IDs of the groups the guid is a member of
</del><ins>+        The UIDs of the groups the uid is a member of
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        return txn.groupsFor(guid)
</del><ins>+        return txn.groupsFor(uid)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def scheduleEventReconciliations(self, txn, groupID, groupGUID):
</del><ins>+    def scheduleEventReconciliations(self, txn, groupID, groupUID):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Find all events who have this groupID as an attendee and create
</span><span class="cx">         work items for them.
</span><span class="lines">@@ -415,29 +419,29 @@
</span><span class="cx">             )
</span><span class="cx">             log.debug(
</span><span class="cx">                 &quot;scheduling group reconciliation for &quot;
</span><del>-                &quot;({eventID}, {groupID}, {groupGUID}): {when}&quot;,
</del><ins>+                &quot;({eventID}, {groupID}, {groupUID}): {when}&quot;,
</ins><span class="cx">                 eventID=eventID,
</span><span class="cx">                 groupID=groupID,
</span><del>-                groupGUID=groupGUID,
</del><ins>+                groupUID=groupUID,
</ins><span class="cx">                 when=notBefore)
</span><span class="cx"> 
</span><span class="cx">             yield txn.enqueue(
</span><span class="cx">                 GroupAttendeeReconciliationWork,
</span><span class="cx">                 eventID=eventID,
</span><span class="cx">                 groupID=groupID,
</span><del>-                groupGUID=groupGUID,
</del><ins>+                groupGuid=groupUID,
</ins><span class="cx">                 notBefore=notBefore
</span><span class="cx">             )
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def groupsToRefresh(self, txn):
</span><del>-        delegatedGUIDs = set((yield allGroupDelegates(txn)))
</del><ins>+        delegatedUIDs = set((yield txn.allGroupDelegates()))
</ins><span class="cx">         self.log.info(
</span><del>-            &quot;There are {count} group delegates&quot;, count=len(delegatedGUIDs)
</del><ins>+            &quot;There are {count} group delegates&quot;, count=len(delegatedUIDs)
</ins><span class="cx">         )
</span><span class="cx"> 
</span><del>-        attendeeGroupGUIDs = set()
</del><ins>+        attendeeGroupUIDs = set()
</ins><span class="cx"> 
</span><span class="cx">         # get all groups from events
</span><span class="cx">         groupAttendee = schema.GROUP_ATTENDEE
</span><span class="lines">@@ -447,7 +451,7 @@
</span><span class="cx">         ).on(txn)
</span><span class="cx">         groupIDs = set([row[0] for row in rows])
</span><span class="cx"> 
</span><del>-        # get groupGUIDs
</del><ins>+        # get groupUIDs
</ins><span class="cx">         if groupIDs:
</span><span class="cx">             gr = schema.GROUPS
</span><span class="cx">             rows = yield Select(
</span><span class="lines">@@ -455,6 +459,8 @@
</span><span class="cx">                 From=gr,
</span><span class="cx">                 Where=gr.GROUP_ID.In(groupIDs)
</span><span class="cx">             ).on(txn)
</span><del>-            attendeeGroupGUIDs = set([row[0] for row in rows])
</del><ins>+            attendeeGroupUIDs = set([row[0] for row in rows])
</ins><span class="cx"> 
</span><del>-        returnValue(delegatedGUIDs.union(attendeeGroupGUIDs))
</del><ins>+        # FIXME: is this a good place to clear out unreferenced groups?
+
+        returnValue(delegatedUIDs.union(attendeeGroupUIDs))
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhotestaccountsaccountsxml"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/accounts/accounts.xml (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/accounts/accounts.xml        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/accounts/accounts.xml        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -18,174 +18,339 @@
</span><span class="cx"> 
</span><span class="cx"> &lt;!DOCTYPE accounts SYSTEM &quot;accounts.dtd&quot;&gt;
</span><span class="cx"> 
</span><del>-&lt;accounts realm=&quot;Test Realm&quot;&gt;
-  &lt;user&gt;
</del><ins>+&lt;directory realm=&quot;Test Realm&quot;&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;admin&lt;/uid&gt;
</span><del>-    &lt;guid&gt;admin&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;admin&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;admin&lt;/password&gt;
</span><del>-    &lt;name&gt;Super User&lt;/name&gt;
-    &lt;first-name&gt;Super&lt;/first-name&gt;
-    &lt;last-name&gt;User&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;Super User&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;apprentice&lt;/uid&gt;
</span><del>-    &lt;guid&gt;apprentice&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;apprentice&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;apprentice&lt;/password&gt;
</span><del>-    &lt;name&gt;Apprentice Super User&lt;/name&gt;
-    &lt;first-name&gt;Apprentice&lt;/first-name&gt;
-    &lt;last-name&gt;Super User&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;Apprentice Super User&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;wsanchez&lt;/uid&gt;
</span><del>-    &lt;guid&gt;wsanchez&lt;/guid&gt;
-    &lt;email-address&gt;wsanchez@example.com&lt;/email-address&gt;
</del><ins>+    &lt;short-name&gt;wsanchez&lt;/short-name&gt;
+    &lt;email&gt;wsanchez@example.com&lt;/email&gt;
</ins><span class="cx">     &lt;password&gt;test&lt;/password&gt;
</span><del>-    &lt;name&gt;Wilfredo Sanchez Vega&lt;/name&gt;
-    &lt;first-name&gt;Wilfredo&lt;/first-name&gt;
-    &lt;last-name&gt;Sanchez Vega&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;Wilfredo Sanchez Vega&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;cdaboo&lt;/uid&gt;
</span><del>-    &lt;guid&gt;cdaboo&lt;/guid&gt;
-    &lt;email-address&gt;cdaboo@example.com&lt;/email-address&gt;
</del><ins>+    &lt;short-name&gt;cdaboo&lt;/short-name&gt;
+    &lt;email&gt;cdaboo@example.com&lt;/email&gt;
</ins><span class="cx">     &lt;password&gt;test&lt;/password&gt;
</span><del>-    &lt;name&gt;Cyrus Daboo&lt;/name&gt;
-    &lt;first-name&gt;Cyrus&lt;/first-name&gt;
-    &lt;last-name&gt;Daboo&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;cyrus Daboo&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;sagen&lt;/uid&gt;
</span><del>-    &lt;guid&gt;sagen&lt;/guid&gt;
-    &lt;email-address&gt;sagen@example.com&lt;/email-address&gt;
</del><ins>+    &lt;short-name&gt;sagen&lt;/short-name&gt;
+    &lt;email&gt;sagen@example.com&lt;/email&gt;
</ins><span class="cx">     &lt;password&gt;test&lt;/password&gt;
</span><del>-    &lt;name&gt;Morgen Sagen&lt;/name&gt;
-    &lt;first-name&gt;Morgen&lt;/first-name&gt;
-    &lt;last-name&gt;Sagen&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;Morgen Sagen&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;dre&lt;/uid&gt;
</span><del>-    &lt;guid&gt;andre&lt;/guid&gt;
-    &lt;email-address&gt;dre@example.com&lt;/email-address&gt;
</del><ins>+    &lt;short-name&gt;andre&lt;/short-name&gt;
+    &lt;email&gt;dre@example.com&lt;/email&gt;
</ins><span class="cx">     &lt;password&gt;test&lt;/password&gt;
</span><del>-    &lt;name&gt;Andre LaBranche&lt;/name&gt;
-    &lt;first-name&gt;Andre&lt;/first-name&gt;
-    &lt;last-name&gt;LaBranche&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;Andre LaBranche&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;glyph&lt;/uid&gt;
</span><del>-    &lt;guid&gt;glyph&lt;/guid&gt;
-    &lt;email-address&gt;glyph@example.com&lt;/email-address&gt;
</del><ins>+    &lt;short-name&gt;glyph&lt;/short-name&gt;
+    &lt;email&gt;glyph@example.com&lt;/email&gt;
</ins><span class="cx">     &lt;password&gt;test&lt;/password&gt;
</span><del>-    &lt;name&gt;Glyph Lefkowitz&lt;/name&gt;
-    &lt;first-name&gt;Glyph&lt;/first-name&gt;
-    &lt;last-name&gt;Lefkowitz&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;user&gt;
</del><ins>+    &lt;full-name&gt;Glyph Lefkowitz&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;user&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;i18nuser&lt;/uid&gt;
</span><del>-    &lt;guid&gt;i18nuser&lt;/guid&gt;
-    &lt;email-address&gt;i18nuser@example.com&lt;/email-address&gt;
</del><ins>+    &lt;short-name&gt;i18nuser&lt;/short-name&gt;
+    &lt;email&gt;i18nuser@example.com&lt;/email&gt;
</ins><span class="cx">     &lt;password&gt;i18nuser&lt;/password&gt;
</span><del>-    &lt;name&gt;まだ&lt;/name&gt;
-    &lt;first-name&gt;ま&lt;/first-name&gt;
-    &lt;last-name&gt;だ&lt;/last-name&gt;
-  &lt;/user&gt;
</del><ins>+    &lt;full-name&gt;まだ&lt;/full-name&gt;
+  &lt;/record&gt;
+
+  &lt;!-- twext.who xml doesn't (yet) support repeat
</ins><span class="cx">   &lt;user repeat=&quot;101&quot;&gt;
</span><span class="cx">     &lt;uid&gt;user%02d&lt;/uid&gt;
</span><span class="cx">     &lt;uid&gt;User %02d&lt;/uid&gt;
</span><del>-    &lt;guid&gt;user%02d&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;user%02d&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;user%02d&lt;/password&gt;
</span><del>-    &lt;name&gt;User %02d&lt;/name&gt;
-    &lt;first-name&gt;User&lt;/first-name&gt;
-    &lt;last-name&gt;%02d&lt;/last-name&gt;
-    &lt;email-address&gt;user%02d@example.com&lt;/email-address&gt;
-  &lt;/user&gt;
</del><ins>+    &lt;full-name&gt;User %02d&lt;/full-name&gt;
+    &lt;email&gt;user%02d@example.com&lt;/email&gt;
+  &lt;/record&gt;
</ins><span class="cx">   &lt;user repeat=&quot;10&quot;&gt;
</span><span class="cx">     &lt;uid&gt;public%02d&lt;/uid&gt;
</span><del>-    &lt;guid&gt;public%02d&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;public%02d&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;public%02d&lt;/password&gt;
</span><del>-    &lt;name&gt;Public %02d&lt;/name&gt;
-    &lt;first-name&gt;Public&lt;/first-name&gt;
-    &lt;last-name&gt;%02d&lt;/last-name&gt;
-  &lt;/user&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Public %02d&lt;/full-name&gt;
+  &lt;/record&gt;
+  --&gt;
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user01&lt;/short-name&gt;
+    &lt;uid&gt;user01&lt;/uid&gt;
+    &lt;password&gt;user01&lt;/password&gt;
+    &lt;full-name&gt;User 01&lt;/full-name&gt;
+    &lt;email&gt;user01@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user02&lt;/short-name&gt;
+    &lt;uid&gt;user02&lt;/uid&gt;
+    &lt;password&gt;user02&lt;/password&gt;
+    &lt;full-name&gt;User 02&lt;/full-name&gt;
+    &lt;email&gt;user02@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user03&lt;/short-name&gt;
+    &lt;uid&gt;user03&lt;/uid&gt;
+    &lt;password&gt;user03&lt;/password&gt;
+    &lt;full-name&gt;User 03&lt;/full-name&gt;
+    &lt;email&gt;user03@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user04&lt;/short-name&gt;
+    &lt;uid&gt;user04&lt;/uid&gt;
+    &lt;password&gt;user04&lt;/password&gt;
+    &lt;full-name&gt;User 04&lt;/full-name&gt;
+    &lt;email&gt;user04@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user05&lt;/short-name&gt;
+    &lt;uid&gt;user05&lt;/uid&gt;
+    &lt;password&gt;user05&lt;/password&gt;
+    &lt;full-name&gt;User 05&lt;/full-name&gt;
+    &lt;email&gt;user05@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user06&lt;/short-name&gt;
+    &lt;uid&gt;user06&lt;/uid&gt;
+    &lt;password&gt;user06&lt;/password&gt;
+    &lt;full-name&gt;User 06&lt;/full-name&gt;
+    &lt;email&gt;user06@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user07&lt;/short-name&gt;
+    &lt;uid&gt;user07&lt;/uid&gt;
+    &lt;password&gt;user07&lt;/password&gt;
+    &lt;full-name&gt;User 07&lt;/full-name&gt;
+    &lt;email&gt;user07@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user08&lt;/short-name&gt;
+    &lt;uid&gt;user08&lt;/uid&gt;
+    &lt;password&gt;user08&lt;/password&gt;
+    &lt;full-name&gt;User 08&lt;/full-name&gt;
+    &lt;email&gt;user08@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user09&lt;/short-name&gt;
+    &lt;uid&gt;user09&lt;/uid&gt;
+    &lt;password&gt;user09&lt;/password&gt;
+    &lt;full-name&gt;User 09&lt;/full-name&gt;
+    &lt;email&gt;user09@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user10&lt;/short-name&gt;
+    &lt;uid&gt;user10&lt;/uid&gt;
+    &lt;password&gt;user10&lt;/password&gt;
+    &lt;full-name&gt;User 10&lt;/full-name&gt;
+    &lt;email&gt;user10@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user11&lt;/short-name&gt;
+    &lt;uid&gt;user11&lt;/uid&gt;
+    &lt;password&gt;user11&lt;/password&gt;
+    &lt;full-name&gt;User 11&lt;/full-name&gt;
+    &lt;email&gt;user11@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user12&lt;/short-name&gt;
+    &lt;uid&gt;user12&lt;/uid&gt;
+    &lt;password&gt;user12&lt;/password&gt;
+    &lt;full-name&gt;User 12&lt;/full-name&gt;
+    &lt;email&gt;user12@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user13&lt;/short-name&gt;
+    &lt;uid&gt;user13&lt;/uid&gt;
+    &lt;password&gt;user13&lt;/password&gt;
+    &lt;full-name&gt;User 13&lt;/full-name&gt;
+    &lt;email&gt;user13@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user14&lt;/short-name&gt;
+    &lt;uid&gt;user14&lt;/uid&gt;
+    &lt;password&gt;user14&lt;/password&gt;
+    &lt;full-name&gt;User 14&lt;/full-name&gt;
+    &lt;email&gt;user14@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user15&lt;/short-name&gt;
+    &lt;uid&gt;user15&lt;/uid&gt;
+    &lt;password&gt;user15&lt;/password&gt;
+    &lt;full-name&gt;User 15&lt;/full-name&gt;
+    &lt;email&gt;user15@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user16&lt;/short-name&gt;
+    &lt;uid&gt;user16&lt;/uid&gt;
+    &lt;password&gt;user16&lt;/password&gt;
+    &lt;full-name&gt;User 16&lt;/full-name&gt;
+    &lt;email&gt;user16@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user17&lt;/short-name&gt;
+    &lt;uid&gt;user17&lt;/uid&gt;
+    &lt;password&gt;user17&lt;/password&gt;
+    &lt;full-name&gt;User 17&lt;/full-name&gt;
+    &lt;email&gt;user17@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user18&lt;/short-name&gt;
+    &lt;uid&gt;user18&lt;/uid&gt;
+    &lt;password&gt;user18&lt;/password&gt;
+    &lt;full-name&gt;User 18&lt;/full-name&gt;
+    &lt;email&gt;user18@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user19&lt;/short-name&gt;
+    &lt;uid&gt;user19&lt;/uid&gt;
+    &lt;password&gt;user19&lt;/password&gt;
+    &lt;full-name&gt;User 19&lt;/full-name&gt;
+    &lt;email&gt;user19@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user20&lt;/short-name&gt;
+    &lt;uid&gt;user20&lt;/uid&gt;
+    &lt;password&gt;user20&lt;/password&gt;
+    &lt;full-name&gt;User 20&lt;/full-name&gt;
+    &lt;email&gt;user20@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user21&lt;/short-name&gt;
+    &lt;uid&gt;user21&lt;/uid&gt;
+    &lt;password&gt;user21&lt;/password&gt;
+    &lt;full-name&gt;User 21&lt;/full-name&gt;
+    &lt;email&gt;user21@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user22&lt;/short-name&gt;
+    &lt;uid&gt;user22&lt;/uid&gt;
+    &lt;password&gt;user22&lt;/password&gt;
+    &lt;full-name&gt;User 22&lt;/full-name&gt;
+    &lt;email&gt;user22@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user23&lt;/short-name&gt;
+    &lt;uid&gt;user23&lt;/uid&gt;
+    &lt;password&gt;user23&lt;/password&gt;
+    &lt;full-name&gt;User 23&lt;/full-name&gt;
+    &lt;email&gt;user23@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user24&lt;/short-name&gt;
+    &lt;uid&gt;user24&lt;/uid&gt;
+    &lt;password&gt;user24&lt;/password&gt;
+    &lt;full-name&gt;User 24&lt;/full-name&gt;
+    &lt;email&gt;user24@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;user&quot;&gt;
+    &lt;short-name&gt;user25&lt;/short-name&gt;
+    &lt;uid&gt;user25&lt;/uid&gt;
+    &lt;password&gt;user25&lt;/password&gt;
+    &lt;full-name&gt;User 25&lt;/full-name&gt;
+    &lt;email&gt;user25@example.com&lt;/email&gt;
+  &lt;/record&gt;
+
+  &lt;record type=&quot;group&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;group01&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group01&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group01&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group01&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 01&lt;/name&gt;
-    &lt;email-address&gt;group01@example.com&lt;/email-address&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;user01&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Group 01&lt;/full-name&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user01&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;group02&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group02&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group02&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group02&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 02&lt;/name&gt;
-    &lt;email-address&gt;group02@example.com&lt;/email-address&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;user06&lt;/member&gt;
-      &lt;member type=&quot;users&quot;&gt;user07&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Group 02&lt;/full-name&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user06&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user07&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;group03&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group03&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group03&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group03&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 03&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;user08&lt;/member&gt;
-      &lt;member type=&quot;users&quot;&gt;user09&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Group 03&lt;/full-name&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user08&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user09&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;group04&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group04&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group04&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group04&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 04&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;groups&quot;&gt;group02&lt;/member&gt;
-      &lt;member type=&quot;groups&quot;&gt;group03&lt;/member&gt;
-      &lt;member type=&quot;users&quot;&gt;user10&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt; &lt;!-- delegategroup --&gt;
</del><ins>+    &lt;full-name&gt;Group 04&lt;/full-name&gt;
+      &lt;member-uid type=&quot;groups&quot;&gt;group02&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;groups&quot;&gt;group03&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user10&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt; &lt;!-- delegategroup --&gt;
</ins><span class="cx">     &lt;uid&gt;group05&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group05&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group05&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group05&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 05&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;groups&quot;&gt;group06&lt;/member&gt;
-      &lt;member type=&quot;users&quot;&gt;user20&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt; &lt;!-- delegatesubgroup --&gt;
</del><ins>+    &lt;full-name&gt;Group 05&lt;/full-name&gt;
+      &lt;member-uid type=&quot;groups&quot;&gt;group06&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user20&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt; &lt;!-- delegatesubgroup --&gt;
</ins><span class="cx">     &lt;uid&gt;group06&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group06&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group06&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group06&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 06&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;user21&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt; &lt;!-- readonlydelegategroup --&gt;
</del><ins>+    &lt;full-name&gt;Group 06&lt;/full-name&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user21&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt; &lt;!-- readonlydelegategroup --&gt;
</ins><span class="cx">     &lt;uid&gt;group07&lt;/uid&gt;
</span><del>-    &lt;guid&gt;group07&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;group07&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;group07&lt;/password&gt;
</span><del>-    &lt;name&gt;Group 07&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;user22&lt;/member&gt;
-      &lt;member type=&quot;users&quot;&gt;user23&lt;/member&gt;
-      &lt;member type=&quot;users&quot;&gt;user24&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-  &lt;group&gt;
</del><ins>+    &lt;full-name&gt;Group 07&lt;/full-name&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user22&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user23&lt;/member-uid&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user24&lt;/member-uid&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;group&quot;&gt;
</ins><span class="cx">     &lt;uid&gt;disabledgroup&lt;/uid&gt;
</span><del>-    &lt;guid&gt;disabledgroup&lt;/guid&gt;
</del><ins>+    &lt;short-name&gt;disabledgroup&lt;/short-name&gt;
</ins><span class="cx">     &lt;password&gt;disabledgroup&lt;/password&gt;
</span><del>-    &lt;name&gt;Disabled Group&lt;/name&gt;
-    &lt;members&gt;
-      &lt;member type=&quot;users&quot;&gt;user01&lt;/member&gt;
-    &lt;/members&gt;
-  &lt;/group&gt;
-&lt;/accounts&gt;
</del><ins>+    &lt;full-name&gt;Disabled Group&lt;/full-name&gt;
+      &lt;member-uid type=&quot;users&quot;&gt;user01&lt;/member-uid&gt;
+  &lt;/record&gt;
+&lt;/directory&gt;
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhotestaccountsaugmentsxmlfromrev12913CalendarServerbranchesuserssagenmove2who3txdavwhotestaccountsaugmentsxml"></a>
<div class="copfile"><h4>Copied: CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/accounts/augments.xml (from rev 12913, CalendarServer/branches/users/sagen/move2who-3/txdav/who/test/accounts/augments.xml) (0 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/accounts/augments.xml                                (rev 0)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/accounts/augments.xml        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -0,0 +1,185 @@
</span><ins>+&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
+&lt;!DOCTYPE augments SYSTEM &quot;augments.dtd&quot;&gt;
+
+&lt;augments&gt;
+  &lt;record&gt;
+    &lt;uid&gt;Default&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+  &lt;/record&gt;
+  &lt;record repeat=&quot;10&quot;&gt;
+    &lt;uid&gt;location%02d&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+  &lt;/record&gt;
+  &lt;record repeat=&quot;4&quot;&gt;
+    &lt;uid&gt;resource%02d&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;resource05&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;none&lt;/auto-schedule-mode&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;resource06&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;accept-always&lt;/auto-schedule-mode&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;resource07&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;decline-always&lt;/auto-schedule-mode&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;resource08&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;accept-if-free&lt;/auto-schedule-mode&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;resource09&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;decline-if-busy&lt;/auto-schedule-mode&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;resource10&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;automatic&lt;/auto-schedule-mode&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;resource11&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;decline-always&lt;/auto-schedule-mode&gt;
+    &lt;auto-accept-group&gt;group01&lt;/auto-accept-group&gt;
+  &lt;/record&gt;
+  &lt;record repeat=&quot;10&quot;&gt;
+    &lt;uid&gt;group%02d&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;disabledgroup&lt;/uid&gt;
+    &lt;enable&gt;false&lt;/enable&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;delegatedroom&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;false&lt;/enable-addressbook&gt;
+    &lt;auto-schedule&gt;false&lt;/auto-schedule&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;03DFF660-8BCC-4198-8588-DD77F776F518&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;enable-login&gt;true&lt;/enable-login&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;80689D41-DAF8-4189-909C-DB017B271892&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;enable-login&gt;true&lt;/enable-login&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;default&lt;/auto-schedule-mode&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;C38BEE7A-36EE-478C-9DCB-CBF4612AFE65&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;enable-login&gt;true&lt;/enable-login&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;default&lt;/auto-schedule-mode&gt;
+    &lt;auto-accept-group&gt;group01&lt;/auto-accept-group&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;CCE95217-A57B-481A-AC3D-FEC9AB6CE3A9&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;enable-login&gt;true&lt;/enable-login&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;0CE0BF31-5F9E-4801-A489-8C70CF287F5F&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;enable-login&gt;true&lt;/enable-login&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;6F9EE33B-78F6-481B-9289-3D0812FF0D64&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;enable-login&gt;true&lt;/enable-login&gt;
+    &lt;auto-schedule&gt;false&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;default&lt;/auto-schedule-mode&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;76E7ECA6-08BC-4AE7-930D-F2E7453993A5&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;enable-login&gt;true&lt;/enable-login&gt;
+    &lt;auto-schedule&gt;false&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;default&lt;/auto-schedule-mode&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;63A2F949-2D8D-4C8D-B8A5-DCF2A94610F3&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;enable-login&gt;true&lt;/enable-login&gt;
+    &lt;auto-schedule&gt;false&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;default&lt;/auto-schedule-mode&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;06E3BDCB-9C19-485A-B14E-F146A80ADDC6&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;enable-login&gt;true&lt;/enable-login&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;default&lt;/auto-schedule-mode&gt;
+  &lt;/record&gt;
+  &lt;record&gt;
+    &lt;uid&gt;4D66A20A-1437-437D-8069-2F14E8322234&lt;/uid&gt;
+    &lt;enable&gt;true&lt;/enable&gt;
+    &lt;enable-calendar&gt;true&lt;/enable-calendar&gt;
+    &lt;enable-addressbook&gt;true&lt;/enable-addressbook&gt;
+    &lt;enable-login&gt;true&lt;/enable-login&gt;
+    &lt;auto-schedule&gt;true&lt;/auto-schedule&gt;
+    &lt;auto-schedule-mode&gt;default&lt;/auto-schedule-mode&gt;
+  &lt;/record&gt;
+&lt;/augments&gt;
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhotestaccountsresourcesxml"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/accounts/resources.xml (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/accounts/resources.xml        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/accounts/resources.xml        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -1,34 +1,273 @@
</span><del>-&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
-
-&lt;!--
-Copyright (c) 2006-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.
- --&gt;
-
-&lt;!DOCTYPE accounts SYSTEM &quot;accounts.dtd&quot;&gt;
-
-&lt;accounts realm=&quot;Test Realm&quot;&gt;
-  &lt;location repeat=&quot;10&quot;&gt;
-    &lt;uid&gt;location%02d&lt;/uid&gt;
-    &lt;guid&gt;location%02d&lt;/guid&gt;
-    &lt;password&gt;location%02d&lt;/password&gt;
-    &lt;name&gt;Room %02d&lt;/name&gt;
-  &lt;/location&gt;
-  &lt;resource repeat=&quot;10&quot;&gt;
-    &lt;uid&gt;resource%02d&lt;/uid&gt;
-    &lt;guid&gt;resource%02d&lt;/guid&gt;
-    &lt;password&gt;resource%02d&lt;/password&gt;
-    &lt;name&gt;Resource %02d&lt;/name&gt;
-  &lt;/resource&gt;
-&lt;/accounts&gt;
</del><ins>+&lt;directory realm=&quot;Test Realm&quot;&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;fantastic&lt;/short-name&gt;
+    &lt;uid&gt;4D66A20A-1437-437D-8069-2F14E8322234&lt;/uid&gt;
+    &lt;full-name&gt;Fantastic Conference Room&lt;/full-name&gt;
+    &lt;extras&gt;
+      &lt;associatedAddress&gt;63A2F949-2D8D-4C8D-B8A5-DCF2A94610F3&lt;/associatedAddress&gt;
+    &lt;/extras&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;jupiter&lt;/short-name&gt;
+    &lt;uid&gt;jupiter&lt;/uid&gt;
+    &lt;full-name&gt;Jupiter Conference Room, Building 2, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;uranus&lt;/short-name&gt;
+    &lt;uid&gt;uranus&lt;/uid&gt;
+    &lt;full-name&gt;Uranus Conference Room, Building 3, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;morgensroom&lt;/short-name&gt;
+    &lt;uid&gt;03DFF660-8BCC-4198-8588-DD77F776F518&lt;/uid&gt;
+    &lt;full-name&gt;Morgen's Room&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;mercury&lt;/short-name&gt;
+    &lt;uid&gt;mercury&lt;/uid&gt;
+    &lt;full-name&gt;Mercury Conference Room, Building 1, 2nd Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location09&lt;/short-name&gt;
+    &lt;uid&gt;location09&lt;/uid&gt;
+    &lt;full-name&gt;Room 09&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location08&lt;/short-name&gt;
+    &lt;uid&gt;location08&lt;/uid&gt;
+    &lt;full-name&gt;Room 08&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location07&lt;/short-name&gt;
+    &lt;uid&gt;location07&lt;/uid&gt;
+    &lt;full-name&gt;Room 07&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location06&lt;/short-name&gt;
+    &lt;uid&gt;location06&lt;/uid&gt;
+    &lt;full-name&gt;Room 06&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location05&lt;/short-name&gt;
+    &lt;uid&gt;location05&lt;/uid&gt;
+    &lt;full-name&gt;Room 05&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location04&lt;/short-name&gt;
+    &lt;uid&gt;location04&lt;/uid&gt;
+    &lt;full-name&gt;Room 04&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location03&lt;/short-name&gt;
+    &lt;uid&gt;location03&lt;/uid&gt;
+    &lt;full-name&gt;Room 03&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location02&lt;/short-name&gt;
+    &lt;uid&gt;location02&lt;/uid&gt;
+    &lt;full-name&gt;Room 02&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location01&lt;/short-name&gt;
+    &lt;uid&gt;location01&lt;/uid&gt;
+    &lt;full-name&gt;Room 01&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;delegatedroom&lt;/short-name&gt;
+    &lt;uid&gt;delegatedroom&lt;/uid&gt;
+    &lt;full-name&gt;Delegated Conference Room&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;mars&lt;/short-name&gt;
+    &lt;uid&gt;redplanet&lt;/uid&gt;
+    &lt;full-name&gt;Mars Conference Room, Building 1, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;sharissroom&lt;/short-name&gt;
+    &lt;uid&gt;80689D41-DAF8-4189-909C-DB017B271892&lt;/uid&gt;
+    &lt;full-name&gt;Shari's Room&lt;/full-name&gt;
+    &lt;extras&gt;
+      &lt;associatedAddress&gt;6F9EE33B-78F6-481B-9289-3D0812FF0D64&lt;/associatedAddress&gt;
+    &lt;/extras&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;pluto&lt;/short-name&gt;
+    &lt;uid&gt;pluto&lt;/uid&gt;
+    &lt;full-name&gt;Pluto Conference Room, Building 2, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;saturn&lt;/short-name&gt;
+    &lt;uid&gt;saturn&lt;/uid&gt;
+    &lt;full-name&gt;Saturn Conference Room, Building 2, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;location10&lt;/short-name&gt;
+    &lt;uid&gt;location10&lt;/uid&gt;
+    &lt;full-name&gt;Room 10&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;pretend&lt;/short-name&gt;
+    &lt;uid&gt;06E3BDCB-9C19-485A-B14E-F146A80ADDC6&lt;/uid&gt;
+    &lt;full-name&gt;Pretend Conference Room&lt;/full-name&gt;
+    &lt;extras&gt;
+      &lt;associatedAddress&gt;76E7ECA6-08BC-4AE7-930D-F2E7453993A5&lt;/associatedAddress&gt;
+    &lt;/extras&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;neptune&lt;/short-name&gt;
+    &lt;uid&gt;neptune&lt;/uid&gt;
+    &lt;full-name&gt;Neptune Conference Room, Building 2, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;Earth&lt;/short-name&gt;
+    &lt;uid&gt;Earth&lt;/uid&gt;
+    &lt;full-name&gt;Earth Conference Room, Building 1, 1st Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;location&quot;&gt;
+    &lt;short-name&gt;venus&lt;/short-name&gt;
+    &lt;uid&gt;venus&lt;/uid&gt;
+    &lt;full-name&gt;Venus Conference Room, Building 1, 2nd Floor&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;sharisotherresource&lt;/short-name&gt;
+    &lt;uid&gt;CCE95217-A57B-481A-AC3D-FEC9AB6CE3A9&lt;/uid&gt;
+    &lt;full-name&gt;Shari's Other Resource&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource15&lt;/short-name&gt;
+    &lt;uid&gt;resource15&lt;/uid&gt;
+    &lt;full-name&gt;Resource 15&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource14&lt;/short-name&gt;
+    &lt;uid&gt;resource14&lt;/uid&gt;
+    &lt;full-name&gt;Resource 14&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource17&lt;/short-name&gt;
+    &lt;uid&gt;resource17&lt;/uid&gt;
+    &lt;full-name&gt;Resource 17&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource16&lt;/short-name&gt;
+    &lt;uid&gt;resource16&lt;/uid&gt;
+    &lt;full-name&gt;Resource 16&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource11&lt;/short-name&gt;
+    &lt;uid&gt;resource11&lt;/uid&gt;
+    &lt;full-name&gt;Resource 11&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource10&lt;/short-name&gt;
+    &lt;uid&gt;resource10&lt;/uid&gt;
+    &lt;full-name&gt;Resource 10&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource13&lt;/short-name&gt;
+    &lt;uid&gt;resource13&lt;/uid&gt;
+    &lt;full-name&gt;Resource 13&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource12&lt;/short-name&gt;
+    &lt;uid&gt;resource12&lt;/uid&gt;
+    &lt;full-name&gt;Resource 12&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource19&lt;/short-name&gt;
+    &lt;uid&gt;resource19&lt;/uid&gt;
+    &lt;full-name&gt;Resource 19&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource18&lt;/short-name&gt;
+    &lt;uid&gt;resource18&lt;/uid&gt;
+    &lt;full-name&gt;Resource 18&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;sharisresource&lt;/short-name&gt;
+    &lt;uid&gt;C38BEE7A-36EE-478C-9DCB-CBF4612AFE65&lt;/uid&gt;
+    &lt;full-name&gt;Shari's Resource&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource20&lt;/short-name&gt;
+    &lt;uid&gt;resource20&lt;/uid&gt;
+    &lt;full-name&gt;Resource 20&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource06&lt;/short-name&gt;
+    &lt;uid&gt;resource06&lt;/uid&gt;
+    &lt;full-name&gt;Resource 06&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource07&lt;/short-name&gt;
+    &lt;uid&gt;resource07&lt;/uid&gt;
+    &lt;full-name&gt;Resource 07&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource04&lt;/short-name&gt;
+    &lt;uid&gt;resource04&lt;/uid&gt;
+    &lt;full-name&gt;Resource 04&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource05&lt;/short-name&gt;
+    &lt;uid&gt;resource05&lt;/uid&gt;
+    &lt;full-name&gt;Resource 05&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource02&lt;/short-name&gt;
+    &lt;uid&gt;resource02&lt;/uid&gt;
+    &lt;full-name&gt;Resource 02&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource03&lt;/short-name&gt;
+    &lt;uid&gt;resource03&lt;/uid&gt;
+    &lt;full-name&gt;Resource 03&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource01&lt;/short-name&gt;
+    &lt;uid&gt;resource01&lt;/uid&gt;
+    &lt;full-name&gt;Resource 01&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;sharisotherresource1&lt;/short-name&gt;
+    &lt;uid&gt;0CE0BF31-5F9E-4801-A489-8C70CF287F5F&lt;/uid&gt;
+    &lt;full-name&gt;Shari's Other Resource1&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource08&lt;/short-name&gt;
+    &lt;uid&gt;resource08&lt;/uid&gt;
+    &lt;full-name&gt;Resource 08&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;resource&quot;&gt;
+    &lt;short-name&gt;resource09&lt;/short-name&gt;
+    &lt;uid&gt;resource09&lt;/uid&gt;
+    &lt;full-name&gt;Resource 09&lt;/full-name&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;address&quot;&gt;
+    &lt;short-name&gt;testaddress1&lt;/short-name&gt;
+    &lt;uid&gt;6F9EE33B-78F6-481B-9289-3D0812FF0D64&lt;/uid&gt;
+    &lt;full-name&gt;Test Address One&lt;/full-name&gt;
+    &lt;extras&gt;
+      &lt;streetAddress&gt;20300 Stevens Creek Blvd, Cupertino, CA 95014&lt;/streetAddress&gt;
+      &lt;geo&gt;37.322281,-122.028345&lt;/geo&gt;
+    &lt;/extras&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;address&quot;&gt;
+    &lt;short-name&gt;il2&lt;/short-name&gt;
+    &lt;uid&gt;63A2F949-2D8D-4C8D-B8A5-DCF2A94610F3&lt;/uid&gt;
+    &lt;full-name&gt;IL2&lt;/full-name&gt;
+    &lt;extras&gt;
+      &lt;streetAddress&gt;2 Infinite Loop, Cupertino, CA 95014&lt;/streetAddress&gt;
+      &lt;geo&gt;37.332633,-122.030502&lt;/geo&gt;
+    &lt;/extras&gt;
+  &lt;/record&gt;
+  &lt;record type=&quot;address&quot;&gt;
+    &lt;short-name&gt;il1&lt;/short-name&gt;
+    &lt;uid&gt;76E7ECA6-08BC-4AE7-930D-F2E7453993A5&lt;/uid&gt;
+    &lt;full-name&gt;IL1&lt;/full-name&gt;
+    &lt;extras&gt;
+      &lt;streetAddress&gt;1 Infinite Loop, Cupertino, CA 95014&lt;/streetAddress&gt;
+      &lt;geo&gt;37.331741,-122.030333&lt;/geo&gt;
+    &lt;/extras&gt;
+  &lt;/record&gt;
+&lt;/directory&gt;
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhotesttest_delegatespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_delegates.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_delegates.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_delegates.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -19,14 +19,14 @@
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx"> from txdav.who.delegates import (
</span><del>-    addDelegate, removeDelegate, delegatesOf, delegatedTo, allGroupDelegates
</del><ins>+    addDelegate, removeDelegate, delegatesOf, delegatedTo,
+    DirectoryService, RecordType as DelegateRecordType
</ins><span class="cx"> )
</span><span class="cx"> from txdav.who.groups import GroupCacher
</span><span class="cx"> from twext.who.idirectory import RecordType
</span><span class="cx"> from twext.who.test.test_xml import xmlService
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks
</span><span class="cx"> from twistedcaldav.test.util import StoreTestCase
</span><del>-from uuid import UUID
</del><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class DelegationTest(StoreTestCase):
</span><span class="lines">@@ -34,14 +34,19 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def setUp(self):
</span><span class="cx">         yield super(DelegationTest, self).setUp()
</span><ins>+        self.store = self.storeUnderTest()
</ins><span class="cx">         self.xmlService = xmlService(self.mktemp(), xmlData=testXMLConfig)
</span><span class="cx">         self.groupCacher = GroupCacher(self.xmlService)
</span><ins>+        self.delegateService = DirectoryService(
+            self.xmlService.realmName,
+            self.store
+        )
+        self.delegateService.setMasterDirectory(self.xmlService)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def test_directDelegation(self):
</span><del>-        store = self.storeUnderTest()
-        txn = store.newTransaction()
</del><ins>+        txn = self.store.newTransaction()
</ins><span class="cx"> 
</span><span class="cx">         delegator = yield self.xmlService.recordWithUID(u&quot;__wsanchez__&quot;)
</span><span class="cx">         delegate1 = yield self.xmlService.recordWithUID(u&quot;__sagen__&quot;)
</span><span class="lines">@@ -50,24 +55,68 @@
</span><span class="cx">         # Add 1 delegate
</span><span class="cx">         yield addDelegate(txn, delegator, delegate1, True)
</span><span class="cx">         delegates = (yield delegatesOf(txn, delegator, True))
</span><del>-        self.assertEquals([&quot;sagen&quot;], [d.shortNames[0] for d in delegates])
</del><ins>+        self.assertEquals([&quot;__sagen__&quot;], [d.uid for d in delegates])
</ins><span class="cx">         delegators = (yield delegatedTo(txn, delegate1, True))
</span><del>-        self.assertEquals([&quot;wsanchez&quot;], [d.shortNames[0] for d in delegators])
</del><ins>+        self.assertEquals([&quot;__wsanchez__&quot;], [d.uid for d in delegators])
</ins><span class="cx"> 
</span><ins>+        yield txn.commit()  # So delegateService will see the changes
+        txn = self.store.newTransaction()
+
+        # The &quot;proxy-write&quot; pseudoGroup will have one member
+        pseudoGroup = yield self.delegateService.recordWithShortName(
+            DelegateRecordType.writeDelegateGroup,
+            u&quot;__wsanchez__&quot;
+        )
+        self.assertEquals(pseudoGroup.uid, u&quot;__wsanchez__#calendar-proxy-write&quot;)
+        self.assertEquals(
+            [r.uid for r in (yield pseudoGroup.members())],
+            [u&quot;__sagen__&quot;]
+        )
+        # The &quot;proxy-read&quot; pseudoGroup will have no members
+        pseudoGroup = yield self.delegateService.recordWithShortName(
+            DelegateRecordType.readDelegateGroup,
+            u&quot;__wsanchez__&quot;
+        )
+        self.assertEquals(pseudoGroup.uid, u&quot;__wsanchez__#calendar-proxy-read&quot;)
+        self.assertEquals(
+            [r.uid for r in (yield pseudoGroup.members())],
+            []
+        )
+        # The &quot;proxy-write-for&quot; pseudoGroup will have one member
+        pseudoGroup = yield self.delegateService.recordWithShortName(
+            DelegateRecordType.writeDelegatorGroup,
+            u&quot;__sagen__&quot;
+        )
+        self.assertEquals(pseudoGroup.uid, u&quot;__sagen__#calendar-proxy-write-for&quot;)
+        self.assertEquals(
+            [r.uid for r in (yield pseudoGroup.members())],
+            [u&quot;__wsanchez__&quot;]
+        )
+        # The &quot;proxy-read-for&quot; pseudoGroup will have no members
+        pseudoGroup = yield self.delegateService.recordWithShortName(
+            DelegateRecordType.readDelegatorGroup,
+            u&quot;__sagen__&quot;
+        )
+        self.assertEquals(pseudoGroup.uid, u&quot;__sagen__#calendar-proxy-read-for&quot;)
+        self.assertEquals(
+            [r.uid for r in (yield pseudoGroup.members())],
+            []
+        )
+
</ins><span class="cx">         # Add another delegate
</span><span class="cx">         yield addDelegate(txn, delegator, delegate2, True)
</span><span class="cx">         delegates = (yield delegatesOf(txn, delegator, True))
</span><span class="cx">         self.assertEquals(
</span><del>-            set([&quot;sagen&quot;, &quot;cdaboo&quot;]),
-            set([d.shortNames[0] for d in delegates])
</del><ins>+            set([&quot;__sagen__&quot;, &quot;__cdaboo__&quot;]),
+            set([d.uid for d in delegates])
</ins><span class="cx">         )
</span><span class="cx">         delegators = (yield delegatedTo(txn, delegate2, True))
</span><del>-        self.assertEquals([&quot;wsanchez&quot;], [d.shortNames[0] for d in delegators])
</del><ins>+        self.assertEquals([&quot;__wsanchez__&quot;], [d.uid for d in delegators])
</ins><span class="cx"> 
</span><span class="cx">         # Remove 1 delegate
</span><span class="cx">         yield removeDelegate(txn, delegator, delegate1, True)
</span><span class="cx">         delegates = (yield delegatesOf(txn, delegator, True))
</span><del>-        self.assertEquals([&quot;cdaboo&quot;], [d.shortNames[0] for d in delegates])
</del><ins>+        self.assertEquals([&quot;__cdaboo__&quot;], [d.uid for d in delegates])
</ins><span class="cx">         delegators = (yield delegatedTo(txn, delegate1, True))
</span><span class="cx">         self.assertEquals(0, len(delegators))
</span><span class="cx"> 
</span><span class="lines">@@ -78,11 +127,40 @@
</span><span class="cx">         delegators = (yield delegatedTo(txn, delegate2, True))
</span><span class="cx">         self.assertEquals(0, len(delegators))
</span><span class="cx"> 
</span><ins>+        yield txn.commit()  # So delegateService will see the changes
</ins><span class="cx"> 
</span><ins>+        # Now set delegate assignments by using pseudoGroup.setMembers()
+        pseudoGroup = yield self.delegateService.recordWithShortName(
+            DelegateRecordType.writeDelegateGroup,
+            u&quot;__wsanchez__&quot;
+        )
+        yield pseudoGroup.setMembers([delegate1, delegate2])
+
+        # Verify the assignments were made
+        txn = self.store.newTransaction()
+        delegates = (yield delegatesOf(txn, delegator, True))
+        self.assertEquals(
+            set([&quot;__sagen__&quot;, &quot;__cdaboo__&quot;]),
+            set([d.uid for d in delegates])
+        )
+        yield txn.commit()
+
+        # Set a different group of assignments:
+        yield pseudoGroup.setMembers([delegate2])
+
+        # Verify the assignments were made
+        txn = self.store.newTransaction()
+        delegates = (yield delegatesOf(txn, delegator, True))
+        self.assertEquals(
+            set([&quot;__cdaboo__&quot;]),
+            set([d.uid for d in delegates])
+        )
+        yield txn.commit()
+
+
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def test_indirectDelegation(self):
</span><del>-        store = self.storeUnderTest()
-        txn = store.newTransaction()
</del><ins>+        txn = self.store.newTransaction()
</ins><span class="cx"> 
</span><span class="cx">         delegator = yield self.xmlService.recordWithUID(u&quot;__wsanchez__&quot;)
</span><span class="cx">         delegate1 = yield self.xmlService.recordWithUID(u&quot;__sagen__&quot;)
</span><span class="lines">@@ -92,37 +170,41 @@
</span><span class="cx">         # Add group delegate, but before the group membership has been
</span><span class="cx">         # pulled in
</span><span class="cx">         yield addDelegate(txn, delegator, group1, True)
</span><del>-        delegates = (yield delegatesOf(txn, delegator, True))
</del><ins>+        # Passing expanded=False will return the group
+        delegates = (yield delegatesOf(txn, delegator, True, expanded=False))
+        self.assertEquals(1, len(delegates))
+        self.assertEquals(delegates[0].uid, u&quot;__top_group_1__&quot;)
+        # Passing expanded=True will return not the group -- it only returns
+        # non-groups
+        delegates = (yield delegatesOf(txn, delegator, True, expanded=True))
</ins><span class="cx">         self.assertEquals(0, len(delegates))
</span><span class="cx"> 
</span><span class="cx">         # Now refresh the group and there will be 3 delegates (contained
</span><span class="cx">         # within 2 nested groups)
</span><span class="cx">         # guid = &quot;49b350c69611477b94d95516b13856ab&quot;
</span><del>-        yield self.groupCacher.refreshGroup(txn, group1.guid)
-        yield self.groupCacher.refreshGroup(txn, group2.guid)
-        delegates = (yield delegatesOf(txn, delegator, True))
</del><ins>+        yield self.groupCacher.refreshGroup(txn, group1.uid)
+        yield self.groupCacher.refreshGroup(txn, group2.uid)
+        delegates = (yield delegatesOf(txn, delegator, True, expanded=True))
</ins><span class="cx">         self.assertEquals(
</span><del>-            set([&quot;sagen&quot;, &quot;cdaboo&quot;, &quot;glyph&quot;]),
-            set([d.shortNames[0] for d in delegates])
</del><ins>+            set([&quot;__sagen__&quot;, &quot;__cdaboo__&quot;, &quot;__glyph__&quot;]),
+            set([d.uid for d in delegates])
</ins><span class="cx">         )
</span><span class="cx">         delegators = (yield delegatedTo(txn, delegate1, True))
</span><del>-        self.assertEquals([&quot;wsanchez&quot;], [d.shortNames[0] for d in delegators])
</del><ins>+        self.assertEquals([&quot;__wsanchez__&quot;], [d.uid for d in delegators])
</ins><span class="cx"> 
</span><span class="cx">         # Verify we can ask for all delegated-to groups
</span><span class="cx">         yield addDelegate(txn, delegator, group2, True)
</span><del>-        groups = (yield allGroupDelegates(txn))
</del><ins>+        groups = (yield txn.allGroupDelegates())
</ins><span class="cx">         self.assertEquals(
</span><del>-            set([
-                UUID(&quot;49b350c69611477b94d95516b13856ab&quot;),
-                UUID(&quot;86144f73345a409782f1b782672087c7&quot;)
-                ]), set(groups))
</del><ins>+            set([u'__sub_group_1__', u'__top_group_1__']), set(groups)
+        )
</ins><span class="cx"> 
</span><span class="cx">         # Delegate to a user who is already indirectly delegated-to
</span><span class="cx">         yield addDelegate(txn, delegator, delegate1, True)
</span><del>-        delegates = (yield delegatesOf(txn, delegator, True))
</del><ins>+        delegates = (yield delegatesOf(txn, delegator, True, expanded=True))
</ins><span class="cx">         self.assertEquals(
</span><del>-            set([&quot;sagen&quot;, &quot;cdaboo&quot;, &quot;glyph&quot;]),
-            set([d.shortNames[0] for d in delegates])
</del><ins>+            set([&quot;__sagen__&quot;, &quot;__cdaboo__&quot;, &quot;__glyph__&quot;]),
+            set([d.uid for d in delegates])
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx">         # Add a member to the group; they become a delegate
</span><span class="lines">@@ -131,35 +213,38 @@
</span><span class="cx">             record = (
</span><span class="cx">                 yield self.xmlService.recordWithShortName(RecordType.user, name)
</span><span class="cx">             )
</span><del>-            newSet.add(record.guid)
-        groupID, name, membershipHash = (yield txn.groupByGUID(group1.guid))
</del><ins>+            newSet.add(record.uid)
+        groupID, name, membershipHash = (yield txn.groupByUID(group1.uid))
</ins><span class="cx">         numAdded, numRemoved = (
</span><span class="cx">             yield self.groupCacher.synchronizeMembers(txn, groupID, newSet)
</span><span class="cx">         )
</span><del>-        delegates = (yield delegatesOf(txn, delegator, True))
</del><ins>+        delegates = (yield delegatesOf(txn, delegator, True, expanded=True))
</ins><span class="cx">         self.assertEquals(
</span><del>-            set([&quot;sagen&quot;, &quot;cdaboo&quot;, &quot;glyph&quot;, &quot;dre&quot;]),
-            set([d.shortNames[0] for d in delegates])
</del><ins>+            set([&quot;__sagen__&quot;, &quot;__cdaboo__&quot;, &quot;__glyph__&quot;, &quot;__dre__&quot;]),
+            set([d.uid for d in delegates])
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx">         # Remove delegate access from the top group
</span><span class="cx">         yield removeDelegate(txn, delegator, group1, True)
</span><del>-        delegates = (yield delegatesOf(txn, delegator, True))
</del><ins>+        delegates = (yield delegatesOf(txn, delegator, True, expanded=True))
</ins><span class="cx">         self.assertEquals(
</span><del>-            set([&quot;sagen&quot;, &quot;cdaboo&quot;]),
-            set([d.shortNames[0] for d in delegates])
</del><ins>+            set([&quot;__sagen__&quot;, &quot;__cdaboo__&quot;]),
+            set([d.uid for d in delegates])
</ins><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx">         # Remove delegate access from the sub group
</span><span class="cx">         yield removeDelegate(txn, delegator, group2, True)
</span><del>-        delegates = (yield delegatesOf(txn, delegator, True))
</del><ins>+        delegates = (yield delegatesOf(txn, delegator, True, expanded=True))
</ins><span class="cx">         self.assertEquals(
</span><del>-            set([&quot;sagen&quot;]),
-            set([d.shortNames[0] for d in delegates])
</del><ins>+            set([&quot;__sagen__&quot;]),
+            set([d.uid for d in delegates])
</ins><span class="cx">         )
</span><ins>+        yield txn.commit()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> testXMLConfig = &quot;&quot;&quot;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
</span><span class="cx"> 
</span><span class="cx"> &lt;directory realm=&quot;xyzzy&quot;&gt;
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhotesttest_groupspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_groups.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_groups.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_groups.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -24,7 +24,6 @@
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks
</span><span class="cx"> from twistedcaldav.test.util import StoreTestCase
</span><span class="cx"> from txdav.common.icommondatastore import NotFoundError
</span><del>-from uuid import UUID
</del><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class GroupCacherTest(StoreTestCase):
</span><span class="lines">@@ -69,22 +68,20 @@
</span><span class="cx">         txn = store.newTransaction()
</span><span class="cx"> 
</span><span class="cx">         record = yield self.xmlService.recordWithUID(u&quot;__top_group_1__&quot;)
</span><del>-        yield self.groupCacher.refreshGroup(txn, record.guid)
</del><ins>+        yield self.groupCacher.refreshGroup(txn, record.uid)
</ins><span class="cx"> 
</span><del>-        groupID, name, membershipHash = (yield txn.groupByGUID(record.guid))
-        self.assertEquals(membershipHash, &quot;4b0e162f2937f0f3daa6d10e5a6a6c33&quot;)
</del><ins>+        groupID, name, membershipHash = (yield txn.groupByUID(record.uid))
</ins><span class="cx"> 
</span><del>-        groupGUID, name, membershipHash = (yield txn.groupByID(groupID))
-        self.assertEquals(groupGUID, record.guid)
-        self.assertEquals(name, &quot;Top Group 1&quot;)
-        self.assertEquals(membershipHash, &quot;4b0e162f2937f0f3daa6d10e5a6a6c33&quot;)
</del><ins>+        self.assertEquals(membershipHash, &quot;f380860ff5e02c2433fbd4b5ed3e090c&quot;)
</ins><span class="cx"> 
</span><ins>+        groupUID, name, membershipHash = (yield txn.groupByID(groupID))
+        self.assertEquals(groupUID, record.uid)
+        self.assertEquals(name, u&quot;Top Group 1&quot;)
+        self.assertEquals(membershipHash, &quot;f380860ff5e02c2433fbd4b5ed3e090c&quot;)
+
</ins><span class="cx">         members = (yield txn.membersOfGroup(groupID))
</span><span class="cx">         self.assertEquals(
</span><del>-            set([UUID(&quot;9064df911dbc4e079c2b6839b0953876&quot;),
-                 UUID(&quot;4ad155cbae9b475f986ce08a7537893e&quot;),
-                 UUID(&quot;3bdcb95484d54f6d8035eac19a6d6e1f&quot;),
-                 UUID(&quot;7d45cb10479e456bb54d528958c5734b&quot;)]),
</del><ins>+            set([u'__cdaboo__', u'__glyph__', u'__sagen__', u'__wsanchez__']),
</ins><span class="cx">             members
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="lines">@@ -97,8 +94,8 @@
</span><span class="cx">         # sagen is in the top group, even though it's actually one level
</span><span class="cx">         # removed
</span><span class="cx">         record = yield self.xmlService.recordWithUID(u&quot;__sagen__&quot;)
</span><del>-        groups = (yield self.groupCacher.cachedGroupsFor(txn, record.guid))
-        self.assertEquals(set([groupID]), groups)
</del><ins>+        groups = (yield self.groupCacher.cachedGroupsFor(txn, record.uid))
+        self.assertEquals(set([u&quot;__top_group_1__&quot;]), groups)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -113,9 +110,9 @@
</span><span class="cx">         txn = store.newTransaction()
</span><span class="cx"> 
</span><span class="cx">         # Refresh the group so it's assigned a group_id
</span><del>-        guid = UUID(&quot;49b350c69611477b94d95516b13856ab&quot;)
-        yield self.groupCacher.refreshGroup(txn, guid)
-        groupID, name, membershipHash = (yield txn.groupByGUID(guid))
</del><ins>+        uid = u&quot;__top_group_1__&quot;
+        yield self.groupCacher.refreshGroup(txn, uid)
+        groupID, name, membershipHash = (yield txn.groupByUID(uid))
</ins><span class="cx"> 
</span><span class="cx">         # Remove two members, and add one member
</span><span class="cx">         newSet = set()
</span><span class="lines">@@ -126,7 +123,7 @@
</span><span class="cx">                     name
</span><span class="cx">                 )
</span><span class="cx">             )
</span><del>-            newSet.add(record.guid)
</del><ins>+            newSet.add(record.uid)
</ins><span class="cx">         numAdded, numRemoved = (
</span><span class="cx">             yield self.groupCacher.synchronizeMembers(
</span><span class="cx">                 txn, groupID, newSet
</span><span class="lines">@@ -159,12 +156,12 @@
</span><span class="cx">         # Non-existent groupID
</span><span class="cx">         self.failUnlessFailure(txn.groupByID(42), NotFoundError)
</span><span class="cx"> 
</span><del>-        guid = UUID(&quot;49b350c69611477b94d95516b13856ab&quot;)
-        hash = &quot;4b0e162f2937f0f3daa6d10e5a6a6c33&quot;
-        yield self.groupCacher.refreshGroup(txn, guid)
-        groupID, name, membershipHash = (yield txn.groupByGUID(guid))
</del><ins>+        uid = u&quot;__top_group_1__&quot;
+        hash = &quot;f380860ff5e02c2433fbd4b5ed3e090c&quot;
+        yield self.groupCacher.refreshGroup(txn, uid)
+        groupID, name, membershipHash = (yield txn.groupByUID(uid))
</ins><span class="cx">         results = (yield txn.groupByID(groupID))
</span><del>-        self.assertEquals([guid, &quot;Top Group 1&quot;, hash], results)
</del><ins>+        self.assertEquals((uid, u&quot;Top Group 1&quot;, hash), results)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -177,32 +174,31 @@
</span><span class="cx">         self.assertEquals(oldExternalAssignments, {})
</span><span class="cx"> 
</span><span class="cx">         newAssignments = {
</span><del>-            UUID(&quot;3BDCB954-84D5-4F6D-8035-EAC19A6D6E1F&quot;):
-            (None, UUID(&quot;49B350C6-9611-477B-94D9-5516B13856AB&quot;))
</del><ins>+            u&quot;__wsanchez__&quot;: (None, u&quot;__top_group_1__&quot;)
</ins><span class="cx">         }
</span><span class="cx">         yield self.groupCacher.applyExternalAssignments(txn, newAssignments)
</span><span class="cx">         oldExternalAssignments = (yield txn.externalDelegates())
</span><span class="cx">         self.assertEquals(
</span><span class="cx">             oldExternalAssignments,
</span><span class="cx">             {
</span><del>-                UUID(&quot;3BDCB954-84D5-4F6D-8035-EAC19A6D6E1F&quot;):
</del><ins>+                u&quot;__wsanchez__&quot;:
</ins><span class="cx">                 (
</span><span class="cx">                     None,
</span><del>-                    UUID(&quot;49B350C6-9611-477B-94D9-5516B13856AB&quot;)
</del><ins>+                    u&quot;__top_group_1__&quot;
</ins><span class="cx">                 )
</span><span class="cx">             }
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx">         newAssignments = {
</span><del>-            UUID(&quot;7D45CB10-479E-456B-B54D-528958C5734B&quot;):
</del><ins>+            u&quot;__cdaboo__&quot;:
</ins><span class="cx">             (
</span><del>-                UUID(&quot;86144F73-345A-4097-82F1-B782672087C7&quot;),
</del><ins>+                u&quot;__sub_group_1__&quot;,
</ins><span class="cx">                 None
</span><span class="cx">             ),
</span><del>-            UUID(&quot;3BDCB954-84D5-4F6D-8035-EAC19A6D6E1F&quot;):
</del><ins>+            u&quot;__wsanchez__&quot;:
</ins><span class="cx">             (
</span><del>-                UUID(&quot;86144F73-345A-4097-82F1-B782672087C7&quot;),
-                UUID(&quot;49B350C6-9611-477B-94D9-5516B13856AB&quot;)
</del><ins>+                u&quot;__sub_group_1__&quot;,
+                u&quot;__top_group_1__&quot;
</ins><span class="cx">             ),
</span><span class="cx">         }
</span><span class="cx">         yield self.groupCacher.applyExternalAssignments(txn, newAssignments)
</span><span class="lines">@@ -210,14 +206,14 @@
</span><span class="cx">         self.assertEquals(
</span><span class="cx">             oldExternalAssignments,
</span><span class="cx">             {
</span><del>-                UUID('3bdcb954-84d5-4f6d-8035-eac19a6d6e1f'):
</del><ins>+                u&quot;__wsanchez__&quot;:
</ins><span class="cx">                 (
</span><del>-                    UUID('86144f73-345a-4097-82f1-b782672087c7'),
-                    UUID('49b350c6-9611-477b-94d9-5516b13856ab')
</del><ins>+                    u&quot;__sub_group_1__&quot;,
+                    u&quot;__top_group_1__&quot;
</ins><span class="cx">                 ),
</span><del>-                UUID('7d45cb10-479e-456b-b54d-528958c5734b'):
</del><ins>+                u&quot;__cdaboo__&quot;:
</ins><span class="cx">                 (
</span><del>-                    UUID('86144f73-345a-4097-82f1-b782672087c7'),
</del><ins>+                    u&quot;__sub_group_1__&quot;,
</ins><span class="cx">                     None
</span><span class="cx">                 )
</span><span class="cx">             }
</span><span class="lines">@@ -228,44 +224,44 @@
</span><span class="cx">             allGroupDelegates,
</span><span class="cx">             set(
</span><span class="cx">                 [
</span><del>-                    UUID('49b350c6-9611-477b-94d9-5516b13856ab'),
-                    UUID('86144f73-345a-4097-82f1-b782672087c7')
</del><ins>+                    u&quot;__top_group_1__&quot;,
+                    u&quot;__sub_group_1__&quot;
</ins><span class="cx">                 ]
</span><span class="cx">             )
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx">         # Fault in the read-only group
</span><del>-        yield self.groupCacher.refreshGroup(txn, UUID('86144f73-345a-4097-82f1-b782672087c7'))
</del><ins>+        yield self.groupCacher.refreshGroup(txn, u&quot;__sub_group_1__&quot;)
</ins><span class="cx"> 
</span><span class="cx">         # Wilfredo should have Sagen and Daboo as read-only delegates
</span><span class="cx">         delegates = (yield txn.delegates(
</span><del>-            UUID(&quot;3BDCB954-84D5-4F6D-8035-EAC19A6D6E1F&quot;), False)
</del><ins>+            u&quot;__wsanchez__&quot;, False, expanded=True)
</ins><span class="cx">         )
</span><span class="cx">         self.assertEquals(
</span><span class="cx">             delegates,
</span><span class="cx">             set(
</span><span class="cx">                 [
</span><del>-                    UUID('4ad155cb-ae9b-475f-986c-e08a7537893e'),
-                    UUID('7d45cb10-479e-456b-b54d-528958c5734b')
</del><ins>+                    u&quot;__sagen__&quot;,
+                    u&quot;__cdaboo__&quot;
</ins><span class="cx">                 ]
</span><span class="cx">             )
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx">         # Fault in the read-write group
</span><del>-        yield self.groupCacher.refreshGroup(txn, UUID('49b350c6-9611-477b-94d9-5516b13856ab'))
</del><ins>+        yield self.groupCacher.refreshGroup(txn, u&quot;__top_group_1__&quot;)
</ins><span class="cx"> 
</span><span class="cx">         # Wilfredo should have 4 users as read-write delegates
</span><span class="cx">         delegates = (yield txn.delegates(
</span><del>-            UUID(&quot;3BDCB954-84D5-4F6D-8035-EAC19A6D6E1F&quot;), True)
</del><ins>+            u&quot;__wsanchez__&quot;, True, expanded=True)
</ins><span class="cx">         )
</span><span class="cx">         self.assertEquals(
</span><span class="cx">             delegates,
</span><span class="cx">             set(
</span><span class="cx">                 [
</span><del>-                    UUID('3bdcb954-84d5-4f6d-8035-eac19a6d6e1f'),
-                    UUID('4ad155cb-ae9b-475f-986c-e08a7537893e'),
-                    UUID('7d45cb10-479e-456b-b54d-528958c5734b'),
-                    UUID('9064df91-1dbc-4e07-9c2b-6839b0953876')
</del><ins>+                    u&quot;__wsanchez__&quot;,
+                    u&quot;__sagen__&quot;,
+                    u&quot;__cdaboo__&quot;,
+                    u&quot;__glyph__&quot;
</ins><span class="cx">                 ]
</span><span class="cx">             )
</span><span class="cx">         )
</span><span class="lines">@@ -275,9 +271,9 @@
</span><span class="cx">         # Now, remove some external assignments
</span><span class="cx">         #
</span><span class="cx">         newAssignments = {
</span><del>-            UUID(&quot;3BDCB954-84D5-4F6D-8035-EAC19A6D6E1F&quot;):
</del><ins>+            u&quot;__wsanchez__&quot;:
</ins><span class="cx">             (
</span><del>-                UUID(&quot;86144F73-345A-4097-82F1-B782672087C7&quot;),
</del><ins>+                u&quot;__sub_group_1__&quot;,
</ins><span class="cx">                 None
</span><span class="cx">             ),
</span><span class="cx">         }
</span><span class="lines">@@ -286,9 +282,9 @@
</span><span class="cx">         self.assertEquals(
</span><span class="cx">             oldExternalAssignments,
</span><span class="cx">             {
</span><del>-                UUID('3bdcb954-84d5-4f6d-8035-eac19a6d6e1f'):
</del><ins>+                u&quot;__wsanchez__&quot;:
</ins><span class="cx">                 (
</span><del>-                    UUID('86144f73-345a-4097-82f1-b782672087c7'),
</del><ins>+                    u&quot;__sub_group_1__&quot;,
</ins><span class="cx">                     None
</span><span class="cx">                 ),
</span><span class="cx">             }
</span><span class="lines">@@ -299,28 +295,28 @@
</span><span class="cx">             allGroupDelegates,
</span><span class="cx">             set(
</span><span class="cx">                 [
</span><del>-                    UUID('86144f73-345a-4097-82f1-b782672087c7')
</del><ins>+                    u&quot;__sub_group_1__&quot;
</ins><span class="cx">                 ]
</span><span class="cx">             )
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx">         # Wilfredo should have Sagen and Daboo as read-only delegates
</span><span class="cx">         delegates = (yield txn.delegates(
</span><del>-            UUID(&quot;3BDCB954-84D5-4F6D-8035-EAC19A6D6E1F&quot;), False)
</del><ins>+            u&quot;__wsanchez__&quot;, False, expanded=True)
</ins><span class="cx">         )
</span><span class="cx">         self.assertEquals(
</span><span class="cx">             delegates,
</span><span class="cx">             set(
</span><span class="cx">                 [
</span><del>-                    UUID('4ad155cb-ae9b-475f-986c-e08a7537893e'),
-                    UUID('7d45cb10-479e-456b-b54d-528958c5734b')
</del><ins>+                    u&quot;__sagen__&quot;,
+                    u&quot;__cdaboo__&quot;
</ins><span class="cx">                 ]
</span><span class="cx">             )
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx">         # Wilfredo should have no read-write delegates
</span><span class="cx">         delegates = (yield txn.delegates(
</span><del>-            UUID(&quot;3BDCB954-84D5-4F6D-8035-EAC19A6D6E1F&quot;), True)
</del><ins>+            u&quot;__wsanchez__&quot;, True, expanded=True)
</ins><span class="cx">         )
</span><span class="cx">         self.assertEquals(
</span><span class="cx">             delegates,
</span><span class="lines">@@ -333,7 +329,7 @@
</span><span class="cx">             allGroupDelegates,
</span><span class="cx">             set(
</span><span class="cx">                 [
</span><del>-                    UUID('86144f73-345a-4097-82f1-b782672087c7')
</del><ins>+                    u&quot;__sub_group_1__&quot;
</ins><span class="cx">                 ]
</span><span class="cx">             )
</span><span class="cx">         )
</span><span class="lines">@@ -424,7 +420,6 @@
</span><span class="cx"> 
</span><span class="cx">   &lt;record type=&quot;user&quot;&gt;
</span><span class="cx">     &lt;uid&gt;__wsanchez__&lt;/uid&gt;
</span><del>-    &lt;guid&gt;3BDCB954-84D5-4F6D-8035-EAC19A6D6E1F&lt;/guid&gt;
</del><span class="cx">     &lt;short-name&gt;wsanchez&lt;/short-name&gt;
</span><span class="cx">     &lt;short-name&gt;wilfredo_sanchez&lt;/short-name&gt;
</span><span class="cx">     &lt;full-name&gt;Wilfredo Sanchez&lt;/full-name&gt;
</span><span class="lines">@@ -435,7 +430,6 @@
</span><span class="cx"> 
</span><span class="cx">   &lt;record type=&quot;user&quot;&gt;
</span><span class="cx">     &lt;uid&gt;__glyph__&lt;/uid&gt;
</span><del>-    &lt;guid&gt;9064DF91-1DBC-4E07-9C2B-6839B0953876&lt;/guid&gt;
</del><span class="cx">     &lt;short-name&gt;glyph&lt;/short-name&gt;
</span><span class="cx">     &lt;full-name&gt;Glyph Lefkowitz&lt;/full-name&gt;
</span><span class="cx">     &lt;password&gt;hpylg&lt;/password&gt;
</span><span class="lines">@@ -445,7 +439,6 @@
</span><span class="cx"> 
</span><span class="cx">   &lt;record type=&quot;user&quot;&gt;
</span><span class="cx">     &lt;uid&gt;__sagen__&lt;/uid&gt;
</span><del>-    &lt;guid&gt;4AD155CB-AE9B-475F-986C-E08A7537893E&lt;/guid&gt;
</del><span class="cx">     &lt;short-name&gt;sagen&lt;/short-name&gt;
</span><span class="cx">     &lt;full-name&gt;Morgen Sagen&lt;/full-name&gt;
</span><span class="cx">     &lt;password&gt;negas&lt;/password&gt;
</span><span class="lines">@@ -455,7 +448,6 @@
</span><span class="cx"> 
</span><span class="cx">   &lt;record type=&quot;user&quot;&gt;
</span><span class="cx">     &lt;uid&gt;__cdaboo__&lt;/uid&gt;
</span><del>-    &lt;guid&gt;7D45CB10-479E-456B-B54D-528958C5734B&lt;/guid&gt;
</del><span class="cx">     &lt;short-name&gt;cdaboo&lt;/short-name&gt;
</span><span class="cx">     &lt;full-name&gt;Cyrus Daboo&lt;/full-name&gt;
</span><span class="cx">     &lt;password&gt;suryc&lt;/password&gt;
</span><span class="lines">@@ -464,7 +456,6 @@
</span><span class="cx"> 
</span><span class="cx">   &lt;record type=&quot;user&quot;&gt;
</span><span class="cx">     &lt;uid&gt;__dre__&lt;/uid&gt;
</span><del>-    &lt;guid&gt;CFC88493-DBFF-42B9-ADC7-9B3DA0B0769B&lt;/guid&gt;
</del><span class="cx">     &lt;short-name&gt;dre&lt;/short-name&gt;
</span><span class="cx">     &lt;full-name&gt;Andre LaBranche&lt;/full-name&gt;
</span><span class="cx">     &lt;password&gt;erd&lt;/password&gt;
</span><span class="lines">@@ -474,7 +465,6 @@
</span><span class="cx"> 
</span><span class="cx">   &lt;record type=&quot;group&quot;&gt;
</span><span class="cx">     &lt;uid&gt;__top_group_1__&lt;/uid&gt;
</span><del>-    &lt;guid&gt;49B350C6-9611-477B-94D9-5516B13856AB&lt;/guid&gt;
</del><span class="cx">     &lt;short-name&gt;top-group-1&lt;/short-name&gt;
</span><span class="cx">     &lt;full-name&gt;Top Group 1&lt;/full-name&gt;
</span><span class="cx">     &lt;email&gt;topgroup1@example.com&lt;/email&gt;
</span><span class="lines">@@ -485,7 +475,6 @@
</span><span class="cx"> 
</span><span class="cx">   &lt;record type=&quot;group&quot;&gt;
</span><span class="cx">     &lt;uid&gt;__sub_group_1__&lt;/uid&gt;
</span><del>-    &lt;guid&gt;86144F73-345A-4097-82F1-B782672087C7&lt;/guid&gt;
</del><span class="cx">     &lt;short-name&gt;sub-group-1&lt;/short-name&gt;
</span><span class="cx">     &lt;full-name&gt;Sub Group 1&lt;/full-name&gt;
</span><span class="cx">     &lt;email&gt;subgroup1@example.com&lt;/email&gt;
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhotesttest_utilpyfromrev12913CalendarServerbranchesuserssagenmove2who3txdavwhotesttest_utilpy"></a>
<div class="copfile"><h4>Copied: CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_util.py (from rev 12913, CalendarServer/branches/users/sagen/move2who-3/txdav/who/test/test_util.py) (0 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_util.py                                (rev 0)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_util.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -0,0 +1,145 @@
</span><ins>+##
+# Copyright (c) 2013 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.
+##
+
+&quot;&quot;&quot;
+txdav.who.util tests
+&quot;&quot;&quot;
+
+import os
+
+from txdav.who.util import directoryFromConfig
+from twisted.internet.defer import inlineCallbacks
+from twisted.trial.unittest import TestCase
+from twistedcaldav.config import ConfigDict
+from twisted.python.filepath import FilePath
+from txdav.who.augment import AugmentedDirectoryService
+from twext.who.aggregate import DirectoryService as AggregateDirectoryService
+from twext.who.xml import DirectoryService as XMLDirectoryService
+from txdav.who.delegates import (
+    DirectoryService as DelegateDirectoryService,
+    RecordType as DelegateRecordType
+)
+from twext.who.idirectory import RecordType
+from txdav.who.idirectory import RecordType as CalRecordType
+
+
+class StubStore(object):
+    pass
+
+
+
+class UtilTest(TestCase):
+
+    def setUp(self):
+        sourceDir = FilePath(__file__).parent().child(&quot;accounts&quot;)
+        self.serverRoot = os.path.abspath(self.mktemp())
+        os.mkdir(self.serverRoot)
+        self.dataRoot = os.path.join(self.serverRoot, &quot;data&quot;)
+        if not os.path.exists(self.dataRoot):
+            os.makedirs(self.dataRoot)
+        destDir = FilePath(self.dataRoot)
+
+        accounts = destDir.child(&quot;accounts.xml&quot;)
+        sourceAccounts = sourceDir.child(&quot;accounts.xml&quot;)
+        accounts.setContent(sourceAccounts.getContent())
+
+        resources = destDir.child(&quot;resources.xml&quot;)
+        sourceResources = sourceDir.child(&quot;resources.xml&quot;)
+        resources.setContent(sourceResources.getContent())
+
+        augments = destDir.child(&quot;augments.xml&quot;)
+        sourceAugments = sourceDir.child(&quot;augments.xml&quot;)
+        augments.setContent(sourceAugments.getContent())
+
+
+    @inlineCallbacks
+    def test_directoryFromConfig(self):
+
+        config = ConfigDict(
+            {
+                &quot;DataRoot&quot;: self.dataRoot,
+                &quot;DirectoryService&quot;: {
+                    &quot;Enabled&quot;: True,
+                    &quot;type&quot;: &quot;XML&quot;,
+                    &quot;params&quot;: {
+                        &quot;xmlFile&quot;: &quot;accounts.xml&quot;,
+                        &quot;recordTypes&quot;: [&quot;users&quot;, &quot;groups&quot;],
+                    },
+                },
+                &quot;ResourceService&quot;: {
+                    &quot;Enabled&quot;: True,
+                    &quot;type&quot;: &quot;XML&quot;,
+                    &quot;params&quot;: {
+                        &quot;xmlFile&quot;: &quot;resources.xml&quot;,
+                        &quot;recordTypes&quot;: [&quot;locations&quot;, &quot;resources&quot;, &quot;addresses&quot;],
+                    },
+                },
+                &quot;AugmentService&quot;: {
+                    &quot;Enabled&quot;: True,
+                    # FIXME: This still uses an actual class name:
+                    &quot;type&quot;: &quot;twistedcaldav.directory.augment.AugmentXMLDB&quot;,
+                    &quot;params&quot;: {
+                        &quot;xmlFiles&quot;: [&quot;augments.xml&quot;],
+                    },
+                },
+            }
+        )
+
+        store = StubStore()
+        service = directoryFromConfig(config, store=store)
+
+        # Inspect the directory service structure
+        self.assertTrue(isinstance(service, AugmentedDirectoryService))
+        self.assertTrue(isinstance(service._directory, AggregateDirectoryService))
+        self.assertEquals(len(service._directory.services), 3)
+        self.assertTrue(
+            isinstance(service._directory.services[0], XMLDirectoryService)
+        )
+        self.assertEquals(
+            set(service._directory.services[0].recordTypes()),
+            set([RecordType.user, RecordType.group])
+        )
+        self.assertTrue(
+            isinstance(service._directory.services[1], XMLDirectoryService)
+        )
+        self.assertEquals(
+            set(service._directory.services[1].recordTypes()),
+            set(
+                [
+                    CalRecordType.location,
+                    CalRecordType.resource,
+                    CalRecordType.address
+                ]
+            )
+        )
+        self.assertTrue(
+            isinstance(service._directory.services[2], DelegateDirectoryService)
+        )
+        self.assertEquals(
+            set(service._directory.services[2].recordTypes()),
+            set(
+                [
+                    DelegateRecordType.readDelegateGroup,
+                    DelegateRecordType.writeDelegateGroup,
+                    DelegateRecordType.readDelegatorGroup,
+                    DelegateRecordType.writeDelegatorGroup,
+                ]
+            )
+        )
+
+        # And make sure it's functional:
+        record = yield service.recordWithUID(&quot;group07&quot;)
+        self.assertEquals(record.fullNames, [u'Group 07'])
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhoutilpyfromrev12913CalendarServerbranchesuserssagenmove2who3txdavwhoutilpy"></a>
<div class="copfile"><h4>Copied: CalendarServer/branches/users/sagen/move2who-4/txdav/who/util.py (from rev 12913, CalendarServer/branches/users/sagen/move2who-3/txdav/who/util.py) (0 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/util.py                                (rev 0)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/util.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -0,0 +1,162 @@
</span><ins>+##
+# Copyright (c) 2006-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.
+##
+
+
+import os
+from twext.python.log import Logger
+from twisted.cred.credentials import UsernamePassword
+from twext.who.aggregate import DirectoryService as AggregateDirectoryService
+from txdav.who.augment import AugmentedDirectoryService
+
+from calendarserver.tap.util import getDBPool, storeFromConfig
+from twext.who.idirectory import RecordType, DirectoryConfigurationError
+from twext.who.ldap import DirectoryService as LDAPDirectoryService
+from twext.who.util import ConstantsContainer
+from twisted.python.filepath import FilePath
+from twisted.python.reflect import namedClass
+from twistedcaldav.config import fullServerPath
+from txdav.who.delegates import DirectoryService as DelegateDirectoryService
+from txdav.who.idirectory import RecordType as CalRecordType
+from txdav.who.xml import DirectoryService as XMLDirectoryService
+
+log = Logger()
+
+
+def directoryFromConfig(config, store=None):
+    &quot;&quot;&quot;
+    Return a directory service based on the config.  If you want to go through
+    AMP to talk to one of these as a client, instantiate
+    txdav.dps.client.DirectoryService
+    &quot;&quot;&quot;
+
+    # MOVE2WHO FIXME: this needs to talk to its own separate database.  In fact,
+    # don't pass store=None if you already have called storeFromConfig()
+    # within this process.  Pass the existing store in here.
+    if store is None:
+        pool, txnFactory = getDBPool(config)
+        store = storeFromConfig(config, txnFactory, None)
+
+    aggregatedServices = []
+
+
+    for serviceKey in (&quot;DirectoryService&quot;, &quot;ResourceService&quot;):
+        serviceValue = config.get(serviceKey, None)
+
+        if not serviceValue.Enabled:
+            continue
+
+        directoryType = serviceValue.type.lower()
+        params = serviceValue.params
+
+        if &quot;xml&quot; in directoryType:
+            xmlFile = params.xmlFile
+            xmlFile = fullServerPath(config.DataRoot, xmlFile)
+            if not xmlFile or not os.path.exists(xmlFile):
+                log.error(&quot;Path not found for XML directory: {p}&quot;, p=xmlFile)
+            fp = FilePath(xmlFile)
+            directory = XMLDirectoryService(fp)
+
+        elif &quot;opendirectory&quot; in directoryType:
+            from twext.who.opendirectory import DirectoryService as ODDirectoryService
+            directory = ODDirectoryService()
+
+        elif &quot;ldap&quot; in directoryType:
+            if params.credentials.dn and params.credentials.password:
+                creds = UsernamePassword(params.credentials.dn,
+                                         params.credentials.password)
+            else:
+                creds = None
+            directory = LDAPDirectoryService(
+                params.uri,
+                params.rdnSchema.base,
+                creds=creds
+            )
+
+        else:
+            log.error(&quot;Invalid DirectoryType: {dt}&quot;, dt=directoryType)
+            raise DirectoryConfigurationError
+
+        # Set the appropriate record types on each service
+        types = []
+        for recordTypeName in params.recordTypes:
+            recordType = {
+                &quot;users&quot;: RecordType.user,
+                &quot;groups&quot;: RecordType.group,
+                &quot;locations&quot;: CalRecordType.location,
+                &quot;resources&quot;: CalRecordType.resource,
+                &quot;addresses&quot;: CalRecordType.address,
+            }.get(recordTypeName, None)
+            if recordType is None:
+                log.error(&quot;Invalid Record Type: {rt}&quot;, rt=recordTypeName)
+                raise DirectoryConfigurationError
+            if recordType in types:
+                log.error(&quot;Duplicate Record Type: {rt}&quot;, rt=recordTypeName)
+                raise DirectoryConfigurationError
+            types.append(recordType)
+
+        directory.recordType = ConstantsContainer(types)
+        aggregatedServices.append(directory)
+
+    #
+    # Setup the Augment Service
+    #
+    if config.AugmentService.type:
+        augmentClass = namedClass(config.AugmentService.type)
+        log.info(
+            &quot;Configuring augment service of type: {augmentClass}&quot;,
+            augmentClass=augmentClass
+        )
+        try:
+            augmentService = augmentClass(**config.AugmentService.params)
+        except IOError:
+            log.error(&quot;Could not start augment service&quot;)
+            raise
+    else:
+        augmentService = None
+
+    userDirectory = None
+    for directory in aggregatedServices:
+        if RecordType.user in directory.recordTypes():
+            userDirectory = directory
+            break
+    else:
+        log.error(&quot;No directory service set up for users&quot;)
+        raise DirectoryConfigurationError
+
+    delegateDirectory = DelegateDirectoryService(
+        userDirectory.realmName,
+        store
+    )
+    aggregatedServices.append(delegateDirectory)
+
+    aggregateDirectory = AggregateDirectoryService(
+        userDirectory.realmName, aggregatedServices
+    )
+    try:
+        augmented = AugmentedDirectoryService(
+            aggregateDirectory, store, augmentService
+        )
+
+        # The delegate directory needs a way to look up user/group records
+        # so hand it a reference to the augmented directory.
+        # FIXME: is there a better pattern to use here?
+        delegateDirectory.setMasterDirectory(augmented)
+
+    except Exception as e:
+        log.error(&quot;Could not create directory service&quot;, error=e)
+        raise
+
+    return augmented
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhoxmlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/xml.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/xml.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/xml.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -143,10 +143,14 @@
</span><span class="cx">         (BaseDirectoryService.recordType, RecordType)
</span><span class="cx">     )
</span><span class="cx"> 
</span><del>-    fieldName = ConstantsContainer(
-        (BaseDirectoryService.fieldName, FieldName)
-    )
</del><ins>+    # MOVE2WHO: Wilfredo had added augment fields into xml, which does make
+    # some sense, but for backwards compatibility right now I will take those
+    # out, and rely on a separate augment service
</ins><span class="cx"> 
</span><ins>+    # fieldName = ConstantsContainer(
+    #     (BaseDirectoryService.fieldName, FieldName)
+    # )
+
</ins><span class="cx">     # XML schema constants
</span><span class="cx"> 
</span><span class="cx">     element = ConstantsContainer(
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txweb2channelhttppy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txweb2/channel/http.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txweb2/channel/http.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txweb2/channel/http.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -137,10 +137,10 @@
</span><span class="cx">     subclass, it can parse either the client side or the server side of the
</span><span class="cx">     connection.
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    
</del><ins>+
</ins><span class="cx">     # Class config:
</span><span class="cx">     parseCloseAsEnd = False
</span><del>-    
</del><ins>+
</ins><span class="cx">     # Instance vars
</span><span class="cx">     chunkedIn = False
</span><span class="cx">     headerlen = 0
</span><span class="lines">@@ -173,12 +173,12 @@
</span><span class="cx">     #  channel.pauseProducing()
</span><span class="cx">     #  channel.resumeProducing()
</span><span class="cx">     #  channel.stopProducing()
</span><del>-    
-    
</del><ins>+
+
</ins><span class="cx">     def __init__(self, channel):
</span><span class="cx">         self.inHeaders = http_headers.Headers()
</span><span class="cx">         self.channel = channel
</span><del>-        
</del><ins>+
</ins><span class="cx">     def lineReceived(self, line):
</span><span class="cx">         if self.chunkedIn:
</span><span class="cx">             # Parsing a chunked input
</span><span class="lines">@@ -208,7 +208,7 @@
</span><span class="cx">                 self.chunkedIn = 1
</span><span class="cx">             elif self.chunkedIn == 3:
</span><span class="cx">                 # TODO: support Trailers (maybe! but maybe not!)
</span><del>-                
</del><ins>+
</ins><span class="cx">                 # After getting the final &quot;0&quot; chunk we're here, and we *EAT MERCILESSLY*
</span><span class="cx">                 # any trailer headers sent, and wait for the blank line to terminate the
</span><span class="cx">                 # request.
</span><span class="lines">@@ -237,7 +237,7 @@
</span><span class="cx">             self.headerlen += len(line)
</span><span class="cx">             if self.headerlen &gt; self.channel.maxHeaderLength:
</span><span class="cx">                 self._abortWithError(responsecode.BAD_REQUEST, 'Headers too long.')
</span><del>-            
</del><ins>+
</ins><span class="cx">             if line[0] in ' \t':
</span><span class="cx">                 # Append a header continuation
</span><span class="cx">                 self.partialHeader += line
</span><span class="lines">@@ -262,7 +262,7 @@
</span><span class="cx">                 # NOTE: in chunked mode, self.length is the size of the current chunk,
</span><span class="cx">                 # so we still have more to read.
</span><span class="cx">                 self.chunkedIn = 2 # Read next chunksize
</span><del>-            
</del><ins>+
</ins><span class="cx">             channel.setLineMode(extraneous)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -293,13 +293,13 @@
</span><span class="cx">         # Set connection parameters from headers
</span><span class="cx">         self.setConnectionParams(connHeaders)
</span><span class="cx">         self.connHeaders = connHeaders
</span><del>-        
</del><ins>+
</ins><span class="cx">     def allContentReceived(self):
</span><span class="cx">         self.finishedReading = True
</span><span class="cx">         self.channel.requestReadFinished(self)
</span><span class="cx">         self.handleContentComplete()
</span><del>-        
-        
</del><ins>+
+
</ins><span class="cx">     def splitConnectionHeaders(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Split off connection control headers from normal headers.
</span><span class="lines">@@ -382,7 +382,7 @@
</span><span class="cx">         # Okay, now implement section 4.4 Message Length to determine
</span><span class="cx">         # how to find the end of the incoming HTTP message.
</span><span class="cx">         transferEncoding = connHeaders.getHeader('transfer-encoding')
</span><del>-        
</del><ins>+
</ins><span class="cx">         if transferEncoding:
</span><span class="cx">             if transferEncoding[-1] == 'chunked':
</span><span class="cx">                 # Chunked
</span><span class="lines">@@ -394,7 +394,7 @@
</span><span class="cx">                 # client-&gt;server data. (Well..it could actually, since TCP has half-close
</span><span class="cx">                 # but the HTTP spec says it can't, so we'll pretend it's right.)
</span><span class="cx">                 self._abortWithError(responsecode.BAD_REQUEST, &quot;Transfer-Encoding received without chunked in last position.&quot;)
</span><del>-            
</del><ins>+
</ins><span class="cx">             # TODO: support gzip/etc encodings.
</span><span class="cx">             # FOR NOW: report an error if the client uses any encodings.
</span><span class="cx">             # They shouldn't, because we didn't send a TE: header saying it's okay.
</span><span class="lines">@@ -423,23 +423,23 @@
</span><span class="cx"> 
</span><span class="cx">         # Set the calculated persistence
</span><span class="cx">         self.channel.setReadPersistent(readPersistent)
</span><del>-        
</del><ins>+
</ins><span class="cx">     def abortParse(self):
</span><span class="cx">         # If we're erroring out while still reading the request
</span><span class="cx">         if not self.finishedReading:
</span><span class="cx">             self.finishedReading = True
</span><span class="cx">             self.channel.setReadPersistent(False)
</span><span class="cx">             self.channel.requestReadFinished(self)
</span><del>-        
</del><ins>+
</ins><span class="cx">     # producer interface
</span><span class="cx">     def pauseProducing(self):
</span><span class="cx">         if not self.finishedReading:
</span><span class="cx">             self.channel.pauseProducing()
</span><del>-        
</del><ins>+
</ins><span class="cx">     def resumeProducing(self):
</span><span class="cx">         if not self.finishedReading:
</span><span class="cx">             self.channel.resumeProducing()
</span><del>-       
</del><ins>+
</ins><span class="cx">     def stopProducing(self):
</span><span class="cx">         if not self.finishedReading:
</span><span class="cx">             self.channel.stopProducing()
</span><span class="lines">@@ -449,13 +449,13 @@
</span><span class="cx">     It is responsible for all the low-level connection oriented behavior.
</span><span class="cx">     Thus, it takes care of keep-alive, de-chunking, etc., and passes
</span><span class="cx">     the non-connection headers on to the user-level Request object.&quot;&quot;&quot;
</span><del>-    
</del><ins>+
</ins><span class="cx">     command = path = version = None
</span><span class="cx">     queued = 0
</span><span class="cx">     request = None
</span><del>-    
</del><ins>+
</ins><span class="cx">     out_version = &quot;HTTP/1.1&quot;
</span><del>-    
</del><ins>+
</ins><span class="cx">     def __init__(self, channel, queued=0):
</span><span class="cx">         HTTPParser.__init__(self, channel)
</span><span class="cx">         self.queued=queued
</span><span class="lines">@@ -466,14 +466,14 @@
</span><span class="cx">             self.transport = StringTransport()
</span><span class="cx">         else:
</span><span class="cx">             self.transport = self.channel.transport
</span><del>-        
</del><ins>+
</ins><span class="cx">         # set the version to a fallback for error generation
</span><span class="cx">         self.version = (1,0)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def gotInitialLine(self, initialLine):
</span><span class="cx">         parts = initialLine.split()
</span><del>-        
</del><ins>+
</ins><span class="cx">         # Parse the initial request line
</span><span class="cx">         if len(parts) != 3:
</span><span class="cx">             if len(parts) == 1:
</span><span class="lines">@@ -490,9 +490,9 @@
</span><span class="cx">                 raise ValueError()
</span><span class="cx">         except ValueError:
</span><span class="cx">             self._abortWithError(responsecode.BAD_REQUEST, &quot;Unknown protocol: %s&quot; % strversion)
</span><del>-        
</del><ins>+
</ins><span class="cx">         self.version = protovers[1:3]
</span><del>-        
</del><ins>+
</ins><span class="cx">         # Ensure HTTP 0 or HTTP 1.
</span><span class="cx">         if self.version[0] &gt; 1:
</span><span class="cx">             self._abortWithError(responsecode.HTTP_VERSION_NOT_SUPPORTED, 'Only HTTP 0.9 and HTTP 1.x are supported.')
</span><span class="lines">@@ -511,18 +511,18 @@
</span><span class="cx"> 
</span><span class="cx">     def processRequest(self):
</span><span class="cx">         self.request.process()
</span><del>-        
</del><ins>+
</ins><span class="cx">     def handleContentChunk(self, data):
</span><span class="cx">         self.request.handleContentChunk(data)
</span><del>-        
</del><ins>+
</ins><span class="cx">     def handleContentComplete(self):
</span><span class="cx">         self.request.handleContentComplete()
</span><del>-        
</del><ins>+
</ins><span class="cx"> ############## HTTPChannelRequest *RESPONSE* methods #############
</span><span class="cx">     producer = None
</span><span class="cx">     chunkedOut = False
</span><span class="cx">     finished = False
</span><del>-    
</del><ins>+
</ins><span class="cx">     ##### Request Callbacks #####
</span><span class="cx">     def writeIntermediateResponse(self, code, headers=None):
</span><span class="cx">         if self.version &gt;= (1,1):
</span><span class="lines">@@ -530,15 +530,15 @@
</span><span class="cx"> 
</span><span class="cx">     def writeHeaders(self, code, headers):
</span><span class="cx">         self._writeHeaders(code, headers, True)
</span><del>-        
</del><ins>+
</ins><span class="cx">     def _writeHeaders(self, code, headers, addConnectionHeaders):
</span><span class="cx">         # HTTP 0.9 doesn't have headers.
</span><span class="cx">         if self.version[0] == 0:
</span><span class="cx">             return
</span><del>-        
</del><ins>+
</ins><span class="cx">         l = []
</span><span class="cx">         code_message = responsecode.RESPONSES.get(code, &quot;Unknown Status&quot;)
</span><del>-        
</del><ins>+
</ins><span class="cx">         l.append('%s %s %s\r\n' % (self.out_version, code,
</span><span class="cx">                                    code_message))
</span><span class="cx">         if headers is not None:
</span><span class="lines">@@ -557,16 +557,16 @@
</span><span class="cx">                 else:
</span><span class="cx">                     # Cannot use persistent connections if we can't do chunking
</span><span class="cx">                     self.channel.dropQueuedRequests()
</span><del>-            
</del><ins>+
</ins><span class="cx">             if self.channel.isLastRequest(self):
</span><span class="cx">                 l.append(&quot;%s: %s\r\n&quot; % ('Connection', 'close'))
</span><span class="cx">             elif self.version &lt; (1,1):
</span><span class="cx">                 l.append(&quot;%s: %s\r\n&quot; % ('Connection', 'Keep-Alive'))
</span><del>-        
</del><ins>+
</ins><span class="cx">         l.append(&quot;\r\n&quot;)
</span><span class="cx">         self.transport.writeSequence(l)
</span><del>-        
-    
</del><ins>+
+
</ins><span class="cx">     def write(self, data):
</span><span class="cx">         if not data:
</span><span class="cx">             return
</span><span class="lines">@@ -574,17 +574,17 @@
</span><span class="cx">             self.transport.writeSequence((&quot;%X\r\n&quot; % len(data), data, &quot;\r\n&quot;))
</span><span class="cx">         else:
</span><span class="cx">             self.transport.write(data)
</span><del>-        
</del><ins>+
</ins><span class="cx">     def finish(self):
</span><span class="cx">         &quot;&quot;&quot;We are finished writing data.&quot;&quot;&quot;
</span><span class="cx">         if self.finished:
</span><span class="cx">             warnings.warn(&quot;Warning! request.finish called twice.&quot;, stacklevel=2)
</span><span class="cx">             return
</span><del>-        
</del><ins>+
</ins><span class="cx">         if self.chunkedOut:
</span><span class="cx">             # write last chunk and closing CRLF
</span><span class="cx">             self.transport.write(&quot;0\r\n\r\n&quot;)
</span><del>-        
</del><ins>+
</ins><span class="cx">         self.finished = True
</span><span class="cx">         if not self.queued:
</span><span class="cx">             self._cleanup()
</span><span class="lines">@@ -596,7 +596,7 @@
</span><span class="cx">         the writing side alone. This is mostly for internal use by
</span><span class="cx">         the HTTP request parsing logic, so that it can call an error
</span><span class="cx">         page generator.
</span><del>-        
</del><ins>+
</ins><span class="cx">         Otherwise, completely shut down the connection.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         self.abortParse()
</span><span class="lines">@@ -604,7 +604,7 @@
</span><span class="cx">             if self.producer:
</span><span class="cx">                 self.producer.stopProducing()
</span><span class="cx">                 self.unregisterProducer()
</span><del>-            
</del><ins>+
</ins><span class="cx">             self.finished = True
</span><span class="cx">             if self.queued:
</span><span class="cx">                 self.transport.reset()
</span><span class="lines">@@ -617,14 +617,14 @@
</span><span class="cx"> 
</span><span class="cx">     def getRemoteHost(self):
</span><span class="cx">         return self.channel.transport.getPeer()
</span><del>-    
</del><ins>+
</ins><span class="cx">     ##### End Request Callbacks #####
</span><span class="cx"> 
</span><span class="cx">     def _abortWithError(self, errorcode, text=''):
</span><span class="cx">         &quot;&quot;&quot;Handle low level protocol errors.&quot;&quot;&quot;
</span><span class="cx">         headers = http_headers.Headers()
</span><span class="cx">         headers.setHeader('content-length', len(text)+1)
</span><del>-        
</del><ins>+
</ins><span class="cx">         self.abortConnection(closeWrite=False)
</span><span class="cx">         self.writeHeaders(errorcode, headers)
</span><span class="cx">         self.write(text)
</span><span class="lines">@@ -632,7 +632,7 @@
</span><span class="cx">         self.finish()
</span><span class="cx">         log.warn(&quot;Aborted request (%d) %s&quot; % (errorcode, text))
</span><span class="cx">         raise AbortedException
</span><del>-    
</del><ins>+
</ins><span class="cx">     def _cleanup(self):
</span><span class="cx">         &quot;&quot;&quot;Called when have finished responding and are no longer queued.&quot;&quot;&quot;
</span><span class="cx">         if self.producer:
</span><span class="lines">@@ -640,7 +640,7 @@
</span><span class="cx">             self.unregisterProducer()
</span><span class="cx">         self.channel.requestWriteFinished(self)
</span><span class="cx">         del self.transport
</span><del>-        
</del><ins>+
</ins><span class="cx">     # methods for channel - end users should not use these
</span><span class="cx"> 
</span><span class="cx">     def noLongerQueued(self):
</span><span class="lines">@@ -674,12 +674,12 @@
</span><span class="cx">     def registerProducer(self, producer, streaming):
</span><span class="cx">         &quot;&quot;&quot;Register a producer.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        
</del><ins>+
</ins><span class="cx">         if self.producer:
</span><span class="cx">             raise ValueError, &quot;registering producer %s before previous one (%s) was unregistered&quot; % (producer, self.producer)
</span><del>-        
</del><ins>+
</ins><span class="cx">         self.producer = producer
</span><del>-        
</del><ins>+
</ins><span class="cx">         if self.queued:
</span><span class="cx">             producer.pauseProducing()
</span><span class="cx">         else:
</span><span class="lines">@@ -698,7 +698,7 @@
</span><span class="cx">             self.producer = None
</span><span class="cx">         if self.request:
</span><span class="cx">             self.request.connectionLost(reason)
</span><del>-    
</del><ins>+
</ins><span class="cx"> class HTTPChannel(basic.LineReceiver, policies.TimeoutMixin, object):
</span><span class="cx">     &quot;&quot;&quot;A receiver for HTTP requests. Handles splitting up the connection
</span><span class="cx">     for the multiple HTTPChannelRequests that may be in progress on this
</span><span class="lines">@@ -714,11 +714,11 @@
</span><span class="cx">     the client.
</span><span class="cx"> 
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    
</del><ins>+
</ins><span class="cx">     implements(interfaces.IHalfCloseableProtocol)
</span><del>-    
</del><ins>+
</ins><span class="cx">     ## Configuration parameters. Set in instances or subclasses.
</span><del>-    
</del><ins>+
</ins><span class="cx">     # How many simultaneous requests to handle.
</span><span class="cx">     maxPipeline = 4
</span><span class="cx"> 
</span><span class="lines">@@ -736,35 +736,35 @@
</span><span class="cx"> 
</span><span class="cx">     # Allow persistent connections?
</span><span class="cx">     allowPersistentConnections = True
</span><del>-    
</del><ins>+
</ins><span class="cx">     # ChannelRequest
</span><span class="cx">     chanRequestFactory = HTTPChannelRequest
</span><span class="cx">     requestFactory = http.Request
</span><del>-    
-    
</del><ins>+
+
</ins><span class="cx">     _first_line = 2
</span><span class="cx">     readPersistent = PERSIST_PIPELINE
</span><del>-    
</del><ins>+
</ins><span class="cx">     _readLost = False
</span><span class="cx">     _writeLost = False
</span><del>-    
</del><ins>+
</ins><span class="cx">     _abortTimer = None
</span><span class="cx">     chanRequest = None
</span><span class="cx"> 
</span><span class="cx">     def _callLater(self, secs, fun):
</span><span class="cx">         reactor.callLater(secs, fun)
</span><del>-    
</del><ins>+
</ins><span class="cx">     def __init__(self):
</span><span class="cx">         # the request queue
</span><span class="cx">         self.requests = []
</span><del>-        
</del><ins>+
</ins><span class="cx">     def connectionMade(self):
</span><span class="cx">         self._secure = interfaces.ISSLTransport(self.transport, None) is not None
</span><span class="cx">         address = self.transport.getHost()
</span><span class="cx">         self._host = _cachedGetHostByAddr(address.host)
</span><span class="cx">         self.setTimeout(self.inputTimeOut)
</span><span class="cx">         self.factory.addConnectedChannel(self)
</span><del>-    
</del><ins>+
</ins><span class="cx">     def lineReceived(self, line):
</span><span class="cx">         if self._first_line:
</span><span class="cx">             self.setTimeout(self.inputTimeOut)
</span><span class="lines">@@ -779,13 +779,13 @@
</span><span class="cx">             if not line and self._first_line == 1:
</span><span class="cx">                 self._first_line = 2
</span><span class="cx">                 return
</span><del>-            
</del><ins>+
</ins><span class="cx">             self._first_line = 0
</span><del>-            
</del><ins>+
</ins><span class="cx">             if not self.allowPersistentConnections:
</span><span class="cx">                 # Don't allow a second request
</span><span class="cx">                 self.readPersistent = False
</span><del>-                
</del><ins>+
</ins><span class="cx">             try:
</span><span class="cx">                 self.chanRequest = self.chanRequestFactory(self, len(self.requests))
</span><span class="cx">                 self.requests.append(self.chanRequest)
</span><span class="lines">@@ -801,7 +801,7 @@
</span><span class="cx">     def lineLengthExceeded(self, line):
</span><span class="cx">         if self._first_line:
</span><span class="cx">             # Fabricate a request object to respond to the line length violation.
</span><del>-            self.chanRequest = self.chanRequestFactory(self, 
</del><ins>+            self.chanRequest = self.chanRequestFactory(self,
</ins><span class="cx">                                                        len(self.requests))
</span><span class="cx">             self.requests.append(self.chanRequest)
</span><span class="cx">             self.chanRequest.gotInitialLine(&quot;GET fake HTTP/1.0&quot;)
</span><span class="lines">@@ -809,7 +809,7 @@
</span><span class="cx">             self.chanRequest.lineLengthExceeded(line, self._first_line)
</span><span class="cx">         except AbortedException:
</span><span class="cx">             pass
</span><del>-            
</del><ins>+
</ins><span class="cx">     def rawDataReceived(self, data):
</span><span class="cx">         self.setTimeout(self.inputTimeOut)
</span><span class="cx">         try:
</span><span class="lines">@@ -821,17 +821,17 @@
</span><span class="cx">         if(self.readPersistent is PERSIST_NO_PIPELINE or
</span><span class="cx">            len(self.requests) &gt;= self.maxPipeline):
</span><span class="cx">             self.pauseProducing()
</span><del>-        
</del><ins>+
</ins><span class="cx">         # reset state variables
</span><span class="cx">         self._first_line = 1
</span><span class="cx">         self.chanRequest = None
</span><span class="cx">         self.setLineMode()
</span><del>-        
</del><ins>+
</ins><span class="cx">         # Set an idle timeout, in case this request takes a long
</span><span class="cx">         # time to finish generating output.
</span><span class="cx">         if len(self.requests) &gt; 0:
</span><span class="cx">             self.setTimeout(self.idleTimeOut)
</span><del>-        
</del><ins>+
</ins><span class="cx">     def _startNextRequest(self):
</span><span class="cx">         # notify next request, if present, it can start writing
</span><span class="cx">         del self.requests[0]
</span><span class="lines">@@ -840,7 +840,7 @@
</span><span class="cx">             self.transport.loseConnection()
</span><span class="cx">         elif self.requests:
</span><span class="cx">             self.requests[0].noLongerQueued()
</span><del>-            
</del><ins>+
</ins><span class="cx">             # resume reading if allowed to
</span><span class="cx">             if(not self._readLost and
</span><span class="cx">                self.readPersistent is not PERSIST_NO_PIPELINE and
</span><span class="lines">@@ -866,11 +866,11 @@
</span><span class="cx">         for request in self.requests[1:]:
</span><span class="cx">             request.connectionLost(None)
</span><span class="cx">         del self.requests[1:]
</span><del>-    
</del><ins>+
</ins><span class="cx">     def isLastRequest(self, request):
</span><span class="cx">         # Is this channel handling the last possible request
</span><span class="cx">         return not self.readPersistent and self.requests[-1] == request
</span><del>-    
</del><ins>+
</ins><span class="cx">     def requestWriteFinished(self, request):
</span><span class="cx">         &quot;&quot;&quot;Called by first request in queue when it is done.&quot;&quot;&quot;
</span><span class="cx">         if request != self.requests[0]: raise TypeError
</span><span class="lines">@@ -878,7 +878,7 @@
</span><span class="cx">         # Don't del because we haven't finished cleanup, so,
</span><span class="cx">         # don't want queue len to be 0 yet.
</span><span class="cx">         self.requests[0] = None
</span><del>-        
</del><ins>+
</ins><span class="cx">         if self.readPersistent or len(self.requests) &gt; 1:
</span><span class="cx">             # Do this in the next reactor loop so as to
</span><span class="cx">             # not cause huge call stacks with fast
</span><span class="lines">@@ -910,26 +910,26 @@
</span><span class="cx">             self._abortTimer = None
</span><span class="cx">             self.transport.loseConnection()
</span><span class="cx">             return
</span><del>-        
</del><ins>+
</ins><span class="cx">         # If between requests, drop connection
</span><span class="cx">         # when all current requests have written their data.
</span><span class="cx">         self._readLost = True
</span><span class="cx">         if not self.requests:
</span><span class="cx">             # No requests in progress, lose now.
</span><span class="cx">             self.transport.loseConnection()
</span><del>-            
</del><ins>+
</ins><span class="cx">         # If currently in the process of reading a request, this is
</span><span class="cx">         # probably a client abort, so lose the connection.
</span><span class="cx">         if self.chanRequest:
</span><span class="cx">             self.transport.loseConnection()
</span><del>-        
</del><ins>+
</ins><span class="cx">     def connectionLost(self, reason):
</span><span class="cx">         self.factory.removeConnectedChannel(self)
</span><span class="cx"> 
</span><span class="cx">         self._writeLost = True
</span><span class="cx">         self.readConnectionLost()
</span><span class="cx">         self.setTimeout(None)
</span><del>-        
</del><ins>+
</ins><span class="cx">         # Tell all requests to abort.
</span><span class="cx">         for request in self.requests:
</span><span class="cx">             if request is not None:
</span><span class="lines">@@ -963,7 +963,7 @@
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     protocol = HTTPChannel
</span><del>-    
</del><ins>+
</ins><span class="cx">     protocolArgs = None
</span><span class="cx"> 
</span><span class="cx">     def __init__(self, requestFactory, maxRequests=600, **kwargs):
</span><span class="lines">@@ -977,9 +977,9 @@
</span><span class="cx">     def buildProtocol(self, addr):
</span><span class="cx">         if self.outstandingRequests &gt;= self.maxRequests:
</span><span class="cx">             return OverloadedServerProtocol()
</span><del>-        
</del><ins>+
</ins><span class="cx">         p = protocol.ServerFactory.buildProtocol(self, addr)
</span><del>-        
</del><ins>+
</ins><span class="cx">         for arg,value in self.protocolArgs.iteritems():
</span><span class="cx">             setattr(p, arg, value)
</span><span class="cx">         return p
</span><span class="lines">@@ -1050,19 +1050,19 @@
</span><span class="cx">         return p
</span><span class="cx"> 
</span><span class="cx"> class HTTPLoggingChannelRequest(HTTPChannelRequest):
</span><del>-    
</del><ins>+
</ins><span class="cx">     class TransportLoggingWrapper(object):
</span><del>-        
</del><ins>+
</ins><span class="cx">         def __init__(self, transport, logData):
</span><del>-            
</del><ins>+
</ins><span class="cx">             self.transport = transport
</span><span class="cx">             self.logData = logData
</span><del>-            
</del><ins>+
</ins><span class="cx">         def write(self, data):
</span><span class="cx">             if self.logData is not None and data:
</span><span class="cx">                 self.logData.append(data)
</span><span class="cx">             self.transport.write(data)
</span><del>-            
</del><ins>+
</ins><span class="cx">         def writeSequence(self, seq):
</span><span class="cx">             if self.logData is not None and seq:
</span><span class="cx">                 self.logData.append(''.join(seq))
</span><span class="lines">@@ -1075,7 +1075,7 @@
</span><span class="cx">         def __init__(self):
</span><span class="cx">             self.request = []
</span><span class="cx">             self.response = []
</span><del>-            
</del><ins>+
</ins><span class="cx">     def __init__(self, channel, queued=0):
</span><span class="cx">         super(HTTPLoggingChannelRequest, self).__init__(channel, queued)
</span><span class="cx"> 
</span><span class="lines">@@ -1093,7 +1093,7 @@
</span><span class="cx">         super(HTTPLoggingChannelRequest, self).gotInitialLine(initialLine)
</span><span class="cx"> 
</span><span class="cx">     def lineReceived(self, line):
</span><del>-        
</del><ins>+
</ins><span class="cx">         if self.logData is not None:
</span><span class="cx">             # We don't want to log basic credentials
</span><span class="cx">             loggedLine = line
</span><span class="lines">@@ -1105,13 +1105,13 @@
</span><span class="cx">         super(HTTPLoggingChannelRequest, self).lineReceived(line)
</span><span class="cx"> 
</span><span class="cx">     def handleContentChunk(self, data):
</span><del>-        
</del><ins>+
</ins><span class="cx">         if self.logData is not None:
</span><span class="cx">             self.logData.request.append(data)
</span><span class="cx">         super(HTTPLoggingChannelRequest, self).handleContentChunk(data)
</span><del>-        
</del><ins>+
</ins><span class="cx">     def handleContentComplete(self):
</span><del>-        
</del><ins>+
</ins><span class="cx">         if self.logData is not None:
</span><span class="cx">             doneTime = time.time()
</span><span class="cx">             self.logData.request.append(&quot;\r\n\r\n&gt;&gt;&gt;&gt; Request complete at: %.3f (elapsed: %.1f ms)&quot; % (doneTime, 1000 * (doneTime - self.startTime),))
</span><span class="lines">@@ -1124,7 +1124,7 @@
</span><span class="cx">         super(HTTPLoggingChannelRequest, self).writeHeaders(code, headers)
</span><span class="cx"> 
</span><span class="cx">     def finish(self):
</span><del>-        
</del><ins>+
</ins><span class="cx">         super(HTTPLoggingChannelRequest, self).finish()
</span><span class="cx"> 
</span><span class="cx">         if self.logData is not None:
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txweb2davresourcepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txweb2/dav/resource.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txweb2/dav/resource.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txweb2/dav/resource.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -997,6 +997,7 @@
</span><span class="cx">             if the authentication scheme is unsupported, or the
</span><span class="cx">             credentials provided by the request are not valid.
</span><span class="cx">         &quot;&quot;&quot;
</span><ins>+
</ins><span class="cx">         # Bypass normal authentication if its already been done (by SACL check)
</span><span class="cx">         if (
</span><span class="cx">             hasattr(request, &quot;authnUser&quot;) and
</span><span class="lines">@@ -1134,7 +1135,7 @@
</span><span class="cx">         # The default behaviour is no ACL; we should inherit from the parent
</span><span class="cx">         # collection.
</span><span class="cx">         #
</span><del>-        return element.ACL()
</del><ins>+        return succeed(element.ACL())
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def setAccessControlList(self, acl):
</span><span class="lines">@@ -1360,6 +1361,7 @@
</span><span class="cx">         @return: a L{Deferred} that callbacks with C{None} or errbacks
</span><span class="cx">             with an L{AccessDeniedError}
</span><span class="cx">         &quot;&quot;&quot;
</span><ins>+
</ins><span class="cx">         if principal is None:
</span><span class="cx">             principal = self.currentPrincipal(request)
</span><span class="cx"> 
</span><span class="lines">@@ -1509,7 +1511,7 @@
</span><span class="cx">                 # If we get to the root without any ACLs, then use the default.
</span><span class="cx">                 acl = self.defaultRootAccessControlList()
</span><span class="cx">             else:
</span><del>-                acl = self.defaultAccessControlList()
</del><ins>+                acl = yield self.defaultAccessControlList()
</ins><span class="cx"> 
</span><span class="cx">         # Dynamically update privileges for those ace's that are inherited.
</span><span class="cx">         if inheritance:
</span><span class="lines">@@ -1618,6 +1620,7 @@
</span><span class="cx">         return []
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def principalsForAuthID(self, request, authid):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Return authentication and authorization principal identifiers
</span><span class="lines">@@ -1637,16 +1640,16 @@
</span><span class="cx">             HTTPError(responsecode.FORBIDDEN) if the principal isn't
</span><span class="cx">             found.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        authnPrincipal = self.findPrincipalForAuthID(authid)
</del><ins>+        authnPrincipal = yield self.findPrincipalForAuthID(authid)
</ins><span class="cx"> 
</span><span class="cx">         if authnPrincipal is None:
</span><del>-            return succeed((None, None))
</del><ins>+            returnValue((None, None))
</ins><span class="cx"> 
</span><del>-        d = self.authorizationPrincipal(request, authid, authnPrincipal)
-        d.addCallback(lambda authzPrincipal: (authnPrincipal, authzPrincipal))
-        return d
</del><ins>+        authzPrincipal = yield self.authorizationPrincipal(request, authid, authnPrincipal)
+        returnValue((authnPrincipal, authzPrincipal))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def findPrincipalForAuthID(self, authid):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Return authentication and authorization principal identifiers
</span><span class="lines">@@ -1662,10 +1665,10 @@
</span><span class="cx">             found return None.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         for collection in self.principalCollections():
</span><del>-            principal = collection.principalForUser(authid)
</del><ins>+            principal = yield collection.principalForUser(authid)
</ins><span class="cx">             if principal is not None:
</span><del>-                return principal
-        return None
</del><ins>+                returnValue(principal)
+        returnValue(None)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def authorizationPrincipal(self, request, authid, authnPrincipal):
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txweb2serverpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txweb2/server.py (12913 => 12914)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txweb2/server.py        2014-03-14 19:21:35 UTC (rev 12913)
+++ CalendarServer/branches/users/sagen/move2who-4/txweb2/server.py        2014-03-14 19:23:36 UTC (rev 12914)
</span><span class="lines">@@ -192,7 +192,7 @@
</span><span class="cx">                        error.defaultErrorHandler, defaultHeadersFilter]
</span><span class="cx"> 
</span><span class="cx">     def __init__(self, *args, **kw):
</span><del>-        
</del><ins>+
</ins><span class="cx">         self.timeStamps = [(&quot;t&quot;, time.time(),)]
</span><span class="cx"> 
</span><span class="cx">         if kw.has_key('site'):
</span><span class="lines">@@ -308,10 +308,10 @@
</span><span class="cx">         clients into using an inappropriate scheme for subsequent requests. What we should do is
</span><span class="cx">         take the port number from the Host header or request-URI and map that to the scheme that
</span><span class="cx">         matches the service we configured to listen on that port.
</span><del>- 
</del><ins>+
</ins><span class="cx">         @param port: the port number to test
</span><span class="cx">         @type port: C{int}
</span><del>-        
</del><ins>+
</ins><span class="cx">         @return: C{True} if scheme is https (secure), C{False} otherwise
</span><span class="cx">         @rtype: C{bool}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -322,7 +322,7 @@
</span><span class="cx">                 return True
</span><span class="cx">             elif port in self.site.BindSSLPorts:
</span><span class="cx">                 return True
</span><del>-        
</del><ins>+
</ins><span class="cx">         return False
</span><span class="cx"> 
</span><span class="cx">     def _fixupURLParts(self):
</span><span class="lines">@@ -558,7 +558,7 @@
</span><span class="cx">                 break
</span><span class="cx">             else:
</span><span class="cx">                 postSegments.insert(0, preSegments.pop())
</span><del>-        
</del><ins>+
</ins><span class="cx">         if cachedParent is None:
</span><span class="cx">             cachedParent = self.site.resource
</span><span class="cx">             postSegments = segments[1:]
</span></span></pre>
</div>
</div>

</body>
</html>