[CalendarServer-changes] [6804] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Tue Jan 25 13:49:42 PST 2011


Revision: 6804
          http://trac.macosforge.org/projects/calendarserver/changeset/6804
Author:   wsanchez at apple.com
Date:     2011-01-25 13:49:41 -0800 (Tue, 25 Jan 2011)
Log Message:
-----------
Don't pass qname to ErrorResponse if you already have an XML object

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/method/put_addressbook_common.py
    CalendarServer/trunk/twistedcaldav/method/put_common.py
    CalendarServer/trunk/twistedcaldav/resource.py

Modified: CalendarServer/trunk/twistedcaldav/method/put_addressbook_common.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/put_addressbook_common.py	2011-01-25 17:02:54 UTC (rev 6803)
+++ CalendarServer/trunk/twistedcaldav/method/put_addressbook_common.py	2011-01-25 21:49:41 UTC (rev 6804)
@@ -166,7 +166,10 @@
             result, message = (yield self.validCollectionSize())
             if not result:
                 log.err(message)
-                raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, customxml.MaxResources.qname()))
+                raise HTTPError(ErrorResponse(
+                    responsecode.FORBIDDEN,
+                    customxml.MaxResources
+                ))
 
             if not self.sourceadbk:
                 # Valid content type check on the source resource if its not in a vcard collection
@@ -174,7 +177,10 @@
                     result, message = self.validContentType()
                     if not result:
                         log.err(message)
-                        raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (carddav_namespace, "supported-address-data")))
+                        raise HTTPError(ErrorResponse(
+                            responsecode.FORBIDDEN,
+                            (carddav_namespace, "supported-address-data")
+                        ))
                 
                     # At this point we need the calendar data to do more tests
                     self.vcard = (yield self.source.vCard())
@@ -185,13 +191,19 @@
                             self.vcard = Component.fromString(self.vcard)
                     except ValueError, e:
                         log.err(str(e))
-                        raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (carddav_namespace, "valid-address-data")))
+                        raise HTTPError(ErrorResponse(
+                            responsecode.FORBIDDEN,
+                            (carddav_namespace, "valid-address-data")
+                        ))
                         
                 # Valid vcard data for CalDAV check
                 result, message = self.validAddressDataCheck()
                 if not result:
                     log.err(message)
-                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (carddav_namespace, "valid-addressbook-object-resource")))
+                    raise HTTPError(ErrorResponse(
+                        responsecode.FORBIDDEN,
+                        (carddav_namespace, "valid-addressbook-object-resource")
+                    ))
 
                 # Must have a valid UID at this point
                 self.uid = self.vcard.resourceUID()
@@ -201,7 +213,10 @@
                 self.uid = yield self.source_index.resourceUIDForName(self.source.name())
                 if self.uid is None:
                     log.err("Source vcard does not have a UID: %s" % self.source.name())
-                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (carddav_namespace, "valid-addressbook-object-resource")))
+                    raise HTTPError(ErrorResponse(
+                        responsecode.FORBIDDEN,
+                        (carddav_namespace, "valid-addressbook-object-resource")
+                    ))
 
                 # FIXME: We need this here because we have to re-index the destination. Ideally it
                 # would be better to copy the index entries from the source and add to the destination.
@@ -211,7 +226,10 @@
             result, message = self.validSizeCheck()
             if not result:
                 log.err(message)
-                raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (carddav_namespace, "max-resource-size")))
+                raise HTTPError(ErrorResponse(
+                    responsecode.FORBIDDEN,
+                    (carddav_namespace, "max-resource-size")
+                ))
 
             # Check access
             returnValue(None)
@@ -407,8 +425,16 @@
                 result, message, rname = yield self.noUIDConflict(self.uid)
                 if not result:
                     log.err(message)
-                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN,
-                        NoUIDConflict(davxml.HRef.fromString(joinURL(parentForURL(self.destination_uri), rname.encode("utf-8"))))
+                    raise HTTPError(ErrorResponse(
+                        responsecode.FORBIDDEN,
+                        NoUIDConflict(
+                            davxml.HRef.fromString(
+                                joinURL(
+                                    parentForURL(self.destination_uri),
+                                    rname.encode("utf-8")
+                                )
+                            )
+                        )
                     ))
             
             # Do the actual put or copy

Modified: CalendarServer/trunk/twistedcaldav/method/put_common.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/put_common.py	2011-01-25 17:02:54 UTC (rev 6803)
+++ CalendarServer/trunk/twistedcaldav/method/put_common.py	2011-01-25 21:49:41 UTC (rev 6804)
@@ -212,7 +212,10 @@
             result, message = (yield self.validCollectionSize())
             if not result:
                 log.err(message)
-                raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, customxml.MaxResources.qname()))
+                raise HTTPError(ErrorResponse(
+                    responsecode.FORBIDDEN,
+                    customxml.MaxResources
+                ))
 
             # Valid data sizes - do before parsing the data
             if self.source is not None:
