
    PeC+                         d dl Z d dlZd dlZd dlmZ d dlmZmZmZ d dl	m
Z
 d dlmZ  e j                  e      Z G d de      Z G d d	e      Z G d
 de      Zd Z G d d      Z G d d      Z G d d      Zy)    N)
xform_name)BotoCoreErrorConnectionErrorHTTPClientError)OperationNotFoundError)CachedPropertyc                       e Zd Zy)EndpointDiscoveryExceptionN)__name__
__module____qualname__     4/usr/lib/python3/dist-packages/botocore/discovery.pyr
   r
      s    r   r
   c                       e Zd ZdZdZy)EndpointDiscoveryRequiredzBEndpoint Discovery is disabled but is required for this operation.zAEndpoint Discovery is not enabled but this operation requires it.Nr   r   r   __doc__fmtr   r   r   r   r      s
    L
MCr   r   c                       e Zd ZdZdZy)EndpointDiscoveryRefreshFailedz=Endpoint Discovery failed to the refresh the known endpoints.z<Endpoint Discovery failed to refresh the required endpoints.Nr   r   r   r   r   r   #   s
    G
HCr   r   c                 X    | j                   }|r|j                  d      r
t               y y )Nrequired)endpoint_discoverygetr   )modelkwargsr   s      r   ,block_endpoint_discovery_required_operationsr   )   s1    11044Z@')) Ar   c                   L    e Zd Zd Zed        Zed        Zd Zd Zd Z	d	dZ
y)
EndpointDiscoveryModelc                     || _         y N)_service_model)selfservice_models     r   __init__zEndpointDiscoveryModel.__init__0   s
    +r   c                 X    | j                   j                  }t        |j                        S r"   )r#   endpoint_discovery_operationr   name)r$   discovery_operations     r   discovery_operation_namez/EndpointDiscoveryModel.discovery_operation_name3   s&    "11NN-2233r   c                     | j                   j                  }g }|j                  r-t        |j                  j                  j                               }|S r"   )r#   r(   input_shapelistmemberskeys)r$   r*   r0   s      r   discovery_operation_keysz/EndpointDiscoveryModel.discovery_operation_keys8   sG    "11NN**+77??DDFGDr   c                     	 | j                   j                  |      }|j                  j                  dd      S # t        $ r Y yw xY w)Nr   F)r#   operation_modelr   r   r   )r$   operation_namer3   s      r   discovery_required_forz-EndpointDiscoveryModel.discovery_required_for@   sM    	"11AAO #5599*eLL% 		s   69 	AAc                     | j                   }|j                  d      s$|j                  dd        |j                  dd        |j                         D ci c]  \  }}||v s|| c}}S c c}}w )NIdentifiers	Operation)r1   r   popitems)r$   r   
input_keyskvs        r   discovery_operation_kwargsz1EndpointDiscoveryModel.discovery_operation_kwargsI   s]    22
zz-(JJ{D)JJ}d+!'CA1
?1CCCs   A+"A+c                 :    | j                  |j                  |      S r"   )_gather_idsr-   r$   	operationparamss      r   gather_identifiersz)EndpointDiscoveryModel.gather_identifiersQ   s    	 5 5v>>r   Nc                     |i }|j                   j                         D ]T  \  }}|j                  j                  d      r	||   ||<   *|j                  dk(  s:||v s?| j                  |||   |       V |S )Nendpointdiscoveryid	structure)r/   r:   metadatar   	type_namer@   )r$   shaperC   idsmember_namemember_shapes         r   r@   z"EndpointDiscoveryModel._gather_idsT   s     ;C).)<)<)> 	I%K$$(()>?#)+#6K &&+5+:O  vk/BCH	I 
r   r"   )r   r   r   r&   r   r+   r1   r5   r>   rD   r@   r   r   r   r    r    /   sD    , 4 4  D?r   r    c                   X    e Zd Z	 ddZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zy)EndpointDiscoveryManagerNc                     |i }|| _         i | _        |t        j                  }|| _        || _        t        j                  |      | _        t        |j                  j                        | _        y r"   )_cache_failed_attemptstime_time_always_discoverweakrefproxy_clientr    metar%   _model)r$   clientcachecurrent_timealways_discovers        r   r&   z!EndpointDiscoveryManager.__init__d   sc     =E "99L!
 / }}V,,V[[-F-FGr   c                 v    |d   }| j                         }|D ]  }|j                  d      }||dz  z   |d<     |S )N	EndpointsCachePeriodInMinutes<   
