• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 gRPC authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""The AsyncIO version of the reflection servicer."""
15
16from typing import AsyncIterable
17
18import grpc
19from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2
20from grpc_reflection.v1alpha._base import BaseReflectionServicer
21
22
23class ReflectionServicer(BaseReflectionServicer):
24    """Servicer handling RPCs for service statuses."""
25
26    async def ServerReflectionInfo(
27        self,
28        request_iterator: AsyncIterable[
29            _reflection_pb2.ServerReflectionRequest
30        ],
31        unused_context,
32    ) -> AsyncIterable[_reflection_pb2.ServerReflectionResponse]:
33        async for request in request_iterator:
34            if request.HasField("file_by_filename"):
35                yield self._file_by_filename(request.file_by_filename)
36            elif request.HasField("file_containing_symbol"):
37                yield self._file_containing_symbol(
38                    request.file_containing_symbol
39                )
40            elif request.HasField("file_containing_extension"):
41                yield self._file_containing_extension(
42                    request.file_containing_extension.containing_type,
43                    request.file_containing_extension.extension_number,
44                )
45            elif request.HasField("all_extension_numbers_of_type"):
46                yield self._all_extension_numbers_of_type(
47                    request.all_extension_numbers_of_type
48                )
49            elif request.HasField("list_services"):
50                yield self._list_services()
51            else:
52                yield _reflection_pb2.ServerReflectionResponse(
53                    error_response=_reflection_pb2.ErrorResponse(
54                        error_code=grpc.StatusCode.INVALID_ARGUMENT.value[0],
55                        error_message=grpc.StatusCode.INVALID_ARGUMENT.value[
56                            1
57                        ].encode(),
58                    )
59                )
60
61
62__all__ = [
63    "ReflectionServicer",
64]
65