Example #1
0
    def HelloMetadata(self, request, context):
        for key, value in context.invocation_metadata():
            if key == request.name:
                break
        else:
            raise KeyError(request.name)

        context.send_initial_metadata(
            (f"initial-{key}", repr(value))
            for key, value in context.invocation_metadata())

        context.set_trailing_metadata(
            (f"trailing-{key}", repr(value))
            for key, value in context.invocation_metadata())

        return helloworld_pb2.HelloReply(message=repr(value))
Example #2
0
    async def HelloStreamMetadata(self, request, context):
        for key, value in context.invocation_metadata():
            if key == request.name:
                break
        else:
            raise KeyError(request.name)

        await context.send_initial_metadata(
            (f"initial-{key}", repr(value))
            for key, value in context.invocation_metadata())

        for c in value:
            yield helloworld_pb2.HelloReply(message=c)

        await context.set_trailing_metadata(
            (f"trailing-{key}", repr(value))
            for key, value in context.invocation_metadata())
Example #3
0
    async def SayHelloSlowly(self, request, context):
        message = FORMAT_STRING.format(request=request)

        for char in message:
            yield helloworld_pb2.HelloReply(message=char)
Example #4
0
 async def SayHello(self, request, context):
     return helloworld_pb2.HelloReply(message=FORMAT_STRING.format(
         request=request))