pull/21458/head
Richard Belleville 4 years ago
parent fd0d0f77df
commit 999bbf1401
  1. 8
      examples/python/data_transmission/client.py
  2. 4
      examples/python/data_transmission/server.py
  3. 10
      examples/python/helloworld/greeter_client_with_options.py
  4. 4
      examples/python/interceptors/default_value/greeter_client.py
  5. 4
      examples/python/interceptors/headers/greeter_client.py
  6. 9
      examples/python/interceptors/headers/greeter_server.py
  7. 4
      examples/python/metadata/metadata_client.py
  8. 4
      examples/python/metadata/metadata_server.py
  9. 27
      examples/python/multiplex/multiplex_client.py
  10. 17
      examples/python/multiplex/multiplex_server.py
  11. 5
      examples/python/multiplex/route_guide_resources.py
  12. 22
      examples/python/route_guide/route_guide_client.py
  13. 5
      examples/python/route_guide/route_guide_resources.py
  14. 13
      examples/python/route_guide/route_guide_server.py
  15. 1
      src/python/grpcio/grpc/_runtime_protos.py
  16. 6
      src/python/grpcio_tests/tests/unit/BUILD.bazel
  17. 24
      tools/distrib/python/grpcio_tools/BUILD.bazel
  18. 4
      tools/distrib/python/grpcio_tools/grpc_tools/protoc.py
  19. 36
      tools/distrib/python/grpcio_tools/grpc_tools/test/BUILD.bazel

@ -36,8 +36,8 @@ CLIENT_ID = 1
# only respond once.)
def simple_method(stub):
print("--------------Call SimpleMethod Begin--------------")
request = protos.Request(
client_id=CLIENT_ID, request_data="called by Python client")
request = protos.Request(client_id=CLIENT_ID,
request_data="called by Python client")
response = stub.SimpleMethod(request)
print("resp from server(%d), the message=%s" %
(response.server_id, response.response_data))
@ -70,8 +70,8 @@ def client_streaming_method(stub):
# but the server can return the response many times.)
def server_streaming_method(stub):
print("--------------Call ServerStreamingMethod Begin--------------")
request = protos.Request(
client_id=CLIENT_ID, request_data="called by Python client")
request = protos.Request(client_id=CLIENT_ID,
request_data="called by Python client")
response_iterator = stub.ServerStreamingMethod(request)
for response in response_iterator:
print("recv from server(%d), message=%s" %

@ -44,8 +44,8 @@ class DemoServer(services.GRPCDemoServicer):
def ClientStreamingMethod(self, request_iterator, context):
print("ClientStreamingMethod called by client...")
for request in request_iterator:
print("recv from client(%d), message= %s" % (request.client_id,
request.request_data))
print("recv from client(%d), message= %s" %
(request.client_id, request.request_data))
response = protos.Response(
server_id=SERVER_ID,
response_data="Python server ClientStreamingMethod ok")

@ -27,11 +27,11 @@ def run():
# of the code.
#
# For more channel options, please see https://grpc.io/grpc/core/group__grpc__arg__keys.html
with grpc.insecure_channel(
target='localhost:50051',
options=[('grpc.lb_policy_name', 'pick_first'),
('grpc.enable_retries', 0), ('grpc.keepalive_timeout_ms',
10000)]) as channel:
with grpc.insecure_channel(target='localhost:50051',
options=[('grpc.lb_policy_name', 'pick_first'),
('grpc.enable_retries', 0),
('grpc.keepalive_timeout_ms', 10000)
]) as channel:
stub = services.GreeterStub(channel)
# Timeout in seconds.
# Please refer gRPC Python documents for more detail. https://grpc.io/grpc/python/grpc.html

@ -18,8 +18,8 @@ import logging
import grpc
protos, services = grpc.protos_and_services(
"protos/helloworld.proto", include_paths=["../../.."])
protos, services = grpc.protos_and_services("protos/helloworld.proto",
include_paths=["../../.."])
import default_value_client_interceptor

@ -18,8 +18,8 @@ import logging
import grpc
protos, services = grpc.protos_and_services(
"protos/helloworld.protos", include_paths=["../../.."])
protos, services = grpc.protos_and_services("protos/helloworld.protos",
include_paths=["../../.."])
import header_manipulator_client_interceptor

@ -18,8 +18,8 @@ import logging
import grpc
protos, services = grpc.protos_and_services(
"protos/helloworld.protos", include_paths=["../../.."])
protos, services = grpc.protos_and_services("protos/helloworld.protos",
include_paths=["../../.."])
from request_header_validator_interceptor import RequestHeaderValidatorInterceptor
@ -33,9 +33,8 @@ def serve():
header_validator = RequestHeaderValidatorInterceptor(
'one-time-password', '42', grpc.StatusCode.UNAUTHENTICATED,
'Access denied!')
server = grpc.server(
futures.ThreadPoolExecutor(max_workers=10),
interceptors=(header_validator,))
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10),
interceptors=(header_validator,))
services.add_GreeterServicer_to_server(Greeter(), server)
server.add_insecure_port('[::]:50051')
server.start()

