123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050 |
- # Copyright 2015 gRPC authors.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- """Interfaces defining the Face layer of RPC Framework."""
- import abc
- import collections
- import enum
- # cardinality, style, abandonment, future, and stream are
- # referenced from specification in this module.
- from grpc.framework.common import cardinality # pylint: disable=unused-import
- from grpc.framework.common import style # pylint: disable=unused-import
- from grpc.framework.foundation import future # pylint: disable=unused-import
- from grpc.framework.foundation import stream # pylint: disable=unused-import
- import six
- # pylint: disable=too-many-arguments
- 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.
- """
- 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.
- """
- super(NoSuchMethodError, self).__init__()
- self.group = group
- self.method = method
- def __repr__(self):
- return 'face.NoSuchMethodError(%s, %s)' % (
- self.group,
- self.method,
- )
- class Abortion(
- 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.
- """
- @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'
- class AbortionError(six.with_metaclass(abc.ABCMeta, Exception)):
- """Common super type for exceptions indicating RPC abortion.
- 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.
- """
- def __init__(self, initial_metadata, terminal_metadata, code, details):
- super(AbortionError, self).__init__()
- self.initial_metadata = initial_metadata
- self.terminal_metadata = terminal_metadata
- self.code = code
- self.details = details
- def __str__(self):
- return '%s(code=%s, details="%s")' % (self.__class__.__name__,
- self.code, self.details)
- class CancellationError(AbortionError):
- """Indicates that an RPC has been cancelled."""
- class ExpirationError(AbortionError):
- """Indicates that an RPC has expired ("timed out")."""
- class LocalShutdownError(AbortionError):
- """Indicates that an RPC has terminated due to local shutdown of RPCs."""
- class RemoteShutdownError(AbortionError):
- """Indicates that an RPC has terminated due to remote shutdown of RPCs."""
- class NetworkError(AbortionError):
- """Indicates that some error occurred on the network."""
- class LocalError(AbortionError):
- """Indicates that an RPC has terminated due to a local defect."""
- class RemoteError(AbortionError):
- """Indicates that an RPC has terminated due to a remote defect."""
- class RpcContext(six.with_metaclass(abc.ABCMeta)):
- """Provides RPC-related information and action."""
- @abc.abstractmethod
- def is_active(self):
- """Describes whether the RPC is active or has terminated."""
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- 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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- def cancel(self):
- """Cancels the RPC.
- 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.
- """
- raise NotImplementedError()
- class Call(six.with_metaclass(abc.ABCMeta, RpcContext)):
- """Invocation-side utility object for an RPC."""
- @abc.abstractmethod
- 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.
- 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.
- 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.
- 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.
- Returns:
- The details value emitted by the service-side of the RPC, or None if there
- was no such value.
- """
- raise NotImplementedError()
- class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)):
- """A context object passed to method implementations."""
- @abc.abstractmethod
- 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.
- 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.
- 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.
- 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.
- 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.
- Args:
- details: The service-side details value of the RPC to be transmitted to
- the invocation side of the RPC.
- """
- raise NotImplementedError()
- class ResponseReceiver(six.with_metaclass(abc.ABCMeta)):
- """Invocation-side object used to accept the output of an RPC."""
- @abc.abstractmethod
- 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.
- """
- 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.
- """
- 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.
- """
- raise NotImplementedError()
- class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)):
- """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):
- """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.
- """
- 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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- class UnaryStreamMultiCallable(six.with_metaclass(abc.ABCMeta)):
- """Affords invoking a unary-stream RPC in any call style."""
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)):
- """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):
- """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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- class StreamStreamMultiCallable(six.with_metaclass(abc.ABCMeta)):
- """Affords invoking a stream-stream RPC in any call style."""
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- class MethodImplementation(six.with_metaclass(abc.ABCMeta)):
- """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.
- """
- class MultiMethodImplementation(six.with_metaclass(abc.ABCMeta)):
- """A general type able to service many methods."""
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- class GenericStub(six.with_metaclass(abc.ABCMeta)):
- """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):
- """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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- raise NotImplementedError()
- @abc.abstractmethod
- 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.
- """
- 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.
- 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.
- 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.
- 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.
- Returns:
- A StreamStreamMultiCallable value for the named stream-stream method.
- """
- raise NotImplementedError()
- class DynamicStub(six.with_metaclass(abc.ABCMeta)):
- """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.
- """
|