Expiration)rT   r   )r$   response	endpointsr]   endpoint
cache_times         r   _parse_endpointsz)EndpointDiscoveryManager._parse_endpointsu   sR    [)	zz|! 	DH!&<=J%1JO%CH\"	D r   c                 j    t        |t              r"t        t        |j	                                     S |S r"   )
isinstancedicttuplesortedr:   )r$   values     r   _cache_itemz$EndpointDiscoveryManager._cache_item}   s'    eT".//Lr   c                        j                   j                  di |}t         fdt        |j	                               D              S )Nc              3   F   K   | ]  \  }}j                  |        y wr"   )ro   ).0r<   r=   r$   s      r   	<genexpr>z=EndpointDiscoveryManager._create_cache_key.<locals>.<genexpr>   s      LTQT%%a(Ls   !r   )rZ   r>   rl   rm   r:   )r$   r   s   ` r   _create_cache_keyz*EndpointDiscoveryManager._create_cache_key   s8    777A&ALVFLLN5KLLLr   c                 :    | j                   j                  ||      S r"   )rZ   rD   rA   s      r   rD   z+EndpointDiscoveryManager.gather_identifiers   s    {{--i@@r   c                 `     | j                   di |}|| j                  v r| j                  |= y y )Nr   )rt   rQ   )r$   r   	cache_keys      r   delete_endpointsz)EndpointDiscoveryManager.delete_endpoints   s4    *D**4V4	#I& $r   c                      | j                   j                  di |}| j                   j                  }t        | j                  |      }t
        j                  d|        |di |S )Nz%Discovering endpoints with kwargs: %sr   )rZ   r>   r+   getattrrX   loggerdebug)r$   r   r4   r*   s       r   _describe_endpointsz,EndpointDiscoveryManager._describe_endpoints   sZ     877A&A==%dllNC<fE",V,,r   c                     || j                   vry | j                         }| j                   |   D cg c]  }||d   k  s| c}S c c}w )Nrc   )rQ   rT   )r$   keynowes       r   _get_current_endpointsz/EndpointDiscoveryManager._get_current_endpoints   sD    dkk!jjl;;s+EasQ|_/DEEEs
   AAc                 2    | j                   di |}	  | j                  di |}| j                  |      }|| j                  |<   | j                  j                  |d        |S # t        t        f$ r# | j                         dz   | j                  |<   Y y w xY w)Nrb   r   )	rt   r}   rh   rQ   rR   r9   r   r   rT   )r$   r   rw   rd   re   s        r   _refresh_current_endpointsz3EndpointDiscoveryManager._refresh_current_endpoints   s    *D**4V4		/t//9&9H--h7I%.DKK	"!!%%i61 	/3zz|b/@D!!),	s   AA$ $/BBc                     || j                   v r0| j                         }|| j                   |   k  ry| j                   |= y)NTF)rR   rT   )r$   rw   r   s      r   _recently_failedz)EndpointDiscoveryManager._recently_failed   sB    ---**,CT**955%%i0r   c                     |d   d   S )Nr   Addressr   )r$   re   s     r   _select_endpointz)EndpointDiscoveryManager._select_endpoint   s    |I&&r   c                 ^   |d   }| j                   j                  |      }| j                  s|st        j	                  d|z         y  | j
                  di |}| j                  |      }|r| j                  |      S | j                  |      }|s% | j                  di |}|r| j                  |      S t        j	                  d|       | j                  j                  |d       }|r| j                  |      S |r1|r% | j                  di |}|r| j                  |      S t               y )Nr8   zAOptional discovery disabled. Skipping discovery for Operation: %sz%Endpoint Discovery has failed for: %sr   )rZ   r5   rU   r{   r|   rt   r   r   r   r   rQ   r   r   )r$   r   rB   discovery_requiredrw   re   recently_failedstale_entriess           r   describe_endpointz*EndpointDiscoveryManager.describe_endpoint   s4   ;'	![[??	J$$-?LLS  +D**4V4	//	:	((33//	:777A&AI,,Y77<fE	48((77 ;D;;EfE	00;;022r   )NNT)r   r   r   r&   rh   ro   rt   rD   rx   r}   r   r   r   r   r   r   r   r   rO   rO   c   sE    EIH"MA'
-F
')r   rO   c                   *    e Zd Zd Zd Zd Zd Zd Zy)EndpointDiscoveryHandlerc                     || _         y r"   )_manager)r$   managers     r   r&   z!EndpointDiscoveryHandler.__init__   s	    r   c                     |j                  d|z  | j                         |j                  d|z  | j                         |j                  d|z  | j                         y )Nzbefore-parameter-build.%szrequest-created.%szneeds-retry.%s)registerrD   register_firstdiscover_endpointhandle_retries)r$   events
service_ids      r   r   z!EndpointDiscoveryHandler.register   sZ    '*4d6M6M	
 	 :-t/E/E	
 	(:5t7J7JKr   c                 h    |j                   }|y | j                  j                  ||      }d|i|d<   y )Nidentifiers	discovery)r   r   rD   )r$   rC   r   contextr   r   rK   s          r   rD   z+EndpointDiscoveryHandler.gather_identifiers   s<    "55%mm..uf= -s3r   c                 0   |j                   j                  di       j                  d      }|y | j                  j                  ||      }|t        j                  d       y |j                  d      sd|z   }t        j                  d|       ||_        y )Nr   r   r8   r7   z&Failed to discover and inject endpointhttpzhttps://z!Injecting discovered endpoint: %s)r   r   r   r   r{   r|   
startswithurl)r$   requestr4   r   rK   rf   s         r   r   z*EndpointDiscoveryHandler.discover_endpoint   s    oo!!+r266}E;==22$# 3 
 LLAB""6*!H,H8(Cr   c                 h   |y |\  }}|j                  di       j                  d      }|j                  di       j                  d      }|dk7  r|dk7  ry |j                  di       }|j                  di       j                  d	      }	|	y | j                  j                  |j                  |	
       y)NResponseMetadataHTTPStatusCodeErrorCodei  InvalidEndpointExceptionr   r   r   r   r   )r   r   rx   r)   )
r$   request_dictrd   rB   r   _status
error_coder   rK   s
             r   r   z'EndpointDiscoveryHandler.handle_retries  s    80"599:JK\\'2.226:
S=Z+EE""9b1kk+r*..}=;
 	&&nn# 	' 	
 r   N)r   r   r   r&   r   rD   r   r   r   r   r   r   r      s     L4r   r   )loggingrS   rV   botocorer   botocore.exceptionsr   r   r   botocore.modelr   botocore.utilsr   	getLoggerr   r{   r
   r   r   r   r    rO   r   r   r   r   <module>r      s        O O 1 )			8	$	 	N : NI%? I*1 1h{ {|9 9r   