|
5 | 5 |
|
6 | 6 |
|
7 | 7 | class GreeterStub(object): |
8 | | - """The hello world service definition. |
| 8 | + """The hello world service definition. |
9 | 9 | """ |
10 | 10 |
|
11 | | - def __init__(self, channel): |
12 | | - """Constructor. |
| 11 | + def __init__(self, channel): |
| 12 | + """Constructor. |
13 | 13 |
|
14 | 14 | Args: |
15 | 15 | channel: A grpc.Channel. |
16 | 16 | """ |
17 | | - self.SayHello = channel.unary_unary( |
18 | | - '/helloworld.Greeter/SayHello', |
19 | | - request_serializer=hello__world__pb2.HelloRequest.SerializeToString, |
20 | | - response_deserializer=hello__world__pb2.HelloReply.FromString, |
| 17 | + self.SayHello = channel.unary_unary( |
| 18 | + '/helloworld.Greeter/SayHello', |
| 19 | + request_serializer=hello__world__pb2.HelloRequest. |
| 20 | + SerializeToString, |
| 21 | + response_deserializer=hello__world__pb2.HelloReply.FromString, |
21 | 22 | ) |
22 | 23 |
|
23 | 24 |
|
24 | 25 | class GreeterServicer(object): |
25 | | - """The hello world service definition. |
| 26 | + """The hello world service definition. |
26 | 27 | """ |
27 | 28 |
|
28 | | - def SayHello(self, request, context): |
29 | | - """Say hello to the request sender (unary-unary) |
| 29 | + def SayHello(self, request, context): |
| 30 | + """Say hello to the request sender (unary-unary) |
30 | 31 | """ |
31 | | - context.set_code(grpc.StatusCode.UNIMPLEMENTED) |
32 | | - context.set_details('Method not implemented!') |
33 | | - raise NotImplementedError('Method not implemented!') |
| 32 | + context.set_code(grpc.StatusCode.UNIMPLEMENTED) |
| 33 | + context.set_details('Method not implemented!') |
| 34 | + raise NotImplementedError('Method not implemented!') |
34 | 35 |
|
35 | 36 |
|
36 | 37 | def add_GreeterServicer_to_server(servicer, server): |
37 | | - rpc_method_handlers = { |
38 | | - 'SayHello': grpc.unary_unary_rpc_method_handler( |
39 | | - servicer.SayHello, |
40 | | - request_deserializer=hello__world__pb2.HelloRequest.FromString, |
41 | | - response_serializer=hello__world__pb2.HelloReply.SerializeToString, |
42 | | - ), |
43 | | - } |
44 | | - generic_handler = grpc.method_handlers_generic_handler( |
45 | | - 'helloworld.Greeter', rpc_method_handlers) |
46 | | - server.add_generic_rpc_handlers((generic_handler,)) |
| 38 | + rpc_method_handlers = { |
| 39 | + 'SayHello': |
| 40 | + grpc.unary_unary_rpc_method_handler( |
| 41 | + servicer.SayHello, |
| 42 | + request_deserializer=hello__world__pb2.HelloRequest.FromString, |
| 43 | + response_serializer=hello__world__pb2.HelloReply.SerializeToString, |
| 44 | + ), |
| 45 | + } |
| 46 | + generic_handler = grpc.method_handlers_generic_handler( |
| 47 | + 'helloworld.Greeter', rpc_method_handlers) |
| 48 | + server.add_generic_rpc_handlers((generic_handler, )) |
0 commit comments