@ -18,8 +18,8 @@ import logging
import grpc
protos, services = grpc.protos_and_services(
"protos/helloworld.proto", include_paths=["../.."])
protos, services = grpc.protos_and_services("protos/helloworld.proto",
include_paths=["../.."])
def run():

@ -19,8 +19,8 @@ import logging
import grpc
protos, services = grpc.protos_and_services(
"protos/helloworld.proto", include_paths=["../.."])
protos, services = grpc.protos_and_services("protos/helloworld.proto",
include_paths=["../.."])
class Greeter(services.GreeterServicer):

@ -21,17 +21,17 @@ import logging
import grpc
hw_protos, hw_services = grpc.protos_and_services(
"protos/helloworld.proto", include_paths=["../.."])
rg_protos, rg_services = grpc.protos_and_services(
"protos/route_guide.proto", include_paths=["../.."])
hw_protos, hw_services = grpc.protos_and_services("protos/helloworld.proto",
include_paths=["../.."])
rg_protos, rg_services = grpc.protos_and_services("protos/route_guide.proto",
include_paths=["../.."])
import route_guide_resources
def make_route_note(message, latitude, longitude):
return rg_protos.RouteNote(
message=message,
location=rg_protos.Point(latitude=latitude, longitude=longitude))
return rg_protos.RouteNote(message=message,
location=rg_protos.Point(latitude=latitude,
longitude=longitude))
def guide_get_one_feature(route_guide_stub, point):
@ -47,17 +47,18 @@ def guide_get_one_feature(route_guide_stub, point):
def guide_get_feature(route_guide_stub):
guide_get_one_feature(route_guide_stub,
rg_protos.Point(
latitude=409146138, longitude=-746188906))
guide_get_one_feature(
route_guide_stub,
rg_protos.Point(latitude=409146138, longitude=-746188906))
guide_get_one_feature(route_guide_stub,
rg_protos.Point(latitude=0, longitude=0))
def guide_list_features(route_guide_stub):
rectangle = rg_protos.Rectangle(
lo=rg_protos.Point(latitude=400000000, longitude=-750000000),
hi=rg_protos.Point(latitude=420000000, longitude=-730000000))
rectangle = rg_protos.Rectangle(lo=rg_protos.Point(latitude=400000000,
longitude=-750000000),
hi=rg_protos.Point(latitude=420000000,
longitude=-730000000))
print("Looking for features between 40, -75 and 42, -73")
features = route_guide_stub.ListFeatures(rectangle)

