<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { overflow: auto; }
#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>
<title>[2214] CalendarServer/branches/users/wsanchez/guid-calendars/twistedcaldav/
 schedule.py</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.macosforge.org/projects/calendarserver/changeset/2214">2214</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2008-03-07 11:03:49 -0800 (Fri, 07 Mar 2008)</dd>
</dl>

<h3>Log Message</h3>
<pre>Clean up variable names</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserswsanchezguidcalendarstwistedcaldavschedulepy">CalendarServer/branches/users/wsanchez/guid-calendars/twistedcaldav/schedule.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserswsanchezguidcalendarstwistedcaldavschedulepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/wsanchez/guid-calendars/twistedcaldav/schedule.py (2213 => 2214)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/wsanchez/guid-calendars/twistedcaldav/schedule.py        2008-03-07 18:25:01 UTC (rev 2213)
+++ CalendarServer/branches/users/wsanchez/guid-calendars/twistedcaldav/schedule.py        2008-03-07 19:03:49 UTC (rev 2214)
</span><span class="lines">@@ -200,9 +200,9 @@
</span><span class="cx">         x.getResult()
</span><span class="cx"> 
</span><span class="cx">         # Must be content-type text/calendar
</span><del>-        content_type = request.headers.getHeader(&quot;content-type&quot;)
-        if content_type is not None and (content_type.mediaType, content_type.mediaSubtype) != (&quot;text&quot;, &quot;calendar&quot;):
-            logging.err(&quot;MIME type %s not allowed in calendar collection&quot; % (content_type,), system=&quot;CalDAV Outbox POST&quot;)
</del><ins>+        contentType = request.headers.getHeader(&quot;content-type&quot;)
+        if contentType is not None and (contentType.mediaType, contentType.mediaSubtype) != (&quot;text&quot;, &quot;calendar&quot;):
+            logging.err(&quot;MIME type %s not allowed in calendar collection&quot; % (contentType,), system=&quot;CalDAV Outbox POST&quot;)
</ins><span class="cx">             raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, &quot;supported-calendar-data&quot;)))
</span><span class="cx">     
</span><span class="cx">         # Must have Originator header
</span><span class="lines">@@ -214,37 +214,37 @@
</span><span class="cx">             originator = originator[0]
</span><span class="cx">     
</span><span class="cx">         # Verify that Originator is a valid calendar user (has an INBOX)
</span><del>-        oprincipal = self.principalForCalendarUserAddress(originator)
-        if oprincipal is None:
</del><ins>+        originatorPrincipal = self.principalForCalendarUserAddress(originator)
+        if originatorPrincipal is None:
</ins><span class="cx">             logging.err(&quot;Could not find principal for originator: %s&quot; % (originator,), system=&quot;CalDAV Outbox POST&quot;)
</span><span class="cx">             raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, &quot;originator-allowed&quot;)))
</span><span class="cx"> 
</span><del>-        inboxURL = oprincipal.scheduleInboxURL()
</del><ins>+        inboxURL = originatorPrincipal.scheduleInboxURL()
</ins><span class="cx">         if inboxURL is None:
</span><span class="cx">             logging.err(&quot;Could not find inbox for originator: %s&quot; % (originator,), system=&quot;CalDAV Outbox POST&quot;)
</span><span class="cx">             raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, &quot;originator-allowed&quot;)))
</span><span class="cx">     
</span><span class="cx">         # Verify that Originator matches the authenticated user
</span><del>-        if davxml.Principal(davxml.HRef(oprincipal.principalURL())) != self.currentPrincipal(request):
</del><ins>+        if davxml.Principal(davxml.HRef(originatorPrincipal.principalURL())) != self.currentPrincipal(request):
</ins><span class="cx">             logging.err(&quot;Originator: %s does not match authorized user: %s&quot; % (originator, self.currentPrincipal(request).children[0],), system=&quot;CalDAV Outbox POST&quot;)
</span><span class="cx">             raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, &quot;originator-allowed&quot;)))
</span><span class="cx"> 
</span><span class="cx">         # Get list of Recipient headers
</span><del>-        rawrecipients = request.headers.getRawHeaders(&quot;recipient&quot;)
-        if rawrecipients is None or (len(rawrecipients) == 0):
</del><ins>+        rawRecipients = request.headers.getRawHeaders(&quot;recipient&quot;)
+        if rawRecipients is None or (len(rawRecipients) == 0):
</ins><span class="cx">             logging.err(&quot;POST request must have at least one Recipient header&quot;, system=&quot;CalDAV Outbox POST&quot;)
</span><span class="cx">             raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, &quot;recipient-specified&quot;)))
</span><span class="cx"> 
</span><span class="cx">         # Recipient header may be comma separated list
</span><span class="cx">         recipients = []
</span><del>-        for rawrecipient in rawrecipients:
-            for r in rawrecipient.split(&quot;,&quot;):
</del><ins>+        for rawRecipient in rawRecipients:
+            for r in rawRecipient.split(&quot;,&quot;):
</ins><span class="cx">                 r = r.strip()
</span><span class="cx">                 if len(r):
</span><span class="cx">                     recipients.append(r)
</span><span class="cx"> 
</span><del>-        timerange = TimeRange(start=&quot;20000101&quot;, end=&quot;20000102&quot;)
-        recipients_state = {&quot;OK&quot;:0, &quot;BAD&quot;:0}
</del><ins>+        timeRange = TimeRange(start=&quot;20000101&quot;, end=&quot;20000102&quot;)
+        recipientsState = {&quot;OK&quot;:0, &quot;BAD&quot;:0}
</ins><span class="cx"> 
</span><span class="cx">         # Parse the calendar object from the HTTP request stream
</span><span class="cx">         try:
</span><span class="lines">@@ -281,9 +281,9 @@
</span><span class="cx">         outboxURL = None
</span><span class="cx">         organizer = calendar.getOrganizer()
</span><span class="cx">         if organizer is not None:
</span><del>-            oprincipal = self.principalForCalendarUserAddress(organizer)
-            if oprincipal is not None:
-                outboxURL = oprincipal.scheduleOutboxURL()
</del><ins>+            organizerPrincipal = self.principalForCalendarUserAddress(organizer)
+            if organizerPrincipal is not None:
+                outboxURL = organizerPrincipal.scheduleOutboxURL()
</ins><span class="cx">         if outboxURL is None:
</span><span class="cx">             logging.err(&quot;ORGANIZER in calendar data is not valid: %s&quot; % (calendar,), system=&quot;CalDAV Outbox POST&quot;)
</span><span class="cx">             raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, &quot;organizer-allowed&quot;)))
</span><span class="lines">@@ -305,11 +305,11 @@
</span><span class="cx">                 raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, &quot;attendee-allowed&quot;)))
</span><span class="cx">             
</span><span class="cx">             # Attendee's Outbox MUST be the request URI
</span><del>-            aoutboxURL = None
-            aprincipal = self.principalForCalendarUserAddress(attendees[0])
-            if aprincipal is not None:
-                aoutboxURL = aprincipal.scheduleOutboxURL()
-            if aoutboxURL is None or aoutboxURL != request.uri:
</del><ins>+            attendeeOutboxURL = None
+            attendeePrincipal = self.principalForCalendarUserAddress(attendees[0])
+            if attendeePrincipal is not None:
+                attendeeOutboxURL = attendeePrincipal.scheduleOutboxURL()
+            if attendeeOutboxURL is None or attendeeOutboxURL != request.uri:
</ins><span class="cx">                 logging.err(&quot;ATTENDEE in calendar data does not match owner of Outbox: %s&quot; % (calendar,), system=&quot;CalDAV Outbox POST&quot;)
</span><span class="cx">                 raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, &quot;attendee-allowed&quot;)))
</span><span class="cx"> 
</span><span class="lines">@@ -326,11 +326,11 @@
</span><span class="cx">             if dtstart is None or dtend is None:
</span><span class="cx">                 logging.err(&quot;VFREEBUSY start/end not valid: %s&quot; % (calendar,), system=&quot;CalDAV Outbox POST&quot;)
</span><span class="cx">                 raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, &quot;valid-calendar-data&quot;)))
</span><del>-            timerange.start = dtstart
-            timerange.end = dtend
</del><ins>+            timeRange.start = dtstart
+            timeRange.end = dtend
</ins><span class="cx"> 
</span><span class="cx">             # Look for maksed UID
</span><del>-            excludeuid = calendar.getMaskUID()
</del><ins>+            excludeUID = calendar.getMaskUID()
</ins><span class="cx"> 
</span><span class="cx">             # Do free busy operation
</span><span class="cx">             freebusy = True
</span><span class="lines">@@ -367,7 +367,7 @@
</span><span class="cx">             if inbox is None:
</span><span class="cx">                 err = HTTPError(ErrorResponse(responsecode.NOT_FOUND, (caldav_namespace, &quot;recipient-exists&quot;)))
</span><span class="cx">                 responses.add(recipient, Failure(exc_value=err), reqstatus=&quot;3.7;Invalid Calendar User&quot;)
</span><del>-                recipients_state[&quot;BAD&quot;] += 1
</del><ins>+                recipientsState[&quot;BAD&quot;] += 1
</ins><span class="cx">             
</span><span class="cx">                 # Process next recipient
</span><span class="cx">                 continue
</span><span class="lines">@@ -376,14 +376,14 @@
</span><span class="cx">                 # Check access controls
</span><span class="cx">                 #
</span><span class="cx">                 try:
</span><del>-                    d = waitForDeferred(inbox.checkPrivileges(request, (caldavxml.Schedule(),), principal=davxml.Principal(davxml.HRef(oprincipal.principalURL()))))
</del><ins>+                    d = waitForDeferred(inbox.checkPrivileges(request, (caldavxml.Schedule(),), principal=davxml.Principal(davxml.HRef(organizerPrincipal.principalURL()))))
</ins><span class="cx">                     yield d
</span><span class="cx">                     d.getResult()
</span><span class="cx">                 except AccessDeniedError:
</span><span class="cx">                     logging.err(&quot;Could not access Inbox for recipient: %s&quot; % (recipient,), system=&quot;CalDAV Outbox POST&quot;)
</span><span class="cx">                     err = HTTPError(ErrorResponse(responsecode.NOT_FOUND, (caldav_namespace, &quot;recipient-permisions&quot;)))
</span><span class="cx">                     responses.add(recipient, Failure(exc_value=err), reqstatus=&quot;3.8;No authority&quot;)
</span><del>-                    recipients_state[&quot;BAD&quot;] += 1
</del><ins>+                    recipientsState[&quot;BAD&quot;] += 1
</ins><span class="cx">                 
</span><span class="cx">                     # Process next recipient
</span><span class="cx">                     continue
</span><span class="lines">@@ -412,46 +412,47 @@
</span><span class="cx">                             yield availability
</span><span class="cx">                             availability = availability.getResult()
</span><span class="cx">                             availability = availability.calendar()
</span><del>-                            report_common.processAvailabilityFreeBusy(availability, fbinfo, timerange)
</del><ins>+                            report_common.processAvailabilityFreeBusy(availability, fbinfo, timeRange)
</ins><span class="cx"> 
</span><span class="cx">                         # Check to see if the recipient is the same calendar user as the organizer.
</span><span class="cx">                         # Needed for masked UID stuff.
</span><del>-                        same_calendar_user = oprincipal.principalURL() == principal.principalURL()
</del><ins>+                        same_calendar_user = organizerPrincipal.principalURL() == principal.principalURL()
</ins><span class="cx"> 
</span><span class="cx">                         # Now process free-busy set calendars
</span><span class="cx">                         matchtotal = 0
</span><del>-                        for calURL in fbset:
-                            cal = waitForDeferred(request.locateResource(calURL))
-                            yield cal
-                            cal = cal.getResult()
-                            if cal is None or not cal.exists() or not isCalendarCollectionResource(cal):
</del><ins>+                        for calendarResourceURL in fbset:
+                            calendarResource = waitForDeferred(request.locateResource(calendarResourceURL))
+                            yield calendarResource
+                            calendarResource = calendarResource.getResult()
+                            if calendarResource is None or not calendarResource.exists() or not isCalendarCollectionResource(calendarResource):
</ins><span class="cx">                                 # We will ignore missing calendars. If the recipient has failed to
</span><span class="cx">                                 # properly manage the free busy set that should not prevent us from working.
</span><span class="cx">                                 continue
</span><span class="cx">                          
</span><span class="cx">                             matchtotal = waitForDeferred(report_common.generateFreeBusyInfo(
</span><span class="cx">                                 request,
</span><del>-                                cal,
</del><ins>+                                calendarResource,
</ins><span class="cx">                                 fbinfo,
</span><del>-                                timerange,
</del><ins>+                                timeRange,
</ins><span class="cx">                                 matchtotal,
</span><del>-                                excludeuid=excludeuid,
-                                organizer=organizer,
-                                same_calendar_user=same_calendar_user))
</del><ins>+                                excludeuid = excludeUID,
+                                organizer = organizer,
+                                same_calendar_user = same_calendar_user
+                            ))
</ins><span class="cx">                             yield matchtotal
</span><span class="cx">                             matchtotal = matchtotal.getResult()
</span><span class="cx">                     
</span><span class="cx">                         # Build VFREEBUSY iTIP reply for this recipient
</span><del>-                        fbresult = report_common.buildFreeBusyResult(fbinfo, timerange, organizer=organizerProp, attendee=attendeeProp, uid=uid, method=&quot;REPLY&quot;)
</del><ins>+                        fbresult = report_common.buildFreeBusyResult(fbinfo, timeRange, organizer=organizerProp, attendee=attendeeProp, uid=uid, method=&quot;REPLY&quot;)
</ins><span class="cx"> 
</span><span class="cx">                         responses.add(recipient, responsecode.OK, reqstatus=&quot;2.0;Success&quot;, calendar=fbresult)
</span><del>-                        recipients_state[&quot;OK&quot;] += 1
</del><ins>+                        recipientsState[&quot;OK&quot;] += 1
</ins><span class="cx">                 
</span><span class="cx">                     except:
</span><span class="cx">                         logging.err(&quot;Could not determine free busy information: %s&quot; % (recipient,), system=&quot;CalDAV Outbox POST&quot;)
</span><span class="cx">                         err = HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, &quot;recipient-permissions&quot;)))
</span><span class="cx">                         responses.add(recipient, Failure(exc_value=err), reqstatus=&quot;3.8;No authority&quot;)
</span><del>-                        recipients_state[&quot;BAD&quot;] += 1
</del><ins>+                        recipientsState[&quot;BAD&quot;] += 1
</ins><span class="cx">                 
</span><span class="cx">                 else:
</span><span class="cx">                     # Hash the iCalendar data for use as the last path element of the URI path
</span><span class="lines">@@ -481,7 +482,7 @@
</span><span class="cx">                     try:
</span><span class="cx">                         d.getResult()
</span><span class="cx">                         responses.add(recipient, responsecode.OK, reqstatus=&quot;2.0;Success&quot;)
</span><del>-                        recipients_state[&quot;OK&quot;] += 1
</del><ins>+                        recipientsState[&quot;OK&quot;] += 1
</ins><span class="cx">         
</span><span class="cx">                         # Store CALDAV:originator property
</span><span class="cx">                         child.writeDeadProperty(caldavxml.Originator(davxml.HRef(originator)))
</span><span class="lines">@@ -496,7 +497,7 @@
</span><span class="cx">                         logging.err(&quot;Could not store data in Inbox : %s&quot; % (inbox,), system=&quot;CalDAV Outbox POST&quot;)
</span><span class="cx">                         err = HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, &quot;recipient-permissions&quot;)))
</span><span class="cx">                         responses.add(recipient, Failure(exc_value=err), reqstatus=&quot;3.8;No authority&quot;)
</span><del>-                        recipients_state[&quot;BAD&quot;] += 1
</del><ins>+                        recipientsState[&quot;BAD&quot;] += 1
</ins><span class="cx"> 
</span><span class="cx">         # Now we have to do auto-respond
</span><span class="cx">         if len(autoresponses) != 0:
</span></span></pre>
</div>
</div>

</body>
</html>