
    Y                     &   S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJrJrJr  SSKJr  SS	KJrJrJrJrJrJrJr  \R2                  " \5      r\R8                  " S
5      r\R8                  " S5      r\R8                  " S5      rSr \" 5       r!\" 5       r" " S S5      r#\#r$ " S S5      r% " S S\5      r& " S S\%5      r' " S S\%5      r( " S S\%5      r) " S S5      r* " S S\5      r+ " S S5      r, " S  S!5      r- " S" S#5      r.g)$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/<service>/<api version>/
or you can look at the test files in /tests/unit/data/endpoints/valid-rules/
    N)Enum)	Formatter)
NamedTuple)
xform_name)IPV4_REquoteurlparse)EndpointResolutionError)	ArnParserInvalidArnExceptionis_valid_ipv4_endpoint_urlis_valid_ipv6_endpoint_urllru_cache_weakrefnormalize_url_pathpercent_encodez\{[a-zA-Z#]+\}z(\w+)\[(\d+)\]z^(?!-)[a-zA-Z\d-]{1,63}(?<!-)$d   c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rSrg)RuleSetStandardLibrary7   z5Rule actions to be performed by the EndpointProvider.c                     Xl         g Npartitions_data)selfr   s     -lib/third_party/botocore/endpoint_provider.py__init__RuleSetStandardLibrary.__init__:   s    .    c                 :    [        U[        5      =(       a    SU;   $ )zODetermine if an object is a function object.

:type argument: Any
:rtype: bool
fn
isinstancedictr   arguments     r   is_funcRuleSetStandardLibrary.is_func=   s     (D)>dh.>>r   c                 :    [        U[        5      =(       a    SU;   $ )zPDetermine if an object is a reference object.

:type argument: Any
:rtype: bool
refr!   r$   s     r   is_refRuleSetStandardLibrary.is_refE   s     (D)?ex.??r   c                 ^    [        U[        5      =(       a    [        R                  U5      SL$ )zTDetermine if an object contains a template string.

:type argument: Any
:rtpe: bool
N)r"   strTEMPLATE_STRING_REsearchr$   s     r   is_template"RuleSetStandardLibrary.is_templateM   s,     x% @"))(34?	
r   c                     Sn[         R                  U5       H8  u  pE  nUb*  UnUR                  S5      nU H  n	Xy   nM	     X4 U 3-  nM4  X4-  nM:     U$ )zgResolve and inject values into a template string.

:type value: str
:type scope_vars: dict
:rtype: str
 #)STRING_FORMATTERparsesplit)
r   value
scope_varsresultliteral	reference_template_valuetemplate_paramsparams
             r   resolve_template_string.RuleSetStandardLibrary.resolve_template_stringX   sr     (8(>(>u(E$G1$!+"+//#"6,E%3%:N -In%566! )F r   c                     U R                  U5      (       a  U R                  X5      $ U R                  U5      (       a  UR                  US   5      $ U R	                  U5      (       a  U R                  X5      $ U$ )z[Return evaluated value based on type.

:type value: Any
:type scope_vars: dict
:rtype: Any
r)   )r&   call_functionr*   getr0   rA   )r   r8   r9   s      r   resolve_value$RuleSetStandardLibrary.resolve_valuek   sm     <<%%e88[[>>%,//e$$//BBr   c                 T    [        U5       nUS:X  a  SU 3nUR                  SS5      $ )z8Normalize function names.

:type value: str
:rtype: str
notr=   .)r   replace)r   r8   normalized_names      r   convert_func_name(RuleSetStandardLibrary.convert_func_name{   s9     (./e# !/!23O&&sC00r   c                     US    Vs/ s H  nU R                  X25      PM     nnU R                  US   5      n[        X5      nU" U6 nSU;   a  US   nX;   a  [        SU S3S9eXrU'   U$ s  snf )zCall the function with the resolved arguments and assign to `scope_vars`
when applicable.

:type func_signature: dict
:type scope_vars: dict
:rtype: Any
argvr    assignzAssignment z= already exists in scoped variables and cannot be overwrittenmsg)rF   rM   getattrr
   )	r   func_signaturer9   arg	func_args	func_namefuncr:   rQ   s	            r   rD   $RuleSetStandardLibrary.call_function   s     &f-
- s/- 	 
 **>$+?@	t'y!~%#H-F#-%fX .A A  "(v
s   A,c                 
    USL$ )zAEvaluates whether a value is set.

:type value: Any
:rytpe: bool
N r   r8   s     r   is_setRuleSetStandardLibrary.is_set   s     D  r   c                     UR                  S5       Hg  n[        R                  U5      nUbH  UR                  5       u  pV[	        U5      nUR                  U5      nUb  U[        U5      :  a    gX   s  $ X   nMi     U$ )a8  Find 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
rJ   N)r7   GET_ATTR_REr/   groupsintrE   len)r   r8   pathpartmatchnameindexs          r   get_attrRuleSetStandardLibrary.get_attr   sx     JJsOD&&t,E #llnE
		$=ESZ$7|# $ r   c                      US   nUS   US'   U$ )Noutputsidrh   r\   )r   	partitionoutputs      r   format_partition_output.RuleSetStandardLibrary.format_partition_output   s    9%"4vr   c                 Z    [         R                  " US   U5      S LnXS   ;   =(       d    U$ )NregionRegexregions)rerg   )r   regionro   matches_regexs       r   is_partition_match)RuleSetStandardLibrary.is_partition_match   s/    =!96B$N9-->>r   c                     U R                   S   nUb2  U H,  nU R                  X5      (       d  M  U R                  U5      s  $    US   nU R                  U5      $ )zJMatch a region string to an AWS partition.

:type value: str
:rtype: dict

partitionsr   )r   ry   rq   )r   r8   r|   ro   aws_partitions        r   r}   $RuleSetStandardLibrary.aws_partition   sb     )),7
'	**5<<77	BB (
 #1++M::r   c                 R   Ub  UR                  S5      (       d  g [        R                  U5      n[	        US   US   US   45      (       d  gUR                  S5      US'   UR                  S5      nUR                  SS	5      R                  S	5      US
'   U$ ! [         a     gf = f)zMParse and validate string for ARN components.

:type value: str
:rtype: dict
Nzarn:ro   serviceresourceaccount	accountId:/
resourceId)
startswith
ARN_PARSER	parse_arnr   allpoprK   r7   )r   r8   arn_dictr   s       r   aws_parse_arn$RuleSetStandardLibrary.aws_parse_arn   s     = 0 0 8 8	!++E2H
 k"HY$7*9MN
 
  (Y 7<<
+!)!1!1#s!;!A!A#!F # 		s   B 
B&%B&c                    ^  Ub  USL a  UR                  S5      S:  a  gUSL a$  [        U 4S jUR                  S5       5       5      $ [        R	                  U5      SL$ )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
NFrJ   r   Tc              3   H   >#    U  H  nTR                  US 5      v   M     g7f)FN)is_valid_host_label).0labelr   s     r   	<genexpr>=RuleSetStandardLibrary.is_valid_host_label.<locals>.<genexpr>   s(      -E ((66-s   ")countr   r7   VALID_HOST_LABEL_RErg   r   r8   allow_subdomainss   `  r   r   *RuleSetStandardLibrary.is_valid_host_label   sh     =,5%++c:JQ:Nt# "[[-  
 #((/t;;r   c                     [        S X4 5       5      (       d$  S[        U5       S[        U5       S3n[        US9eX:H  $ )z\Evaluates two string values for equality.

:type value1: str
:type value2: str
:rtype: bool
c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )r"   r-   r   vals     r   r   7RuleSetStandardLibrary.string_equals.<locals>.<genexpr>  s     D3CC:c3''3C   z!Both values must be strings, not  and rJ   rR   r   typer
   r   value1value2rS   s       r   string_equals$RuleSetStandardLibrary.string_equals  sI     DF3CDDD5d6l^5fVWXC)c22r   c                      Uc  g[        U5      $ )zKPerform percent-encoding on an input string.

:type value: str
:rytpe: str
N)r   r]   s     r   
uri_encode!RuleSetStandardLibrary.uri_encode  s     =e$$r   c                    Uc  g[        U5      n UR                    UR                  nUR                  nUS;  d  [        U5      S:  a  gUR                  n[        [        U5      5      nUR                  S5      (       d  U S3nUUR                  UU[        U5      =(       d    [        U5      S.$ ! [         a     gf = f)zCParse a URL string into components.

:type value: str
:rtype: dict
N)httpshttpr   r   )scheme	authorityre   normalizedPathisIp)r	   port
ValueErrorr   queryrd   re   r   r   endswithnetlocr   r   )r   r8   url_componentsr   r   re   normalized_paths          r   	parse_url RuleSetStandardLibrary.parse_url  s     =!%	   &&$$**c%j1n"" 24 89'',,!0 13O '..-.u5 1)%0
 	
  		s   B3 3
C ?C c                     [        S X4 5       5      (       d$  S[        U5       S[        U5       S3n[        US9eXL $ )z_Evaluates two boolean values for equality.

:type value1: bool
:type value2: bool
:rtype: bool
c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )r"   boolr   s     r   r   8RuleSetStandardLibrary.boolean_equals.<locals>.<genexpr>J  s     E4DS:c4((4Dr   z"Both arguments must be bools, not r   rJ   rR   r   r   s       r   boolean_equals%RuleSetStandardLibrary.boolean_equalsC  sI     EV4DEEE6tF|nE$v,WXYC)c22r   c                 H     UR                  S5        g! [         a     gf = f)zUEvaluates if a string only contains ASCII characters.

:type value: str
:rtype: bool
asciiTF)encodeUnicodeEncodeErrorr]   s     r   is_asciiRuleSetStandardLibrary.is_asciiO  s(    	LL!! 		s    
!!c                    [        U[        5      (       d  S[        U5       S3n[        US9eX#:  d%  [	        U5      U:  d  U R                  U5      (       d  gUSL a   [	        U5      U-
  n[	        U5      U-
  nXU $ XU $ )zComputes 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
zInput must be a string, not rJ   rR   NT)r"   r-   r   r
   rd   r   )r   r8   startstopreverserS   r_startr_stops           r   	substring RuleSetStandardLibrary.substring[  s     %%%0eQ?C)c22=CJ-T]]55I5Id?%j4'GZ%'F((4  r   c                     U(       + $ )zXA function implementation of the logical operator `not`.

:type value: Any
:rtype: bool
r\   r]   s     r   _notRuleSetStandardLibrary._notr  s     yr   c                     Ub:  [        U5      S:  d+  UR                  5       U:w  d  [        R                  " U5      b  gU R	                  XS9$ )a  Evaluates 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
   F)r   )rd   lowerr   rg   r   r   s      r   !aws_is_virtual_hostable_s3_bucket8RuleSetStandardLibrary.aws_is_virtual_hostable_s3_bucketz  sO      M5zA~{{}%}}U#/'' ( 
 	
r   r   N)__name__
__module____qualname____firstlineno____doc__r   r&   r*   r0   rA   rF   rM   rD   r^   rj   rq   ry   r}   r   r   r   r   r   r   r   r   r   r   __static_attributes__r\   r   r   r   r   7   sz    ?/?@	
& 	12!.
?;"6<(
 	%#
J
 
!.
r   r   c                   .    \ rS rSrSrSS jrS rS rSrg)	BaseRulei  z-Base interface for individual endpoint rules.Nc                     Xl         X l        g r   
conditionsdocumentation)r   r   r   s      r   r   BaseRule.__init__  s    $*r   c                     [        5       er   )NotImplementedError)r   r9   rule_libs      r   evaluateBaseRule.evaluate  s    !##r   c                 `    U R                    H  nUR                  X15      nUSL d  Ub  M    g   g)z{Determine if all conditions in a rule are met.

:type scope_vars: dict
:type rule_lib: RuleSetStandardLibrary
:rtype: bool
FT)r   rD   )r   r9   r   rU   r:   s        r   evaluate_conditionsBaseRule.evaluate_conditions  s5     #ooN++NGF&. . r   r   r   )	r   r   r   r   r   r   r   r   r   r\   r   r   r   r     s    7+$r   r   c                   8    \ rS rSr% Sr\\S'   \\S'   \\S'   Srg)RuleSetEndpointi  z.A resolved endpoint object returned by a rule.url
propertiesheadersr\   N)	r   r   r   r   r   r-   __annotations__r#   r   r\   r   r   r   r     s    8	HMr   r   c                   :   ^  \ rS rSrU 4S jrS rS rS rSrU =r	$ )EndpointRulei  c                 2   > [         TU ]  " S0 UD6  Xl        g Nr\   )superr   endpoint)r   r   kwargs	__class__s      r   r   EndpointRule.__init__  s    "6" r   c                     U R                  X5      (       ag  UR                  U R                  S   U5      nU R                  U R                  R	                  S0 5      UU5      nU R                  X5      n[        X4US9$ g)zmDetermine if conditions are met to provide a valid endpoint.

