aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio/grpc/framework/foundation/callable_util.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/python/grpcio/grpc/framework/foundation/callable_util.py')
-rw-r--r--src/python/grpcio/grpc/framework/foundation/callable_util.py47
1 files changed, 24 insertions, 23 deletions
diff --git a/src/python/grpcio/grpc/framework/foundation/callable_util.py b/src/python/grpcio/grpc/framework/foundation/callable_util.py
index 4f029f97bb..3b8351c19b 100644
--- a/src/python/grpcio/grpc/framework/foundation/callable_util.py
+++ b/src/python/grpcio/grpc/framework/foundation/callable_util.py
@@ -26,7 +26,6 @@
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
"""Utilities for working with callables."""
import abc
@@ -39,7 +38,7 @@ import six
class Outcome(six.with_metaclass(abc.ABCMeta)):
- """A sum type describing the outcome of some call.
+ """A sum type describing the outcome of some call.
Attributes:
kind: One of Kind.RETURNED or Kind.RAISED respectively indicating that the
@@ -50,31 +49,31 @@ class Outcome(six.with_metaclass(abc.ABCMeta)):
Kind.RAISED.
"""
- @enum.unique
- class Kind(enum.Enum):
- """Identifies the general kind of the outcome of some call."""
+ @enum.unique
+ class Kind(enum.Enum):
+ """Identifies the general kind of the outcome of some call."""
- RETURNED = object()
- RAISED = object()
+ RETURNED = object()
+ RAISED = object()
class _EasyOutcome(
- collections.namedtuple(
- '_EasyOutcome', ['kind', 'return_value', 'exception']),
- Outcome):
- """A trivial implementation of Outcome."""
+ collections.namedtuple('_EasyOutcome',
+ ['kind', 'return_value', 'exception']), Outcome):
+ """A trivial implementation of Outcome."""
def _call_logging_exceptions(behavior, message, *args, **kwargs):
- try:
- return _EasyOutcome(Outcome.Kind.RETURNED, behavior(*args, **kwargs), None)
- except Exception as e: # pylint: disable=broad-except
- logging.exception(message)
- return _EasyOutcome(Outcome.Kind.RAISED, None, e)
+ try:
+ return _EasyOutcome(Outcome.Kind.RETURNED,
+ behavior(*args, **kwargs), None)
+ except Exception as e: # pylint: disable=broad-except
+ logging.exception(message)
+ return _EasyOutcome(Outcome.Kind.RAISED, None, e)
def with_exceptions_logged(behavior, message):
- """Wraps a callable in a try-except that logs any exceptions it raises.
+ """Wraps a callable in a try-except that logs any exceptions it raises.
Args:
behavior: Any callable.
@@ -86,14 +85,16 @@ def with_exceptions_logged(behavior, message):
future.Outcome describing whether the given behavior returned a value or
raised an exception.
"""
- @functools.wraps(behavior)
- def wrapped_behavior(*args, **kwargs):
- return _call_logging_exceptions(behavior, message, *args, **kwargs)
- return wrapped_behavior
+
+ @functools.wraps(behavior)
+ def wrapped_behavior(*args, **kwargs):
+ return _call_logging_exceptions(behavior, message, *args, **kwargs)
+
+ return wrapped_behavior
def call_logging_exceptions(behavior, message, *args, **kwargs):
- """Calls a behavior in a try-except that logs any exceptions it raises.
+ """Calls a behavior in a try-except that logs any exceptions it raises.
Args:
behavior: Any callable.
@@ -105,4 +106,4 @@ def call_logging_exceptions(behavior, message, *args, **kwargs):
An Outcome describing whether the given behavior returned a value or raised
an exception.
"""
- return _call_logging_exceptions(behavior, message, *args, **kwargs)
+ return _call_logging_exceptions(behavior, message, *args, **kwargs)