@@ -220,13 +223,19 @@
                 result, message = self.validContentLength()
                 if not result:
                     log.err(message)
-                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "max-resource-size")))
+                    raise HTTPError(ErrorResponse(
+                        responsecode.FORBIDDEN,
+                        (caldav_namespace, "max-resource-size")
+                    ))
             else:
                 # Valid calendar data size check
                 result, message = self.validSizeCheck()
                 if not result:
                     log.err(message)
-                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "max-resource-size")))
+                    raise HTTPError(ErrorResponse(
+                        responsecode.FORBIDDEN,
+                        (caldav_namespace, "max-resource-size")
+                    ))
 
             if not self.sourcecal:
                 # Valid content type check on the source resource if its not in a calendar collection
@@ -234,14 +243,21 @@
                     result, message = self.validContentType()
                     if not result:
                         log.err(message)
-                        raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "supported-calendar-data")))
+                        raise HTTPError(ErrorResponse(
+                            responsecode.FORBIDDEN,
+                            (caldav_namespace, "supported-calendar-data")
+                        ))
                 
                     # At this point we need the calendar data to do more tests
                     try:
                         self.calendar = (yield self.source.iCalendarForUser(self.request))
                     except ValueError, e:
                         log.err(str(e))
-                        raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-data"), description="Can't parse calendar data"))
+                        raise HTTPError(ErrorResponse(
+                            responsecode.FORBIDDEN,
+                            (caldav_namespace, "valid-calendar-data"),
+                            description="Can't parse calendar data"
+                        ))
                 else:
                     try:
                         if type(self.calendar) in (types.StringType, types.UnicodeType,):
@@ -249,19 +265,30 @@
                             self.calendar = Component.fromString(self.calendar)
                     except ValueError, e:
                         log.err(str(e))
-                        raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-data"), description="Can't parse calendar data"))
+                        raise HTTPError(ErrorResponse(
+                            responsecode.FORBIDDEN,
+                            (caldav_namespace, "valid-calendar-data"),
+                            description="Can't parse calendar data"
+                        ))
                         
                 # Valid calendar data check
                 result, message = self.validCalendarDataCheck()
                 if not result:
                     log.err(message)
-                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-data"), description=message))
+                    raise HTTPError(ErrorResponse(
+                        responsecode.FORBIDDEN,
+                        (caldav_namespace, "valid-calendar-data"),
+                        description=message
+                    ))
                     
                 # Valid calendar data for CalDAV check
                 result, message = self.validCalDAVDataCheck()
                 if not result:
                     log.err(message)
-                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-object-resource")))
+                    raise HTTPError(ErrorResponse(
+                        responsecode.FORBIDDEN,
+                        (caldav_namespace, "valid-calendar-object-resource")
+                    ))
 
                 # Valid attendee list size check
                 result, message = self.validAttendeeListSizeCheck()
@@ -286,7 +313,10 @@
                 self.uid = yield self.source_index.resourceUIDForName(self.source.name())
                 if self.uid is None:
                     log.err("Source calendar does not have a UID: %s" % self.source)
-                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-object-resource")))
+                    raise HTTPError(ErrorResponse(
+                        responsecode.FORBIDDEN,
+                        (caldav_namespace, "valid-calendar-object-resource")
+                    ))
 
                 # FIXME: We need this here because we have to re-index the destination. Ideally it
                 # would be better to copy the index entries from the source and add to the destination.
@@ -493,7 +523,10 @@
             # Must be a value we know about
             self.access = self.calendar.accessLevel(default=None)
             if self.access is None:
-                raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (calendarserver_namespace, "valid-access-restriction")))
+                raise HTTPError(ErrorResponse(
+                    responsecode.FORBIDDEN,
+                    (calendarserver_namespace, "valid-access-restriction")
+                ))
                 
             # Only DAV:owner is able to set the property to other than PUBLIC
             if not self.internal_request:
@@ -501,7 +534,10 @@
                     
                     authz = self.destinationparent.currentPrincipal(self.request)
                     if davxml.Principal(parent_owner) != authz and self.access != Component.ACCESS_PUBLIC:
-                        raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (calendarserver_namespace, "valid-access-restriction-change")))
+                        raise HTTPError(ErrorResponse(
+                            responsecode.FORBIDDEN,
+                            (calendarserver_namespace, "valid-access-restriction-change")
+                        ))
                     
                     return None
     
@@ -526,7 +562,10 @@
             except (ValueError, TypeError), ex:
                 msg = "Cannot truncate calendar resource: %s" % (ex,)
                 log.err(msg)
-                raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-data"), description=msg))
+                raise HTTPError(ErrorResponse(
+                    responsecode.FORBIDDEN,
+                    (caldav_namespace, "valid-calendar-data"), description=msg
+                ))
             if result:
                 self.calendardata = str(self.calendar)
                 return result