:type scope_vars: dict
:rtype: RuleSetEndpoint
r   r   )r   r   r   N)r   rF   r   resolve_propertiesrE   resolve_headersr   )r   r9   r   r   r   r   s         r   r   EndpointRule.evaluate  s     ##J99((u)=zJC00!!,3J
 **:@G"  r   c           
      n   [        U[        5      (       a#  U Vs/ s H  nU R                  XBU5      PM     sn$ [        U[        5      (       a5  UR	                  5        VVs0 s H  u  pVXPR                  XbU5      _M     snn$ UR                  U5      (       a  UR                  X5      $ U$ s  snf s  snnf )zTraverse `properties` attribute, resolving any template strings.

:type properties: dict/list/str
:type scope_vars: dict
:type rule_lib: RuleSetStandardLibrary
:rtype: dict
)r"   listr   r#   itemsr0   rA   )r   r   r9   r   propkeyr8   s          r   r   EndpointRule.resolve_properties  s     j$'' '&D ''(C&  
D)) #-"2"2"4"4JC ,,UII"4  !!*--33JKK
s   B,!B1c                     0 nU R                   R                  S0 5      nUR                  5        H(  u  pVU Vs/ s H  orR                  Xq5      PM     snX5'   M*     U$ s  snf )zIterate through headers attribute resolving all values.

:type scope_vars: dict
:type rule_lib: RuleSetStandardLibrary
:rtype: dict
r   )r   rE   r  rF   )r   r9   r   resolved_headersr   headervaluesitems           r   r   EndpointRule.resolve_headers  se     --##Ir2%mmoNFEK(EKT&&t8V($ .  (s   A)r   )
r   r   r   r   r   r   r   r   r   __classcell__r   s   @r   r   r     s    !(.   r   r   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )	ErrorRulei  c                 2   > [         TU ]  " S0 UD6  Xl        g r   )r   r   error)r   r  r   r   s      r   r   ErrorRule.__init__  s    "6"
r   c                 z    U R                  X5      (       a%  UR                  U R                  U5      n[        US9eg)zIf an error rule's conditions are met, raise an error rule.

:type scope_vars: dict
:type rule_lib: RuleSetStandardLibrary
:rtype: EndpointResolutionError
rR   N)r   rF   r  r
   )r   r9   r   r  s       r   r   ErrorRule.evaluate  s9     ##J99**4::zBE)e44r   )r  )r   r   r   r   r   r   r   r  r  s   @r   r  r    s    
 
