def add_message_type(self, package, module_name, service_name, method_name, input_type): message_name = input_type.split('.')[-1:][0] method_key = f'/{package}.{service_name}/{method_name}' pb2_module = __import__(f'{package}.{module_name}_pb2', fromlist=[f'{module_name}_pb2']) if method_key not in self._MESSAGE_TYPE_MAP: self._MESSAGE_TYPE_MAP[method_key] = {} well_known_types = get_well_known_types() if input_type in well_known_types: self._MESSAGE_TYPE_MAP[method_key] = { 'message': well_known_types[input_type], 'message_type': 'well_known_message' } elif input_type.startswith(f'.{package}'): self._MESSAGE_TYPE_MAP[method_key] = { 'message': getattr(pb2_module, message_name), 'message_name': message_name } if message_name not in self._FIELD_TYPE_MAP: self._FIELD_TYPE_MAP[message_name] = { 'well_known_type': {}, 'message_type': {} }
def __init__(self, channel, options, channel_key): self.api_resources = {} self._well_known_types = get_well_known_types() self._related_message_types = {} self._client_interceptor = _ClientInterceptor(options, channel_key) self._channel = channel self._intercept_channel = grpc.intercept_channel(channel, self._client_interceptor) self._get_server_reflection_info()