pull/20905/head
Richard Belleville 5 years ago
parent 6f0b772afa
commit e4d58fba6d
  1. 18
      src/python/grpcio/grpc/_channel.py
  2. 16
      src/python/grpcio_tests/tests/unit/_interceptor_test.py

@ -277,11 +277,15 @@ class _RpcError(grpc.RpcError, grpc.Call, grpc.Future):
def __init__(self, state):
if state.cancelled:
raise ValueError("Cannot instantiate an _RpcError for a cancelled RPC.")
raise ValueError(
"Cannot instantiate an _RpcError for a cancelled RPC.")
if state.code is grpc.StatusCode.OK:
raise ValueError("Cannot instantiate an _RpcError for a successfully completed RPC.")
raise ValueError(
"Cannot instantiate an _RpcError for a successfully completed RPC."
)
if state.code is None:
raise ValueError("Cannot instantiate an _RpcError for an incomplete RPC.")
raise ValueError(
"Cannot instantiate an _RpcError for an incomplete RPC.")
self._state = state
def initial_metadata(self):
@ -324,22 +328,22 @@ class _RpcError(grpc.RpcError, grpc.Call, grpc.Future):
"""See grpc.Future.done."""
return True
def result(self, timeout=None):
def result(self, timeout=None): # pylint: disable=unused-argument
"""See grpc.Future.result."""
raise self
def exception(self, timeout=None):
def exception(self, timeout=None): # pylint: disable=unused-argument
"""See grpc.Future.exception."""
return self
def traceback(self, timeout=None):
def traceback(self, timeout=None): # pylint: disable=unused-argument
"""See grpc.Future.traceback."""
try:
raise self
except grpc.RpcError:
return sys.exc_info()[2]
def add_done_callback(self, timeout=None):
def add_done_callback(self, fn, timeout=None): # pylint: disable=unused-argument
"""See grpc.Future.add_done_callback."""
fn(self)

@ -243,8 +243,12 @@ class _LoggingInterceptor(
def intercept_unary_unary(self, continuation, client_call_details, request):
self.record.append(self.tag + ':intercept_unary_unary')
result = continuation(client_call_details, request)
assert isinstance(result, grpc.Call), '{} is not an instance of grpc.Call'.format(result)
assert isinstance(result, grpc.Future), '{} is not an instance of grpc.Future'.format(result)
assert isinstance(
result,
grpc.Call), '{} is not an instance of grpc.Call'.format(result)
assert isinstance(
result,
grpc.Future), '{} is not an instance of grpc.Future'.format(result)
return result
def intercept_unary_stream(self, continuation, client_call_details,
@ -256,8 +260,12 @@ class _LoggingInterceptor(
request_iterator):
self.record.append(self.tag + ':intercept_stream_unary')
result = continuation(client_call_details, request_iterator)
assert isinstance(result, grpc.Call), '{} is not an instance of grpc.Call'.format(result)
assert isinstance(result, grpc.Future), '{} is not an instance of grpc.Future'.format(result)
assert isinstance(
result,
grpc.Call), '{} is not an instance of grpc.Call'.format(result)
assert isinstance(
result,
grpc.Future), '{} is not an instance of grpc.Future'.format(result)
return result
def intercept_stream_stream(self, continuation, client_call_details,

Loading…
Cancel
Save