o ?cX@spdZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl mZmZmZdd lmZdd lmZmZmZmZmZmZeeZed Zed Zed Z dZ!eZ"eZ#GdddZ$GdddZ%Gddde Z&Gddde%Z'Gddde%Z(Gddde%Z)GdddZ*GdddeZ+Gdd d Z,Gd!d"d"Z-Gd#d$d$Z.dS)%a| NOTE: All classes and functions in this module are considered private and are subject to abrupt breaking changes. Please do not use them directly. To view the raw JSON that the objects in this module represent, please go to any `endpoint-rule-set.json` file in /botocore/data/// or you can look at the test files in /tests/unit/data/endpoints/valid-rules/ N)Enum) lru_cache) Formatter) NamedTuple) xform_name)IPV4_REquoteurlparse)EndpointResolutionError) ArnParserInvalidArnExceptionis_valid_ipv4_endpoint_urlis_valid_ipv6_endpoint_urlnormalize_url_pathpercent_encodez\{[a-zA-Z#]+\}z(\w+)\[(\d+)\]z^(?!-)[a-zA-Z\d-]{1,63}(?s z7RuleSetStandardLibary.call_function..argvrassignz Assignment z= already exists in scoped variables and cannot be overwrittenmsg)r:getattrr )rfunc_signaturer-Z func_args func_namefuncr.rArr>rr4s   z#RuleSetStandardLibary.call_functioncCs|duS)zYEvaluates whether a value is set. :type value: Any :rytpe: bool Nrrr,rrris_setszRuleSetStandardLibary.is_setcCsr|dD]1}t|}|dur2|\}}t|}||}|dus)|t|kr,dS||S||}q|S)apFind an attribute within a value given a path string. The path can contain the name of the attribute and an index in brackets. A period separating attribute names indicates the one to the right is nested. The index will always occur at the end of the path. :type value: dict or list :type path: str :rtype: Any r8N)r+ GET_ATTR_REr%groupsintr5len)rr,pathpartmatchnameindexrrrget_attrs     zRuleSetStandardLibary.get_attrcCs|d}|d|d<|S)NZoutputsidrQr)r partitionoutputrrrformat_partition_outputs z-RuleSetStandardLibary.format_partition_outputcCs$t|d|du}||dvp|S)NZ regionRegexZregions)rerP)rregionrUZ matches_regexrrris_partition_matchsz(RuleSetStandardLibary.is_partition_matchcCsL|durdS|jd}|D]}|||r||Sq |d}||S)zbMatch a region string to an AWS partition. :type value: str :rtype: dict N partitionsr)rrZrW)rr,r[rU aws_partitionrrrr\s   z#RuleSetStandardLibary.aws_partitioncCs|dus |ds dSzt|}Wn tyYdSwt|d|d|dfs,dS|d|d<|d}d|vr>dnd }|||d <|S) zeParse and validate string for ARN components. :type value: str :rtype: dict Nzarn:rUZserviceresourceaccountZ accountId:/Z resourceId) startswith ARN_PARSERZ parse_arnr allpopr+)rr,Zarn_dictr] delimiterrrr aws_parse_arns   z#RuleSetStandardLibary.aws_parse_arncsT|dus|dur|ddkrdS|dur#tfdd|dDSt|duS)zEvaluates whether a value is a valid host label per RFC 1123. If allow_subdomains is True, split on `.` and validate each component separately. :type value: str :type allow_subdomains: bool :rtype: bool NFr8rTc3|] }|dVqdSFN)is_valid_host_labelr<labelrrr   z.)countrcr+VALID_HOST_LABEL_RErPrr,allow_subdomainsrrlrris  z)RuleSetStandardLibary.is_valid_host_labelcCsBtdd||fDsdt|dt|d}t|d||kS)z|Evaluates two string values for equality. :type value1: str :type value2: str :rtype: bool cs|]}t|tVqdSr)rr#r<valrrrrmz6RuleSetStandardLibary.string_equals..z!Both values must be strings, not  and r8rBrctyper rZvalue1Zvalue2rCrrr string_equals  z#RuleSetStandardLibary.string_equalscCs|durdSt|S)zcPerform percent-encoding on an input string. :type value: str :rytpe: str N)rrHrrr uri_encodesz RuleSetStandardLibary.uri_encodecCs|durdSt|}z|jWn tyYdSw|j}|j}|dvs*t|dkr,dS|j}tt|}| ds?|d}||j ||t |pKt |dS)z[Parse a URL string into components. :type value: str :rtype: dict N)httpshttprr`)scheme authorityrNZnormalizedPathZisIp) r port ValueErrorrqueryrMrNrrendswithnetlocr r)rr,Zurl_componentsrrrNZnormalized_pathrrr parse_url s.     zRuleSetStandardLibary.parse_urlcCsBtdd||fDsdt|dt|d}t|d||uS)zEvaluates two boolean values for equality. :type value1: bool :type value2: bool :rtype: bool csrsr)rboolrtrrrrmLrvz7RuleSetStandardLibary.boolean_equals..z"Both arguments must be bools, not rwr8rBrxrzrrrboolean_equalsEr|z$RuleSetStandardLibary.boolean_equalscCs&z|dWdStyYdSw)zmEvaluates if a string only contains ASCII characters. :type value: str :rtype: bool asciiTF)encodeUnicodeEncodeErrorrHrrris_asciiQs   zRuleSetStandardLibary.is_asciicCs~t|tsdt|d}t|d||ks!t||ks!||s#dS|dur9t||}t||}|||S|||S)aComputes a substring given the start index and end index. If `reverse` is True, slice the string from the end instead. :type value: str :type start: int :type end: int :type reverse: bool :rtype: str zInput must be a string, not r8rBNT)rr#ryr rMr)rr,startstopreverserCZr_startZr_stoprrr substring]s      zRuleSetStandardLibary.substringcCs| S)zpA function implementation of the logical operator `not`. :type value: Any :rtype: bool rrHrrr_nottszRuleSetStandardLibary._notcsd|dust|dks||kst|durdS|dur+tfdd|dDSj|ddS) aEvaluates whether a value is a valid bucket name for virtual host style bucket URLs. To pass, the value must meet the following criteria: 1. is_valid_host_label(value) is True 2. length between 3 and 63 characters (inclusive) 3. does not contain uppercase characters 4. is not formatted as an IP address If allow_subdomains is True, split on `.` and validate each component separately. :type value: str :type allow_subdomains: bool :rtype: bool NFTc3rgrh)!aws_is_virtual_hostable_s3_bucketrjrlrrrmrnzJRuleSetStandardLibary.aws_is_virtual_hostable_s3_bucket..r8)rr)rMlowerrrPrcr+rirqrrlrr|s    z7RuleSetStandardLibary.aws_is_virtual_hostable_s3_bucketN)__name__ __module__ __qualname____doc__rrr"r&r3r6r:r4rIrSrWrZr\rfrir{r}rrrrrrrrrrr7s2    %   rc@s*eZdZdZd ddZddZddZdS) BaseRulez-Base interface for individual endpoint rules.NcCs||_||_dSr) conditions documentation)rrrrrrrs zBaseRule.__init__cCstr)NotImplementedError)rr-rule_librrrevaluateszBaseRule.evaluatecCs2|jD]}|||}|dus|durdSqdS)zDetermine if all conditions in a rule are met. :type scope_vars: dict :type rule_lib: RuleSetStandardLibrary :rtype: bool FNT)rr4)rr-rrEr.rrrevaluate_conditionss  zBaseRule.evaluate_conditionsr)rrrrrrrrrrrrs   rc@s*eZdZUdZeed<eed<eed<dS)RuleSetEndpointz.A resolved endpoint object returned by a rule.url propertiesheadersN)rrrrr#__annotations__rrrrrrs  rcs4eZdZfddZddZddZddZZS) EndpointRulec tjdi|||_dSNr)superrendpoint)rrkwargs __class__rrr zEndpointRule.__init__cCsT|||r(||jd|}||jdi||}|||}t|||dSdS)zDetermine if conditions are met to provide a valid endpoint. :type scope_vars: dict :rtype: RuleSetEndpoint rr)rrrN)rr6rresolve_propertiesr5resolve_headersr)rr-rrrrrrrrs   zEndpointRule.evaluatecs^t|trfdd|DSt|tr"fdd|DS|r-|S|S)zTraverse `properties` attribute, resolving any template strings. :type properties: dict/list/str :type scope_vars: dict :type rule_lib: RuleSetStandardLibrary :rtype: dict csg|] }|qSrr)r<proprr-rrrr?s z3EndpointRule.resolve_properties..cs i|] \}}||qSrrr<keyr,rrr sz3EndpointRule.resolve_properties..)rlistritemsr&r3)rrr-rrrrrs    zEndpointRule.resolve_propertiescs@i}|jdi}|D]\}}fdd|D||<q |S)zIterate through headers attribute resolving all values. :type scope_vars: dict :type rule_lib: RuleSetStandardLibrary :rtype: dict rcsg|]}|qSrr;)r<itemrr-rrr?s z0EndpointRule.resolve_headers..)rr5r)rr-rZresolved_headersrheadervaluesrrrrs  zEndpointRule.resolve_headers)rrrrrrr __classcell__rrrrrs  rcs$eZdZfddZddZZS) ErrorRulec rr)rrerror)rrrrrrrrzErrorRule.__init__cCs(|||r||j|}t|ddS)zIf an error rule's conditions are met, raise an error rule. :type scope_vars: dict :type rule_lib: RuleSetStandardLibrary :rtype: EndpointResolutionError rBN)rr6rr )rr-rrrrrrs  zErrorRule.evaluate)rrrrrrrrrrrs rcs(eZdZdZfddZddZZS)TreeRulezA tree rule is non-terminal meaning it will never be returned to a provider. Additionally this means it has no attributes that need to be resolved. c s&tjdi|dd|D|_dS)NcSg|] }tjdi|qSr RuleCreatorcreater<rulerrrr?z%TreeRule.__init__..r)rrrules)rrrrrrrszTreeRule.__init__cCs8|||r|jD]}|||}|r|Sq dS)zIf a tree rule's conditions are met, iterate its sub-rules and return first result found. :type scope_vars: dict :type rule_lib: RuleSetStandardLibrary :rtype: RuleSetEndpoint/EndpointResolutionError N)rrrcopy)rr-rrZ rule_resultrrrrs  zTreeRule.evaluate)rrrrrrrrrrrrs rc@s$eZdZeZeZeZe ddZ dS)rcKsH|d}zt||}Wntytd|ddw|di|S)z_Create a rule instance from metadata. :rtype: TreeRule/EndpointRule/ErrorRule ryzUnknown rule type: z1. A rule must be of type tree, endpoint or error.rBNr)rdrDAttributeErrorr )clsrZ rule_typeZ rule_classrrrr/s   zRuleCreator.createN) rrrrrrrrtree classmethodrrrrrr)s rc@seZdZdZeZeZdS) ParameterTypez8Translation from `type` attribute to native Python type.N)rrrrr#stringrbooleanrrrrrAsrc@s4eZdZdZ     d ddZddZddZdS) ParameterDefinitionz9The spec of an individual parameter defined in a RuleSet.NcCs`||_z tt|j|_Wntytd|ddw||_||_ ||_ ||_ ||_ dS)NzUnknown parameter type: z0. A parameter must be of type string or boolean.rB) rQrDrrr,parameter_typerr rZbuilt_indefaultrequired deprecated)rrQrrbuiltInrrrrrrrKs"    zParameterDefinition.__init__cCst||jstd|jd|jdd|jdurC|jd}|jd}|jd}|r4|d |7}|r>|d |d7}t|dS) zwPerform base validation on parameter input. :type value: Any :raises: EndpointParametersError zValue (z) is the wrong type. Must be r8rBNz has been deprecated.messagesince z Deprecated since )rrr rQrr5loggerinfo)rr,Zdepr_strrCrrrrvalidate_inputes       z"ParameterDefinition.validate_inputcCs.|dur |jdur |jS|dur|||S)z>Process input against spec, applying default if value is None.N)rrrHrrr process_input}s  z!ParameterDefinition.process_input)NNNNN)rrrrrrrrrrrrHs  rc@s4eZdZdZ d ddZddZddZd d ZdS) RuleSetz:Collection of rules to derive a routable service endpoint.NcCs6||_|||_dd|D|_t||_||_dS)NcSrrrrrrrr?rz$RuleSet.__init__..)version_ingest_parameter_spec parametersrrrr)rrrrr[rrrrrs    zRuleSet.__init__cCsdd|DS)Nc SsHi|] \}}|t||d|d|d|d|d|dqS)ryrrrrr)rr5)r<rQspecrrrrs z2RuleSet._ingest_parameter_spec..)r)rrrrrrs zRuleSet._ingest_parameter_speccCs8|jD]\}}|||}|dur|||<qdS)zYProcess each input parameter against its spec. :type input_params: dict N)rrrr5)rZ input_paramsrQrr,rrrprocess_input_parameterss z RuleSet.process_input_parameterscCs<|||jD]}|||j}|dur|SqdS)zmEvaluate input parameters against rules returning first match. :type input_parameters: dict N)rrrrr)rinput_parametersrZ evaluationrrrrs  zRuleSet.evaluater)rrrrrrrrrrrrrs   rc@s*eZdZdZddZeedddZdS)EndpointProviderz.z"No endpoint found for parameters: rB)rrrjoinrr )rrZparams_for_errorrZ param_stringrrrresolve_endpoints z!EndpointProvider.resolve_endpointN)rrrrrr CACHE_SIZErrrrrrs r)/rloggingrXenumr functoolsrrrtypingrZbotocorerZbotocore.compatrrr Zbotocore.exceptionsr Zbotocore.utilsr r r rrr getLoggerrrcompiler$rJrprrbr)rrrrrrrrrrrrrrrsB           gA>2