U
    n/e                     @   sH   d dl Z d dlmZmZmZmZmZ G dd deZG dd deZdS )    N)EndpointDiscoveryHandlerEndpointDiscoveryManagerEndpointDiscoveryRefreshFailedHTTPClientErrorloggerc                   @   s   e Zd Zdd Zdd ZdS )AioEndpointDiscoveryManagerc              	      s   | j f |}zH| jf |}t|r.|I d H }| |}|| j|< | j|d  |W S  tt	fk
r   | 
 d | j|< Y d S X d S )N<   )_create_cache_keyZ_describe_endpointsinspectisawaitableZ_parse_endpoints_cacheZ_failed_attemptspopConnectionErrorr   _time)selfkwargs	cache_keyresponse	endpoints r   9/tmp/pip-unpacked-wheel-8mnez3y6/aiobotocore/discovery.py_refresh_current_endpoints   s    



z6AioEndpointDiscoveryManager._refresh_current_endpointsc                    s   |d }| j |}| js0|s0td|  d S | jf |}| |}|rT| |S | |}|s| j	f |I d H }|r| |S td| | j
|d }|r| |S |r|r| j	f |I d H }|r| |S t d S )N	OperationzAOptional discovery disabled. Skipping discovery for Operation: %sz%Endpoint Discovery has failed for: %s)_modelZdiscovery_required_forZ_always_discoverr   debugr	   Z_get_current_endpointsZ_select_endpointZ_recently_failedr   r   getr   )r   r   Z	operationZdiscovery_requiredr   r   Zrecently_failedZstale_entriesr   r   r   describe_endpoint   s:    






z-AioEndpointDiscoveryManager.describe_endpointN)__name__
__module____qualname__r   r   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd ZdS )AioEndpointDiscoveryHandlerc                    st   |j di d}|d kr d S | jj||dI d H }|d krLtd d S |ds^d| }td| ||_d S )NZ	discoveryZidentifiers)r   ZIdentifiersz&Failed to discover and inject endpointhttpzhttps://z!Injecting discovered endpoint: %s)contextr   _managerr   r   r   
startswithurl)r   requestZoperation_namer   idsZendpointr   r   r   discover_endpointJ   s     

z-AioEndpointDiscoveryHandler.discover_endpointN)r   r   r   r(   r   r   r   r   r    I   s   r    )	r
   Zbotocore.discoveryr   r   r   r   r   r   r    r   r   r   r   <module>   s   	=