def _parse_request_syntax(self, input_string: str) -> None: if "**Request Syntax**" not in input_string: return request_syntax_index = input_string.index("**Request Syntax**") while request_syntax_index > 0 and input_string[request_syntax_index - 1] == " ": request_syntax_index = request_syntax_index - 1 request_syntax_string = get_line_with_indented( input_string[request_syntax_index:], True) SyntaxGrammar.reset() SyntaxGrammar.enable_packrat() try: match = SyntaxGrammar.request_syntax.parseString( request_syntax_string) except ParseException as e: self.logger.warning( f"Cannot parse request syntax for {self.prefix}") self.logger.debug(e) return argument_groups = match.asDict().get("arguments", []) for argument_dict in argument_groups: argument_name = argument_dict["name"] argument_prefix = self.prefix + get_class_prefix(argument_name) argument_value = TypeValue(self.service_name, argument_prefix, argument_dict["value"]) argument_type = argument_value.get_type() argument = self._find_argument_or_append(argument_name) argument.type = argument_type
def parse_fake_service_package( session: Session, service_name: ServiceName, package_data: type[BasePackageData]) -> ServicePackage: """ Create fake boto3 service module structure. Used by stubs and master package. Arguments: session -- boto3 session. service_name -- Target service name. package_data -- Package data. Returns: ServiceModule structure. """ shape_parser = ShapeParser(session, service_name) boto3_client = get_boto3_client(session, service_name) boto3_resource = get_boto3_resource(session, service_name) result = ServicePackage( data=package_data, service_name=service_name, client=Client( name=Client.get_class_name(service_name), service_name=service_name, boto3_client=boto3_client, ), ) if boto3_resource is not None: result.service_resource = ServiceResource( name=ServiceResource.get_class_name(service_name), service_name=service_name, boto3_service_resource=boto3_resource, ) waiter_names: list[str] = boto3_client.waiter_names for waiter_name in waiter_names: real_class_name = get_class_prefix(waiter_name) waiter_class_name = f"{real_class_name}Waiter" result.waiters.append( Waiter( waiter_class_name, waiter_name=waiter_name, service_name=service_name, )) for paginator_name in shape_parser.get_paginator_names(): operation_name = xform_name(paginator_name) result.paginators.append( Paginator( f"{paginator_name}Paginator", operation_name=operation_name, service_name=service_name, paginator_name=paginator_name, )) return result
def parse_fake_service_package(session: Session, service_name: ServiceName) -> ServicePackage: """ Create fake boto3 service module structure. Used by stubs and master package. Arguments: session -- boto3 session. service_name -- Target service name. Returns: ServiceModule structure. """ shape_parser = ShapeParser(session, service_name) result = ServicePackage( name=service_name.module_name, pypi_name=service_name.pypi_name, service_name=service_name, client=Client(), ) boto3_client = get_boto3_client(session, service_name) boto3_resource = get_boto3_resource(session, service_name) if boto3_resource is not None: result.service_resource = ServiceResource() for waiter_name in boto3_client.waiter_names: real_class_name = get_class_prefix(waiter_name) waiter_class_name = f"{real_class_name}Waiter" result.waiters.append( Waiter(waiter_class_name, waiter_name=waiter_name)) for paginator_name in shape_parser.get_paginator_names(): operation_name = xform_name(paginator_name) result.paginators.append( Paginator(f"{paginator_name}Paginator", operation_name=operation_name)) return result
def test_get_class_prefix(self) -> None: assert get_class_prefix("my_func") == "MyFunc" assert get_class_prefix("") == "" assert get_class_prefix("myFunc") == "MyFunc"
def test_get_class_prefix(self) -> None: self.assertEqual(get_class_prefix("my_func"), "MyFunc") self.assertEqual(get_class_prefix(""), "") self.assertEqual(get_class_prefix("myFunc"), "MyFunc")