From c824eb4e90fe150b113b2ceaa14fa4105718cc46 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Tue, 8 Sep 2015 19:03:18 +0000 Subject: [PATCH 1/8] Make servers and stubs context managers Servers and stubs were context managers in the Alpha API; they may not need to be in the Beta API but it's easy enough to do, eases migration, and probably helps some use cases. For now the stub is given empty __enter__ and __exit__ methods; we can always come back and implement the actual work of context management in a later change. --- src/python/grpcio/grpc/beta/_server.py | 18 ++++++++++++++++-- src/python/grpcio/grpc/beta/_stub.py | 6 ++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/python/grpcio/grpc/beta/_server.py b/src/python/grpcio/grpc/beta/_server.py index daa42c475ad..05b954d1860 100644 --- a/src/python/grpcio/grpc/beta/_server.py +++ b/src/python/grpcio/grpc/beta/_server.py @@ -86,13 +86,13 @@ class Server(interfaces.Server): return self._grpc_link.add_port( address, server_credentials._intermediary_low_credentials) # pylint: disable=protected-access - def start(self): + def _start(self): self._grpc_link.join_link(self._end_link) self._end_link.join_link(self._grpc_link) self._grpc_link.start() self._end_link.start() - def stop(self, grace): + def _stop(self, grace): stop_event = threading.Event() if 0 < grace: disassembly_thread = threading.Thread( @@ -105,6 +105,20 @@ class Server(interfaces.Server): _disassemble(self._grpc_link, self._end_link, self._pool, stop_event, 0) return stop_event + def start(self): + self._start() + + def stop(self, grace): + return self._stop(grace) + + def __enter__(self): + self._start() + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + self._stop(0).wait() + return False + def server( implementations, multi_implementation, request_deserializers, diff --git a/src/python/grpcio/grpc/beta/_stub.py b/src/python/grpcio/grpc/beta/_stub.py index cfbecb852b2..11dab889cd0 100644 --- a/src/python/grpcio/grpc/beta/_stub.py +++ b/src/python/grpcio/grpc/beta/_stub.py @@ -49,6 +49,12 @@ class _AutoIntermediary(object): def __getattr__(self, attr): return getattr(self._delegate, attr) + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + return False + def __del__(self): self._on_deletion() From 3b0fefb246caf9cf983d8ab7b69ce97b8ea7ba48 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Tue, 8 Sep 2015 19:09:51 +0000 Subject: [PATCH 2/8] Beta maintenance of Python dependencies (1) Move dependency on protobuf from grpcio to grpcio_test. While the most-commonly-foreseen use case of grpcio makes use of protobuf, technically protobuf is not strictly needed and there's no actual in-code relationship between grpcio and protobuf. (2) Loosen the dependency on protobuf from ==3.0.0a3 to >=3.0.0a3. (3) Update all references to 0.10.0* to 0.11.0. (4) Alphabetize the grpcio_test dependencies. --- src/python/grpcio/requirements.txt | 1 - src/python/grpcio_health_checking/setup.py | 4 ++-- src/python/grpcio_test/requirements.txt | 5 +++-- src/python/grpcio_test/setup.py | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/python/grpcio/requirements.txt b/src/python/grpcio/requirements.txt index 43395df03b9..608ba402e09 100644 --- a/src/python/grpcio/requirements.txt +++ b/src/python/grpcio/requirements.txt @@ -1,3 +1,2 @@ enum34==1.0.4 futures==2.2.0 -protobuf==3.0.0a3 diff --git a/src/python/grpcio_health_checking/setup.py b/src/python/grpcio_health_checking/setup.py index fcde0dab8c9..38629aa8159 100644 --- a/src/python/grpcio_health_checking/setup.py +++ b/src/python/grpcio_health_checking/setup.py @@ -51,7 +51,7 @@ _PACKAGE_DIRECTORIES = { } _INSTALL_REQUIRES = ( - 'grpcio>=0.10.0a0', + 'grpcio>=0.11.0', ) _SETUP_REQUIRES = _INSTALL_REQUIRES @@ -63,7 +63,7 @@ _COMMAND_CLASS = { setuptools.setup( name='grpcio_health_checking', - version='0.10.0a0', + version='0.11.0', packages=list(_PACKAGES), package_dir=_PACKAGE_DIRECTORIES, install_requires=_INSTALL_REQUIRES, diff --git a/src/python/grpcio_test/requirements.txt b/src/python/grpcio_test/requirements.txt index 856198def57..cf8b8a89994 100644 --- a/src/python/grpcio_test/requirements.txt +++ b/src/python/grpcio_test/requirements.txt @@ -1,5 +1,6 @@ +grpcio>=0.11.0 +oauth2client>=1.4.7 +protobuf>=3.0.0a3 pytest>=2.6 pytest-cov>=2.0 pytest-xdist>=1.11 -oauth2client>=1.4.7 -grpcio>=0.10.0a0 diff --git a/src/python/grpcio_test/setup.py b/src/python/grpcio_test/setup.py index 802dd1e53af..161578a5153 100644 --- a/src/python/grpcio_test/setup.py +++ b/src/python/grpcio_test/setup.py @@ -71,7 +71,7 @@ _SETUP_REQUIRES = ( _INSTALL_REQUIRES = ( 'oauth2client>=1.4.7', - 'grpcio>=0.10.0a0', + 'grpcio>=0.11.0', ) _COMMAND_CLASS = { @@ -80,7 +80,7 @@ _COMMAND_CLASS = { setuptools.setup( name='grpcio_test', - version='0.10.0a0', + version='0.11.0', packages=_PACKAGES, package_dir=_PACKAGE_DIRECTORIES, package_data=_PACKAGE_DATA, From 675aee6a743b205c48a037a6e2829645ae7ae512 Mon Sep 17 00:00:00 2001 From: Julien Boeuf Date: Tue, 8 Sep 2015 17:21:05 -0700 Subject: [PATCH 3/8] Fixing #3286 - We cannot use call_data after the final callback as this one may trigger the deletion of the call object (hence the call_data). --- src/core/security/server_auth_filter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/security/server_auth_filter.c b/src/core/security/server_auth_filter.c index b767f854987..d134201e87c 100644 --- a/src/core/security/server_auth_filter.c +++ b/src/core/security/server_auth_filter.c @@ -128,9 +128,11 @@ static void on_md_processing_done( calld->num_consumed_md = num_consumed_md; grpc_metadata_batch_filter(&calld->md_op->data.metadata, remove_consumed_md, elem); + grpc_metadata_array_destroy(&calld->md); calld->on_done_recv->cb(calld->on_done_recv->cb_arg, 1); } else { gpr_slice message; + grpc_metadata_array_destroy(&calld->md); error_details = error_details != NULL ? error_details : "Authentication metadata processing failed."; @@ -139,7 +141,6 @@ static void on_md_processing_done( grpc_transport_stream_op_add_close(&calld->transport_op, status, &message); grpc_call_next_op(elem, &calld->transport_op); } - grpc_metadata_array_destroy(&calld->md); } static void auth_on_recv(void *user_data, int success) { From 0bee681ab15b3eef5833ca6a93a92cbc6d2ccd5d Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Tue, 8 Sep 2015 20:35:45 -0700 Subject: [PATCH 4/8] Bump version of gRPC.podspec to 0.11 Technically unnecessary, but for consistency with the other beta releases. --- gRPC.podspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gRPC.podspec b/gRPC.podspec index d0e1e2d848d..df3c8ee55cd 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -36,14 +36,14 @@ Pod::Spec.new do |s| s.name = 'gRPC' - s.version = '0.7.0' + s.version = '0.11.0' s.summary = 'gRPC client library for iOS/OSX' s.homepage = 'http://www.grpc.io' s.license = 'New BSD' s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' } # s.source = { :git => 'https://github.com/grpc/grpc.git', - # :tag => 'release-0_10_0-objectivec-0.6.0' } + # :tag => 'release-0_11_0-objectivec-0.11.0' } s.ios.deployment_target = '6.0' s.osx.deployment_target = '10.8' @@ -585,6 +585,6 @@ Pod::Spec.new do |s| ss.dependency 'gRPC/GRPCClient' ss.dependency 'gRPC/RxLibrary' - ss.dependency 'Protobuf', '~> 3.0.0-alpha-3' + ss.dependency 'Protobuf', '~> 3.0.0-alpha-4' end end From 7f51a041b4bc6e0eb45bc3adde40ab4bf1d63551 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Tue, 8 Sep 2015 21:31:59 -0700 Subject: [PATCH 5/8] Restrict deployment targets to the protobuf requirement. --- gRPC.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gRPC.podspec b/gRPC.podspec index df3c8ee55cd..4edc3e5dc7a 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -45,8 +45,8 @@ Pod::Spec.new do |s| # s.source = { :git => 'https://github.com/grpc/grpc.git', # :tag => 'release-0_11_0-objectivec-0.11.0' } - s.ios.deployment_target = '6.0' - s.osx.deployment_target = '10.8' + s.ios.deployment_target = '7.1' + s.osx.deployment_target = '10.9' s.requires_arc = true objc_dir = 'src/objective-c' From 6c99ad0b7623f91eabc358f84cbe0b1d70b6bc33 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Thu, 10 Sep 2015 08:30:51 -0700 Subject: [PATCH 6/8] Python version set to 0.11.0b0 --- src/python/grpcio/setup.py | 2 +- src/python/grpcio_health_checking/setup.py | 4 ++-- src/python/grpcio_test/requirements.txt | 2 +- src/python/grpcio_test/setup.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/python/grpcio/setup.py b/src/python/grpcio/setup.py index 4735ce080b0..151b2bfcb4d 100644 --- a/src/python/grpcio/setup.py +++ b/src/python/grpcio/setup.py @@ -104,7 +104,7 @@ _COMMAND_CLASS = { setuptools.setup( name='grpcio', - version='0.11.0', + version='0.11.0b0', ext_modules=_EXTENSION_MODULES, packages=list(_PACKAGES), package_dir=_PACKAGE_DIRECTORIES, diff --git a/src/python/grpcio_health_checking/setup.py b/src/python/grpcio_health_checking/setup.py index 38629aa8159..35253ba3123 100644 --- a/src/python/grpcio_health_checking/setup.py +++ b/src/python/grpcio_health_checking/setup.py @@ -51,7 +51,7 @@ _PACKAGE_DIRECTORIES = { } _INSTALL_REQUIRES = ( - 'grpcio>=0.11.0', + 'grpcio>=0.11.0b0', ) _SETUP_REQUIRES = _INSTALL_REQUIRES @@ -63,7 +63,7 @@ _COMMAND_CLASS = { setuptools.setup( name='grpcio_health_checking', - version='0.11.0', + version='0.11.0b0', packages=list(_PACKAGES), package_dir=_PACKAGE_DIRECTORIES, install_requires=_INSTALL_REQUIRES, diff --git a/src/python/grpcio_test/requirements.txt b/src/python/grpcio_test/requirements.txt index cf8b8a89994..fea80ca07f1 100644 --- a/src/python/grpcio_test/requirements.txt +++ b/src/python/grpcio_test/requirements.txt @@ -1,4 +1,4 @@ -grpcio>=0.11.0 +grpcio>=0.11.0b0 oauth2client>=1.4.7 protobuf>=3.0.0a3 pytest>=2.6 diff --git a/src/python/grpcio_test/setup.py b/src/python/grpcio_test/setup.py index 161578a5153..216119f0e7b 100644 --- a/src/python/grpcio_test/setup.py +++ b/src/python/grpcio_test/setup.py @@ -71,7 +71,7 @@ _SETUP_REQUIRES = ( _INSTALL_REQUIRES = ( 'oauth2client>=1.4.7', - 'grpcio>=0.11.0', + 'grpcio>=0.11.0b0', ) _COMMAND_CLASS = { @@ -80,7 +80,7 @@ _COMMAND_CLASS = { setuptools.setup( name='grpcio_test', - version='0.11.0', + version='0.11.0b0', packages=_PACKAGES, package_dir=_PACKAGE_DIRECTORIES, package_data=_PACKAGE_DATA, From 38fc0bb3d591246b527d52ec19583a833ab84f8b Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Thu, 10 Sep 2015 08:49:57 -0700 Subject: [PATCH 7/8] Fix Python docgen The old package directory handling was stale in grpcio's setup.py command support module and docgen had a typo. --- src/python/grpcio/commands.py | 2 +- tools/distrib/python/docgen.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py index 89c0fbf0f3f..8a2f2d6283e 100644 --- a/src/python/grpcio/commands.py +++ b/src/python/grpcio/commands.py @@ -64,7 +64,7 @@ class SphinxDocumentation(setuptools.Command): import sphinx.apidoc metadata = self.distribution.metadata src_dir = os.path.join( - os.getcwd(), self.distribution.package_dir['grpc']) + os.getcwd(), self.distribution.package_dir[''], 'grpc') sys.path.append(src_dir) sphinx.apidoc.main([ '', '--force', '--full', '-H', metadata.name, '-A', metadata.author, diff --git a/tools/distrib/python/docgen.py b/tools/distrib/python/docgen.py index d76792c56f4..2acd3cc12f2 100755 --- a/tools/distrib/python/docgen.py +++ b/tools/distrib/python/docgen.py @@ -81,7 +81,7 @@ if args.submit: assert args.doc_branch github_user = args.gh_user github_repository_owner = ( - args.gh_repo_owner if args.gh_repo_owner else gh_user) + args.gh_repo_owner if args.gh_repo_owner else args.gh_user) # Create a temporary directory out of tree, checkout gh-pages from the # specified repository, edit it, and push it. It's up to the user to then go # onto GitHub and make a PR against grpc/grpc:gh-pages. From 061d288f559f786c1541f56192303314a61e5489 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Tue, 8 Sep 2015 21:34:33 +0000 Subject: [PATCH 8/8] Beta Python documentation correction and update --- examples/python/helloworld/README.md | 3 - examples/python/helloworld/greeter_client.py | 9 +- examples/python/helloworld/greeter_server.py | 6 +- examples/python/route_guide/README.md | 36 ++- .../python/route_guide/route_guide_client.py | 21 +- .../python/route_guide/route_guide_pb2.py | 267 +++++++++++++----- .../python/route_guide/route_guide_server.py | 6 +- examples/python/route_guide/run_codegen.sh | 2 +- 8 files changed, 230 insertions(+), 120 deletions(-) mode change 100755 => 100644 examples/python/helloworld/greeter_client.py mode change 100755 => 100644 examples/python/route_guide/route_guide_client.py diff --git a/examples/python/helloworld/README.md b/examples/python/helloworld/README.md index 8fde0d2315c..070b9e88376 100644 --- a/examples/python/helloworld/README.md +++ b/examples/python/helloworld/README.md @@ -91,9 +91,6 @@ Which internally invokes the proto-compiler as: $ protoc -I ../../protos --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` ../../protos/helloworld.proto ``` -Optionally, you can just skip the code generation step as the generated python module has already -been generated for you (helloworld_pb2.py). - ### The client Client-side code can be found in [greeter_client.py](greeter_client.py). diff --git a/examples/python/helloworld/greeter_client.py b/examples/python/helloworld/greeter_client.py old mode 100755 new mode 100644 index 370ce467703..561b25bcb2e --- a/examples/python/helloworld/greeter_client.py +++ b/examples/python/helloworld/greeter_client.py @@ -29,15 +29,18 @@ """The Python implementation of the GRPC helloworld.Greeter client.""" +from grpc.beta import implementations + import helloworld_pb2 _TIMEOUT_SECONDS = 10 def run(): - with helloworld_pb2.early_adopter_create_Greeter_stub('localhost', 50051) as stub: - response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'), _TIMEOUT_SECONDS) - print "Greeter client received: " + response.message + channel = implementations.insecure_channel('localhost', 50051) + stub = helloworld_pb2.beta_create_Greeter_stub(channel) + response = stub.SayHello(helloworld_pb2.HelloRequest(name='you'), _TIMEOUT_SECONDS) + print "Greeter client received: " + response.message if __name__ == '__main__': diff --git a/examples/python/helloworld/greeter_server.py b/examples/python/helloworld/greeter_server.py index 81353666b10..1514d8f270b 100644 --- a/examples/python/helloworld/greeter_server.py +++ b/examples/python/helloworld/greeter_server.py @@ -36,15 +36,15 @@ import helloworld_pb2 _ONE_DAY_IN_SECONDS = 60 * 60 * 24 -class Greeter(helloworld_pb2.EarlyAdopterGreeterServicer): +class Greeter(helloworld_pb2.BetaGreeterServicer): def SayHello(self, request, context): return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name) def serve(): - server = helloworld_pb2.early_adopter_create_Greeter_server( - Greeter(), 50051, None, None) + server = helloworld_pb2.beta_create_Greeter_server(Greeter()) + server.add_insecure_port('[::]:50051') server.start() try: while True: diff --git a/examples/python/route_guide/README.md b/examples/python/route_guide/README.md index 636e134964d..cb1aa7d78ae 100644 --- a/examples/python/route_guide/README.md +++ b/examples/python/route_guide/README.md @@ -29,7 +29,7 @@ Then change your current directory to `examples/python/route_guide`: $ cd examples/python/route_guide ``` -You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Python quick start guide](../python). +You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Python quick start guide](../helloworld). ## Defining the service @@ -99,12 +99,11 @@ $ protoc -I ../../protos --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`w Note that as we've already provided a version of the generated code in the example repository, running this command regenerates the appropriate file rather than creates a new one. The generated code file is called `route_guide_pb2.py` and contains: - classes for the messages defined in route_guide.proto - abstract classes for the service defined in route_guide.proto - - `EarlyAdopterRouteGuideServicer`, which defines the interface for implementations of the RouteGuide service - - `EarlyAdopterRouteGuideServer`, which may be started and stopped - - `EarlyAdopterRouteGuideStub`, which can be used by clients to invoke RouteGuide RPCs + - `BetaRouteGuideServicer`, which defines the interface for implementations of the RouteGuide service + - `BetaRouteGuideStub`, which can be used by clients to invoke RouteGuide RPCs - functions for application use - - `early_adopter_create_RouteGuide_server`, which creates a gRPC server given an `EarlyAdopterRouteGuideServicer` object - - `early_adopter_create_RouteGuide_stub`, which can be used by clients to create a stub object + - `beta_create_RouteGuide_server`, which creates a gRPC server given a `BetaRouteGuideServicer` object + - `beta_create_RouteGuide_stub`, which can be used by clients to create a stub object ## Creating the server @@ -119,11 +118,11 @@ You can find the example `RouteGuide` server in [route_guide_server.py](route_gu ### Implementing RouteGuide -`route_guide_server.py` has a `RouteGuideServicer` class that implements the generated interface `route_guide_pb2.EarlyAdopterRouteGuideServicer`: +`route_guide_server.py` has a `RouteGuideServicer` class that implements the generated interface `route_guide_pb2.BetaRouteGuideServicer`: ```python # RouteGuideServicer provides an implementation of the methods of the RouteGuide service. -class RouteGuideServicer(route_guide_pb2.EarlyAdopterRouteGuideServicer): +class RouteGuideServicer(route_guide_pb2.BetaRouteGuideServicer): ``` `RouteGuideServicer` implements all the `RouteGuide` service methods. @@ -141,7 +140,7 @@ Let's look at the simplest type first, `GetFeature`, which just gets a `Point` f return feature ``` -The method is passed a `route_guide_pb2.Point` request for the RPC, and an `RpcContext` object that provides RPC-specific information such as timeout limits. It returns a `route_guide_pb2.Feature` response. +The method is passed a `route_guide_pb2.Point` request for the RPC, and a `ServicerContext` object that provides RPC-specific information such as timeout limits. It returns a `route_guide_pb2.Feature` response. #### Response-streaming RPC @@ -212,8 +211,8 @@ Once you have implemented all the `RouteGuide` methods, the next step is to star ```python def serve(): - server = route_guide_pb2.early_adopter_create_RouteGuide_server( - RouteGuideServicer(), 50051, None, None) + server = route_guide_pb2.beta_create_RouteGuide_server(RouteGuideServicer()) + server.add_insecure_port('[::]:50051') server.start() ``` @@ -228,17 +227,14 @@ You can see the complete example client code in [route_guide_client.py](route_gu To call service methods, we first need to create a *stub*. -We use the `early_adopter_create_RouteGuide_stub` function of the `route_guide_pb2` module, generated from our .proto. +We use the `beta_create_RouteGuide_stub` function of the `route_guide_pb2` module, generated from our .proto. ```python -stub = RouteGuide::Stub.new('localhost', 50051) +channel = implementations.insecure_channel('localhost', 50051) +stub = beta_create_RouteGuide_stub(channel) ``` -The returned object implements all the methods defined by the `EarlyAdopterRouteGuideStub` interface, and is also a [context manager](https://docs.python.org/2/library/stdtypes.html#typecontextmanager). All RPCs invoked on the stub must be invoked within the stub's context, so it is common for stubs to be created and used with a [with statement](https://docs.python.org/2/reference/compound_stmts.html#the-with-statement): - -```python -with route_guide_pb2.early_adopter_create_RouteGuide_stub('localhost', 50051) as stub: -``` +The returned object implements all the methods defined by the `BetaRouteGuideStub` interface. ### Calling service methods @@ -255,7 +251,7 @@ feature = stub.GetFeature(point, timeout_in_seconds) An asynchronous call to `GetFeature` is similar, but like calling a local method asynchronously in a thread pool: ```python -feature_future = stub.GetFeature.async(point, timeout_in_seconds) +feature_future = stub.GetFeature.future(point, timeout_in_seconds) feature = feature_future.result() ``` @@ -276,7 +272,7 @@ route_summary = stub.RecordRoute(point_sequence, timeout_in_seconds) ``` ```python -route_summary_future = stub.RecordRoute.async(point_sequence, timeout_in_seconds) +route_summary_future = stub.RecordRoute.future(point_sequence, timeout_in_seconds) route_summary = route_summary_future.result() ``` diff --git a/examples/python/route_guide/route_guide_client.py b/examples/python/route_guide/route_guide_client.py old mode 100755 new mode 100644 index 078231543e1..b1dfad551dc --- a/examples/python/route_guide/route_guide_client.py +++ b/examples/python/route_guide/route_guide_client.py @@ -32,6 +32,8 @@ import random import time +from grpc.beta import implementations + import route_guide_pb2 import route_guide_resources @@ -115,15 +117,16 @@ def guide_route_chat(stub): def run(): - with route_guide_pb2.early_adopter_create_RouteGuide_stub('localhost', 50051) as stub: - print "-------------- GetFeature --------------" - guide_get_feature(stub) - print "-------------- ListFeatures --------------" - guide_list_features(stub) - print "-------------- RecordRoute --------------" - guide_record_route(stub) - print "-------------- RouteChat --------------" - guide_route_chat(stub) + channel = implementations.insecure_channel('localhost', 50051) + stub = route_guide_pb2.beta_create_RouteGuide_stub(channel) + print "-------------- GetFeature --------------" + guide_get_feature(stub) + print "-------------- ListFeatures --------------" + guide_list_features(stub) + print "-------------- RecordRoute --------------" + guide_record_route(stub) + print "-------------- RouteChat --------------" + guide_route_chat(stub) if __name__ == '__main__': diff --git a/examples/python/route_guide/route_guide_pb2.py b/examples/python/route_guide/route_guide_pb2.py index 2a4532bb750..d4d9f8dcd5d 100644 --- a/examples/python/route_guide/route_guide_pb2.py +++ b/examples/python/route_guide/route_guide_pb2.py @@ -1,8 +1,6 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: route_guide.proto -import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection @@ -17,8 +15,9 @@ _sym_db = _symbol_database.Default() DESCRIPTOR = _descriptor.FileDescriptor( name='route_guide.proto', - package='', - serialized_pb=_b('\n\x11route_guide.proto\",\n\x05Point\x12\x10\n\x08latitude\x18\x01 \x01(\x05\x12\x11\n\tlongitude\x18\x02 \x01(\x05\"3\n\tRectangle\x12\x12\n\x02lo\x18\x01 \x01(\x0b\x32\x06.Point\x12\x12\n\x02hi\x18\x02 \x01(\x0b\x32\x06.Point\"1\n\x07\x46\x65\x61ture\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x18\n\x08location\x18\x02 \x01(\x0b\x32\x06.Point\"6\n\tRouteNote\x12\x18\n\x08location\x18\x01 \x01(\x0b\x32\x06.Point\x12\x0f\n\x07message\x18\x02 \x01(\t\"b\n\x0cRouteSummary\x12\x13\n\x0bpoint_count\x18\x01 \x01(\x05\x12\x15\n\rfeature_count\x18\x02 \x01(\x05\x12\x10\n\x08\x64istance\x18\x03 \x01(\x05\x12\x14\n\x0c\x65lapsed_time\x18\x04 \x01(\x05\x32\xad\x01\n\nRouteGuide\x12 \n\nGetFeature\x12\x06.Point\x1a\x08.Feature\"\x00\x12(\n\x0cListFeatures\x12\n.Rectangle\x1a\x08.Feature\"\x00\x30\x01\x12(\n\x0bRecordRoute\x12\x06.Point\x1a\r.RouteSummary\"\x00(\x01\x12)\n\tRouteChat\x12\n.RouteNote\x1a\n.RouteNote\"\x00(\x01\x30\x01') + package='routeguide', + syntax='proto3', + serialized_pb=b'\n\x11route_guide.proto\x12\nrouteguide\",\n\x05Point\x12\x10\n\x08latitude\x18\x01 \x01(\x05\x12\x11\n\tlongitude\x18\x02 \x01(\x05\"I\n\tRectangle\x12\x1d\n\x02lo\x18\x01 \x01(\x0b\x32\x11.routeguide.Point\x12\x1d\n\x02hi\x18\x02 \x01(\x0b\x32\x11.routeguide.Point\"<\n\x07\x46\x65\x61ture\x12\x0c\n\x04name\x18\x01 \x01(\t\x12#\n\x08location\x18\x02 \x01(\x0b\x32\x11.routeguide.Point\"A\n\tRouteNote\x12#\n\x08location\x18\x01 \x01(\x0b\x32\x11.routeguide.Point\x12\x0f\n\x07message\x18\x02 \x01(\t\"b\n\x0cRouteSummary\x12\x13\n\x0bpoint_count\x18\x01 \x01(\x05\x12\x15\n\rfeature_count\x18\x02 \x01(\x05\x12\x10\n\x08\x64istance\x18\x03 \x01(\x05\x12\x14\n\x0c\x65lapsed_time\x18\x04 \x01(\x05\x32\x85\x02\n\nRouteGuide\x12\x36\n\nGetFeature\x12\x11.routeguide.Point\x1a\x13.routeguide.Feature\"\x00\x12>\n\x0cListFeatures\x12\x15.routeguide.Rectangle\x1a\x13.routeguide.Feature\"\x00\x30\x01\x12>\n\x0bRecordRoute\x12\x11.routeguide.Point\x1a\x18.routeguide.RouteSummary\"\x00(\x01\x12?\n\tRouteChat\x12\x15.routeguide.RouteNote\x1a\x15.routeguide.RouteNote\"\x00(\x01\x30\x01\x42\x0f\n\x07\x65x.grpc\xa2\x02\x03RTGb\x06proto3' ) _sym_db.RegisterFileDescriptor(DESCRIPTOR) @@ -27,20 +26,20 @@ _sym_db.RegisterFileDescriptor(DESCRIPTOR) _POINT = _descriptor.Descriptor( name='Point', - full_name='Point', + full_name='routeguide.Point', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='latitude', full_name='Point.latitude', index=0, + name='latitude', full_name='routeguide.Point.latitude', index=0, number=1, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='longitude', full_name='Point.longitude', index=1, + name='longitude', full_name='routeguide.Point.longitude', index=1, number=2, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, @@ -54,30 +53,31 @@ _POINT = _descriptor.Descriptor( ], options=None, is_extendable=False, + syntax='proto3', extension_ranges=[], oneofs=[ ], - serialized_start=21, - serialized_end=65, + serialized_start=33, + serialized_end=77, ) _RECTANGLE = _descriptor.Descriptor( name='Rectangle', - full_name='Rectangle', + full_name='routeguide.Rectangle', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='lo', full_name='Rectangle.lo', index=0, + name='lo', full_name='routeguide.Rectangle.lo', index=0, number=1, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='hi', full_name='Rectangle.hi', index=1, + name='hi', full_name='routeguide.Rectangle.hi', index=1, number=2, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, @@ -91,30 +91,31 @@ _RECTANGLE = _descriptor.Descriptor( ], options=None, is_extendable=False, + syntax='proto3', extension_ranges=[], oneofs=[ ], - serialized_start=67, - serialized_end=118, + serialized_start=79, + serialized_end=152, ) _FEATURE = _descriptor.Descriptor( name='Feature', - full_name='Feature', + full_name='routeguide.Feature', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='name', full_name='Feature.name', index=0, + name='name', full_name='routeguide.Feature.name', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='location', full_name='Feature.location', index=1, + name='location', full_name='routeguide.Feature.location', index=1, number=2, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, @@ -128,32 +129,33 @@ _FEATURE = _descriptor.Descriptor( ], options=None, is_extendable=False, + syntax='proto3', extension_ranges=[], oneofs=[ ], - serialized_start=120, - serialized_end=169, + serialized_start=154, + serialized_end=214, ) _ROUTENOTE = _descriptor.Descriptor( name='RouteNote', - full_name='RouteNote', + full_name='routeguide.RouteNote', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='location', full_name='RouteNote.location', index=0, + name='location', full_name='routeguide.RouteNote.location', index=0, number=1, type=11, cpp_type=10, label=1, has_default_value=False, default_value=None, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='message', full_name='RouteNote.message', index=1, + name='message', full_name='routeguide.RouteNote.message', index=1, number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), @@ -165,44 +167,45 @@ _ROUTENOTE = _descriptor.Descriptor( ], options=None, is_extendable=False, + syntax='proto3', extension_ranges=[], oneofs=[ ], - serialized_start=171, - serialized_end=225, + serialized_start=216, + serialized_end=281, ) _ROUTESUMMARY = _descriptor.Descriptor( name='RouteSummary', - full_name='RouteSummary', + full_name='routeguide.RouteSummary', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='point_count', full_name='RouteSummary.point_count', index=0, + name='point_count', full_name='routeguide.RouteSummary.point_count', index=0, number=1, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='feature_count', full_name='RouteSummary.feature_count', index=1, + name='feature_count', full_name='routeguide.RouteSummary.feature_count', index=1, number=2, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='distance', full_name='RouteSummary.distance', index=2, + name='distance', full_name='routeguide.RouteSummary.distance', index=2, number=3, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), _descriptor.FieldDescriptor( - name='elapsed_time', full_name='RouteSummary.elapsed_time', index=3, + name='elapsed_time', full_name='routeguide.RouteSummary.elapsed_time', index=3, number=4, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, @@ -216,11 +219,12 @@ _ROUTESUMMARY = _descriptor.Descriptor( ], options=None, is_extendable=False, + syntax='proto3', extension_ranges=[], oneofs=[ ], - serialized_start=227, - serialized_end=325, + serialized_start=283, + serialized_end=381, ) _RECTANGLE.fields_by_name['lo'].message_type = _POINT @@ -236,58 +240,61 @@ DESCRIPTOR.message_types_by_name['RouteSummary'] = _ROUTESUMMARY Point = _reflection.GeneratedProtocolMessageType('Point', (_message.Message,), dict( DESCRIPTOR = _POINT, __module__ = 'route_guide_pb2' - # @@protoc_insertion_point(class_scope:Point) + # @@protoc_insertion_point(class_scope:routeguide.Point) )) _sym_db.RegisterMessage(Point) Rectangle = _reflection.GeneratedProtocolMessageType('Rectangle', (_message.Message,), dict( DESCRIPTOR = _RECTANGLE, __module__ = 'route_guide_pb2' - # @@protoc_insertion_point(class_scope:Rectangle) + # @@protoc_insertion_point(class_scope:routeguide.Rectangle) )) _sym_db.RegisterMessage(Rectangle) Feature = _reflection.GeneratedProtocolMessageType('Feature', (_message.Message,), dict( DESCRIPTOR = _FEATURE, __module__ = 'route_guide_pb2' - # @@protoc_insertion_point(class_scope:Feature) + # @@protoc_insertion_point(class_scope:routeguide.Feature) )) _sym_db.RegisterMessage(Feature) RouteNote = _reflection.GeneratedProtocolMessageType('RouteNote', (_message.Message,), dict( DESCRIPTOR = _ROUTENOTE, __module__ = 'route_guide_pb2' - # @@protoc_insertion_point(class_scope:RouteNote) + # @@protoc_insertion_point(class_scope:routeguide.RouteNote) )) _sym_db.RegisterMessage(RouteNote) RouteSummary = _reflection.GeneratedProtocolMessageType('RouteSummary', (_message.Message,), dict( DESCRIPTOR = _ROUTESUMMARY, __module__ = 'route_guide_pb2' - # @@protoc_insertion_point(class_scope:RouteSummary) + # @@protoc_insertion_point(class_scope:routeguide.RouteSummary) )) _sym_db.RegisterMessage(RouteSummary) +DESCRIPTOR.has_options = True +DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), b'\n\007ex.grpc\242\002\003RTG') import abc -from grpc._adapter import fore -from grpc._adapter import rear -from grpc.framework.assembly import implementations -from grpc.framework.assembly import utilities +from grpc.beta import implementations as beta_implementations +from grpc.early_adopter import implementations as early_adopter_implementations +from grpc.framework.alpha import utilities as alpha_utilities +from grpc.framework.common import cardinality +from grpc.framework.interfaces.face import utilities as face_utilities class EarlyAdopterRouteGuideServicer(object): """""" __metaclass__ = abc.ABCMeta @abc.abstractmethod - def GetFeature(self, request): + def GetFeature(self, request, context): raise NotImplementedError() @abc.abstractmethod - def ListFeatures(self, request): + def ListFeatures(self, request, context): raise NotImplementedError() @abc.abstractmethod - def RecordRoute(self, request_iterator): + def RecordRoute(self, request_iterator, context): raise NotImplementedError() @abc.abstractmethod - def RouteChat(self, request_iterator): + def RouteChat(self, request_iterator, context): raise NotImplementedError() class EarlyAdopterRouteGuideServer(object): """""" @@ -317,54 +324,158 @@ class EarlyAdopterRouteGuideStub(object): def RouteChat(self, request_iterator): raise NotImplementedError() RouteChat.async = None -def early_adopter_create_RouteGuide_server(servicer, port, root_certificates, key_chain_pairs): - method_implementations = { - "GetFeature": utilities.unary_unary_inline(servicer.GetFeature), - "ListFeatures": utilities.unary_stream_inline(servicer.ListFeatures), - "RecordRoute": utilities.stream_unary_inline(servicer.RecordRoute), - "RouteChat": utilities.stream_stream_inline(servicer.RouteChat), +def early_adopter_create_RouteGuide_server(servicer, port, private_key=None, certificate_chain=None): + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + method_service_descriptions = { + "GetFeature": alpha_utilities.unary_unary_service_description( + servicer.GetFeature, + route_guide_pb2.Point.FromString, + route_guide_pb2.Feature.SerializeToString, + ), + "ListFeatures": alpha_utilities.unary_stream_service_description( + servicer.ListFeatures, + route_guide_pb2.Rectangle.FromString, + route_guide_pb2.Feature.SerializeToString, + ), + "RecordRoute": alpha_utilities.stream_unary_service_description( + servicer.RecordRoute, + route_guide_pb2.Point.FromString, + route_guide_pb2.RouteSummary.SerializeToString, + ), + "RouteChat": alpha_utilities.stream_stream_service_description( + servicer.RouteChat, + route_guide_pb2.RouteNote.FromString, + route_guide_pb2.RouteNote.SerializeToString, + ), + } + return early_adopter_implementations.server("routeguide.RouteGuide", method_service_descriptions, port, private_key=private_key, certificate_chain=certificate_chain) +def early_adopter_create_RouteGuide_stub(host, port, metadata_transformer=None, secure=False, root_certificates=None, private_key=None, certificate_chain=None, server_host_override=None): + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + method_invocation_descriptions = { + "GetFeature": alpha_utilities.unary_unary_invocation_description( + route_guide_pb2.Point.SerializeToString, + route_guide_pb2.Feature.FromString, + ), + "ListFeatures": alpha_utilities.unary_stream_invocation_description( + route_guide_pb2.Rectangle.SerializeToString, + route_guide_pb2.Feature.FromString, + ), + "RecordRoute": alpha_utilities.stream_unary_invocation_description( + route_guide_pb2.Point.SerializeToString, + route_guide_pb2.RouteSummary.FromString, + ), + "RouteChat": alpha_utilities.stream_stream_invocation_description( + route_guide_pb2.RouteNote.SerializeToString, + route_guide_pb2.RouteNote.FromString, + ), } + return early_adopter_implementations.stub("routeguide.RouteGuide", method_invocation_descriptions, host, port, metadata_transformer=metadata_transformer, secure=secure, root_certificates=root_certificates, private_key=private_key, certificate_chain=certificate_chain, server_host_override=server_host_override) + +class BetaRouteGuideServicer(object): + """""" + __metaclass__ = abc.ABCMeta + @abc.abstractmethod + def GetFeature(self, request, context): + raise NotImplementedError() + @abc.abstractmethod + def ListFeatures(self, request, context): + raise NotImplementedError() + @abc.abstractmethod + def RecordRoute(self, request_iterator, context): + raise NotImplementedError() + @abc.abstractmethod + def RouteChat(self, request_iterator, context): + raise NotImplementedError() + +class BetaRouteGuideStub(object): + """The interface to which stubs will conform.""" + __metaclass__ = abc.ABCMeta + @abc.abstractmethod + def GetFeature(self, request, timeout): + raise NotImplementedError() + GetFeature.future = None + @abc.abstractmethod + def ListFeatures(self, request, timeout): + raise NotImplementedError() + @abc.abstractmethod + def RecordRoute(self, request_iterator, timeout): + raise NotImplementedError() + RecordRoute.future = None + @abc.abstractmethod + def RouteChat(self, request_iterator, timeout): + raise NotImplementedError() + +def beta_create_RouteGuide_server(servicer, pool=None, pool_size=None, default_timeout=None, maximum_timeout=None): + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 import route_guide_pb2 import route_guide_pb2 import route_guide_pb2 import route_guide_pb2 request_deserializers = { - "GetFeature": route_guide_pb2.Point.FromString, - "ListFeatures": route_guide_pb2.Rectangle.FromString, - "RecordRoute": route_guide_pb2.Point.FromString, - "RouteChat": route_guide_pb2.RouteNote.FromString, + ('routeguide.RouteGuide', 'GetFeature'): route_guide_pb2.Point.FromString, + ('routeguide.RouteGuide', 'ListFeatures'): route_guide_pb2.Rectangle.FromString, + ('routeguide.RouteGuide', 'RecordRoute'): route_guide_pb2.Point.FromString, + ('routeguide.RouteGuide', 'RouteChat'): route_guide_pb2.RouteNote.FromString, } response_serializers = { - "GetFeature": lambda x: x.SerializeToString(), - "ListFeatures": lambda x: x.SerializeToString(), - "RecordRoute": lambda x: x.SerializeToString(), - "RouteChat": lambda x: x.SerializeToString(), + ('routeguide.RouteGuide', 'GetFeature'): route_guide_pb2.Feature.SerializeToString, + ('routeguide.RouteGuide', 'ListFeatures'): route_guide_pb2.Feature.SerializeToString, + ('routeguide.RouteGuide', 'RecordRoute'): route_guide_pb2.RouteSummary.SerializeToString, + ('routeguide.RouteGuide', 'RouteChat'): route_guide_pb2.RouteNote.SerializeToString, } - link = fore.activated_fore_link(port, request_deserializers, response_serializers, root_certificates, key_chain_pairs) - return implementations.assemble_service(method_implementations, link) -def early_adopter_create_RouteGuide_stub(host, port): method_implementations = { - "GetFeature": utilities.unary_unary_inline(None), - "ListFeatures": utilities.unary_stream_inline(None), - "RecordRoute": utilities.stream_unary_inline(None), - "RouteChat": utilities.stream_stream_inline(None), + ('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): import route_guide_pb2 import route_guide_pb2 import route_guide_pb2 import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + import route_guide_pb2 + request_serializers = { + ('routeguide.RouteGuide', 'GetFeature'): route_guide_pb2.Point.SerializeToString, + ('routeguide.RouteGuide', 'ListFeatures'): route_guide_pb2.Rectangle.SerializeToString, + ('routeguide.RouteGuide', 'RecordRoute'): route_guide_pb2.Point.SerializeToString, + ('routeguide.RouteGuide', 'RouteChat'): route_guide_pb2.RouteNote.SerializeToString, + } response_deserializers = { - "GetFeature": route_guide_pb2.Feature.FromString, - "ListFeatures": route_guide_pb2.Feature.FromString, - "RecordRoute": route_guide_pb2.RouteSummary.FromString, - "RouteChat": route_guide_pb2.RouteNote.FromString, + ('routeguide.RouteGuide', 'GetFeature'): route_guide_pb2.Feature.FromString, + ('routeguide.RouteGuide', 'ListFeatures'): route_guide_pb2.Feature.FromString, + ('routeguide.RouteGuide', 'RecordRoute'): route_guide_pb2.RouteSummary.FromString, + ('routeguide.RouteGuide', 'RouteChat'): route_guide_pb2.RouteNote.FromString, } - request_serializers = { - "GetFeature": lambda x: x.SerializeToString(), - "ListFeatures": lambda x: x.SerializeToString(), - "RecordRoute": lambda x: x.SerializeToString(), - "RouteChat": lambda x: x.SerializeToString(), + cardinalities = { + 'GetFeature': cardinality.Cardinality.UNARY_UNARY, + 'ListFeatures': cardinality.Cardinality.UNARY_STREAM, + 'RecordRoute': cardinality.Cardinality.STREAM_UNARY, + 'RouteChat': cardinality.Cardinality.STREAM_STREAM, } - link = rear.activated_rear_link(host, port, request_serializers, response_deserializers) - return implementations.assemble_dynamic_inline_stub(method_implementations, link) + 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) # @@protoc_insertion_point(module_scope) diff --git a/examples/python/route_guide/route_guide_server.py b/examples/python/route_guide/route_guide_server.py index 44bbacf5f32..f23b98bf367 100644 --- a/examples/python/route_guide/route_guide_server.py +++ b/examples/python/route_guide/route_guide_server.py @@ -65,7 +65,7 @@ def get_distance(start, end): R = 6371000; # metres return R * c; -class RouteGuideServicer(route_guide_pb2.EarlyAdopterRouteGuideServicer): +class RouteGuideServicer(route_guide_pb2.BetaRouteGuideServicer): """Provides methods that implement functionality of route guide server.""" def __init__(self): @@ -121,8 +121,8 @@ class RouteGuideServicer(route_guide_pb2.EarlyAdopterRouteGuideServicer): def serve(): - server = route_guide_pb2.early_adopter_create_RouteGuide_server( - RouteGuideServicer(), 50051, None, None) + server = route_guide_pb2.beta_create_RouteGuide_server(RouteGuideServicer()) + server.add_insecure_port('[::]:50051') server.start() try: while True: diff --git a/examples/python/route_guide/run_codegen.sh b/examples/python/route_guide/run_codegen.sh index 689e0978de6..a5759025b8d 100755 --- a/examples/python/route_guide/run_codegen.sh +++ b/examples/python/route_guide/run_codegen.sh @@ -1,4 +1,4 @@ #!/bin/bash # Runs the protoc with gRPC plugin to generate protocol messages and gRPC stubs. -protoc -I . --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` route_guide.proto +protoc -I ../../protos --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_python_plugin` ../../protos/route_guide.proto