Exemplo n.º 1
0
def _test_sunny_day():
    if sys.version_info[0] == 3:
        import grpc
        protos, services = grpc.protos_and_services(
            os.path.join("tests", "unit", "data", "foo", "bar.proto"))
        assert protos.BarMessage is not None
        assert services.BarStub is not None
    else:
        _assert_unimplemented("Python 3")
Exemplo n.º 2
0
def _assert_unimplemented(msg_substr):
    import grpc
    try:
        protos, services = grpc.protos_and_services(
            "tests/unit/data/foo/bar.proto")
    except NotImplementedError as e:
        assert msg_substr in str(e), "{} was not in '{}'".format(
            msg_substr, str(e))
    else:
        assert False, "Did not raise NotImplementedError"
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Client of the Python example of customizing authentication mechanism."""

import argparse
import contextlib
import logging

import grpc
import _credentials

helloworld_pb2, helloworld_pb2_grpc = grpc.protos_and_services(
    "helloworld.proto")

_LOGGER = logging.getLogger(__name__)
_LOGGER.setLevel(logging.INFO)

_SERVER_ADDR_TEMPLATE = 'localhost:%d'
_SIGNATURE_HEADER_KEY = 'x-signature'


class AuthGateway(grpc.AuthMetadataPlugin):

    def __call__(self, context, callback):
        """Implements authentication by passing metadata to a callback.

        Implementations of this method must not block.
Exemplo n.º 4
0
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Python implementation of the GRPC helloworld.Greeter server."""

from concurrent import futures
import logging

import grpc

protos, services = grpc.protos_and_services("helloworld.proto")


class Greeter(services.GreeterServicer):
    def SayHello(self, request, context):
        return protos.HelloReply(message='Hello, %s!' % request.name)


def serve():
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    services.add_GreeterServicer_to_server(Greeter(), server)
    server.add_insecure_port('[::]:50051')
    server.start()
    server.wait_for_termination()

Exemplo n.º 5
0
def _test_sunny_day():
    import grpc
    protos, services = grpc.protos_and_services(
        os.path.join(_DATA_DIR, "foo", "bar.proto"))
    assert protos.BarMessage is not None
    assert services.BarStub is not None
Exemplo n.º 6
0
def _test_well_known_types():
    import grpc
    protos, services = grpc.protos_and_services(
        os.path.join(_DATA_DIR, "foo", "bar_with_wkt.proto"))
    assert protos.BarMessage is not None
    assert services.BarStub is not None
Exemplo n.º 7
0
from distutils.util import strtobool
import json
import os
import queue
import random
import threading
import time
import uuid

try:
    import grpc

    try:
        # Use dynmaic code generation which is available in
        # grpc-tools >= 1.32.0
        msg_pb2, msg_pb2_grpc = grpc.protos_and_services(
            "directord/drivers/generated/msg.proto")
        grpc_MessageServiceServicer = msg_pb2_grpc.MessageServiceServicer
    except (AttributeError, NotImplementedError):
        # Fall back to our generated version which requires grpc <= 1.26.0
        from directord.drivers.generated import msg_pb2
        from directord.drivers.generated import msg_pb2_grpc
        from directord.drivers.generated.msg_pb2_grpc import (
            MessageServiceServicer as grpc_MessageServiceServicer, )
    DRIVER_AVAILABLE = True
except (ImportError, ModuleNotFoundError):
    DRIVER_AVAILABLE = False
    grpc_MessageServiceServicer = object
    pass

from directord import drivers
from directord import utils
Exemplo n.º 8
0
# -*- coding: utf-8 -*-
"""
Usage: nameko run performance_nameko
"""
import grpc

from nameko_grpc.entrypoint import Grpc

example_pb2, example_pb2_grpc = grpc.protos_and_services("example.proto")
entrypoint = Grpc.implementing(example_pb2_grpc.exampleStub)


class example:
    name = "example"

    @entrypoint
    def unary_unary(self, request, context):
        message = request.value * (request.multiplier or 1)
        return example_pb2.ExampleReply(message=message)

    @entrypoint
    def unary_stream(self, request, context):
        message = request.value * (request.multiplier or 1)
        for i in range(request.response_count):
            yield example_pb2.ExampleReply(message=message, seqno=i + 1)

    @entrypoint
    def stream_unary(self, request, context):
        messages = []
        for index, req in enumerate(request):
            message = req.value * (req.multiplier or 1)