r   r  c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )TreeRulei  zA 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                    > [         TU ]  " S0 UD6  U Vs/ s H  n[        R                  " S0 UD6PM     snU l        g s  snf r   )r   r   RuleCreatorcreaterules)r   r  r   ruler   s       r   r   TreeRule.__init__  s:    "6"=BCUTk((040UC
Cs    ?c                     U R                  X5      (       a>  U R                   H.  nUR                  UR                  5       U5      nU(       d  M,  Us  $    g)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)r   r  r   copy)r   r9   r   r  rule_results        r   r   TreeRule.evaluate  sJ     ##J99

"mmJOO,=xH;&&	 #
 r   )r  )	r   r   r   r   r   r   r   r   r  r  s   @r   r  r    s    D r   r  c                   0    \ rS rSr\r\r\r	\
S 5       rSrg)r  i(  c                     UR                  S5      n [        X5      nU" S0 UD6$ ! [         a    [        SU S3S9ef = f)zOCreate a rule instance from metadata.

:rtype: TreeRule/EndpointRule/ErrorRule
r   zUnknown rule type: z1. A rule must be of type tree, endpoint or error.rR   r\   )r   rT   AttributeErrorr
   )clsr   	rule_type
rule_classs       r   r  RuleCreator.create-  s`     JJv&		( 0J '''  	))) 56 6 	s   & >r\   N)r   r   r   r   r   r   r  r  r  treeclassmethodr  r   r\   r   r   r  r  (  s#    HED( (r   r  c                        \ rS rSrSr\r\rSr	g)ParameterTypei?  z8Translation from `type` attribute to native Python type.r\   N)
r   r   r   r   r   r-   stringr   booleanr   r\   r   r   r+  r+  ?  s    BFGr   r+  c                   8    \ rS rSrSr     SS jrS rS rSrg)	ParameterDefinitioniF  z9The spec of an individual parameter defined in a RuleSet.Nc                     Xl          [        [        UR                  5       5      R                  U l        X0l        X@l	        XPl
        X`l        Xpl        g ! [         a    [        SU S3S9ef = f)NzUnknown parameter type: z0. A parameter must be of type string or boolean.rR   )rh   rT   r+  r   r8   parameter_typer#  r
   r   builtindefaultrequired
