| 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 |
|
| 16 |
from typing import AsyncIterable |
| 17 |
|
| 18 |
import grpc |
| 19 |
from grpc_reflection.v1alpha import reflection_pb2 as _reflection_pb2 |
| 20 |
from grpc_reflection.v1alpha._base import BaseReflectionServicer |
| 21 |
|
| 22 |
|
| 23 |
class ReflectionServicer(BaseReflectionServicer): |
| 24 |
"""Servicer handling RPCs for service statuses.""" |
| 25 |
|
| 26 |
async def ServerReflectionInfo( |
| 27 |
self, request_iterator: AsyncIterable[ |
| 28 |
_reflection_pb2.ServerReflectionRequest], unused_context |
| 29 |
) -> AsyncIterable[_reflection_pb2.ServerReflectionResponse]: |
| 30 |
async for request in request_iterator: |
| 31 |
if request.HasField('file_by_filename'): |
| 32 |
yield self._file_by_filename(request.file_by_filename) |
| 33 |
elif request.HasField('file_containing_symbol'): |
| 34 |
yield self._file_containing_symbol( |
| 35 |
request.file_containing_symbol) |
| 36 |
elif request.HasField('file_containing_extension'): |
| 37 |
yield self._file_containing_extension( |
| 38 |
request.file_containing_extension.containing_type, |
| 39 |
request.file_containing_extension.extension_number) |
| 40 |
elif request.HasField('all_extension_numbers_of_type'): |
| 41 |
yield self._all_extension_numbers_of_type( |
| 42 |
request.all_extension_numbers_of_type) |
| 43 |
elif request.HasField('list_services'): |
| 44 |
yield self._list_services() |
| 45 |
else: |
| 46 |
yield _reflection_pb2.ServerReflectionResponse( |
| 47 |
error_response=_reflection_pb2.ErrorResponse( |
| 48 |
error_code=grpc.StatusCode.INVALID_ARGUMENT.value[0], |
| 49 |
error_message=grpc.StatusCode.INVALID_ARGUMENT.value[1]. |
| 50 |
encode(), |
| 51 |
)) |
| 52 |
|
| 53 |
|
| 54 |
__all__ = [ |
| 55 |
"ReflectionServicer", |
| 56 |
] |