@ -20,10 +20,10 @@ import logging
import grpc
hw_protos, hw_services = grpc.protos_and_services(
"protos/helloworld.proto", include_paths=["../.."])
rg_protos, rg_services = grpc.protos_and_services(
"protos/route_guide.proto", include_paths=["../.."])
hw_protos, hw_services = grpc.protos_and_services("protos/helloworld.proto",
include_paths=["../.."])
rg_protos, rg_services = grpc.protos_and_services("protos/route_guide.proto",
include_paths=["../.."])
import route_guide_resources
@ -103,11 +103,10 @@ class _RouteGuideServicer(rg_services.RouteGuideServicer):
prev_point = point
elapsed_time = time.time() - start_time
return rg_protos.RouteSummary(
point_count=point_count,
feature_count=feature_count,
distance=int(distance),
elapsed_time=int(elapsed_time))
return rg_protos.RouteSummary(point_count=point_count,
feature_count=feature_count,
distance=int(distance),
elapsed_time=int(elapsed_time))
def RouteChat(self, request_iterator, context):
prev_notes = []

@ -32,8 +32,7 @@ def read_route_guide_database():
for item in json.load(route_guide_db_file):
feature = protos.Feature(
name=item["name"],
location=protos.Point(
latitude=item["location"]["latitude"],
longitude=item["location"]["longitude"]))
location=protos.Point(latitude=item["location"]["latitude"],
longitude=item["location"]["longitude"]))
feature_list.append(feature)
return feature_list

@ -20,15 +20,15 @@ import logging
import grpc
protos, services = grpc.protos_and_services(
"protos/route_guide.proto", include_paths=["../.."])
protos, services = grpc.protos_and_services("protos/route_guide.proto",
include_paths=["../.."])
import route_guide_resources
def make_route_note(message, latitude, longitude):
return protos.RouteNote(
message=message,
location=protos.Point(latitude=latitude, longitude=longitude))
return protos.RouteNote(message=message,
location=protos.Point(latitude=latitude,
longitude=longitude))
def guide_get_one_feature(stub, point):
@ -44,16 +44,16 @@ def guide_get_one_feature(stub, point):
def guide_get_feature(stub):
guide_get_one_feature(stub,
protos.Point(
latitude=409146138, longitude=-746188906))
guide_get_one_feature(
stub, protos.Point(latitude=409146138, longitude=-746188906))
guide_get_one_feature(stub, protos.Point(latitude=0, longitude=0))
def guide_list_features(stub):
rectangle = protos.Rectangle(
lo=protos.Point(latitude=400000000, longitude=-750000000),
hi=protos.Point(latitude=420000000, longitude=-730000000))
rectangle = protos.Rectangle(lo=protos.Point(latitude=400000000,
longitude=-750000000),
hi=protos.Point(latitude=420000000,
longitude=-730000000))
print("Looking for features between 40, -75 and 42, -73")
features = stub.ListFeatures(rectangle)

@ -31,8 +31,7 @@ def read_route_guide_database():
for item in json.load(route_guide_db_file):
feature = protos.Feature(
name=item["name"],
location=protos.Point(
latitude=item["location"]["latitude"],
longitude=item["location"]["longitude"]))
location=protos.Point(latitude=item["location"]["latitude"],
longitude=item["location"]["longitude"]))
feature_list.append(feature)
return feature_list

@ -20,8 +20,8 @@ import logging
import grpc
protos, services = grpc.protos_and_services(
"protos/route_guide.proto", include_paths=["../.."])
protos, services = grpc.protos_and_services("protos/route_guide.proto",
include_paths=["../.."])
import route_guide_resources
@ -96,11 +96,10 @@ class RouteGuideServicer(services.RouteGuideServicer):
prev_point = point
elapsed_time = time.time() - start_time
return protos.RouteSummary(
point_count=point_count,
feature_count=feature_count,
distance=int(distance),
elapsed_time=int(elapsed_time))
return protos.RouteSummary(point_count=point_count,
feature_count=feature_count,
distance=int(distance),
elapsed_time=int(elapsed_time))
def RouteChat(self, request_iterator, context):
prev_notes = []

