<!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>[13069] CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py</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/13069">13069</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2014-03-31 15:43:14 -0700 (Mon, 31 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>lint</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarserverprovisionrootpy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserssagenmove2who4calendarserverprovisionrootpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py (13068 => 13069)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py        2014-03-31 22:18:29 UTC (rev 13068)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/provision/root.py        2014-03-31 22:43:14 UTC (rev 13069)
</span><span class="lines">@@ -19,7 +19,6 @@
</span><span class="cx">     &quot;RootResource&quot;,
</span><span class="cx"> ]
</span><span class="cx"> 
</span><del>-from txdav.who.wiki import uidForAuthToken
</del><span class="cx"> from twext.python.log import Logger
</span><span class="cx"> from twisted.cred.error import LoginFailed, UnauthorizedLogin
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks, returnValue, succeed
</span><span class="lines">@@ -35,6 +34,7 @@
</span><span class="cx"> from twistedcaldav.extensions import ReadOnlyResourceMixIn
</span><span class="cx"> from twistedcaldav.resource import CalDAVComplianceMixIn
</span><span class="cx"> from txdav.who.wiki import DirectoryService as WikiDirectoryService
</span><ins>+from txdav.who.wiki import uidForAuthToken
</ins><span class="cx"> from txdav.xml import element as davxml
</span><span class="cx"> from txweb2 import responsecode
</span><span class="cx"> from txweb2.auth.wrapper import UnauthorizedResponse
</span><span class="lines">@@ -44,7 +44,10 @@
</span><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class RootResource (ReadOnlyResourceMixIn, DirectoryPrincipalPropertySearchMixIn, CalDAVComplianceMixIn, DAVFile):
</del><ins>+class RootResource(
+    ReadOnlyResourceMixIn, DirectoryPrincipalPropertySearchMixIn,
+    CalDAVComplianceMixIn, DAVFile
+):
</ins><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     A special root resource that contains support checking SACLs
</span><span class="cx">     as well as adding responseFilters.
</span><span class="lines">@@ -56,17 +59,17 @@
</span><span class="cx">     # starts with any of these, then the list of SACLs are checked.  If the
</span><span class="cx">     # request path does not start with any of these, then no SACLs are checked.
</span><span class="cx">     saclMap = {
</span><del>-        &quot;addressbooks&quot; : (&quot;addressbook&quot;,),
-        &quot;calendars&quot; : (&quot;calendar&quot;,),
-        &quot;directory&quot; : (&quot;addressbook&quot;,),
-        &quot;principals&quot; : (&quot;addressbook&quot;, &quot;calendar&quot;),
-        &quot;webcal&quot; : (&quot;calendar&quot;,),
</del><ins>+        &quot;addressbooks&quot;: (&quot;addressbook&quot;,),
+        &quot;calendars&quot;: (&quot;calendar&quot;,),
+        &quot;directory&quot;: (&quot;addressbook&quot;,),
+        &quot;principals&quot;: (&quot;addressbook&quot;, &quot;calendar&quot;),
+        &quot;webcal&quot;: (&quot;calendar&quot;,),
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     # If a top-level resource path starts with any of these, an unauthenticated
</span><span class="cx">     # request is redirected to the auth url (config.WebCalendarAuthPath)
</span><span class="cx">     authServiceMap = {
</span><del>-        &quot;webcal&quot; : True,
</del><ins>+        &quot;webcal&quot;: True,
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     def __init__(self, path, *args, **kwargs):
</span><span class="lines">@@ -80,11 +83,17 @@
</span><span class="cx"> 
</span><span class="cx">         self.contentFilters = []
</span><span class="cx"> 
</span><del>-        if config.EnableResponseCache and config.Memcached.Pools.Default.ClientEnabled:
</del><ins>+        if (
+            config.EnableResponseCache and
+            config.Memcached.Pools.Default.ClientEnabled
+        ):
</ins><span class="cx">             self.responseCache = MemcacheResponseCache(self.fp)
</span><span class="cx"> 
</span><del>-            # These class attributes need to be setup with our memcache notifier
-            DirectoryPrincipalResource.cacheNotifierFactory = MemcacheChangeNotifier
</del><ins>+            # These class attributes need to be setup with our memcache\
+            # notifier
+            DirectoryPrincipalResource.cacheNotifierFactory = (
+                MemcacheChangeNotifier
+            )
</ins><span class="cx">         else:
</span><span class="cx">             self.responseCache = DisabledCache()
</span><span class="cx"> 
</span><span class="lines">@@ -96,7 +105,9 @@
</span><span class="cx">     def deadProperties(self):
</span><span class="cx">         if not hasattr(self, &quot;_dead_properties&quot;):
</span><span class="cx">             # Get the property store from super
</span><del>-            deadProperties = namedClass(config.RootResourcePropStoreClass)(self)
</del><ins>+            deadProperties = (
+                namedClass(config.RootResourcePropStoreClass)(self)
+            )
</ins><span class="cx"> 
</span><span class="cx">             # Wrap the property store in a memory store
</span><span class="cx">             if isinstance(deadProperties, xattrPropertyStore):
</span><span class="lines">@@ -158,7 +169,9 @@
</span><span class="cx">         request.checkingSACL = True
</span><span class="cx"> 
</span><span class="cx">         for collection in self.principalCollections():
</span><del>-            principal = yield collection._principalForURI(authzUser.children[0].children[0].data)
</del><ins>+            principal = yield collection._principalForURI(
+                authzUser.children[0].children[0].data
+            )
</ins><span class="cx">             if principal is None:
</span><span class="cx">                 response = (yield UnauthorizedResponse.makeResponse(
</span><span class="cx">                     request.credentialFactories,
</span><span class="lines">@@ -183,7 +196,10 @@
</span><span class="cx">         if access:
</span><span class="cx">             returnValue(True)
</span><span class="cx"> 
</span><del>-        log.warn(&quot;User %r is not enabled with the %r SACL(s)&quot; % (username, saclServices,))
</del><ins>+        log.warn(
+            &quot;User {user!r} is not enabled with the {sacl!r} SACL(s)&quot;,
+            user=username, sacl=saclServices
+        )
</ins><span class="cx">         raise HTTPError(responsecode.FORBIDDEN)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -227,45 +243,71 @@
</span><span class="cx">                     token = None
</span><span class="cx"> 
</span><span class="cx">                 if token is not None and token != &quot;unauthenticated&quot;:
</span><del>-                    log.debug(&quot;Wiki sessionID cookie value: %s&quot; % (token,))
</del><ins>+                    log.debug(
+                        &quot;Wiki sessionID cookie value: {token}&quot;, token=token
+                    )
</ins><span class="cx"> 
</span><span class="cx">                     record = None
</span><span class="cx">                     try:
</span><del>-                        uid = (yield uidForAuthToken(token))
</del><ins>+                        uid = yield uidForAuthToken(token)
</ins><span class="cx">                         if uid == &quot;unauthenticated&quot;:
</span><span class="cx">                             uid = None
</span><span class="cx"> 
</span><del>-                    except WebError, w:
</del><ins>+                    except WebError as w:
</ins><span class="cx">                         uid = None
</span><span class="cx">                         # FORBIDDEN status means it's an unknown token
</span><span class="cx">                         if int(w.status) == responsecode.NOT_FOUND:
</span><del>-                            log.debug(&quot;Unknown wiki token: %s&quot; % (token,))
</del><ins>+                            log.debug(
+                                &quot;Unknown wiki token: {token}&quot;, token=token
+                            )
</ins><span class="cx">                         else:
</span><del>-                            log.error(&quot;Failed to look up wiki token %s: %s&quot; %
-                                (token, w.message,))
</del><ins>+                            log.error(
+                                &quot;Failed to look up wiki token {token}: &quot;
+                                &quot;{message}&quot;,
+                                token=token, message=w.message
+                            )
</ins><span class="cx"> 
</span><del>-                    except Exception, e:
-                        log.error(&quot;Failed to look up wiki token (%s)&quot; % (e,))
</del><ins>+                    except Exception as e:
+                        log.error(
+                            &quot;Failed to look up wiki token: {error}&quot;,
+                            error=e
+                        )
</ins><span class="cx">                         uid = None
</span><span class="cx"> 
</span><span class="cx">                     if uid is not None:
</span><del>-                        log.debug(&quot;Wiki lookup returned uid: %s&quot; % (uid,))
</del><ins>+                        log.debug(
+                            &quot;Wiki lookup returned uid: {uid}&quot;, uid=uid
+                        )
</ins><span class="cx">                         principal = None
</span><span class="cx">                         directory = request.site.resource.getDirectory()
</span><span class="cx">                         record = yield directory.recordWithUID(uid)
</span><span class="cx">                         if record is not None:
</span><span class="cx">                             username = record.shortNames[0]
</span><del>-                            log.debug(&quot;Wiki user record for user %s : %s&quot; % (username, record))
</del><ins>+                            log.debug(
+                                &quot;Wiki user record for user {user}: {record}&quot;,
+                                user=username, record=record
+                            )
</ins><span class="cx">                             for collection in self.principalCollections():
</span><del>-                                principal = yield collection.principalForRecord(record)
</del><ins>+                                principal = (
+                                    yield collection.principalForRecord(record)
+                                )
</ins><span class="cx">                                 if principal is not None:
</span><span class="cx">                                     break
</span><span class="cx"> 
</span><span class="cx">                         if principal:
</span><del>-                            log.debug(&quot;Wiki-authenticated principal %s being assigned to authnUser and authzUser&quot; % (record.uid,))
-                            request.authzUser = request.authnUser = davxml.Principal(
-                                davxml.HRef.fromString(&quot;/principals/__uids__/%s/&quot; % (record.uid,))
</del><ins>+                            log.debug(
+                                &quot;Wiki-authenticated principal {record.uid} &quot;
+                                &quot;being assigned to authnUser and authzUser&quot;,
+                                record=record
</ins><span class="cx">                             )
</span><ins>+                            request.authzUser = request.authnUser = (
+                                davxml.Principal(
+                                    davxml.HRef.fromString(
+                                        &quot;/principals/__uids__/{}/&quot;
+                                        .format(record.uid)
+                                    )
+                                )
+                            )
</ins><span class="cx"> 
</span><span class="cx">         if not hasattr(request, &quot;authzUser&quot;) and config.WebCalendarAuthPath:
</span><span class="cx">             topLevel = request.path.strip(&quot;/&quot;).split(&quot;/&quot;)[0]
</span><span class="lines">@@ -275,25 +317,27 @@
</span><span class="cx"> 
</span><span class="cx">                 # Use config.ServerHostName if no x-forwarded-host header,
</span><span class="cx">                 # otherwise use the final hostname in x-forwarded-host.
</span><del>-                host = request.headers.getRawHeaders(&quot;x-forwarded-host&quot;,
-                    [config.ServerHostName])[-1].split(&quot;,&quot;)[-1].strip()
</del><ins>+                host = request.headers.getRawHeaders(
+                    &quot;x-forwarded-host&quot;,
+                    [config.ServerHostName]
+                )[-1].split(&quot;,&quot;)[-1].strip()
</ins><span class="cx">                 port = 443 if config.EnableSSL else 80
</span><span class="cx">                 scheme = &quot;https&quot; if config.EnableSSL else &quot;http&quot;
</span><span class="cx"> 
</span><span class="cx">                 response = RedirectResponse(
</span><del>-                        request.unparseURL(
-                            host=host,
-                            port=port,
-                            scheme=scheme,
-                            path=config.WebCalendarAuthPath,
-                            querystring=&quot;redirect=%s://%s%s&quot; % (
-                                scheme,
-                                host,
-                                request.path
-                            )
-                        ),
-                        temporary=True
-                    )
</del><ins>+                    request.unparseURL(
+                        host=host,
+                        port=port,
+                        scheme=scheme,
+                        path=config.WebCalendarAuthPath,
+                        querystring=&quot;redirect={}://{}{}&quot;.format(
+                            scheme,
+                            host,
+                            request.path
+                        )
+                    ),
+                    temporary=True
+                )
</ins><span class="cx">                 raise HTTPError(response)
</span><span class="cx"> 
</span><span class="cx">         # We don't want the /inbox resource to pay attention to SACLs because
</span><span class="lines">@@ -303,10 +347,17 @@
</span><span class="cx">         if segments[0] in (&quot;inbox&quot;, &quot;timezones&quot;):
</span><span class="cx">             request.checkedSACL = True
</span><span class="cx"> 
</span><del>-        elif (len(segments) &gt; 2 and segments[0] in (&quot;calendars&quot;, &quot;principals&quot;) and
</del><ins>+        elif (
</ins><span class="cx">             (
</span><del>-                segments[1] == &quot;wikis&quot; or
-                (segments[1] == &quot;__uids__&quot; and segments[2].startswith(WikiDirectoryService.uidPrefix))
</del><ins>+                len(segments) &gt; 2 and
+                segments[0] in (&quot;calendars&quot;, &quot;principals&quot;) and
+                (
+                    segments[1] == &quot;wikis&quot; or
+                    (
+                        segments[1] == &quot;__uids__&quot; and
+                        segments[2].startswith(WikiDirectoryService.uidPrefix)
+                    )
+                )
</ins><span class="cx">             )
</span><span class="cx">         ):
</span><span class="cx">             # This is a wiki-related calendar resource. SACLs are not checked.
</span><span class="lines">@@ -321,12 +372,21 @@
</span><span class="cx">                 else:
</span><span class="cx">                     wikiName = segments[2][5:]
</span><span class="cx">                 if wikiName:
</span><del>-                    log.debug(&quot;Wiki principal %s being assigned to authzUser&quot; % (wikiName,))
</del><ins>+                    log.debug(
+                        &quot;Wiki principal {name} being assigned to authzUser&quot;,
+                        name=wikiName
+                    )
</ins><span class="cx">                     request.authzUser = davxml.Principal(
</span><del>-                        davxml.HRef.fromString(&quot;/principals/wikis/%s/&quot; % (wikiName,))
</del><ins>+                        davxml.HRef.fromString(
+                            &quot;/principals/wikis/{}/&quot;.format(wikiName)
+                        )
</ins><span class="cx">                     )
</span><span class="cx"> 
</span><del>-        elif self.useSacls and not hasattr(request, &quot;checkedSACL&quot;) and not hasattr(request, &quot;checkingSACL&quot;):
</del><ins>+        elif (
+            self.useSacls and
+            not hasattr(request, &quot;checkedSACL&quot;) and
+            not hasattr(request, &quot;checkingSACL&quot;)
+        ):
</ins><span class="cx">             yield self.checkSacl(request)
</span><span class="cx"> 
</span><span class="cx">         if config.RejectClients:
</span><span class="lines">@@ -337,28 +397,37 @@
</span><span class="cx">             if agent is not None:
</span><span class="cx">                 for reject in config.RejectClients:
</span><span class="cx">                     if reject.search(agent) is not None:
</span><del>-                        log.info(&quot;Rejecting user-agent: %s&quot; % (agent,))
</del><ins>+                        log.info(&quot;Rejecting user-agent: {agent}&quot;, agent=agent)
</ins><span class="cx">                         raise HTTPError(StatusResponse(
</span><span class="cx">                             responsecode.FORBIDDEN,
</span><del>-                            &quot;Your client software (%s) is not allowed to access this service.&quot; % (agent,)
</del><ins>+                            &quot;Your client software ({}) is not allowed to &quot;
+                            &quot;access this service.&quot;
+                            .format(agent)
</ins><span class="cx">                         ))
</span><span class="cx"> 
</span><del>-        if config.EnableResponseCache and request.method == &quot;PROPFIND&quot; and not getattr(request, &quot;notInCache&quot;, False) and len(segments) &gt; 1:
</del><ins>+        if (
+            config.EnableResponseCache and
+            request.method == &quot;PROPFIND&quot; and
+            not getattr(request, &quot;notInCache&quot;, False) and
+            len(segments) &gt; 1
+        ):
</ins><span class="cx">             try:
</span><del>-                authnUser, authzUser = (yield self.authenticate(request))
</del><ins>+                authnUser, authzUser = yield self.authenticate(request)
</ins><span class="cx">                 request.authnUser = authnUser
</span><span class="cx">                 request.authzUser = authzUser
</span><span class="cx">             except (UnauthorizedLogin, LoginFailed):
</span><del>-                response = (yield UnauthorizedResponse.makeResponse(
</del><ins>+                response = yield UnauthorizedResponse.makeResponse(
</ins><span class="cx">                     request.credentialFactories,
</span><span class="cx">                     request.remoteAddr
</span><del>-                ))
</del><ins>+                )
</ins><span class="cx">                 raise HTTPError(response)
</span><span class="cx"> 
</span><span class="cx">             try:
</span><span class="cx">                 if not getattr(request, &quot;checkingCache&quot;, False):
</span><span class="cx">                     request.checkingCache = True
</span><del>-                    response = (yield self.responseCache.getResponseForRequest(request))
</del><ins>+                    response = yield self.responseCache.getResponseForRequest(
+                        request
+                    )
</ins><span class="cx">                     if response is None:
</span><span class="cx">                         request.notInCache = True
</span><span class="cx">                         raise KeyError(&quot;Not found in cache.&quot;)
</span><span class="lines">@@ -367,7 +436,9 @@
</span><span class="cx">             except KeyError:
</span><span class="cx">                 pass
</span><span class="cx"> 
</span><del>-        child = (yield super(RootResource, self).locateChild(request, segments))
</del><ins>+        child = yield super(RootResource, self).locateChild(
+            request, segments
+        )
</ins><span class="cx">         returnValue(child)
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>