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 = [] if interceptors: attrs_and_interceptor_classes = ((self._unary_unary_interceptors, UnaryUnaryClientInterceptor), (self._unary_stream_interceptors, UnaryStreamClientInterceptor), (self._stream_unary_interceptors, StreamUnaryClientInterceptor)) # pylint: disable=cell-var-from-loop for attr, interceptor_class in attrs_and_interceptor_classes: attr.extend([ interceptor for interceptor in interceptors if isinstance(interceptor, interceptor_class) ]) invalid_interceptors = set(interceptors) - set( self._unary_unary_interceptors) - set( self._unary_stream_interceptors) - set( self._stream_unary_interceptors) if invalid_interceptors: raise ValueError( "Interceptor must be " + "{} or ".format(UnaryUnaryClientInterceptor.__name__) + "{} or ".format(UnaryStreamClientInterceptor.__name__) + "{}. ".format(StreamUnaryClientInterceptor.__name__) + "The following are invalid: {}".format(invalid_interceptors) ) self._loop = asyncio.get_event_loop() self._channel = cygrpc.AioChannel( _common.encode(target), _augment_channel_arguments(options, compression), credentials, self._loop)
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, target: Text, options: Optional[ChannelArgumentType], credentials: Optional[grpc.ChannelCredentials], compression: Optional[grpc.Compression], interceptors: Optional[Sequence[UnaryUnaryClientInterceptor]]): """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. """ if compression: raise NotImplementedError("TODO: compression not implemented yet") if interceptors is None: self._unary_unary_interceptors = None else: self._unary_unary_interceptors = list( filter( lambda interceptor: isinstance( interceptor, UnaryUnaryClientInterceptor), interceptors)) invalid_interceptors = set(interceptors) - set( self._unary_unary_interceptors) if invalid_interceptors: raise ValueError( "Interceptor must be "+\ "UnaryUnaryClientInterceptors, the following are invalid: {}"\ .format(invalid_interceptors)) self._loop = asyncio.get_event_loop() self._channel = cygrpc.AioChannel(_common.encode(target), options, credentials, self._loop) self._ongoing_calls = _OngoingCalls()
def __init__(self, target, options, credentials, compression): """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. """ if options: raise NotImplementedError("TODO: options not implemented yet") if credentials: raise NotImplementedError("TODO: credentials not implemented yet") if compression: raise NotImplementedError("TODO: compression not implemented yet") self._channel = cygrpc.AioChannel(_common.encode(target))