@@ -694,7 +733,10 @@
             except ValueError:
                 msg = "Invalid per-user data merge"
                 log.err(msg)
-                raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-data"), description=msg))
+                raise HTTPError(ErrorResponse(
+                    responsecode.FORBIDDEN,
+                    (caldav_namespace, "valid-calendar-data"), description=msg
+                ))
             self.calendardata = None
 
 
@@ -845,10 +887,17 @@
                     result, message, rname = yield self.noUIDConflict(self.uid) 
                     if not result: 
                         log.err(message)
-                        raise HTTPError(ErrorResponse(responsecode.FORBIDDEN,
-                            NoUIDConflict(davxml.HRef.fromString(
-                                joinURL(parentForURL(self.destination_uri),
-                                        rname.encode("utf-8"))))))
+                        raise HTTPError(ErrorResponse(
+                            responsecode.FORBIDDEN,
+                            NoUIDConflict(
+                                davxml.HRef.fromString(
+                                    joinURL(
+                                        parentForURL(self.destination_uri),
+                                        rname.encode("utf-8")
+                                    )
+                                )
+                            )
+                        ))
 
 
             # Handle RRULE truncation
@@ -876,14 +925,22 @@
                     else:
                         msg = "Attendee cannot create event for Organizer: %s" % (implicit_result,)
                         log.err(msg)
-                        raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "attendee-allowed"), description=msg))
+                        raise HTTPError(ErrorResponse(
+                            responsecode.FORBIDDEN,
+                            (caldav_namespace, "attendee-allowed"),
+                            description=msg
+                        ))
 
                     returnValue(StatusResponse(responsecode.OK, "Resource modified but immediately deleted by the server."))
 
                 else:
                     msg = "Invalid return status code from ImplicitScheduler: %s" % (implicit_result,)
                     log.err(msg)
-                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-data"), description=msg))
+                    raise HTTPError(ErrorResponse(
+                        responsecode.FORBIDDEN,
+                        (caldav_namespace, "valid-calendar-data"),
+                        description=msg
+                    ))
             else:
                 self.isScheduleResource, data_changed, did_implicit_action = implicit_result
 
@@ -915,12 +972,16 @@
             # FIXME: transaction needs to be rolled back.
 
             if isinstance(err, InvalidOverriddenInstanceError):
-                raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-data"), description="Invalid overridden instance"))
+                raise HTTPError(ErrorResponse(
+                    responsecode.FORBIDDEN,
+                    (caldav_namespace, "valid-calendar-data"),
+                    description="Invalid overridden instance"
+                ))
             elif isinstance(err, TooManyInstancesError):
                 raise HTTPError(ErrorResponse(
                     responsecode.FORBIDDEN,
-                        NumberOfRecurrencesWithinLimits(PCDATAElement(str(err.max_allowed)))
-                    ))
+                    NumberOfRecurrencesWithinLimits(PCDATAElement(str(err.max_allowed)))
+                ))
             else:
                 # Display the traceback.  Unfortunately this will usually be
                 # duplicated by the higher-level exception handler that captures

Modified: CalendarServer/trunk/twistedcaldav/resource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/resource.py	2011-01-25 17:02:54 UTC (rev 6803)
+++ CalendarServer/trunk/twistedcaldav/resource.py	2011-01-25 21:49:41 UTC (rev 6804)
@@ -1345,14 +1345,20 @@
                 if revision > current_revision:
                     raise ValueError
             except ValueError:
-                raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (dav_namespace, "valid-sync-token")))
+                raise HTTPError(ErrorResponse(
+                    responsecode.FORBIDDEN,
+                    (dav_namespace, "valid-sync-token")
+                ))
         else:
             revision = 0
 
         try:
             changed, removed, notallowed = yield self._indexWhatChanged(revision, depth)
         except SyncTokenValidException:
-            raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (dav_namespace, "valid-sync-token")))
+            raise HTTPError(ErrorResponse(
+                responsecode.FORBIDDEN,
+                (dav_namespace, "valid-sync-token")
+            ))
 
         returnValue((changed, removed, notallowed, current_token))
 
@@ -1459,7 +1465,7 @@
                 self.log_error("Cannot create a calendar collection because there are too many already present in %s" % (parent,))
                 raise HTTPError(ErrorResponse(
                     responsecode.FORBIDDEN,
-                    customxml.MaxCollections.qname()
+                    customxml.MaxCollections
                 ))
                 
         returnValue((yield self.createCalendarCollection()))
@@ -1552,7 +1558,7 @@
                 self.log_error("Cannot create a calendar collection because there are too many already present in %s" % (parent,))
                 raise HTTPError(ErrorResponse(
                     responsecode.FORBIDDEN,
-                    customxml.MaxCollections.qname()
+                    customxml.MaxCollections
                 ))
                 
         returnValue((yield self.createAddressBookCollection()))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110125/dea828eb/attachment-0001.html>


More information about the calendarserver-changes mailing list