[CalendarServer-changes] [14541] CalendarServer/trunk/txdav/common/datastore/podding/conduit.py

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 9 17:25:39 PDT 2015


Revision: 14541
          http://trac.calendarserver.org//changeset/14541
Author:   wsanchez at apple.com
Date:     2015-03-09 17:25:39 -0700 (Mon, 09 Mar 2015)
Log Message:
-----------
Lint.
ex->error in log keys; logging is API, use useful symbol names.

Modified Paths:
--------------
    CalendarServer/trunk/txdav/common/datastore/podding/conduit.py

Modified: CalendarServer/trunk/txdav/common/datastore/podding/conduit.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/podding/conduit.py	2015-03-10 00:01:19 UTC (rev 14540)
+++ CalendarServer/trunk/txdav/common/datastore/podding/conduit.py	2015-03-10 00:25:39 UTC (rev 14541)
@@ -19,19 +19,23 @@
 from txdav.common.idirectoryservice import DirectoryRecordNotFoundError
 from txdav.common.datastore.podding.attachments import AttachmentsConduitMixin
 from txdav.common.datastore.podding.base import FailedCrossPodRequestError
-from txdav.common.datastore.podding.directory import DirectoryPoddingConduitMixin
+from txdav.common.datastore.podding.directory import (
+    DirectoryPoddingConduitMixin
+)
 from txdav.common.datastore.podding.request import ConduitRequest
-from txdav.common.datastore.podding.sharing_invites import SharingInvitesConduitMixin
+from txdav.common.datastore.podding.sharing_invites import (
+    SharingInvitesConduitMixin
+)
 from txdav.common.datastore.podding.store_api import StoreAPIConduitMixin
 from txdav.common.datastore.podding.util import UtilityConduitMixin
 
 from twisted.internet.defer import inlineCallbacks, returnValue
 from twisted.python.reflect import namedClass
 
-
 log = Logger()
 
 
