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