deprecated)r   rh   r1  r   builtInr3  r4  r5  s           r   r   ParameterDefinition.__init__I  s     		")~335#e  + $  	).~.> ?A A 	s   -A A,c                    [        XR                  5      (       d$  [        SU R                   SU R                   S3S9eU R                  by  U R                   S3nU R                  R                  S5      nU R                  R                  S5      nU(       a  US	U 3-  nU(       a	  US
U S3-  n[        R                  U5        g)z_Perform base validation on parameter input.

:type value: Any
:raises: EndpointParametersError
zValue (z) is the wrong type. Must be rJ   rR   Nz has been deprecated.messagesince
z
Deprecated since )r"   r1  r
   rh   r5  rE   loggerinfo)r   r8   depr_strrS   r:  s        r   validate_input"ParameterDefinition.validate_inputc  s     %!4!455)dii[ )!!%!4!4 5Q8  ??&))$9:H//%%i0COO''0EbJ&1%::KK!r   c                     UcE  U R                   b  U R                   $ U R                  (       a  [        SU R                   35      e U$ U R	                  U5        U$ )z>Process input against spec, applying default if value is None.z)Cannot find value for required parameter )r3  r4  r
   rh   r?  r]   s     r   process_input!ParameterDefinition.process_input{  s^    =||'||#}}-?		{K    &r   )r2  r3  r5  r   rh   r1  r4  )NNNNN)	r   r   r   r   r   r   r?  rB  r   r\   r   r   r/  r/  F  s%    C %40r   r/  c                   6    \ rS rSrSr S	S jrS rS rS rSr	g)
RuleSeti  z:Collection of rules to derive a routable service endpoint.Nc                     Xl         U R                  U5      U l        U Vs/ s H  n[        R                  " S0 UD6PM     snU l        [        U5      U l        XPl        g s  snf r   )	version_ingest_parameter_spec
parametersr  r  r  r   r   r   )r   rG  rI  r  r|   r   r  s          r   r   RuleSet.__init__  sW     55jA=BCUTk((040UC
.z:* Ds    A c                    UR                  5        VVs0 s He  u  p#U[        UUS   UR                  S5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      5      _Mg     snn$ s  snnf )Nr   r   r6  r3  r4  r5  )r  r/  rE   )r   rI  rh   specs       r   rH  RuleSet._ingest_parameter_spec  s     )..0
 1
 %V)##$&  1
 	
 
s   A,Bc                     U R                   R                  5        H.  u  p#UR                  UR                  U5      5      nUc  M*  XAU'   M0     g)zIProcess each input parameter against its spec.

:type input_params: dict
N)rI  r  rB  rE   )r   input_paramsrh   rL  r8   s        r   process_input_parameters RuleSet.process_input_parameters  sK    
 ////1JD&&|'7'7'=>E %*T" 2 r   c                     U R                  U5        U R                   H4  nUR                  UR                  5       U R                  5      nUc  M2  Us  $    g)z]Evaluate input parameters against rules returning first match.