+
 class PoddingConduit(
     UtilityConduitMixin,
     StoreAPIConduitMixin,
@@ -42,29 +46,33 @@
     """
     This class is the API/RPC bridge between cross-pod requests and the store.
 
-    Each cross-pod request/response is described by a Python C{dict} that is serialized
-    to JSON for the HTTP request/response.
+    Each cross-pod request/response is described by a Python C{dict} that is
+    serialized to JSON for the HTTP request/response.
 
-    Each request C{dict} has an "action" key that indicates what call is being made, and
-    the other keys are arguments to that call.
+    Each request C{dict} has an "action" key that indicates what call is being
+    made, and the other keys are arguments to that call.
 
-    Each response C{dict} has a "result" key that indicates the call result, and other
-    optional keys for any values returned by the call.
+    Each response C{dict} has a "result" key that indicates the call result,
+    and other optional keys for any values returned by the call.
 
-    The conduit provides two methods for each action: one for the sending side and one for
-    the receiving side, called "send_{action}" and "recv_{action}", respectively, where
-    {action} is the action value.
+    The conduit provides two methods for each action: one for the sending side
+    and one for the receiving side, called "send_{action}" and "recv_{action}",
+    respectively, where {action} is the action value.
 
-    The "send_{action}" calls each have a set of arguments specific to the call itself. The
-    code takes care of packing that into a C{dict} and sending to the appropriate pod.
+    The "send_{action}" calls each have a set of arguments specific to the call
+    itself.
+    The code takes care of packing that into a C{dict} and sending to the
+    appropriate pod.
 
-    The "recv_{action}" calls take a single C{dict} argument that is the deserialized JSON
-    data from the incoming request. The return value is a C{dict} with the result.
+    The "recv_{action}" calls take a single C{dict} argument that is the
+    deserialized JSON data from the incoming request.
+    The return value is a C{dict} with the result.
 
-    Some simple forms of send_/recv_ methods can be auto-generated to simplify coding.
+    Some simple forms of send_/recv_ methods can be auto-generated to simplify
+    coding.
 
-    Actual implementations of this will be done via mix-ins for the different sub-systems using
-    the conduit.
+    Actual implementations of this will be done via mix-ins for the different
+    sub-systems using the conduit.
     """
 
     conduitRequestClass = ConduitRequest
@@ -83,9 +91,12 @@
         Verify that the specified uids are valid for the request and return the
         matching directory records.
 
-        @param source_uid: UID for the user on whose behalf the request is being made
+        @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
+
+        @param destination_uid: UID for the user to whom the request is being
+            sent.
         @type destination_uid: C{str}
 
         @return: L{Deferred} resulting in C{tuple} of L{IStoreDirectoryRecord}
@@ -93,42 +104,65 @@
 
         source = yield self.store.directoryService().recordWithUID(source_uid)
         if source is None:
-            raise DirectoryRecordNotFoundError("Cross-pod source: {}".format(source_uid))
+            raise DirectoryRecordNotFoundError(
+                "Cross-pod source: {}".format(source_uid)
+            )
         if not source.thisServer():
-            raise FailedCrossPodRequestError("Cross-pod source not on this server: {}".format(source_uid))
+            raise FailedCrossPodRequestError(
+                "Cross-pod source not on this server: {}".format(source_uid)
+            )
 
-        destination = yield self.store.directoryService().recordWithUID(destination_uid)
+        destination = yield self.store.directoryService().recordWithUID(
+            destination_uid
+        )
         if destination is None:
-            raise DirectoryRecordNotFoundError("Cross-pod destination: {}".format(destination_uid))
+            raise DirectoryRecordNotFoundError(
+                "Cross-pod destination: {}".format(destination_uid)
+            )
         if destination.thisServer():
-            raise FailedCrossPodRequestError("Cross-pod destination on this server: {}".format(destination_uid))
+            raise FailedCrossPodRequestError(
+                "Cross-pod destination on this server: {}"
+                .format(destination_uid)
+            )
 
         returnValue((source, destination,))
 
 
     def sendRequest(self, txn, recipient, data, stream=None, streamType=None):
-        return self.sendRequestToServer(txn, recipient.server(), data, stream, streamType)
+        return self.sendRequestToServer(
+            txn, recipient.server(), data, stream, streamType
+        )
 
 
     @inlineCallbacks
-    def sendRequestToServer(self, txn, server, data, stream=None, streamType=None, writeStream=None):
+    def sendRequestToServer(
+        self, txn, server, data, stream=None, streamType=None, writeStream=None
+    ):
+        request = self.conduitRequestClass(
+            server, data, stream, streamType, writeStream
+        )
 
-        request = self.conduitRequestClass(server, data, stream, streamType, writeStream)
         try:
             response = (yield request.doRequest(txn))
         except Exception as e:
-            raise FailedCrossPodRequestError("Failed cross-pod request: {}".format(e))
+            raise FailedCrossPodRequestError(
+                "Failed cross-pod request: {}".format(e)
+            )
+
         if response["result"] == "exception":
             raise namedClass(response["class"])(response["details"])
         elif response["result"] != "ok":
-            raise FailedCrossPodRequestError("Cross-pod request failed: {}".format(response))
+            raise FailedCrossPodRequestError(
+                "Cross-pod request failed: {}".format(response)
+            )
         else:
             returnValue(response.get("value"))
 
 
     def isStreamAction(self, data):
         """
-        Check to see if this is a request that will return a data stream rather than a JSON response.
+        Check to see if this is a request that will return a data stream rather
+        than a JSON response.
         e.g., this is used to retrieve attachment data on another pod.
 
         @param data: the JSON data to process
@@ -138,7 +172,11 @@
         try:
             action = data["action"]
         except (KeyError, TypeError) as e:
-            log.error("JSON data must have an object as its root with an 'action' attribute: {ex}\n{json}", ex=e, json=data)
+            log.error(
+                "JSON data must have an object as its root with an "
+                "'action' attribute: {error}\n{json}",
+                error=e, json=data
+            )
             return False
 
         return action in self.streamingActions
@@ -156,8 +194,16 @@
         try:
             action = data["action"]
         except (KeyError, TypeError) as e:
-            log.error("JSON data must have an object as its root with an 'action' attribute: {ex}\n{json}", ex=e, json=data)
-            raise FailedCrossPodRequestError("JSON data must have an object as its root with an 'action' attribute: {}\n{}".format(e, data,))
+            log.error(
+                "JSON data must have an object as its root with an "
+                "'action' attribute: {error}\n{json}",
+                error=e, json=data
+            )
+            raise FailedCrossPodRequestError(
+                "JSON data must have an object as its root with an 'action' "
+                "attribute: {}\n{}"
+                .format(e, data,)
+            )
 
         if action == "ping":
             result = {"result": "ok"}
@@ -166,7 +212,9 @@
         method = "recv_{}".format(action.replace("-", "_"))
         if not hasattr(self, method):
             log.error("Unsupported action: {action}", action=action)
-            raise FailedCrossPodRequestError("Unsupported action: {}".format(action))
+            raise FailedCrossPodRequestError(
+                "Unsupported action: {}".format(action)
+            )
 
         # Need a transaction to work with
         txn = self.store.newTransaction(repr("Conduit request"))
@@ -181,10 +229,15 @@
         except Exception as e:
             # Send the exception over to the other side
             yield txn.abort()
-            log.error("Failed action: {action}, {ex}", action=action, ex=e)
+            log.error(
+                "Failed action: {action}, {error}", action=action, error=e
+            )
             result = {
                 "result": "exception",
-                "class": ".".join((e.__class__.__module__, e.__class__.__name__,)),
+                "class": ".".join((
+                    e.__class__.__module__,
+                    e.__class__.__name__,
+                )),
                 "details": str(e),
             }
 
@@ -202,20 +255,30 @@
         @param data: the JSON data to process
         @type data: C{dict}
 
-        @return: a L{tuple} of content-type and name, if successful, else a L{dict} for a JSON result
+        @return: a L{tuple} of content-type and name, if successful, else a
+            L{dict} for a JSON result
         @rtype: L{tuple} of (L{str}, L{str}), or L{dict}
         """
         # Must have a dict with an "action" key
         try:
             action = data["action"]
         except (KeyError, TypeError) as e:
-            log.error("JSON data must have an object as its root with an 'action' attribute: {ex}\n{json}", ex=e, json=data)
-            raise FailedCrossPodRequestError("JSON data must have an object as its root with an 'action' attribute: {}\n{}".format(e, data,))
+            log.error(
+                "JSON data must have an object as its root with an "
+                "'action' attribute: {ex}\n{json}",
+                ex=e, json=data
+            )
+            raise FailedCrossPodRequestError(
+                "JSON data must have an object as its root with an "
+                "'action' attribute: {}\n{}".format(e, data)
+            )
 
         method = "recv_{}".format(action.replace("-", "_"))
         if not hasattr(self, method):
             log.error("Unsupported action: {action}", action=action)
-            raise FailedCrossPodRequestError("Unsupported action: {}".format(action))
+            raise FailedCrossPodRequestError(
+                "Unsupported action: {}".format(action)
+            )
 
         # Need a transaction to work with
         txn = self.store.newTransaction(repr("Conduit request"))
@@ -229,7 +292,9 @@
             log.error("Failed action: {action}, {ex}", action=action, ex=e)
             result = {
                 "result": "exception",
-                "class": ".".join((e.__class__.__module__, e.__class__.__name__,)),
+                "class": ".".join((
+                    e.__class__.__module__, e.__class__.__name__,
+                )),
                 "details": str(e),
             }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150309/7ffc4bc1/attachment-0001.html>


More information about the calendarserver-changes mailing list