diff options
author | robot-piglet <[email protected]> | 2025-08-29 14:19:24 +0300 |
---|---|---|
committer | robot-piglet <[email protected]> | 2025-08-29 14:40:38 +0300 |
commit | 5715939b5b1a1812ed85171fb519f9c1c3c326e8 (patch) | |
tree | 5d981253427e490749bbb50d3616507fa0d6d1bc /contrib/python/grpcio/py3/grpc/framework | |
parent | c390a008ee5d15e1d8f49326671908f375e0851b (diff) |
Intermediate changes
commit_hash:88dd3a7e237f5ebeb9b302a0e6866042635fda83
Diffstat (limited to 'contrib/python/grpcio/py3/grpc/framework')
11 files changed, 1210 insertions, 1078 deletions
diff --git a/contrib/python/grpcio/py3/grpc/framework/common/cardinality.py b/contrib/python/grpcio/py3/grpc/framework/common/cardinality.py index c98735622d7..3d3d4d3427c 100644 --- a/contrib/python/grpcio/py3/grpc/framework/common/cardinality.py +++ b/contrib/python/grpcio/py3/grpc/framework/common/cardinality.py @@ -20,7 +20,7 @@ import enum class Cardinality(enum.Enum): """Describes the streaming semantics of an RPC method.""" - UNARY_UNARY = 'request-unary/response-unary' - UNARY_STREAM = 'request-unary/response-streaming' - STREAM_UNARY = 'request-streaming/response-unary' - STREAM_STREAM = 'request-streaming/response-streaming' + UNARY_UNARY = "request-unary/response-unary" + UNARY_STREAM = "request-unary/response-streaming" + STREAM_UNARY = "request-streaming/response-unary" + STREAM_STREAM = "request-streaming/response-streaming" diff --git a/contrib/python/grpcio/py3/grpc/framework/common/style.py b/contrib/python/grpcio/py3/grpc/framework/common/style.py index f6138d417ff..10bf5f17697 100644 --- a/contrib/python/grpcio/py3/grpc/framework/common/style.py +++ b/contrib/python/grpcio/py3/grpc/framework/common/style.py @@ -20,5 +20,5 @@ import enum class Service(enum.Enum): """Describes the control flow style of RPC method implementation.""" - INLINE = 'inline' - EVENT = 'event' + INLINE = "inline" + EVENT = "event" diff --git a/contrib/python/grpcio/py3/grpc/framework/foundation/abandonment.py b/contrib/python/grpcio/py3/grpc/framework/foundation/abandonment.py index 660ce991c41..c4cb7d5c072 100644 --- a/contrib/python/grpcio/py3/grpc/framework/foundation/abandonment.py +++ b/contrib/python/grpcio/py3/grpc/framework/foundation/abandonment.py @@ -17,6 +17,6 @@ class Abandoned(Exception): """Indicates that some computation is being abandoned. - Abandoning a computation is different than returning a value or raising - an exception indicating some operational or programming defect. - """ + Abandoning a computation is different than returning a value or raising + an exception indicating some operational or programming defect. + """ diff --git a/contrib/python/grpcio/py3/grpc/framework/foundation/callable_util.py b/contrib/python/grpcio/py3/grpc/framework/foundation/callable_util.py index 0a638eb62e8..b64131b4029 100644 --- a/contrib/python/grpcio/py3/grpc/framework/foundation/callable_util.py +++ b/contrib/python/grpcio/py3/grpc/framework/foundation/callable_util.py @@ -25,14 +25,14 @@ _LOGGER = logging.getLogger(__name__) class Outcome(ABC): """A sum type describing the outcome of some call. - Attributes: - kind: One of Kind.RETURNED or Kind.RAISED respectively indicating that the - call returned a value or raised an exception. - return_value: The value returned by the call. Must be present if kind is - Kind.RETURNED. - exception: The exception raised by the call. Must be present if kind is - Kind.RAISED. - """ + Attributes: + kind: One of Kind.RETURNED or Kind.RAISED respectively indicating that the + call returned a value or raised an exception. + return_value: The value returned by the call. Must be present if kind is + Kind.RETURNED. + exception: The exception raised by the call. Must be present if kind is + Kind.RAISED. + """ @enum.unique class Kind(enum.Enum): @@ -43,15 +43,19 @@ class Outcome(ABC): class _EasyOutcome( - collections.namedtuple('_EasyOutcome', - ['kind', 'return_value', 'exception']), 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) + return _EasyOutcome( + Outcome.Kind.RETURNED, behavior(*args, **kwargs), None + ) except Exception as e: # pylint: disable=broad-except _LOGGER.exception(message) return _EasyOutcome(Outcome.Kind.RAISED, None, e) @@ -60,16 +64,16 @@ def _call_logging_exceptions(behavior, message, *args, **kwargs): def with_exceptions_logged(behavior, message): """Wraps a callable in a try-except that logs any exceptions it raises. - Args: - behavior: Any callable. - message: A string to log if the behavior raises an exception. + Args: + behavior: Any callable. + message: A string to log if the behavior raises an exception. - Returns: - A callable that when executed invokes the given behavior. The returned - callable takes the same arguments as the given behavior but returns a - future.Outcome describing whether the given behavior returned a value or - raised an exception. - """ + Returns: + A callable that when executed invokes the given behavior. The returned + callable takes the same arguments as the given behavior but returns a + future.Outcome describing whether the given behavior returned a value or + raised an exception. + """ @functools.wraps(behavior) def wrapped_behavior(*args, **kwargs): @@ -81,14 +85,14 @@ def with_exceptions_logged(behavior, message): def call_logging_exceptions(behavior, message, *args, **kwargs): """Calls a behavior in a try-except that logs any exceptions it raises. - Args: - behavior: Any callable. - message: A string to log if the behavior raises an exception. - *args: Positional arguments to pass to the given behavior. - **kwargs: Keyword arguments to pass to the given behavior. + Args: + behavior: Any callable. + message: A string to log if the behavior raises an exception. + *args: Positional arguments to pass to the given behavior. + **kwargs: Keyword arguments to pass to the given behavior. - Returns: - An Outcome describing whether the given behavior returned a value or raised - an exception. - """ + Returns: + An Outcome describing whether the given behavior returned a value or raised + an exception. + """ return _call_logging_exceptions(behavior, message, *args, **kwargs) diff --git a/contrib/python/grpcio/py3/grpc/framework/foundation/future.py b/contrib/python/grpcio/py3/grpc/framework/foundation/future.py index c7996aa8a56..73b0d0bdbe1 100644 --- a/contrib/python/grpcio/py3/grpc/framework/foundation/future.py +++ b/contrib/python/grpcio/py3/grpc/framework/foundation/future.py @@ -45,9 +45,9 @@ class CancelledError(Exception): class Future(abc.ABC): """A representation of a computation in another control flow. - Computations represented by a Future may be yet to be begun, may be ongoing, - or may have already completed. - """ + Computations represented by a Future may be yet to be begun, may be ongoing, + or may have already completed. + """ # NOTE(nathaniel): This isn't the return type that I would want to have if it # were up to me. Were this interface being written from scratch, the return @@ -63,17 +63,17 @@ class Future(abc.ABC): def cancel(self): """Attempts to cancel the computation. - This method does not block. - - Returns: - True if the computation has not yet begun, will not be allowed to take - place, and determination of both was possible without blocking. False - under all other circumstances including but not limited to the - computation's already having begun, the computation's already having - finished, and the computation's having been scheduled for execution on a - remote system for which a determination of whether or not it commenced - before being cancelled cannot be made without blocking. - """ + This method does not block. + + Returns: + True if the computation has not yet begun, will not be allowed to take + place, and determination of both was possible without blocking. False + under all other circumstances including but not limited to the + computation's already having begun, the computation's already having + finished, and the computation's having been scheduled for execution on a + remote system for which a determination of whether or not it commenced + before being cancelled cannot be made without blocking. + """ raise NotImplementedError() # NOTE(nathaniel): Here too this isn't the return type that I'd want this @@ -94,27 +94,27 @@ class Future(abc.ABC): def cancelled(self): """Describes whether the computation was cancelled. - This method does not block. + This method does not block. - Returns: - True if the computation was cancelled any time before its result became - immediately available. False under all other circumstances including but - not limited to this object's cancel method not having been called and - the computation's result having become immediately available. - """ + Returns: + True if the computation was cancelled any time before its result became + immediately available. False under all other circumstances including but + not limited to this object's cancel method not having been called and + the computation's result having become immediately available. + """ raise NotImplementedError() @abc.abstractmethod def running(self): """Describes whether the computation is taking place. - This method does not block. + This method does not block. - Returns: - True if the computation is scheduled to take place in the future or is - taking place now, or False if the computation took place in the past or - was cancelled. - """ + Returns: + True if the computation is scheduled to take place in the future or is + taking place now, or False if the computation took place in the past or + was cancelled. + """ raise NotImplementedError() # NOTE(nathaniel): These aren't quite the semantics I'd like here either. I @@ -125,95 +125,95 @@ class Future(abc.ABC): def done(self): """Describes whether the computation has taken place. - This method does not block. + This method does not block. - Returns: - True if the computation is known to have either completed or have been - unscheduled or interrupted. False if the computation may possibly be - executing or scheduled to execute later. - """ + Returns: + True if the computation is known to have either completed or have been + unscheduled or interrupted. False if the computation may possibly be + executing or scheduled to execute later. + """ raise NotImplementedError() @abc.abstractmethod def result(self, timeout=None): """Accesses the outcome of the computation or raises its exception. - This method may return immediately or may block. + This method may return immediately or may block. - Args: - timeout: The length of time in seconds to wait for the computation to - finish or be cancelled, or None if this method should block until the - computation has finished or is cancelled no matter how long that takes. + Args: + timeout: The length of time in seconds to wait for the computation to + finish or be cancelled, or None if this method should block until the + computation has finished or is cancelled no matter how long that takes. - Returns: - The return value of the computation. + Returns: + The return value of the computation. - Raises: - TimeoutError: If a timeout value is passed and the computation does not - terminate within the allotted time. - CancelledError: If the computation was cancelled. - Exception: If the computation raised an exception, this call will raise - the same exception. - """ + Raises: + TimeoutError: If a timeout value is passed and the computation does not + terminate within the allotted time. + CancelledError: If the computation was cancelled. + Exception: If the computation raised an exception, this call will raise + the same exception. + """ raise NotImplementedError() @abc.abstractmethod def exception(self, timeout=None): """Return the exception raised by the computation. - This method may return immediately or may block. + This method may return immediately or may block. - Args: - timeout: The length of time in seconds to wait for the computation to - terminate or be cancelled, or None if this method should block until - the computation is terminated or is cancelled no matter how long that - takes. + Args: + timeout: The length of time in seconds to wait for the computation to + terminate or be cancelled, or None if this method should block until + the computation is terminated or is cancelled no matter how long that + takes. - Returns: - The exception raised by the computation, or None if the computation did - not raise an exception. + Returns: + The exception raised by the computation, or None if the computation did + not raise an exception. - Raises: - TimeoutError: If a timeout value is passed and the computation does not - terminate within the allotted time. - CancelledError: If the computation was cancelled. - """ + Raises: + TimeoutError: If a timeout value is passed and the computation does not + terminate within the allotted time. + CancelledError: If the computation was cancelled. + """ raise NotImplementedError() @abc.abstractmethod def traceback(self, timeout=None): """Access the traceback of the exception raised by the computation. - This method may return immediately or may block. + This method may return immediately or may block. - Args: - timeout: The length of time in seconds to wait for the computation to - terminate or be cancelled, or None if this method should block until - the computation is terminated or is cancelled no matter how long that - takes. + Args: + timeout: The length of time in seconds to wait for the computation to + terminate or be cancelled, or None if this method should block until + the computation is terminated or is cancelled no matter how long that + takes. - Returns: - The traceback of the exception raised by the computation, or None if the - computation did not raise an exception. + Returns: + The traceback of the exception raised by the computation, or None if the + computation did not raise an exception. - Raises: - TimeoutError: If a timeout value is passed and the computation does not - terminate within the allotted time. - CancelledError: If the computation was cancelled. - """ + Raises: + TimeoutError: If a timeout value is passed and the computation does not + terminate within the allotted time. + CancelledError: If the computation was cancelled. + """ raise NotImplementedError() @abc.abstractmethod def add_done_callback(self, fn): """Adds a function to be called at completion of the computation. - The callback will be passed this Future object describing the outcome of - the computation. + The callback will be passed this Future object describing the outcome of + the computation. - If the computation has already completed, the callback will be called - immediately. + If the computation has already completed, the callback will be called + immediately. - Args: - fn: A callable taking this Future object as its single parameter. - """ + Args: + fn: A callable taking this Future object as its single parameter. + """ raise NotImplementedError() diff --git a/contrib/python/grpcio/py3/grpc/framework/foundation/logging_pool.py b/contrib/python/grpcio/py3/grpc/framework/foundation/logging_pool.py index 53d2cd00825..a4e140f174d 100644 --- a/contrib/python/grpcio/py3/grpc/framework/foundation/logging_pool.py +++ b/contrib/python/grpcio/py3/grpc/framework/foundation/logging_pool.py @@ -27,8 +27,9 @@ def _wrap(behavior): return behavior(*args, **kwargs) except Exception: _LOGGER.exception( - 'Unexpected exception from %s executed in logging pool!', - behavior) + "Unexpected exception from %s executed in logging pool!", + behavior, + ) raise return _wrapping @@ -50,9 +51,9 @@ class _LoggingPool(object): return self._backing_pool.submit(_wrap(fn), *args, **kwargs) def map(self, func, *iterables, **kwargs): - return self._backing_pool.map(_wrap(func), - *iterables, - timeout=kwargs.get('timeout', None)) + return self._backing_pool.map( + _wrap(func), *iterables, timeout=kwargs.get("timeout", None) + ) def shutdown(self, wait=True): self._backing_pool.shutdown(wait=wait) @@ -61,11 +62,11 @@ class _LoggingPool(object): def pool(max_workers): """Creates a thread pool that logs exceptions raised by the tasks within it. - Args: - max_workers: The maximum number of worker threads to allow the pool. + Args: + max_workers: The maximum number of worker threads to allow the pool. - Returns: - A futures.ThreadPoolExecutor-compatible thread pool that logs exceptions - raised by the tasks executed within it. - """ + Returns: + A futures.ThreadPoolExecutor-compatible thread pool that logs exceptions + raised by the tasks executed within it. + """ return _LoggingPool(futures.ThreadPoolExecutor(max_workers)) diff --git a/contrib/python/grpcio/py3/grpc/framework/foundation/stream.py b/contrib/python/grpcio/py3/grpc/framework/foundation/stream.py index 150a22435ee..70ca1d91575 100644 --- a/contrib/python/grpcio/py3/grpc/framework/foundation/stream.py +++ b/contrib/python/grpcio/py3/grpc/framework/foundation/stream.py @@ -23,9 +23,9 @@ class Consumer(abc.ABC): def consume(self, value): """Accepts a value. - Args: - value: Any value accepted by this Consumer. - """ + Args: + value: Any value accepted by this Consumer. + """ raise NotImplementedError() @abc.abstractmethod @@ -37,7 +37,7 @@ class Consumer(abc.ABC): def consume_and_terminate(self, value): """Supplies a value and signals that no more values will be supplied. - Args: - value: Any value accepted by this Consumer. - """ + Args: + value: Any value accepted by this Consumer. + """ raise NotImplementedError() diff --git a/contrib/python/grpcio/py3/grpc/framework/interfaces/base/base.py b/contrib/python/grpcio/py3/grpc/framework/interfaces/base/base.py index 8caee325c2c..d1c0b079116 100644 --- a/contrib/python/grpcio/py3/grpc/framework/interfaces/base/base.py +++ b/contrib/python/grpcio/py3/grpc/framework/interfaces/base/base.py @@ -56,37 +56,37 @@ class NoSuchMethodError(Exception): class Outcome(object): """The outcome of an operation. - Attributes: - kind: A Kind value coarsely identifying how the operation terminated. - code: An application-specific code value or None if no such value was - provided. - details: An application-specific details value or None if no such value was - provided. - """ + Attributes: + kind: A Kind value coarsely identifying how the operation terminated. + code: An application-specific code value or None if no such value was + provided. + details: An application-specific details value or None if no such value was + provided. + """ @enum.unique class Kind(enum.Enum): """Ways in which an operation can terminate.""" - COMPLETED = 'completed' - CANCELLED = 'cancelled' - EXPIRED = 'expired' - LOCAL_SHUTDOWN = 'local shutdown' - REMOTE_SHUTDOWN = 'remote shutdown' - RECEPTION_FAILURE = 'reception failure' - TRANSMISSION_FAILURE = 'transmission failure' - LOCAL_FAILURE = 'local failure' - REMOTE_FAILURE = 'remote failure' + COMPLETED = "completed" + CANCELLED = "cancelled" + EXPIRED = "expired" + LOCAL_SHUTDOWN = "local shutdown" + REMOTE_SHUTDOWN = "remote shutdown" + RECEPTION_FAILURE = "reception failure" + TRANSMISSION_FAILURE = "transmission failure" + LOCAL_FAILURE = "local failure" + REMOTE_FAILURE = "remote failure" class Completion(abc.ABC): """An aggregate of the values exchanged upon operation completion. - Attributes: - terminal_metadata: A terminal metadata value for the operaton. - code: A code value for the operation. - message: A message value for the operation. - """ + Attributes: + terminal_metadata: A terminal metadata value for the operaton. + code: A code value for the operation. + message: A message value for the operation. + """ class OperationContext(abc.ABC): @@ -96,37 +96,37 @@ class OperationContext(abc.ABC): def outcome(self): """Indicates the operation's outcome (or that the operation is ongoing). - Returns: - None if the operation is still active or the Outcome value for the - operation if it has terminated. - """ + Returns: + None if the operation is still active or the Outcome value for the + operation if it has terminated. + """ raise NotImplementedError() @abc.abstractmethod def add_termination_callback(self, callback): """Adds a function to be called upon operation termination. - Args: - callback: A callable to be passed an Outcome value on operation - termination. - - Returns: - None if the operation has not yet terminated and the passed callback will - later be called when it does terminate, or if the operation has already - terminated an Outcome value describing the operation termination and the - passed callback will not be called as a result of this method call. - """ + Args: + callback: A callable to be passed an Outcome value on operation + termination. + + Returns: + None if the operation has not yet terminated and the passed callback will + later be called when it does terminate, or if the operation has already + terminated an Outcome value describing the operation termination and the + passed callback will not be called as a result of this method call. + """ raise NotImplementedError() @abc.abstractmethod def time_remaining(self): """Describes the length of allowed time remaining for the operation. - Returns: - A nonnegative float indicating the length of allowed time in seconds - remaining for the operation to complete before it is considered to have - timed out. Zero is returned if the operation has terminated. - """ + Returns: + A nonnegative float indicating the length of allowed time in seconds + remaining for the operation to complete before it is considered to have + timed out. Zero is returned if the operation has terminated. + """ raise NotImplementedError() @abc.abstractmethod @@ -138,9 +138,9 @@ class OperationContext(abc.ABC): def fail(self, exception): """Indicates that the operation has failed. - Args: - exception: An exception germane to the operation failure. May be None. - """ + Args: + exception: An exception germane to the operation failure. May be None. + """ raise NotImplementedError() @@ -148,23 +148,25 @@ class Operator(abc.ABC): """An interface through which to participate in an operation.""" @abc.abstractmethod - def advance(self, - initial_metadata=None, - payload=None, - completion=None, - allowance=None): + def advance( + self, + initial_metadata=None, + payload=None, + completion=None, + allowance=None, + ): """Progresses the operation. - Args: - initial_metadata: An initial metadata value. Only one may ever be - communicated in each direction for an operation, and they must be - communicated no later than either the first payload or the completion. - payload: A payload value. - completion: A Completion value. May only ever be non-None once in either - direction, and no payloads may be passed after it has been communicated. - allowance: A positive integer communicating the number of additional - payloads allowed to be passed by the remote side of the operation. - """ + Args: + initial_metadata: An initial metadata value. Only one may ever be + communicated in each direction for an operation, and they must be + communicated no later than either the first payload or the completion. + payload: A payload value. + completion: A Completion value. May only ever be non-None once in either + direction, and no payloads may be passed after it has been communicated. + allowance: A positive integer communicating the number of additional + payloads allowed to be passed by the remote side of the operation. + """ raise NotImplementedError() @@ -175,37 +177,36 @@ class ProtocolReceiver(abc.ABC): def context(self, protocol_context): """Accepts the protocol context object for the operation. - Args: - protocol_context: The protocol context object for the operation. - """ + Args: + protocol_context: The protocol context object for the operation. + """ raise NotImplementedError() class Subscription(abc.ABC): """Describes customer code's interest in values from the other side. - Attributes: - kind: A Kind value describing the overall kind of this value. - termination_callback: A callable to be passed the Outcome associated with - the operation after it has terminated. Must be non-None if kind is - Kind.TERMINATION_ONLY. Must be None otherwise. - allowance: A callable behavior that accepts positive integers representing - the number of additional payloads allowed to be passed to the other side - of the operation. Must be None if kind is Kind.FULL. Must not be None - otherwise. - operator: An Operator to be passed values from the other side of the - operation. Must be non-None if kind is Kind.FULL. Must be None otherwise. - protocol_receiver: A ProtocolReceiver to be passed protocol objects as they - become available during the operation. Must be non-None if kind is - Kind.FULL. - """ + Attributes: + kind: A Kind value describing the overall kind of this value. + termination_callback: A callable to be passed the Outcome associated with + the operation after it has terminated. Must be non-None if kind is + Kind.TERMINATION_ONLY. Must be None otherwise. + allowance: A callable behavior that accepts positive integers representing + the number of additional payloads allowed to be passed to the other side + of the operation. Must be None if kind is Kind.FULL. Must not be None + otherwise. + operator: An Operator to be passed values from the other side of the + operation. Must be non-None if kind is Kind.FULL. Must be None otherwise. + protocol_receiver: A ProtocolReceiver to be passed protocol objects as they + become available during the operation. Must be non-None if kind is + Kind.FULL. + """ @enum.unique class Kind(enum.Enum): - - NONE = 'none' - TERMINATION_ONLY = 'termination only' - FULL = 'full' + NONE = "none" + TERMINATION_ONLY = "termination only" + FULL = "full" class Servicer(abc.ABC): @@ -215,24 +216,24 @@ class Servicer(abc.ABC): def service(self, group, method, context, output_operator): """Services an operation. - Args: - group: The group identifier of the operation to be serviced. - method: The method identifier of the operation to be serviced. - context: An OperationContext object affording contextual information and - actions. - output_operator: An Operator that will accept output values of the - operation. - - Returns: - A Subscription via which this object may or may not accept more values of - the operation. - - Raises: - NoSuchMethodError: If this Servicer does not handle operations with the - given group and method. - abandonment.Abandoned: If the operation has been aborted and there no - longer is any reason to service the operation. - """ + Args: + group: The group identifier of the operation to be serviced. + method: The method identifier of the operation to be serviced. + context: An OperationContext object affording contextual information and + actions. + output_operator: An Operator that will accept output values of the + operation. + + Returns: + A Subscription via which this object may or may not accept more values of + the operation. + + Raises: + NoSuchMethodError: If this Servicer does not handle operations with the + given group and method. + abandonment.Abandoned: If the operation has been aborted and there no + longer is any reason to service the operation. + """ raise NotImplementedError() @@ -248,78 +249,80 @@ class End(abc.ABC): def stop(self, grace): """Stops this object's service of operations. - This object will refuse service of new operations as soon as this method is - called but operations under way at the time of the call may be given a - grace period during which they are allowed to finish. - - Args: - grace: A duration of time in seconds to allow ongoing operations to - terminate before being forcefully terminated by the stopping of this - End. May be zero to terminate all ongoing operations and immediately - stop. - - Returns: - A threading.Event that will be set to indicate all operations having - terminated and this End having completely stopped. The returned event - may not be set until after the full grace period (if some ongoing - operation continues for the full length of the period) or it may be set - much sooner (if for example this End had no operations in progress at - the time its stop method was called). - """ + This object will refuse service of new operations as soon as this method is + called but operations under way at the time of the call may be given a + grace period during which they are allowed to finish. + + Args: + grace: A duration of time in seconds to allow ongoing operations to + terminate before being forcefully terminated by the stopping of this + End. May be zero to terminate all ongoing operations and immediately + stop. + + Returns: + A threading.Event that will be set to indicate all operations having + terminated and this End having completely stopped. The returned event + may not be set until after the full grace period (if some ongoing + operation continues for the full length of the period) or it may be set + much sooner (if for example this End had no operations in progress at + the time its stop method was called). + """ raise NotImplementedError() @abc.abstractmethod - def operate(self, - group, - method, - subscription, - timeout, - initial_metadata=None, - payload=None, - completion=None, - protocol_options=None): + def operate( + self, + group, + method, + subscription, + timeout, + initial_metadata=None, + payload=None, + completion=None, + protocol_options=None, + ): """Commences an operation. - Args: - group: The group identifier of the invoked operation. - method: The method identifier of the invoked operation. - subscription: A Subscription to which the results of the operation will be - passed. - timeout: A length of time in seconds to allow for the operation. - initial_metadata: An initial metadata value to be sent to the other side - of the operation. May be None if the initial metadata will be later - passed via the returned operator or if there will be no initial metadata - passed at all. - payload: An initial payload for the operation. - completion: A Completion value indicating the end of transmission to the - other side of the operation. - protocol_options: A value specified by the provider of a Base interface - implementation affording custom state and behavior. - - Returns: - A pair of objects affording information about the operation and action - continuing the operation. The first element of the returned pair is an - OperationContext for the operation and the second element of the - returned pair is an Operator to which operation values not passed in - this call should later be passed. - """ + Args: + group: The group identifier of the invoked operation. + method: The method identifier of the invoked operation. + subscription: A Subscription to which the results of the operation will be + passed. + timeout: A length of time in seconds to allow for the operation. + initial_metadata: An initial metadata value to be sent to the other side + of the operation. May be None if the initial metadata will be later + passed via the returned operator or if there will be no initial metadata + passed at all. + payload: An initial payload for the operation. + completion: A Completion value indicating the end of transmission to the + other side of the operation. + protocol_options: A value specified by the provider of a Base interface + implementation affording custom state and behavior. + + Returns: + A pair of objects affording information about the operation and action + continuing the operation. The first element of the returned pair is an + OperationContext for the operation and the second element of the + returned pair is an Operator to which operation values not passed in + this call should later be passed. + """ raise NotImplementedError() @abc.abstractmethod def operation_stats(self): """Reports the number of terminated operations broken down by outcome. - Returns: - A dictionary from Outcome.Kind value to an integer identifying the number - of operations that terminated with that outcome kind. - """ + Returns: + A dictionary from Outcome.Kind value to an integer identifying the number + of operations that terminated with that outcome kind. + """ raise NotImplementedError() @abc.abstractmethod def add_idle_action(self, action): """Adds an action to be called when this End has no ongoing operations. - Args: - action: A callable that accepts no arguments. - """ + Args: + action: A callable that accepts no arguments. + """ raise NotImplementedError() diff --git a/contrib/python/grpcio/py3/grpc/framework/interfaces/base/utilities.py b/contrib/python/grpcio/py3/grpc/framework/interfaces/base/utilities.py index 281db62b5d4..d188339b1eb 100644 --- a/contrib/python/grpcio/py3/grpc/framework/interfaces/base/utilities.py +++ b/contrib/python/grpcio/py3/grpc/framework/interfaces/base/utilities.py @@ -18,54 +18,66 @@ import collections from grpc.framework.interfaces.base import base -class _Completion(base.Completion, - collections.namedtuple('_Completion', ( - 'terminal_metadata', - 'code', - 'message', - ))): +class _Completion( + base.Completion, + collections.namedtuple( + "_Completion", + ( + "terminal_metadata", + "code", + "message", + ), + ), +): """A trivial implementation of base.Completion.""" -class _Subscription(base.Subscription, - collections.namedtuple('_Subscription', ( - 'kind', - 'termination_callback', - 'allowance', - 'operator', - 'protocol_receiver', - ))): +class _Subscription( + base.Subscription, + collections.namedtuple( + "_Subscription", + ( + "kind", + "termination_callback", + "allowance", + "operator", + "protocol_receiver", + ), + ), +): """A trivial implementation of base.Subscription.""" -_NONE_SUBSCRIPTION = _Subscription(base.Subscription.Kind.NONE, None, None, - None, None) +_NONE_SUBSCRIPTION = _Subscription( + base.Subscription.Kind.NONE, None, None, None, None +) def completion(terminal_metadata, code, message): """Creates a base.Completion aggregating the given operation values. - Args: - terminal_metadata: A terminal metadata value for an operaton. - code: A code value for an operation. - message: A message value for an operation. + Args: + terminal_metadata: A terminal metadata value for an operaton. + code: A code value for an operation. + message: A message value for an operation. - Returns: - A base.Completion aggregating the given operation values. - """ + Returns: + A base.Completion aggregating the given operation values. + """ return _Completion(terminal_metadata, code, message) def full_subscription(operator, protocol_receiver): """Creates a "full" base.Subscription for the given base.Operator. - Args: - operator: A base.Operator to be used in an operation. - protocol_receiver: A base.ProtocolReceiver to be used in an operation. - - Returns: - A base.Subscription of kind base.Subscription.Kind.FULL wrapping the given - base.Operator and base.ProtocolReceiver. - """ - return _Subscription(base.Subscription.Kind.FULL, None, None, operator, - protocol_receiver) + Args: + operator: A base.Operator to be used in an operation. + protocol_receiver: A base.ProtocolReceiver to be used in an operation. + + Returns: + A base.Subscription of kind base.Subscription.Kind.FULL wrapping the given + base.Operator and base.ProtocolReceiver. + """ + return _Subscription( + base.Subscription.Kind.FULL, None, None, operator, protocol_receiver + ) diff --git a/contrib/python/grpcio/py3/grpc/framework/interfaces/face/face.py b/contrib/python/grpcio/py3/grpc/framework/interfaces/face/face.py index ed0de6a7de2..9239fcc9eb9 100644 --- a/contrib/python/grpcio/py3/grpc/framework/interfaces/face/face.py +++ b/contrib/python/grpcio/py3/grpc/framework/interfaces/face/face.py @@ -30,62 +30,66 @@ from grpc.framework.foundation import stream # pylint: disable=unused-import class NoSuchMethodError(Exception): """Raised by customer code to indicate an unrecognized method. - Attributes: - group: The group of the unrecognized method. - name: The name of the unrecognized method. - """ + Attributes: + group: The group of the unrecognized method. + name: The name of the unrecognized method. + """ def __init__(self, group, method): """Constructor. - Args: - group: The group identifier of the unrecognized RPC name. - method: The method identifier of the unrecognized RPC name. - """ + Args: + group: The group identifier of the unrecognized RPC name. + method: The method identifier of the unrecognized RPC name. + """ super(NoSuchMethodError, self).__init__() self.group = group self.method = method def __repr__(self): - return 'face.NoSuchMethodError(%s, %s)' % ( + return "face.NoSuchMethodError(%s, %s)" % ( self.group, self.method, ) class Abortion( - collections.namedtuple('Abortion', ( - 'kind', - 'initial_metadata', - 'terminal_metadata', - 'code', - 'details', - ))): + collections.namedtuple( + "Abortion", + ( + "kind", + "initial_metadata", + "terminal_metadata", + "code", + "details", + ), + ) +): """A value describing RPC abortion. - Attributes: - kind: A Kind value identifying how the RPC failed. - initial_metadata: The initial metadata from the other side of the RPC or - None if no initial metadata value was received. - terminal_metadata: The terminal metadata from the other side of the RPC or - None if no terminal metadata value was received. - code: The code value from the other side of the RPC or None if no code value - was received. - details: The details value from the other side of the RPC or None if no - details value was received. - """ + Attributes: + kind: A Kind value identifying how the RPC failed. + initial_metadata: The initial metadata from the other side of the RPC or + None if no initial metadata value was received. + terminal_metadata: The terminal metadata from the other side of the RPC or + None if no terminal metadata value was received. + code: The code value from the other side of the RPC or None if no code value + was received. + details: The details value from the other side of the RPC or None if no + details value was received. + """ @enum.unique class Kind(enum.Enum): """Types of RPC abortion.""" - CANCELLED = 'cancelled' - EXPIRED = 'expired' - LOCAL_SHUTDOWN = 'local shutdown' - REMOTE_SHUTDOWN = 'remote shutdown' - NETWORK_FAILURE = 'network failure' - LOCAL_FAILURE = 'local failure' - REMOTE_FAILURE = 'remote failure' + CANCELLED = "cancelled" + EXPIRED = "expired" + LOCAL_SHUTDOWN = "local shutdown" + REMOTE_SHUTDOWN = "remote shutdown" + NETWORK_FAILURE = "network failure" + LOCAL_FAILURE = "local failure" + REMOTE_FAILURE = "remote failure" class AbortionError(Exception, metaclass=abc.ABCMeta): @@ -99,7 +103,7 @@ class AbortionError(Exception, metaclass=abc.ABCMeta): was received. details: The details value from the other side of the RPC or None if no details value was received. - """ + """ def __init__(self, initial_metadata, terminal_metadata, code, details): super(AbortionError, self).__init__() @@ -109,8 +113,11 @@ class AbortionError(Exception, metaclass=abc.ABCMeta): self.details = details def __str__(self): - return '%s(code=%s, details="%s")' % (self.__class__.__name__, - self.code, self.details) + return '%s(code=%s, details="%s")' % ( + self.__class__.__name__, + self.code, + self.details, + ) class CancellationError(AbortionError): @@ -153,39 +160,39 @@ class RpcContext(abc.ABC): def time_remaining(self): """Describes the length of allowed time remaining for the RPC. - Returns: - A nonnegative float indicating the length of allowed time in seconds - remaining for the RPC to complete before it is considered to have timed - out. - """ + Returns: + A nonnegative float indicating the length of allowed time in seconds + remaining for the RPC to complete before it is considered to have timed + out. + """ raise NotImplementedError() @abc.abstractmethod def add_abortion_callback(self, abortion_callback): """Registers a callback to be called if the RPC is aborted. - Args: - abortion_callback: A callable to be called and passed an Abortion value - in the event of RPC abortion. - """ + Args: + abortion_callback: A callable to be called and passed an Abortion value + in the event of RPC abortion. + """ raise NotImplementedError() @abc.abstractmethod def cancel(self): """Cancels the RPC. - Idempotent and has no effect if the RPC has already terminated. - """ + Idempotent and has no effect if the RPC has already terminated. + """ raise NotImplementedError() @abc.abstractmethod def protocol_context(self): """Accesses a custom object specified by an implementation provider. - Returns: - A value specified by the provider of a Face interface implementation - affording custom state and behavior. - """ + Returns: + A value specified by the provider of a Face interface implementation + affording custom state and behavior. + """ raise NotImplementedError() @@ -196,52 +203,52 @@ class Call(RpcContext, metaclass=abc.ABCMeta): def initial_metadata(self): """Accesses the initial metadata from the service-side of the RPC. - This method blocks until the value is available or is known not to have been - emitted from the service-side of the RPC. + This method blocks until the value is available or is known not to have been + emitted from the service-side of the RPC. - Returns: - The initial metadata object emitted by the service-side of the RPC, or - None if there was no such value. - """ + Returns: + The initial metadata object emitted by the service-side of the RPC, or + None if there was no such value. + """ raise NotImplementedError() @abc.abstractmethod def terminal_metadata(self): """Accesses the terminal metadata from the service-side of the RPC. - This method blocks until the value is available or is known not to have been - emitted from the service-side of the RPC. + This method blocks until the value is available or is known not to have been + emitted from the service-side of the RPC. - Returns: - The terminal metadata object emitted by the service-side of the RPC, or - None if there was no such value. - """ + Returns: + The terminal metadata object emitted by the service-side of the RPC, or + None if there was no such value. + """ raise NotImplementedError() @abc.abstractmethod def code(self): """Accesses the code emitted by the service-side of the RPC. - This method blocks until the value is available or is known not to have been - emitted from the service-side of the RPC. + This method blocks until the value is available or is known not to have been + emitted from the service-side of the RPC. - Returns: - The code object emitted by the service-side of the RPC, or None if there - was no such value. - """ + Returns: + The code object emitted by the service-side of the RPC, or None if there + was no such value. + """ raise NotImplementedError() @abc.abstractmethod def details(self): """Accesses the details value emitted by the service-side of the RPC. - This method blocks until the value is available or is known not to have been - emitted from the service-side of the RPC. + This method blocks until the value is available or is known not to have been + emitted from the service-side of the RPC. - Returns: - The details value emitted by the service-side of the RPC, or None if there - was no such value. - """ + Returns: + The details value emitted by the service-side of the RPC, or None if there + was no such value. + """ raise NotImplementedError() @@ -252,65 +259,65 @@ class ServicerContext(RpcContext, metaclass=abc.ABCMeta): def invocation_metadata(self): """Accesses the metadata from the invocation-side of the RPC. - This method blocks until the value is available or is known not to have been - emitted from the invocation-side of the RPC. + This method blocks until the value is available or is known not to have been + emitted from the invocation-side of the RPC. - Returns: - The metadata object emitted by the invocation-side of the RPC, or None if - there was no such value. - """ + Returns: + The metadata object emitted by the invocation-side of the RPC, or None if + there was no such value. + """ raise NotImplementedError() @abc.abstractmethod def initial_metadata(self, initial_metadata): """Accepts the service-side initial metadata value of the RPC. - This method need not be called by method implementations if they have no - service-side initial metadata to transmit. + This method need not be called by method implementations if they have no + service-side initial metadata to transmit. - Args: - initial_metadata: The service-side initial metadata value of the RPC to - be transmitted to the invocation side of the RPC. - """ + Args: + initial_metadata: The service-side initial metadata value of the RPC to + be transmitted to the invocation side of the RPC. + """ raise NotImplementedError() @abc.abstractmethod def terminal_metadata(self, terminal_metadata): """Accepts the service-side terminal metadata value of the RPC. - This method need not be called by method implementations if they have no - service-side terminal metadata to transmit. + This method need not be called by method implementations if they have no + service-side terminal metadata to transmit. - Args: - terminal_metadata: The service-side terminal metadata value of the RPC to - be transmitted to the invocation side of the RPC. - """ + Args: + terminal_metadata: The service-side terminal metadata value of the RPC to + be transmitted to the invocation side of the RPC. + """ raise NotImplementedError() @abc.abstractmethod def code(self, code): """Accepts the service-side code of the RPC. - This method need not be called by method implementations if they have no - code to transmit. + This method need not be called by method implementations if they have no + code to transmit. - Args: - code: The code of the RPC to be transmitted to the invocation side of the - RPC. - """ + Args: + code: The code of the RPC to be transmitted to the invocation side of the + RPC. + """ raise NotImplementedError() @abc.abstractmethod def details(self, details): """Accepts the service-side details of the RPC. - This method need not be called by method implementations if they have no - service-side details to transmit. + This method need not be called by method implementations if they have no + service-side details to transmit. - Args: - details: The service-side details value of the RPC to be transmitted to - the invocation side of the RPC. - """ + Args: + details: The service-side details value of the RPC to be transmitted to + the invocation side of the RPC. + """ raise NotImplementedError() @@ -321,31 +328,31 @@ class ResponseReceiver(abc.ABC): def initial_metadata(self, initial_metadata): """Receives the initial metadata from the service-side of the RPC. - Args: - initial_metadata: The initial metadata object emitted from the - service-side of the RPC. - """ + Args: + initial_metadata: The initial metadata object emitted from the + service-side of the RPC. + """ raise NotImplementedError() @abc.abstractmethod def response(self, response): """Receives a response from the service-side of the RPC. - Args: - response: A response object emitted from the service-side of the RPC. - """ + Args: + response: A response object emitted from the service-side of the RPC. + """ raise NotImplementedError() @abc.abstractmethod def complete(self, terminal_metadata, code, details): """Receives the completion values emitted from the service-side of the RPC. - Args: - terminal_metadata: The terminal metadata object emitted from the - service-side of the RPC. - code: The code object emitted from the service-side of the RPC. - details: The details object emitted from the service-side of the RPC. - """ + Args: + terminal_metadata: The terminal metadata object emitted from the + service-side of the RPC. + code: The code object emitted from the service-side of the RPC. + details: The details object emitted from the service-side of the RPC. + """ raise NotImplementedError() @@ -353,77 +360,81 @@ class UnaryUnaryMultiCallable(abc.ABC): """Affords invoking a unary-unary RPC in any call style.""" @abc.abstractmethod - def __call__(self, - request, - timeout, - metadata=None, - with_call=False, - protocol_options=None): + def __call__( + self, + request, + timeout, + metadata=None, + with_call=False, + protocol_options=None, + ): """Synchronously invokes the underlying RPC. - Args: - request: The request value for the RPC. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of - the RPC. - with_call: Whether or not to include return a Call for the RPC in addition - to the response. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - The response value for the RPC, and a Call for the RPC if with_call was - set to True at invocation. - - Raises: - AbortionError: Indicating that the RPC was aborted. - """ + Args: + request: The request value for the RPC. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of + the RPC. + with_call: Whether or not to include return a Call for the RPC in addition + to the response. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + The response value for the RPC, and a Call for the RPC if with_call was + set to True at invocation. + + Raises: + AbortionError: Indicating that the RPC was aborted. + """ raise NotImplementedError() @abc.abstractmethod def future(self, request, timeout, metadata=None, protocol_options=None): """Asynchronously invokes the underlying RPC. - Args: - request: The request value for the RPC. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of - the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - An object that is both a Call for the RPC and a future.Future. In the - event of RPC completion, the return Future's result value will be the - response value of the RPC. In the event of RPC abortion, the returned - Future's exception value will be an AbortionError. - """ + Args: + request: The request value for the RPC. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of + the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + An object that is both a Call for the RPC and a future.Future. In the + event of RPC completion, the return Future's result value will be the + response value of the RPC. In the event of RPC abortion, the returned + Future's exception value will be an AbortionError. + """ raise NotImplementedError() @abc.abstractmethod - def event(self, - request, - receiver, - abortion_callback, - timeout, - metadata=None, - protocol_options=None): + def event( + self, + request, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None, + ): """Asynchronously invokes the underlying RPC. - Args: - request: The request value for the RPC. - receiver: A ResponseReceiver to be passed the response data of the RPC. - abortion_callback: A callback to be called and passed an Abortion value - in the event of RPC abortion. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of - the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - A Call for the RPC. - """ + Args: + request: The request value for the RPC. + receiver: A ResponseReceiver to be passed the response data of the RPC. + abortion_callback: A callback to be called and passed an Abortion value + in the event of RPC abortion. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of + the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + A Call for the RPC. + """ raise NotImplementedError() @@ -434,45 +445,47 @@ class UnaryStreamMultiCallable(abc.ABC): def __call__(self, request, timeout, metadata=None, protocol_options=None): """Invokes the underlying RPC. - Args: - request: The request value for the RPC. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of - the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - An object that is both a Call for the RPC and an iterator of response - values. Drawing response values from the returned iterator may raise - AbortionError indicating abortion of the RPC. - """ + Args: + request: The request value for the RPC. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of + the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + An object that is both a Call for the RPC and an iterator of response + values. Drawing response values from the returned iterator may raise + AbortionError indicating abortion of the RPC. + """ raise NotImplementedError() @abc.abstractmethod - def event(self, - request, - receiver, - abortion_callback, - timeout, - metadata=None, - protocol_options=None): + def event( + self, + request, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None, + ): """Asynchronously invokes the underlying RPC. - Args: - request: The request value for the RPC. - receiver: A ResponseReceiver to be passed the response data of the RPC. - abortion_callback: A callback to be called and passed an Abortion value - in the event of RPC abortion. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of - the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - A Call object for the RPC. - """ + Args: + request: The request value for the RPC. + receiver: A ResponseReceiver to be passed the response data of the RPC. + abortion_callback: A callback to be called and passed an Abortion value + in the event of RPC abortion. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of + the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + A Call object for the RPC. + """ raise NotImplementedError() @@ -480,80 +493,82 @@ class StreamUnaryMultiCallable(abc.ABC): """Affords invoking a stream-unary RPC in any call style.""" @abc.abstractmethod - def __call__(self, - request_iterator, - timeout, - metadata=None, - with_call=False, - protocol_options=None): + def __call__( + self, + request_iterator, + timeout, + metadata=None, + with_call=False, + protocol_options=None, + ): """Synchronously invokes the underlying RPC. - Args: - request_iterator: An iterator that yields request values for the RPC. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of - the RPC. - with_call: Whether or not to include return a Call for the RPC in addition - to the response. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - The response value for the RPC, and a Call for the RPC if with_call was - set to True at invocation. - - Raises: - AbortionError: Indicating that the RPC was aborted. - """ + Args: + request_iterator: An iterator that yields request values for the RPC. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of + the RPC. + with_call: Whether or not to include return a Call for the RPC in addition + to the response. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + The response value for the RPC, and a Call for the RPC if with_call was + set to True at invocation. + + Raises: + AbortionError: Indicating that the RPC was aborted. + """ raise NotImplementedError() @abc.abstractmethod - def future(self, - request_iterator, - timeout, - metadata=None, - protocol_options=None): + def future( + self, request_iterator, timeout, metadata=None, protocol_options=None + ): """Asynchronously invokes the underlying RPC. - Args: - request_iterator: An iterator that yields request values for the RPC. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of - the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - An object that is both a Call for the RPC and a future.Future. In the - event of RPC completion, the return Future's result value will be the - response value of the RPC. In the event of RPC abortion, the returned - Future's exception value will be an AbortionError. - """ + Args: + request_iterator: An iterator that yields request values for the RPC. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of + the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + An object that is both a Call for the RPC and a future.Future. In the + event of RPC completion, the return Future's result value will be the + response value of the RPC. In the event of RPC abortion, the returned + Future's exception value will be an AbortionError. + """ raise NotImplementedError() @abc.abstractmethod - def event(self, - receiver, - abortion_callback, - timeout, - metadata=None, - protocol_options=None): + def event( + self, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None, + ): """Asynchronously invokes the underlying RPC. - Args: - receiver: A ResponseReceiver to be passed the response data of the RPC. - abortion_callback: A callback to be called and passed an Abortion value - in the event of RPC abortion. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of - the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - A single object that is both a Call object for the RPC and a - stream.Consumer to which the request values of the RPC should be passed. - """ + Args: + receiver: A ResponseReceiver to be passed the response data of the RPC. + abortion_callback: A callback to be called and passed an Abortion value + in the event of RPC abortion. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of + the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + A single object that is both a Call object for the RPC and a + stream.Consumer to which the request values of the RPC should be passed. + """ raise NotImplementedError() @@ -561,97 +576,97 @@ class StreamStreamMultiCallable(abc.ABC): """Affords invoking a stream-stream RPC in any call style.""" @abc.abstractmethod - def __call__(self, - request_iterator, - timeout, - metadata=None, - protocol_options=None): + def __call__( + self, request_iterator, timeout, metadata=None, protocol_options=None + ): """Invokes the underlying RPC. - Args: - request_iterator: An iterator that yields request values for the RPC. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of - the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - An object that is both a Call for the RPC and an iterator of response - values. Drawing response values from the returned iterator may raise - AbortionError indicating abortion of the RPC. - """ + Args: + request_iterator: An iterator that yields request values for the RPC. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of + the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + An object that is both a Call for the RPC and an iterator of response + values. Drawing response values from the returned iterator may raise + AbortionError indicating abortion of the RPC. + """ raise NotImplementedError() @abc.abstractmethod - def event(self, - receiver, - abortion_callback, - timeout, - metadata=None, - protocol_options=None): + def event( + self, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None, + ): """Asynchronously invokes the underlying RPC. - Args: - receiver: A ResponseReceiver to be passed the response data of the RPC. - abortion_callback: A callback to be called and passed an Abortion value - in the event of RPC abortion. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of - the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - A single object that is both a Call object for the RPC and a - stream.Consumer to which the request values of the RPC should be passed. - """ + Args: + receiver: A ResponseReceiver to be passed the response data of the RPC. + abortion_callback: A callback to be called and passed an Abortion value + in the event of RPC abortion. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of + the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + A single object that is both a Call object for the RPC and a + stream.Consumer to which the request values of the RPC should be passed. + """ raise NotImplementedError() class MethodImplementation(abc.ABC): """A sum type that describes a method implementation. - Attributes: - cardinality: A cardinality.Cardinality value. - style: A style.Service value. - unary_unary_inline: The implementation of the method as a callable value - that takes a request value and a ServicerContext object and returns a - response value. Only non-None if cardinality is - cardinality.Cardinality.UNARY_UNARY and style is style.Service.INLINE. - unary_stream_inline: The implementation of the method as a callable value - that takes a request value and a ServicerContext object and returns an - iterator of response values. Only non-None if cardinality is - cardinality.Cardinality.UNARY_STREAM and style is style.Service.INLINE. - stream_unary_inline: The implementation of the method as a callable value - that takes an iterator of request values and a ServicerContext object and - returns a response value. Only non-None if cardinality is - cardinality.Cardinality.STREAM_UNARY and style is style.Service.INLINE. - stream_stream_inline: The implementation of the method as a callable value - that takes an iterator of request values and a ServicerContext object and - returns an iterator of response values. Only non-None if cardinality is - cardinality.Cardinality.STREAM_STREAM and style is style.Service.INLINE. - unary_unary_event: The implementation of the method as a callable value that - takes a request value, a response callback to which to pass the response - value of the RPC, and a ServicerContext. Only non-None if cardinality is - cardinality.Cardinality.UNARY_UNARY and style is style.Service.EVENT. - unary_stream_event: The implementation of the method as a callable value - that takes a request value, a stream.Consumer to which to pass the - response values of the RPC, and a ServicerContext. Only non-None if - cardinality is cardinality.Cardinality.UNARY_STREAM and style is - style.Service.EVENT. - stream_unary_event: The implementation of the method as a callable value - that takes a response callback to which to pass the response value of the - RPC and a ServicerContext and returns a stream.Consumer to which the - request values of the RPC should be passed. Only non-None if cardinality - is cardinality.Cardinality.STREAM_UNARY and style is style.Service.EVENT. - stream_stream_event: The implementation of the method as a callable value - that takes a stream.Consumer to which to pass the response values of the - RPC and a ServicerContext and returns a stream.Consumer to which the - request values of the RPC should be passed. Only non-None if cardinality - is cardinality.Cardinality.STREAM_STREAM and style is - style.Service.EVENT. - """ + Attributes: + cardinality: A cardinality.Cardinality value. + style: A style.Service value. + unary_unary_inline: The implementation of the method as a callable value + that takes a request value and a ServicerContext object and returns a + response value. Only non-None if cardinality is + cardinality.Cardinality.UNARY_UNARY and style is style.Service.INLINE. + unary_stream_inline: The implementation of the method as a callable value + that takes a request value and a ServicerContext object and returns an + iterator of response values. Only non-None if cardinality is + cardinality.Cardinality.UNARY_STREAM and style is style.Service.INLINE. + stream_unary_inline: The implementation of the method as a callable value + that takes an iterator of request values and a ServicerContext object and + returns a response value. Only non-None if cardinality is + cardinality.Cardinality.STREAM_UNARY and style is style.Service.INLINE. + stream_stream_inline: The implementation of the method as a callable value + that takes an iterator of request values and a ServicerContext object and + returns an iterator of response values. Only non-None if cardinality is + cardinality.Cardinality.STREAM_STREAM and style is style.Service.INLINE. + unary_unary_event: The implementation of the method as a callable value that + takes a request value, a response callback to which to pass the response + value of the RPC, and a ServicerContext. Only non-None if cardinality is + cardinality.Cardinality.UNARY_UNARY and style is style.Service.EVENT. + unary_stream_event: The implementation of the method as a callable value + that takes a request value, a stream.Consumer to which to pass the + response values of the RPC, and a ServicerContext. Only non-None if + cardinality is cardinality.Cardinality.UNARY_STREAM and style is + style.Service.EVENT. + stream_unary_event: The implementation of the method as a callable value + that takes a response callback to which to pass the response value of the + RPC and a ServicerContext and returns a stream.Consumer to which the + request values of the RPC should be passed. Only non-None if cardinality + is cardinality.Cardinality.STREAM_UNARY and style is style.Service.EVENT. + stream_stream_event: The implementation of the method as a callable value + that takes a stream.Consumer to which to pass the response values of the + RPC and a ServicerContext and returns a stream.Consumer to which the + request values of the RPC should be passed. Only non-None if cardinality + is cardinality.Cardinality.STREAM_STREAM and style is + style.Service.EVENT. + """ class MultiMethodImplementation(abc.ABC): @@ -661,27 +676,27 @@ class MultiMethodImplementation(abc.ABC): def service(self, group, method, response_consumer, context): """Services an RPC. - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. - response_consumer: A stream.Consumer to be called to accept the response - values of the RPC. - context: a ServicerContext object. - - Returns: - A stream.Consumer with which to accept the request values of the RPC. The - consumer returned from this method may or may not be invoked to - completion: in the case of RPC abortion, RPC Framework will simply stop - passing values to this object. Implementations must not assume that this - object will be called to completion of the request stream or even called - at all. - - Raises: - abandonment.Abandoned: May or may not be raised when the RPC has been - aborted. - NoSuchMethodError: If this MultiMethod does not recognize the given group - and name for the RPC and is not able to service the RPC. - """ + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. + response_consumer: A stream.Consumer to be called to accept the response + values of the RPC. + context: a ServicerContext object. + + Returns: + A stream.Consumer with which to accept the request values of the RPC. The + consumer returned from this method may or may not be invoked to + completion: in the case of RPC abortion, RPC Framework will simply stop + passing values to this object. Implementations must not assume that this + object will be called to completion of the request stream or even called + at all. + + Raises: + abandonment.Abandoned: May or may not be raised when the RPC has been + aborted. + NoSuchMethodError: If this MultiMethod does not recognize the given group + and name for the RPC and is not able to service the RPC. + """ raise NotImplementedError() @@ -689,361 +704,381 @@ class GenericStub(abc.ABC): """Affords RPC invocation via generic methods.""" @abc.abstractmethod - def blocking_unary_unary(self, - group, - method, - request, - timeout, - metadata=None, - with_call=False, - protocol_options=None): + def blocking_unary_unary( + self, + group, + method, + request, + timeout, + metadata=None, + with_call=False, + protocol_options=None, + ): """Invokes a unary-request-unary-response method. - This method blocks until either returning the response value of the RPC - (in the event of RPC completion) or raising an exception (in the event of - RPC abortion). - - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. - request: The request value for the RPC. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of the RPC. - with_call: Whether or not to include return a Call for the RPC in addition - to the response. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - The response value for the RPC, and a Call for the RPC if with_call was - set to True at invocation. - - Raises: - AbortionError: Indicating that the RPC was aborted. - """ + This method blocks until either returning the response value of the RPC + (in the event of RPC completion) or raising an exception (in the event of + RPC abortion). + + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. + request: The request value for the RPC. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of the RPC. + with_call: Whether or not to include return a Call for the RPC in addition + to the response. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + The response value for the RPC, and a Call for the RPC if with_call was + set to True at invocation. + + Raises: + AbortionError: Indicating that the RPC was aborted. + """ raise NotImplementedError() @abc.abstractmethod - def future_unary_unary(self, - group, - method, - request, - timeout, - metadata=None, - protocol_options=None): + def future_unary_unary( + self, + group, + method, + request, + timeout, + metadata=None, + protocol_options=None, + ): """Invokes a unary-request-unary-response method. - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. - request: The request value for the RPC. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - An object that is both a Call for the RPC and a future.Future. In the - event of RPC completion, the return Future's result value will be the - response value of the RPC. In the event of RPC abortion, the returned - Future's exception value will be an AbortionError. - """ + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. + request: The request value for the RPC. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + An object that is both a Call for the RPC and a future.Future. In the + event of RPC completion, the return Future's result value will be the + response value of the RPC. In the event of RPC abortion, the returned + Future's exception value will be an AbortionError. + """ raise NotImplementedError() @abc.abstractmethod - def inline_unary_stream(self, - group, - method, - request, - timeout, - metadata=None, - protocol_options=None): + def inline_unary_stream( + self, + group, + method, + request, + timeout, + metadata=None, + protocol_options=None, + ): """Invokes a unary-request-stream-response method. - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. - request: The request value for the RPC. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - An object that is both a Call for the RPC and an iterator of response - values. Drawing response values from the returned iterator may raise - AbortionError indicating abortion of the RPC. - """ + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. + request: The request value for the RPC. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + An object that is both a Call for the RPC and an iterator of response + values. Drawing response values from the returned iterator may raise + AbortionError indicating abortion of the RPC. + """ raise NotImplementedError() @abc.abstractmethod - def blocking_stream_unary(self, - group, - method, - request_iterator, - timeout, - metadata=None, - with_call=False, - protocol_options=None): + def blocking_stream_unary( + self, + group, + method, + request_iterator, + timeout, + metadata=None, + with_call=False, + protocol_options=None, + ): """Invokes a stream-request-unary-response method. - This method blocks until either returning the response value of the RPC - (in the event of RPC completion) or raising an exception (in the event of - RPC abortion). - - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. - request_iterator: An iterator that yields request values for the RPC. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of the RPC. - with_call: Whether or not to include return a Call for the RPC in addition - to the response. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - The response value for the RPC, and a Call for the RPC if with_call was - set to True at invocation. - - Raises: - AbortionError: Indicating that the RPC was aborted. - """ + This method blocks until either returning the response value of the RPC + (in the event of RPC completion) or raising an exception (in the event of + RPC abortion). + + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. + request_iterator: An iterator that yields request values for the RPC. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of the RPC. + with_call: Whether or not to include return a Call for the RPC in addition + to the response. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + The response value for the RPC, and a Call for the RPC if with_call was + set to True at invocation. + + Raises: + AbortionError: Indicating that the RPC was aborted. + """ raise NotImplementedError() @abc.abstractmethod - def future_stream_unary(self, - group, - method, - request_iterator, - timeout, - metadata=None, - protocol_options=None): + def future_stream_unary( + self, + group, + method, + request_iterator, + timeout, + metadata=None, + protocol_options=None, + ): """Invokes a stream-request-unary-response method. - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. - request_iterator: An iterator that yields request values for the RPC. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - An object that is both a Call for the RPC and a future.Future. In the - event of RPC completion, the return Future's result value will be the - response value of the RPC. In the event of RPC abortion, the returned - Future's exception value will be an AbortionError. - """ + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. + request_iterator: An iterator that yields request values for the RPC. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + An object that is both a Call for the RPC and a future.Future. In the + event of RPC completion, the return Future's result value will be the + response value of the RPC. In the event of RPC abortion, the returned + Future's exception value will be an AbortionError. + """ raise NotImplementedError() @abc.abstractmethod - def inline_stream_stream(self, - group, - method, - request_iterator, - timeout, - metadata=None, - protocol_options=None): + def inline_stream_stream( + self, + group, + method, + request_iterator, + timeout, + metadata=None, + protocol_options=None, + ): """Invokes a stream-request-stream-response method. - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. - request_iterator: An iterator that yields request values for the RPC. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - An object that is both a Call for the RPC and an iterator of response - values. Drawing response values from the returned iterator may raise - AbortionError indicating abortion of the RPC. - """ + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. + request_iterator: An iterator that yields request values for the RPC. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + An object that is both a Call for the RPC and an iterator of response + values. Drawing response values from the returned iterator may raise + AbortionError indicating abortion of the RPC. + """ raise NotImplementedError() @abc.abstractmethod - def event_unary_unary(self, - group, - method, - request, - receiver, - abortion_callback, - timeout, - metadata=None, - protocol_options=None): + def event_unary_unary( + self, + group, + method, + request, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None, + ): """Event-driven invocation of a unary-request-unary-response method. - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. - request: The request value for the RPC. - receiver: A ResponseReceiver to be passed the response data of the RPC. - abortion_callback: A callback to be called and passed an Abortion value - in the event of RPC abortion. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - A Call for the RPC. - """ + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. + request: The request value for the RPC. + receiver: A ResponseReceiver to be passed the response data of the RPC. + abortion_callback: A callback to be called and passed an Abortion value + in the event of RPC abortion. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + A Call for the RPC. + """ raise NotImplementedError() @abc.abstractmethod - def event_unary_stream(self, - group, - method, - request, - receiver, - abortion_callback, - timeout, - metadata=None, - protocol_options=None): + def event_unary_stream( + self, + group, + method, + request, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None, + ): """Event-driven invocation of a unary-request-stream-response method. - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. - request: The request value for the RPC. - receiver: A ResponseReceiver to be passed the response data of the RPC. - abortion_callback: A callback to be called and passed an Abortion value - in the event of RPC abortion. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - A Call for the RPC. - """ + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. + request: The request value for the RPC. + receiver: A ResponseReceiver to be passed the response data of the RPC. + abortion_callback: A callback to be called and passed an Abortion value + in the event of RPC abortion. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + A Call for the RPC. + """ raise NotImplementedError() @abc.abstractmethod - def event_stream_unary(self, - group, - method, - receiver, - abortion_callback, - timeout, - metadata=None, - protocol_options=None): + def event_stream_unary( + self, + group, + method, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None, + ): """Event-driven invocation of a unary-request-unary-response method. - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. - receiver: A ResponseReceiver to be passed the response data of the RPC. - abortion_callback: A callback to be called and passed an Abortion value - in the event of RPC abortion. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - A pair of a Call object for the RPC and a stream.Consumer to which the - request values of the RPC should be passed. - """ + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. + receiver: A ResponseReceiver to be passed the response data of the RPC. + abortion_callback: A callback to be called and passed an Abortion value + in the event of RPC abortion. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + A pair of a Call object for the RPC and a stream.Consumer to which the + request values of the RPC should be passed. + """ raise NotImplementedError() @abc.abstractmethod - def event_stream_stream(self, - group, - method, - receiver, - abortion_callback, - timeout, - metadata=None, - protocol_options=None): + def event_stream_stream( + self, + group, + method, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None, + ): """Event-driven invocation of a unary-request-stream-response method. - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. - receiver: A ResponseReceiver to be passed the response data of the RPC. - abortion_callback: A callback to be called and passed an Abortion value - in the event of RPC abortion. - timeout: A duration of time in seconds to allow for the RPC. - metadata: A metadata value to be passed to the service-side of the RPC. - protocol_options: A value specified by the provider of a Face interface - implementation affording custom state and behavior. - - Returns: - A pair of a Call object for the RPC and a stream.Consumer to which the - request values of the RPC should be passed. - """ + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. + receiver: A ResponseReceiver to be passed the response data of the RPC. + abortion_callback: A callback to be called and passed an Abortion value + in the event of RPC abortion. + timeout: A duration of time in seconds to allow for the RPC. + metadata: A metadata value to be passed to the service-side of the RPC. + protocol_options: A value specified by the provider of a Face interface + implementation affording custom state and behavior. + + Returns: + A pair of a Call object for the RPC and a stream.Consumer to which the + request values of the RPC should be passed. + """ raise NotImplementedError() @abc.abstractmethod def unary_unary(self, group, method): """Creates a UnaryUnaryMultiCallable for a unary-unary method. - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. - Returns: - A UnaryUnaryMultiCallable value for the named unary-unary method. - """ + Returns: + A UnaryUnaryMultiCallable value for the named unary-unary method. + """ raise NotImplementedError() @abc.abstractmethod def unary_stream(self, group, method): """Creates a UnaryStreamMultiCallable for a unary-stream method. - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. - Returns: - A UnaryStreamMultiCallable value for the name unary-stream method. - """ + Returns: + A UnaryStreamMultiCallable value for the name unary-stream method. + """ raise NotImplementedError() @abc.abstractmethod def stream_unary(self, group, method): """Creates a StreamUnaryMultiCallable for a stream-unary method. - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. - Returns: - A StreamUnaryMultiCallable value for the named stream-unary method. - """ + Returns: + A StreamUnaryMultiCallable value for the named stream-unary method. + """ raise NotImplementedError() @abc.abstractmethod def stream_stream(self, group, method): """Creates a StreamStreamMultiCallable for a stream-stream method. - Args: - group: The group identifier of the RPC. - method: The method identifier of the RPC. + Args: + group: The group identifier of the RPC. + method: The method identifier of the RPC. - Returns: - A StreamStreamMultiCallable value for the named stream-stream method. - """ + Returns: + A StreamStreamMultiCallable value for the named stream-stream method. + """ raise NotImplementedError() class DynamicStub(abc.ABC): """Affords RPC invocation via attributes corresponding to afforded methods. - Instances of this type may be scoped to a single group so that attribute - access is unambiguous. - - Instances of this type respond to attribute access as follows: if the - requested attribute is the name of a unary-unary method, the value of the - attribute will be a UnaryUnaryMultiCallable with which to invoke an RPC; if - the requested attribute is the name of a unary-stream method, the value of the - attribute will be a UnaryStreamMultiCallable with which to invoke an RPC; if - the requested attribute is the name of a stream-unary method, the value of the - attribute will be a StreamUnaryMultiCallable with which to invoke an RPC; and - if the requested attribute is the name of a stream-stream method, the value of - the attribute will be a StreamStreamMultiCallable with which to invoke an RPC. - """ + Instances of this type may be scoped to a single group so that attribute + access is unambiguous. + + Instances of this type respond to attribute access as follows: if the + requested attribute is the name of a unary-unary method, the value of the + attribute will be a UnaryUnaryMultiCallable with which to invoke an RPC; if + the requested attribute is the name of a unary-stream method, the value of the + attribute will be a UnaryStreamMultiCallable with which to invoke an RPC; if + the requested attribute is the name of a stream-unary method, the value of the + attribute will be a StreamUnaryMultiCallable with which to invoke an RPC; and + if the requested attribute is the name of a stream-stream method, the value of + the attribute will be a StreamStreamMultiCallable with which to invoke an RPC. + """ diff --git a/contrib/python/grpcio/py3/grpc/framework/interfaces/face/utilities.py b/contrib/python/grpcio/py3/grpc/framework/interfaces/face/utilities.py index f27bd676155..01807a16026 100644 --- a/contrib/python/grpcio/py3/grpc/framework/interfaces/face/utilities.py +++ b/contrib/python/grpcio/py3/grpc/framework/interfaces/face/utilities.py @@ -22,147 +22,224 @@ from grpc.framework.foundation import stream # pylint: disable=unused-import from grpc.framework.interfaces.face import face -class _MethodImplementation(face.MethodImplementation, - collections.namedtuple('_MethodImplementation', [ - 'cardinality', - 'style', - 'unary_unary_inline', - 'unary_stream_inline', - 'stream_unary_inline', - 'stream_stream_inline', - 'unary_unary_event', - 'unary_stream_event', - 'stream_unary_event', - 'stream_stream_event', - ])): +class _MethodImplementation( + face.MethodImplementation, + collections.namedtuple( + "_MethodImplementation", + [ + "cardinality", + "style", + "unary_unary_inline", + "unary_stream_inline", + "stream_unary_inline", + "stream_stream_inline", + "unary_unary_event", + "unary_stream_event", + "stream_unary_event", + "stream_stream_event", + ], + ), +): pass def unary_unary_inline(behavior): """Creates an face.MethodImplementation for the given behavior. - Args: - behavior: The implementation of a unary-unary RPC method as a callable value - that takes a request value and an face.ServicerContext object and - returns a response value. - - Returns: - An face.MethodImplementation derived from the given behavior. - """ - return _MethodImplementation(cardinality.Cardinality.UNARY_UNARY, - style.Service.INLINE, behavior, None, None, - None, None, None, None, None) + Args: + behavior: The implementation of a unary-unary RPC method as a callable value + that takes a request value and an face.ServicerContext object and + returns a response value. + + Returns: + An face.MethodImplementation derived from the given behavior. + """ + return _MethodImplementation( + cardinality.Cardinality.UNARY_UNARY, + style.Service.INLINE, + behavior, + None, + None, + None, + None, + None, + None, + None, + ) def unary_stream_inline(behavior): """Creates an face.MethodImplementation for the given behavior. - Args: - behavior: The implementation of a unary-stream RPC method as a callable - value that takes a request value and an face.ServicerContext object and - returns an iterator of response values. - - Returns: - An face.MethodImplementation derived from the given behavior. - """ - return _MethodImplementation(cardinality.Cardinality.UNARY_STREAM, - style.Service.INLINE, None, behavior, None, - None, None, None, None, None) + Args: + behavior: The implementation of a unary-stream RPC method as a callable + value that takes a request value and an face.ServicerContext object and + returns an iterator of response values. + + Returns: + An face.MethodImplementation derived from the given behavior. + """ + return _MethodImplementation( + cardinality.Cardinality.UNARY_STREAM, + style.Service.INLINE, + None, + behavior, + None, + None, + None, + None, + None, + None, + ) def stream_unary_inline(behavior): """Creates an face.MethodImplementation for the given behavior. - Args: - behavior: The implementation of a stream-unary RPC method as a callable - value that takes an iterator of request values and an - face.ServicerContext object and returns a response value. - - Returns: - An face.MethodImplementation derived from the given behavior. - """ - return _MethodImplementation(cardinality.Cardinality.STREAM_UNARY, - style.Service.INLINE, None, None, behavior, - None, None, None, None, None) + Args: + behavior: The implementation of a stream-unary RPC method as a callable + value that takes an iterator of request values and an + face.ServicerContext object and returns a response value. + + Returns: + An face.MethodImplementation derived from the given behavior. + """ + return _MethodImplementation( + cardinality.Cardinality.STREAM_UNARY, + style.Service.INLINE, + None, + None, + behavior, + None, + None, + None, + None, + None, + ) def stream_stream_inline(behavior): """Creates an face.MethodImplementation for the given behavior. - Args: - behavior: The implementation of a stream-stream RPC method as a callable - value that takes an iterator of request values and an - face.ServicerContext object and returns an iterator of response values. - - Returns: - An face.MethodImplementation derived from the given behavior. - """ - return _MethodImplementation(cardinality.Cardinality.STREAM_STREAM, - style.Service.INLINE, None, None, None, - behavior, None, None, None, None) + Args: + behavior: The implementation of a stream-stream RPC method as a callable + value that takes an iterator of request values and an + face.ServicerContext object and returns an iterator of response values. + + Returns: + An face.MethodImplementation derived from the given behavior. + """ + return _MethodImplementation( + cardinality.Cardinality.STREAM_STREAM, + style.Service.INLINE, + None, + None, + None, + behavior, + None, + None, + None, + None, + ) def unary_unary_event(behavior): """Creates an face.MethodImplementation for the given behavior. - Args: - behavior: The implementation of a unary-unary RPC method as a callable - value that takes a request value, a response callback to which to pass - the response value of the RPC, and an face.ServicerContext. - - Returns: - An face.MethodImplementation derived from the given behavior. - """ - return _MethodImplementation(cardinality.Cardinality.UNARY_UNARY, - style.Service.EVENT, None, None, None, None, - behavior, None, None, None) + Args: + behavior: The implementation of a unary-unary RPC method as a callable + value that takes a request value, a response callback to which to pass + the response value of the RPC, and an face.ServicerContext. + + Returns: + An face.MethodImplementation derived from the given behavior. + """ + return _MethodImplementation( + cardinality.Cardinality.UNARY_UNARY, + style.Service.EVENT, + None, + None, + None, + None, + behavior, + None, + None, + None, + ) def unary_stream_event(behavior): """Creates an face.MethodImplementation for the given behavior. - Args: - behavior: The implementation of a unary-stream RPC method as a callable - value that takes a request value, a stream.Consumer to which to pass the - the response values of the RPC, and an face.ServicerContext. - - Returns: - An face.MethodImplementation derived from the given behavior. - """ - return _MethodImplementation(cardinality.Cardinality.UNARY_STREAM, - style.Service.EVENT, None, None, None, None, - None, behavior, None, None) + Args: + behavior: The implementation of a unary-stream RPC method as a callable + value that takes a request value, a stream.Consumer to which to pass the + the response values of the RPC, and an face.ServicerContext. + + Returns: + An face.MethodImplementation derived from the given behavior. + """ + return _MethodImplementation( + cardinality.Cardinality.UNARY_STREAM, + style.Service.EVENT, + None, + None, + None, + None, + None, + behavior, + None, + None, + ) def stream_unary_event(behavior): """Creates an face.MethodImplementation for the given behavior. - Args: - behavior: The implementation of a stream-unary RPC method as a callable - value that takes a response callback to which to pass the response value - of the RPC and an face.ServicerContext and returns a stream.Consumer to - which the request values of the RPC should be passed. - - Returns: - An face.MethodImplementation derived from the given behavior. - """ - return _MethodImplementation(cardinality.Cardinality.STREAM_UNARY, - style.Service.EVENT, None, None, None, None, - None, None, behavior, None) + Args: + behavior: The implementation of a stream-unary RPC method as a callable + value that takes a response callback to which to pass the response value + of the RPC and an face.ServicerContext and returns a stream.Consumer to + which the request values of the RPC should be passed. + + Returns: + An face.MethodImplementation derived from the given behavior. + """ + return _MethodImplementation( + cardinality.Cardinality.STREAM_UNARY, + style.Service.EVENT, + None, + None, + None, + None, + None, + None, + behavior, + None, + ) def stream_stream_event(behavior): """Creates an face.MethodImplementation for the given behavior. - Args: - behavior: The implementation of a stream-stream RPC method as a callable - value that takes a stream.Consumer to which to pass the response values - of the RPC and an face.ServicerContext and returns a stream.Consumer to - which the request values of the RPC should be passed. - - Returns: - An face.MethodImplementation derived from the given behavior. - """ - return _MethodImplementation(cardinality.Cardinality.STREAM_STREAM, - style.Service.EVENT, None, None, None, None, - None, None, None, behavior) + Args: + behavior: The implementation of a stream-stream RPC method as a callable + value that takes a stream.Consumer to which to pass the response values + of the RPC and an face.ServicerContext and returns a stream.Consumer to + which the request values of the RPC should be passed. + + Returns: + An face.MethodImplementation derived from the given behavior. + """ + return _MethodImplementation( + cardinality.Cardinality.STREAM_STREAM, + style.Service.EVENT, + None, + None, + None, + None, + None, + None, + None, + behavior, + ) |