aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/python/route_guide
diff options
context:
space:
mode:
authorGravatar Nathaniel Manista <nathaniel@google.com>2016-12-15 22:58:29 +0000
committerGravatar Nathaniel Manista <nathaniel@google.com>2016-12-21 21:05:19 +0000
commitc15ee83882dad131b7ff9c71e29ec9cc1663781e (patch)
treec7e7f3ab368bd2857dff25d3cd7f6a7aab4bb8ff /examples/python/route_guide
parent47f1f9e1ead610ccfc464bf3f6d2918867a0a212 (diff)
Update Python examples with fresh generated code
Diffstat (limited to 'examples/python/route_guide')
-rw-r--r--examples/python/route_guide/route_guide_client.py3
-rw-r--r--examples/python/route_guide/route_guide_pb2.py485
-rw-r--r--examples/python/route_guide/route_guide_pb2_grpc.py114
-rw-r--r--examples/python/route_guide/route_guide_server.py5
4 files changed, 374 insertions, 233 deletions
diff --git a/examples/python/route_guide/route_guide_client.py b/examples/python/route_guide/route_guide_client.py
index 8a80ed892d..d2955231c3 100644
--- a/examples/python/route_guide/route_guide_client.py
+++ b/examples/python/route_guide/route_guide_client.py
@@ -37,6 +37,7 @@ import time
import grpc
import route_guide_pb2
+import route_guide_pb2_grpc
import route_guide_resources
@@ -116,7 +117,7 @@ def guide_route_chat(stub):
def run():
channel = grpc.insecure_channel('localhost:50051')
- stub = route_guide_pb2.RouteGuideStub(channel)
+ stub = route_guide_pb2_grpc.RouteGuideStub(channel)
print("-------------- GetFeature --------------")
guide_get_feature(stub)
print("-------------- ListFeatures --------------")
diff --git a/examples/python/route_guide/route_guide_pb2.py b/examples/python/route_guide/route_guide_pb2.py
index 924e186e06..e6775eb814 100644
--- a/examples/python/route_guide/route_guide_pb2.py
+++ b/examples/python/route_guide/route_guide_pb2.py
@@ -277,240 +277,265 @@ _sym_db.RegisterMessage(RouteSummary)
DESCRIPTOR.has_options = True
DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\033io.grpc.examples.routeguideB\017RouteGuideProtoP\001\242\002\003RTG'))
-import grpc
-from grpc.beta import implementations as beta_implementations
-from grpc.beta import interfaces as beta_interfaces
-from grpc.framework.common import cardinality
-from grpc.framework.interfaces.face import utilities as face_utilities
-
-
-class RouteGuideStub(object):
- """Interface exported by the server.
- """
-
- def __init__(self, channel):
- """Constructor.
-
- Args:
- channel: A grpc.Channel.
+try:
+ # THESE ELEMENTS WILL BE DEPRECATED.
+ # Please use the generated *_pb2_grpc.py files instead.
+ import grpc
+ from grpc.framework.common import cardinality
+ from grpc.framework.interfaces.face import utilities as face_utilities
+ from grpc.beta import implementations as beta_implementations
+ from grpc.beta import interfaces as beta_interfaces
+
+
+ class RouteGuideStub(object):
+ """Interface exported by the server.
"""
- self.GetFeature = channel.unary_unary(
- '/routeguide.RouteGuide/GetFeature',
- request_serializer=Point.SerializeToString,
- response_deserializer=Feature.FromString,
- )
- self.ListFeatures = channel.unary_stream(
- '/routeguide.RouteGuide/ListFeatures',
- request_serializer=Rectangle.SerializeToString,
- response_deserializer=Feature.FromString,
- )
- self.RecordRoute = channel.stream_unary(
- '/routeguide.RouteGuide/RecordRoute',
- request_serializer=Point.SerializeToString,
- response_deserializer=RouteSummary.FromString,
- )
- self.RouteChat = channel.stream_stream(
- '/routeguide.RouteGuide/RouteChat',
- request_serializer=RouteNote.SerializeToString,
- response_deserializer=RouteNote.FromString,
- )
-
-
-class RouteGuideServicer(object):
- """Interface exported by the server.
- """
-
- def GetFeature(self, request, context):
- """A simple RPC.
-
- Obtains the feature at a given position.
-
- A feature with an empty name is returned if there's no feature at the given
- position.
- """
- context.set_code(grpc.StatusCode.UNIMPLEMENTED)
- context.set_details('Method not implemented!')
- raise NotImplementedError('Method not implemented!')
-
- def ListFeatures(self, request, context):
- """A server-to-client streaming RPC.
- Obtains the Features available within the given Rectangle. Results are
- streamed rather than returned at once (e.g. in a response message with a
- repeated field), as the rectangle may cover a large area and contain a
- huge number of features.
+ def __init__(self, channel):
+ """Constructor.
+
+ Args:
+ channel: A grpc.Channel.
+ """
+ self.GetFeature = channel.unary_unary(
+ '/routeguide.RouteGuide/GetFeature',
+ request_serializer=Point.SerializeToString,
+ response_deserializer=Feature.FromString,
+ )
+ self.ListFeatures = channel.unary_stream(
+ '/routeguide.RouteGuide/ListFeatures',
+ request_serializer=Rectangle.SerializeToString,
+ response_deserializer=Feature.FromString,
+ )
+ self.RecordRoute = channel.stream_unary(
+ '/routeguide.RouteGuide/RecordRoute',
+ request_serializer=Point.SerializeToString,
+ response_deserializer=RouteSummary.FromString,
+ )
+ self.RouteChat = channel.stream_stream(
+ '/routeguide.RouteGuide/RouteChat',
+ request_serializer=RouteNote.SerializeToString,
+ response_deserializer=RouteNote.FromString,
+ )
+
+
+ class RouteGuideServicer(object):
+ """Interface exported by the server.
"""
- context.set_code(grpc.StatusCode.UNIMPLEMENTED)
- context.set_details('Method not implemented!')
- raise NotImplementedError('Method not implemented!')
-
- def RecordRoute(self, request_iterator, context):
- """A client-to-server streaming RPC.
- Accepts a stream of Points on a route being traversed, returning a
- RouteSummary when traversal is completed.
+ def GetFeature(self, request, context):
+ """A simple RPC.
+
+ Obtains the feature at a given position.
+
+ A feature with an empty name is returned if there's no feature at the given
+ position.
+ """
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
+ context.set_details('Method not implemented!')
+ raise NotImplementedError('Method not implemented!')
+
+ def ListFeatures(self, request, context):
+ """A server-to-client streaming RPC.
+
+ Obtains the Features available within the given Rectangle. Results are
+ streamed rather than returned at once (e.g. in a response message with a
+ repeated field), as the rectangle may cover a large area and contain a
+ huge number of features.
+ """
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
+ context.set_details('Method not implemented!')
+ raise NotImplementedError('Method not implemented!')
+
+ def RecordRoute(self, request_iterator, context):
+ """A client-to-server streaming RPC.
+
+ Accepts a stream of Points on a route being traversed, returning a
+ RouteSummary when traversal is completed.
+ """
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
+ context.set_details('Method not implemented!')
+ raise NotImplementedError('Method not implemented!')
+
+ def RouteChat(self, request_iterator, context):
+ """A Bidirectional streaming RPC.
+
+ Accepts a stream of RouteNotes sent while a route is being traversed,
+ while receiving other RouteNotes (e.g. from other users).
+ """
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
+ context.set_details('Method not implemented!')
+ raise NotImplementedError('Method not implemented!')
+
+
+ def add_RouteGuideServicer_to_server(servicer, server):
+ rpc_method_handlers = {
+ 'GetFeature': grpc.unary_unary_rpc_method_handler(
+ servicer.GetFeature,
+ request_deserializer=Point.FromString,
+ response_serializer=Feature.SerializeToString,
+ ),
+ 'ListFeatures': grpc.unary_stream_rpc_method_handler(
+ servicer.ListFeatures,
+ request_deserializer=Rectangle.FromString,
+ response_serializer=Feature.SerializeToString,
+ ),
+ 'RecordRoute': grpc.stream_unary_rpc_method_handler(
+ servicer.RecordRoute,
+ request_deserializer=Point.FromString,
+ response_serializer=RouteSummary.SerializeToString,
+ ),
+ 'RouteChat': grpc.stream_stream_rpc_method_handler(
+ servicer.RouteChat,
+ request_deserializer=RouteNote.FromString,
+ response_serializer=RouteNote.SerializeToString,
+ ),
+ }
+ generic_handler = grpc.method_handlers_generic_handler(
+ 'routeguide.RouteGuide', rpc_method_handlers)
+ server.add_generic_rpc_handlers((generic_handler,))
+
+
+ class BetaRouteGuideServicer(object):
+ """The Beta API is deprecated for 0.15.0 and later.
+
+ It is recommended to use the GA API (classes and functions in this
+ file not marked beta) for all further purposes. This class was generated
+ only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0."""
+ """Interface exported by the server.
"""
- context.set_code(grpc.StatusCode.UNIMPLEMENTED)
- context.set_details('Method not implemented!')
- raise NotImplementedError('Method not implemented!')
-
- def RouteChat(self, request_iterator, context):
- """A Bidirectional streaming RPC.
-
- Accepts a stream of RouteNotes sent while a route is being traversed,
- while receiving other RouteNotes (e.g. from other users).
- """
- context.set_code(grpc.StatusCode.UNIMPLEMENTED)
- context.set_details('Method not implemented!')
- raise NotImplementedError('Method not implemented!')
-
-
-def add_RouteGuideServicer_to_server(servicer, server):
- rpc_method_handlers = {
- 'GetFeature': grpc.unary_unary_rpc_method_handler(
- servicer.GetFeature,
- request_deserializer=Point.FromString,
- response_serializer=Feature.SerializeToString,
- ),
- 'ListFeatures': grpc.unary_stream_rpc_method_handler(
- servicer.ListFeatures,
- request_deserializer=Rectangle.FromString,
- response_serializer=Feature.SerializeToString,
- ),
- 'RecordRoute': grpc.stream_unary_rpc_method_handler(
- servicer.RecordRoute,
- request_deserializer=Point.FromString,
- response_serializer=RouteSummary.SerializeToString,
- ),
- 'RouteChat': grpc.stream_stream_rpc_method_handler(
- servicer.RouteChat,
- request_deserializer=RouteNote.FromString,
- response_serializer=RouteNote.SerializeToString,
- ),
- }
- generic_handler = grpc.method_handlers_generic_handler(
- 'routeguide.RouteGuide', rpc_method_handlers)
- server.add_generic_rpc_handlers((generic_handler,))
-
-
-class BetaRouteGuideServicer(object):
- """Interface exported by the server.
- """
- def GetFeature(self, request, context):
- """A simple RPC.
-
- Obtains the feature at a given position.
-
- A feature with an empty name is returned if there's no feature at the given
- position.
- """
- context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
- def ListFeatures(self, request, context):
- """A server-to-client streaming RPC.
-
- Obtains the Features available within the given Rectangle. Results are
- streamed rather than returned at once (e.g. in a response message with a
- repeated field), as the rectangle may cover a large area and contain a
- huge number of features.
- """
- context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
- def RecordRoute(self, request_iterator, context):
- """A client-to-server streaming RPC.
-
- Accepts a stream of Points on a route being traversed, returning a
- RouteSummary when traversal is completed.
- """
- context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
- def RouteChat(self, request_iterator, context):
- """A Bidirectional streaming RPC.
-
- Accepts a stream of RouteNotes sent while a route is being traversed,
- while receiving other RouteNotes (e.g. from other users).
- """
- context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
-
-
-class BetaRouteGuideStub(object):
- """Interface exported by the server.
- """
- def GetFeature(self, request, timeout, metadata=None, with_call=False, protocol_options=None):
- """A simple RPC.
-
- Obtains the feature at a given position.
-
- A feature with an empty name is returned if there's no feature at the given
- position.
- """
- raise NotImplementedError()
- GetFeature.future = None
- def ListFeatures(self, request, timeout, metadata=None, with_call=False, protocol_options=None):
- """A server-to-client streaming RPC.
-
- Obtains the Features available within the given Rectangle. Results are
- streamed rather than returned at once (e.g. in a response message with a
- repeated field), as the rectangle may cover a large area and contain a
- huge number of features.
- """
- raise NotImplementedError()
- def RecordRoute(self, request_iterator, timeout, metadata=None, with_call=False, protocol_options=None):
- """A client-to-server streaming RPC.
-
- Accepts a stream of Points on a route being traversed, returning a
- RouteSummary when traversal is completed.
- """
- raise NotImplementedError()
- RecordRoute.future = None
- def RouteChat(self, request_iterator, timeout, metadata=None, with_call=False, protocol_options=None):
- """A Bidirectional streaming RPC.
-
- Accepts a stream of RouteNotes sent while a route is being traversed,
- while receiving other RouteNotes (e.g. from other users).
+ def GetFeature(self, request, context):
+ """A simple RPC.
+
+ Obtains the feature at a given position.
+
+ A feature with an empty name is returned if there's no feature at the given
+ position.
+ """
+ context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
+ def ListFeatures(self, request, context):
+ """A server-to-client streaming RPC.
+
+ Obtains the Features available within the given Rectangle. Results are
+ streamed rather than returned at once (e.g. in a response message with a
+ repeated field), as the rectangle may cover a large area and contain a
+ huge number of features.
+ """
+ context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
+ def RecordRoute(self, request_iterator, context):
+ """A client-to-server streaming RPC.
+
+ Accepts a stream of Points on a route being traversed, returning a
+ RouteSummary when traversal is completed.
+ """
+ context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
+ def RouteChat(self, request_iterator, context):
+ """A Bidirectional streaming RPC.
+
+ Accepts a stream of RouteNotes sent while a route is being traversed,
+ while receiving other RouteNotes (e.g. from other users).
+ """
+ context.code(beta_interfaces.StatusCode.UNIMPLEMENTED)
+
+
+ class BetaRouteGuideStub(object):
+ """The Beta API is deprecated for 0.15.0 and later.
+
+ It is recommended to use the GA API (classes and functions in this
+ file not marked beta) for all further purposes. This class was generated
+ only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0."""
+ """Interface exported by the server.
"""
- raise NotImplementedError()
-
-
-def beta_create_RouteGuide_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None):
- request_deserializers = {
- ('routeguide.RouteGuide', 'GetFeature'): Point.FromString,
- ('routeguide.RouteGuide', 'ListFeatures'): Rectangle.FromString,
- ('routeguide.RouteGuide', 'RecordRoute'): Point.FromString,
- ('routeguide.RouteGuide', 'RouteChat'): RouteNote.FromString,
- }
- response_serializers = {
- ('routeguide.RouteGuide', 'GetFeature'): Feature.SerializeToString,
- ('routeguide.RouteGuide', 'ListFeatures'): Feature.SerializeToString,
- ('routeguide.RouteGuide', 'RecordRoute'): RouteSummary.SerializeToString,
- ('routeguide.RouteGuide', 'RouteChat'): RouteNote.SerializeToString,
- }
- method_implementations = {
- ('routeguide.RouteGuide', 'GetFeature'): face_utilities.unary_unary_inline(servicer.GetFeature),
- ('routeguide.RouteGuide', 'ListFeatures'): face_utilities.unary_stream_inline(servicer.ListFeatures),
- ('routeguide.RouteGuide', 'RecordRoute'): face_utilities.stream_unary_inline(servicer.RecordRoute),
- ('routeguide.RouteGuide', 'RouteChat'): face_utilities.stream_stream_inline(servicer.RouteChat),
- }
- server_options = beta_implementations.server_options(request_deserializers=request_deserializers, response_serializers=response_serializers, thread_pool=pool, thread_pool_size=pool_size, default_timeout=default_timeout, maximum_timeout=maximum_timeout)
- return beta_implementations.server(method_implementations, options=server_options)
-
-
-def beta_create_RouteGuide_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None):
- request_serializers = {
- ('routeguide.RouteGuide', 'GetFeature'): Point.SerializeToString,
- ('routeguide.RouteGuide', 'ListFeatures'): Rectangle.SerializeToString,
- ('routeguide.RouteGuide', 'RecordRoute'): Point.SerializeToString,
- ('routeguide.RouteGuide', 'RouteChat'): RouteNote.SerializeToString,
- }
- response_deserializers = {
- ('routeguide.RouteGuide', 'GetFeature'): Feature.FromString,
- ('routeguide.RouteGuide', 'ListFeatures'): Feature.FromString,
- ('routeguide.RouteGuide', 'RecordRoute'): RouteSummary.FromString,
- ('routeguide.RouteGuide', 'RouteChat'): RouteNote.FromString,
- }
- cardinalities = {
- 'GetFeature': cardinality.Cardinality.UNARY_UNARY,
- 'ListFeatures': cardinality.Cardinality.UNARY_STREAM,
- 'RecordRoute': cardinality.Cardinality.STREAM_UNARY,
- 'RouteChat': cardinality.Cardinality.STREAM_STREAM,
- }
- stub_options = beta_implementations.stub_options(host=host, metadata_transformer=metadata_transformer, request_serializers=request_serializers, response_deserializers=response_deserializers, thread_pool=pool, thread_pool_size=pool_size)
- return beta_implementations.dynamic_stub(channel, 'routeguide.RouteGuide', cardinalities, options=stub_options)
+ def GetFeature(self, request, timeout, metadata=None, with_call=False, protocol_options=None):
+ """A simple RPC.
+
+ Obtains the feature at a given position.
+
+ A feature with an empty name is returned if there's no feature at the given
+ position.
+ """
+ raise NotImplementedError()
+ GetFeature.future = None
+ def ListFeatures(self, request, timeout, metadata=None, with_call=False, protocol_options=None):
+ """A server-to-client streaming RPC.
+
+ Obtains the Features available within the given Rectangle. Results are
+ streamed rather than returned at once (e.g. in a response message with a
+ repeated field), as the rectangle may cover a large area and contain a
+ huge number of features.
+ """
+ raise NotImplementedError()
+ def RecordRoute(self, request_iterator, timeout, metadata=None, with_call=False, protocol_options=None):
+ """A client-to-server streaming RPC.
+
+ Accepts a stream of Points on a route being traversed, returning a
+ RouteSummary when traversal is completed.
+ """
+ raise NotImplementedError()
+ RecordRoute.future = None
+ def RouteChat(self, request_iterator, timeout, metadata=None, with_call=False, protocol_options=None):
+ """A Bidirectional streaming RPC.
+
+ Accepts a stream of RouteNotes sent while a route is being traversed,
+ while receiving other RouteNotes (e.g. from other users).
+ """
+ raise NotImplementedError()
+
+
+ def beta_create_RouteGuide_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None):
+ """The Beta API is deprecated for 0.15.0 and later.
+
+ It is recommended to use the GA API (classes and functions in this
+ file not marked beta) for all further purposes. This function was
+ generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0"""
+ request_deserializers = {
+ ('routeguide.RouteGuide', 'GetFeature'): Point.FromString,
+ ('routeguide.RouteGuide', 'ListFeatures'): Rectangle.FromString,
+ ('routeguide.RouteGuide', 'RecordRoute'): Point.FromString,
+ ('routeguide.RouteGuide', 'RouteChat'): RouteNote.FromString,
+ }
+ response_serializers = {
+ ('routeguide.RouteGuide', 'GetFeature'): Feature.SerializeToString,
+ ('routeguide.RouteGuide', 'ListFeatures'): Feature.SerializeToString,
+ ('routeguide.RouteGuide', 'RecordRoute'): RouteSummary.SerializeToString,
+ ('routeguide.RouteGuide', 'RouteChat'): RouteNote.SerializeToString,
+ }
+ method_implementations = {
+ ('routeguide.RouteGuide', 'GetFeature'): face_utilities.unary_unary_inline(servicer.GetFeature),
+ ('routeguide.RouteGuide', 'ListFeatures'): face_utilities.unary_stream_inline(servicer.ListFeatures),
+ ('routeguide.RouteGuide', 'RecordRoute'): face_utilities.stream_unary_inline(servicer.RecordRoute),
+ ('routeguide.RouteGuide', 'RouteChat'): face_utilities.stream_stream_inline(servicer.RouteChat),
+ }
+ server_options = beta_implementations.server_options(request_deserializers=request_deserializers, response_serializers=response_serializers, thread_pool=pool, thread_pool_size=pool_size, default_timeout=default_timeout, maximum_timeout=maximum_timeout)
+ return beta_implementations.server(method_implementations, options=server_options)
+
+
+ def beta_create_RouteGuide_stub(channel, host=None, metadata_transformer=None, pool=None, pool_size=None):
+ """The Beta API is deprecated for 0.15.0 and later.
+
+ It is recommended to use the GA API (classes and functions in this
+ file not marked beta) for all further purposes. This function was
+ generated only to ease transition from grpcio<0.15.0 to grpcio>=0.15.0"""
+ request_serializers = {
+ ('routeguide.RouteGuide', 'GetFeature'): Point.SerializeToString,
+ ('routeguide.RouteGuide', 'ListFeatures'): Rectangle.SerializeToString,
+ ('routeguide.RouteGuide', 'RecordRoute'): Point.SerializeToString,
+ ('routeguide.RouteGuide', 'RouteChat'): RouteNote.SerializeToString,
+ }
+ response_deserializers = {
+ ('routeguide.RouteGuide', 'GetFeature'): Feature.FromString,
+ ('routeguide.RouteGuide', 'ListFeatures'): Feature.FromString,
+ ('routeguide.RouteGuide', 'RecordRoute'): RouteSummary.FromString,
+ ('routeguide.RouteGuide', 'RouteChat'): RouteNote.FromString,
+ }
+ cardinalities = {
+ 'GetFeature': cardinality.Cardinality.UNARY_UNARY,
+ 'ListFeatures': cardinality.Cardinality.UNARY_STREAM,
+ 'RecordRoute': cardinality.Cardinality.STREAM_UNARY,
+ 'RouteChat': cardinality.Cardinality.STREAM_STREAM,
+ }
+ stub_options = beta_implementations.stub_options(host=host, metadata_transformer=metadata_transformer, request_serializers=request_serializers, response_deserializers=response_deserializers, thread_pool=pool, thread_pool_size=pool_size)
+ return beta_implementations.dynamic_stub(channel, 'routeguide.RouteGuide', cardinalities, options=stub_options)
+except ImportError:
+ pass
# @@protoc_insertion_point(module_scope)
diff --git a/examples/python/route_guide/route_guide_pb2_grpc.py b/examples/python/route_guide/route_guide_pb2_grpc.py
new file mode 100644
index 0000000000..27b24c747d
--- /dev/null
+++ b/examples/python/route_guide/route_guide_pb2_grpc.py
@@ -0,0 +1,114 @@
+import grpc
+from grpc.framework.common import cardinality
+from grpc.framework.interfaces.face import utilities as face_utilities
+
+import route_guide_pb2 as route__guide__pb2
+
+
+class RouteGuideStub(object):
+ """Interface exported by the server.
+ """
+
+ def __init__(self, channel):
+ """Constructor.
+
+ Args:
+ channel: A grpc.Channel.
+ """
+ self.GetFeature = channel.unary_unary(
+ '/routeguide.RouteGuide/GetFeature',
+ request_serializer=route__guide__pb2.Point.SerializeToString,
+ response_deserializer=route__guide__pb2.Feature.FromString,
+ )
+ self.ListFeatures = channel.unary_stream(
+ '/routeguide.RouteGuide/ListFeatures',
+ request_serializer=route__guide__pb2.Rectangle.SerializeToString,
+ response_deserializer=route__guide__pb2.Feature.FromString,
+ )
+ self.RecordRoute = channel.stream_unary(
+ '/routeguide.RouteGuide/RecordRoute',
+ request_serializer=route__guide__pb2.Point.SerializeToString,
+ response_deserializer=route__guide__pb2.RouteSummary.FromString,
+ )
+ self.RouteChat = channel.stream_stream(
+ '/routeguide.RouteGuide/RouteChat',
+ request_serializer=route__guide__pb2.RouteNote.SerializeToString,
+ response_deserializer=route__guide__pb2.RouteNote.FromString,
+ )
+
+
+class RouteGuideServicer(object):
+ """Interface exported by the server.
+ """
+
+ def GetFeature(self, request, context):
+ """A simple RPC.
+
+ Obtains the feature at a given position.
+
+ A feature with an empty name is returned if there's no feature at the given
+ position.
+ """
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
+ context.set_details('Method not implemented!')
+ raise NotImplementedError('Method not implemented!')
+
+ def ListFeatures(self, request, context):
+ """A server-to-client streaming RPC.
+
+ Obtains the Features available within the given Rectangle. Results are
+ streamed rather than returned at once (e.g. in a response message with a
+ repeated field), as the rectangle may cover a large area and contain a
+ huge number of features.
+ """
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
+ context.set_details('Method not implemented!')
+ raise NotImplementedError('Method not implemented!')
+
+ def RecordRoute(self, request_iterator, context):
+ """A client-to-server streaming RPC.
+
+ Accepts a stream of Points on a route being traversed, returning a
+ RouteSummary when traversal is completed.
+ """
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
+ context.set_details('Method not implemented!')
+ raise NotImplementedError('Method not implemented!')
+
+ def RouteChat(self, request_iterator, context):
+ """A Bidirectional streaming RPC.
+
+ Accepts a stream of RouteNotes sent while a route is being traversed,
+ while receiving other RouteNotes (e.g. from other users).
+ """
+ context.set_code(grpc.StatusCode.UNIMPLEMENTED)
+ context.set_details('Method not implemented!')
+ raise NotImplementedError('Method not implemented!')
+
+
+def add_RouteGuideServicer_to_server(servicer, server):
+ rpc_method_handlers = {
+ 'GetFeature': grpc.unary_unary_rpc_method_handler(
+ servicer.GetFeature,
+ request_deserializer=route__guide__pb2.Point.FromString,
+ response_serializer=route__guide__pb2.Feature.SerializeToString,
+ ),
+ 'ListFeatures': grpc.unary_stream_rpc_method_handler(
+ servicer.ListFeatures,
+ request_deserializer=route__guide__pb2.Rectangle.FromString,
+ response_serializer=route__guide__pb2.Feature.SerializeToString,
+ ),
+ 'RecordRoute': grpc.stream_unary_rpc_method_handler(
+ servicer.RecordRoute,
+ request_deserializer=route__guide__pb2.Point.FromString,
+ response_serializer=route__guide__pb2.RouteSummary.SerializeToString,
+ ),
+ 'RouteChat': grpc.stream_stream_rpc_method_handler(
+ servicer.RouteChat,
+ request_deserializer=route__guide__pb2.RouteNote.FromString,
+ response_serializer=route__guide__pb2.RouteNote.SerializeToString,
+ ),
+ }
+ generic_handler = grpc.method_handlers_generic_handler(
+ 'routeguide.RouteGuide', rpc_method_handlers)
+ server.add_generic_rpc_handlers((generic_handler,))
diff --git a/examples/python/route_guide/route_guide_server.py b/examples/python/route_guide/route_guide_server.py
index 3ffe678476..bf49217932 100644
--- a/examples/python/route_guide/route_guide_server.py
+++ b/examples/python/route_guide/route_guide_server.py
@@ -36,6 +36,7 @@ import math
import grpc
import route_guide_pb2
+import route_guide_pb2_grpc
import route_guide_resources
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
@@ -68,7 +69,7 @@ def get_distance(start, end):
R = 6371000; # metres
return R * c;
-class RouteGuideServicer(route_guide_pb2.RouteGuideServicer):
+class RouteGuideServicer(route_guide_pb2_grpc.RouteGuideServicer):
"""Provides methods that implement functionality of route guide server."""
def __init__(self):
@@ -125,7 +126,7 @@ class RouteGuideServicer(route_guide_pb2.RouteGuideServicer):
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
- route_guide_pb2.add_RouteGuideServicer_to_server(
+ route_guide_pb2_grpc.add_RouteGuideServicer_to_server(
RouteGuideServicer(), server)
server.add_insecure_port('[::]:50051')
server.start()