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

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 9 11:46:46 PDT 2015


Revision: 14671
          http://trac.calendarserver.org//changeset/14671
Author:   cdaboo at apple.com
Date:     2015-04-09 11:46:46 -0700 (Thu, 09 Apr 2015)
Log Message:
-----------
Move POST-trash handler onto CalDAVResource-based object.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/calendar.py
    CalendarServer/trunk/twistedcaldav/resource.py

Modified: CalendarServer/trunk/twistedcaldav/directory/calendar.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/calendar.py	2015-04-09 18:44:22 UTC (rev 14670)
+++ CalendarServer/trunk/twistedcaldav/directory/calendar.py	2015-04-09 18:46:46 UTC (rev 14671)
@@ -30,14 +30,12 @@
 
 from txweb2 import responsecode
 from txweb2.auth.wrapper import UnauthorizedResponse
-from txweb2.dav.http import ErrorResponse
 from txweb2.dav.util import joinURL
-from txweb2.http import HTTPError, RedirectResponse, JSONResponse
+from txweb2.http import HTTPError, RedirectResponse
 from txweb2.http_headers import ETag, MimeType
 
 from twisted.internet.defer import succeed, inlineCallbacks, returnValue
 
-from twistedcaldav.caldavxml import caldav_namespace
 from twistedcaldav.config import config
 from twistedcaldav.directory.common import uidsResourceName, \
     CommonUIDProvisioningResource, CommonHomeTypeProvisioningResource
@@ -321,45 +319,3 @@
 
     def principalForRecord(self):
         return self.parent.principalForRecord(self.record)
-
-
-    @inlineCallbacks
-    def POST_handler_action(self, request, action):
-        """
-        Handle a POST request with an action= query parameter
-
-        @param request: the request to process
-        @type request: L{Request}
-        @param action: the action to execute
-        @type action: C{str}
-        """
-        if action == "emptytrash":
-            days = int(request.args.get("days", ("0",))[0])
-            yield self._newStoreHome.emptyTrash(days=days)
-            returnValue(
-                self._ok("ok", "Empty Trash")
-            )
-
-        elif action == "gettrashcontents":
-            contents = yield self._newStoreHome.getTrashContents()
-            returnValue(
-                self._ok("ok", "Trash Contents", contents)
-            )
-
-        else:
-            raise HTTPError(ErrorResponse(
-                responsecode.FORBIDDEN,
-                (caldav_namespace, "valid-action-parameter",),
-                "The action parameter in the request-URI is not valid",
-            ))
-
-
-    def _ok(self, status, description, result=None):
-        if result is None:
-            result = {}
-        result["status"] = status
-        result["description"] = description
-        return JSONResponse(
-            responsecode.OK,
-            result,
-        )

Modified: CalendarServer/trunk/twistedcaldav/resource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/resource.py	2015-04-09 18:44:22 UTC (rev 14670)
+++ CalendarServer/trunk/twistedcaldav/resource.py	2015-04-09 18:46:46 UTC (rev 14671)
@@ -54,9 +54,7 @@
     davPrivilegeSet
 from txweb2.dav.resource import TwistedACLInheritable
 from txweb2.dav.util import joinURL, parentForURL, normalizeURL
-from txweb2.http import (
-    HTTPError, RedirectResponse, StatusResponse, Response
-)
+from txweb2.http import HTTPError, RedirectResponse, StatusResponse, Response, JSONResponse
 from txweb2.dav.http import ErrorResponse
 from txweb2.http_headers import MimeType, ETag
 from txweb2.stream import MemoryStream
@@ -2706,7 +2704,49 @@
         returnValue((changed, deleted, notallowed))
 
 
+    @inlineCallbacks
+    def POST_handler_action(self, request, action):
+        """
+        Handle a POST request with an action= query parameter
 
+        @param request: the request to process
+        @type request: L{Request}
+        @param action: the action to execute
+        @type action: C{str}
+        """
+        if action == "emptytrash":
+            days = int(request.args.get("days", ("0",))[0])
+            yield self._newStoreHome.emptyTrash(days=days)
+            returnValue(
+                self._ok("ok", "Empty Trash")
+            )
+
+        elif action == "gettrashcontents":
+            contents = yield self._newStoreHome.getTrashContents()
+            returnValue(
+                self._ok("ok", "Trash Contents", contents)
+            )
+
+        else:
+            raise HTTPError(ErrorResponse(
+                responsecode.FORBIDDEN,
+                (caldav_namespace, "valid-action-parameter",),
+                "The action parameter in the request-URI is not valid",
+            ))
+
+
+    def _ok(self, status, description, result=None):
+        if result is None:
+            result = {}
+        result["status"] = status
+        result["description"] = description
+        return JSONResponse(
+            responsecode.OK,
+            result,
+        )
+
+
+
 class AddressBookHomeResource (CommonHomeResource):
     """
     Address book home collection resource.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150409/cd66e234/attachment-0001.html>


More information about the calendarserver-changes mailing list