:type input_parameters: dict
N)rP  r  r   r  r   )r   input_parametersr  
evaluations       r   r   RuleSet.evaluate  sP    
 	%%&67JJD'7'<'<'>NJ%!!  r   )r   rI  r   r  rG  r   )
r   r   r   r   r   r   rH  rP  r   r   r\   r   r   rE  rE    s     D EI+
	
r   rE  c                   6    \ rS rSrSrS r\" \S9S 5       rSr	g)EndpointProvideri  z<Derives endpoints from a RuleSet for given input parameters.c                 ,    [        S0 UDSU0D6U l        g )Nr|   r\   )rE  ruleset)r   ruleset_datapartition_datas      r   r   EndpointProvider.__init__  s    II.Ir   )maxsizec           	          UR                  5       nU R                  R                  U5      nUcE  SR                  UR	                  5        VVs/ s H  u  pEU SU 3PM     snn5      n[        SU 3S9eU$ s  snnf )zXMatch input parameters to a rule.

:type input_parameters: dict
:rtype: RuleSetEndpoint
r;  z: z"No endpoint found for parameters:
rR   )r  rY  r   joinr  r
   )r   rS  params_for_errorr   r  r8   param_strings          r   resolve_endpoint!EndpointProvider.resolve_endpoint  s     ,002<<(()9:995E5K5K5MN5MzsC55'"5MNL *9,H   Os   A6
)rY  N)
r   r   r   r   r   r   r   
CACHE_SIZErb  r   r\   r   r   rW  rW    s$    FJ z* +r   rW  )/r   loggingrv   enumr   r,  r   typingr   botocorer   botocore.compatr   r   r	   botocore.exceptionsr
   botocore.utilsr   r   r   r   r   r   r   	getLoggerr   r<  compiler.   ra   r   rd  r   r5   r   RuleSetStandardLibaryr   r   r   r  r  r  r+  r/  rE  rW  r\   r   r   <module>ro     s    	     4 4 7   
		8	$ZZ 12 jj*+jj%  
[
; \
 \
B /  0j > 8 > B $x 4( (.D A AH/ /d r   