@ -14,6 +14,7 @@
import sys
def _uninstalled_protos(*args, **kwargs):
raise NotImplementedError(
"Install the grpcio-tools package to use the protos function.")

@ -116,15 +116,15 @@ py2and3_test(
name = "_dynamic_stubs_test",
size = "small",
srcs = ["_dynamic_stubs_test.py"],
main = "_dynamic_stubs_test.py",
imports = ["../../"],
data = [
"data/foo/bar.proto",
],
imports = ["../../"],
main = "_dynamic_stubs_test.py",
deps = [
"@six",
"//src/python/grpcio/grpc:grpcio",
"//src/python/grpcio_tests/tests/testing",
"//tools/distrib/python/grpcio_tools:grpc_tools",
"@six",
],
)

@ -12,7 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
package(default_visibility = ["//src/python:__subpackages__", "//tools/distrib/python/grpcio_tools:__subpackages__"])
package(default_visibility = [
"//src/python:__subpackages__",
"//tools/distrib/python/grpcio_tools:__subpackages__",
])
load("//bazel:cython_library.bzl", "pyx_library")
@ -20,11 +23,11 @@ cc_library(
name = "protoc_lib",
srcs = ["grpc_tools/main.cc"],
hdrs = ["grpc_tools/main.h"],
includes = ["."],
deps = [
"@com_google_protobuf//:protoc_lib",
"//src/compiler:grpc_plugin_support",
"//src/compiler:grpc_plugin_support",
"@com_google_protobuf//:protoc_lib",
],
includes = ["."],
)
pyx_library(
@ -35,11 +38,14 @@ pyx_library(
py_library(
name = "grpc_tools",
srcs = ["grpc_tools/__init__.py", "grpc_tools/protoc.py"],
deps = [
":cyprotoc",
"@com_google_protobuf//:protobuf_python",
"//src/python/grpcio/grpc:grpcio",
srcs = [
"grpc_tools/__init__.py",
"grpc_tools/protoc.py",
],
srcs_version = "PY2AND3",
deps = [
":cyprotoc",
"//src/python/grpcio/grpc:grpcio",
"@com_google_protobuf//:protobuf_python",
],
)

@ -101,8 +101,8 @@ if sys.version_info[0] > 2:
def _generated_file_to_module_name(self, filepath):
components = filepath.split(os.path.sep)
return ".".join(
components[:-1] + [os.path.splitext(components[-1])[0]])
return ".".join(components[:-1] +
[os.path.splitext(components[-1])[0]])
def exec_module(self, module):
assert module.__name__ == self._module_name

@ -4,38 +4,38 @@ load("//bazel:python_rules.bzl", "py_grpc_library", "py_proto_library")
proto_library(
name = "simplest_proto",
testonly = True,
srcs = ["simplest.proto"],
strip_import_prefix = "/tools/distrib/python/grpcio_tools/",
testonly = True,
)
proto_library(
name = "complicated_proto",
testonly = True,
srcs = ["complicated.proto"],
deps = [":simplest_proto"],
strip_import_prefix = "/tools/distrib/python/grpcio_tools/",
testonly = True,
deps = [":simplest_proto"],
)
py_proto_library(
name = "complicated_py_pb2",
deps = ["complicated_proto"],
testonly = True,
deps = ["complicated_proto"],
)
py_test(
name = "protoc_test",
srcs = ["protoc_test.py"],
deps = [
"//tools/distrib/python/grpcio_tools:grpc_tools",
":complicated_py_pb2",
],
data = [
"simple.proto",
"simpler.proto",
"simplest.proto",
"complicated.proto",
"flawed.proto",
],
python_version = "PY3",
name = "protoc_test",
srcs = ["protoc_test.py"],
data = [
"complicated.proto",
"flawed.proto",
"simple.proto",
"simpler.proto",
"simplest.proto",
],
python_version = "PY3",
deps = [
":complicated_py_pb2",
"//tools/distrib/python/grpcio_tools:grpc_tools",
],
)

Loading…
Cancel
Save