Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __mapping__(self) -> typing.Dict[str, grpclib.const.Handler]:
return {
'/dummy.DummyService/UnaryUnary': grpclib.const.Handler(
self.UnaryUnary,
grpclib.const.Cardinality.UNARY_UNARY,
dummy_pb2.DummyRequest,
dummy_pb2.DummyReply,
),
'/dummy.DummyService/UnaryStream': grpclib.const.Handler(
self.UnaryStream,
grpclib.const.Cardinality.UNARY_STREAM,
dummy_pb2.DummyRequest,
dummy_pb2.DummyReply,
),
'/dummy.DummyService/StreamUnary': grpclib.const.Handler(
self.StreamUnary,
grpclib.const.Cardinality.STREAM_UNARY,
dummy_pb2.DummyRequest,
dummy_pb2.DummyReply,
),
'/dummy.DummyService/StreamStream': grpclib.const.Handler(
self.StreamStream,
grpclib.const.Cardinality.STREAM_STREAM,
dummy_pb2.DummyRequest,
dummy_pb2.DummyReply,
),
buf.add('')
buf.add('class {}Stub:', service.name)
with buf.indent():
buf.add('')
buf.add('def __init__(self, channel: {}.{}) -> None:'
.format(client.__name__, client.Channel.__name__))
with buf.indent():
for method in service.methods:
name, cardinality, request_type, reply_type = method
full_name = '/{}/{}'.format(service_name, name)
method_cls: type
if cardinality is const.Cardinality.UNARY_UNARY:
method_cls = client.UnaryUnaryMethod
elif cardinality is const.Cardinality.UNARY_STREAM:
method_cls = client.UnaryStreamMethod
elif cardinality is const.Cardinality.STREAM_UNARY:
method_cls = client.StreamUnaryMethod
elif cardinality is const.Cardinality.STREAM_STREAM:
method_cls = client.StreamStreamMethod
else:
raise TypeError(cardinality)
method_cls = cast(type, method_cls) # FIXME: redundant
buf.add('self.{} = {}.{}('.format(name, client.__name__,
method_cls.__name__))
with buf.indent():
buf.add('channel,')
buf.add('{!r},'.format(full_name))
buf.add('{},', request_type)
buf.add('{},', reply_type)
buf.add(')')
return buf.content()
),
'/helloworld.Greeter/UnaryStreamGreeting': grpclib.const.Handler(
self.UnaryStreamGreeting,
grpclib.const.Cardinality.UNARY_STREAM,
helloworld.helloworld_pb2.HelloRequest,
helloworld.helloworld_pb2.HelloReply,
),
'/helloworld.Greeter/StreamUnaryGreeting': grpclib.const.Handler(
self.StreamUnaryGreeting,
grpclib.const.Cardinality.STREAM_UNARY,
helloworld.helloworld_pb2.HelloRequest,
helloworld.helloworld_pb2.HelloReply,
),
'/helloworld.Greeter/StreamStreamGreeting': grpclib.const.Handler(
self.StreamStreamGreeting,
grpclib.const.Cardinality.STREAM_STREAM,
helloworld.helloworld_pb2.HelloRequest,
helloworld.helloworld_pb2.HelloReply,
),
),
'/ClientMaster.AngelCleintMaster/Clock': grpclib.const.Handler(
self.Clock,
grpclib.const.Cardinality.UNARY_UNARY,
client_master_pb2.ClockReq,
client_master_pb2.ClockResp,
),
'/ClientMaster.AngelCleintMaster/GetClockMap': grpclib.const.Handler(
self.GetClockMap,
grpclib.const.Cardinality.UNARY_UNARY,
client_master_pb2.GetClockMapReq,
client_master_pb2.GetClockMapResp,
),
'/ClientMaster.AngelCleintMaster/GetGlobalBatchSize': grpclib.const.Handler(
self.GetGlobalBatchSize,
grpclib.const.Cardinality.UNARY_UNARY,
common_pb2.VoidReq,
client_master_pb2.GetGlobalBatchResp,
),
'/ClientMaster.AngelCleintMaster/CompleteTask': grpclib.const.Handler(
self.CompleteTask,
grpclib.const.Cardinality.UNARY_UNARY,
common_pb2.CompleteTaskReq,
common_pb2.VoidResp,
),
def __mapping__(self) -> typing.Dict[str, grpclib.const.Handler]:
return {
'/helloworld.Greeter/UnaryUnaryGreeting': grpclib.const.Handler(
self.UnaryUnaryGreeting,
grpclib.const.Cardinality.UNARY_UNARY,
streaming.helloworld_pb2.HelloRequest,
streaming.helloworld_pb2.HelloReply,
),
'/helloworld.Greeter/UnaryStreamGreeting': grpclib.const.Handler(
self.UnaryStreamGreeting,
grpclib.const.Cardinality.UNARY_STREAM,
streaming.helloworld_pb2.HelloRequest,
streaming.helloworld_pb2.HelloReply,
),
'/helloworld.Greeter/StreamUnaryGreeting': grpclib.const.Handler(
self.StreamUnaryGreeting,
grpclib.const.Cardinality.STREAM_UNARY,
streaming.helloworld_pb2.HelloRequest,
streaming.helloworld_pb2.HelloReply,
),
'/helloworld.Greeter/StreamStreamGreeting': grpclib.const.Handler(
self.StreamStreamGreeting,
grpclib.const.Cardinality.STREAM_STREAM,
streaming.helloworld_pb2.HelloRequest,
streaming.helloworld_pb2.HelloReply,
),
buf.add('')
buf.add('def __mapping__(self) -> typing.Dict[str, {}.{}]:',
const.__name__,
const.Handler.__name__)
with buf.indent():
buf.add('return {{')
with buf.indent():
for method in service.methods:
name, cardinality, request_type, reply_type = method
full_name = '/{}/{}'.format(service_name, name)
buf.add("'{}': {}.{}(", full_name, const.__name__,
const.Handler.__name__)
with buf.indent():
buf.add('self.{},', name)
buf.add('{}.{}.{},', const.__name__,
const.Cardinality.__name__,
cardinality.name)
buf.add('{},', request_type)
buf.add('{},', reply_type)
buf.add('),')
buf.add('}}')
buf.add('')
buf.add('')
buf.add('class {}Stub:', service.name)
with buf.indent():
buf.add('')
buf.add('def __init__(self, channel: {}.{}) -> None:'
.format(client.__name__, client.Channel.__name__))
with buf.indent():
for method in service.methods:
name, cardinality, request_type, reply_type = method
else:
await stream.send_request(end=True)
reply = await stream.recv_message()
assert reply is not None
return reply
class StreamStreamMethod(ServiceMethod[_SendType, _RecvType]):
"""
Represents STREAM-STREAM gRPC method type.
.. autocomethod:: __call__
.. autocomethod:: open
:async-with:
"""
_cardinality = Cardinality.STREAM_STREAM
async def __call__(
self,
messages: Sequence[_SendType],
*,
timeout: Optional[float] = None,
metadata: Optional[_MetadataLike] = None,
) -> List[_RecvType]:
"""Coroutine to perform defined call.
:param messages: sequence of messages
:param float timeout: request timeout (seconds)
:param metadata: custom request metadata, dict or list of pairs
:return: sequence of messages
"""
async with self.open(timeout=timeout, metadata=metadata) as stream:
buf.add('),')
buf.add('}}')
buf.add('')
buf.add('')
buf.add('class {}Stub:', service.name)
with buf.indent():
buf.add('')
buf.add('def __init__(self, channel: {}.{}) -> None:'
.format(client.__name__, client.Channel.__name__))
with buf.indent():
for method in service.methods:
name, cardinality, request_type, reply_type = method
full_name = '/{}/{}'.format(service_name, name)
method_cls: type
if cardinality is const.Cardinality.UNARY_UNARY:
method_cls = client.UnaryUnaryMethod
elif cardinality is const.Cardinality.UNARY_STREAM:
method_cls = client.UnaryStreamMethod
elif cardinality is const.Cardinality.STREAM_UNARY:
method_cls = client.StreamUnaryMethod
elif cardinality is const.Cardinality.STREAM_STREAM:
method_cls = client.StreamStreamMethod
else:
raise TypeError(cardinality)
method_cls = cast(type, method_cls) # FIXME: redundant
buf.add('self.{} = {}.{}('.format(name, client.__name__,
method_cls.__name__))
with buf.indent():
buf.add('channel,')
buf.add('{!r},'.format(full_name))
buf.add('{},', request_type)
def __mapping__(self) -> typing.Dict[str, grpclib.const.Handler]:
return {
'/grpc.reflection.v1.ServerReflection/ServerReflectionInfo': grpclib.const.Handler(
self.ServerReflectionInfo,
grpclib.const.Cardinality.STREAM_STREAM,
grpclib.reflection.v1.reflection_pb2.ServerReflectionRequest,
grpclib.reflection.v1.reflection_pb2.ServerReflectionResponse,
),