Exemple #1
0
    def __init__(self, target: str, options: ChannelArgumentType,
                 credentials: Optional[grpc.ChannelCredentials],
                 compression: Optional[grpc.Compression],
                 interceptors: Optional[Sequence[ClientInterceptor]]):
        """Constructor.

        Args:
          target: The target to which to connect.
          options: Configuration options for the channel.
          credentials: A cygrpc.ChannelCredentials or None.
          compression: An optional value indicating the compression method to be
            used over the lifetime of the channel.
          interceptors: An optional list of interceptors that would be used for
            intercepting any RPC executed with that channel.
        """
        self._unary_unary_interceptors = []
        self._unary_stream_interceptors = []
        self._stream_unary_interceptors = []
        self._stream_stream_interceptors = []

        if interceptors is not None:
            for interceptor in interceptors:
                if isinstance(interceptor, UnaryUnaryClientInterceptor):
                    self._unary_unary_interceptors.append(interceptor)
                elif isinstance(interceptor, UnaryStreamClientInterceptor):
                    self._unary_stream_interceptors.append(interceptor)
                elif isinstance(interceptor, StreamUnaryClientInterceptor):
                    self._stream_unary_interceptors.append(interceptor)
                elif isinstance(interceptor, StreamStreamClientInterceptor):
                    self._stream_stream_interceptors.append(interceptor)
                else:
                    raise ValueError(
                        "Interceptor {} must be ".format(interceptor) +
                        "{} or ".format(UnaryUnaryClientInterceptor.__name__) +
                        "{} or ".format(UnaryStreamClientInterceptor.__name__)
                        + "{} or ".format(
                            StreamUnaryClientInterceptor.__name__) +
                        "{}. ".format(StreamStreamClientInterceptor.__name__))

        self._loop = cygrpc.get_working_loop()
        self._channel = cygrpc.AioChannel(
            _common.encode(target),
            _augment_channel_arguments(options, compression), credentials,
            self._loop)
 def __init__(self, thread_pool: Optional[Executor],
              generic_handlers: Optional[Sequence[grpc.GenericRpcHandler]],
              interceptors: Optional[Sequence[Any]],
              options: ChannelArgumentType,
              maximum_concurrent_rpcs: Optional[int],
              compression: Optional[grpc.Compression]):
     self._loop = cygrpc.get_working_loop()
     if interceptors:
         invalid_interceptors = [
             interceptor for interceptor in interceptors
             if not isinstance(interceptor, ServerInterceptor)
         ]
         if invalid_interceptors:
             raise ValueError(
                 'Interceptor must be ServerInterceptor, the '
                 f'following are invalid: {invalid_interceptors}')
     self._server = cygrpc.AioServer(
         self._loop, thread_pool, generic_handlers, interceptors,
         _augment_channel_arguments(options, compression),
         maximum_concurrent_rpcs)