U
    W¨+d&  ã                   @   sN   d dl m  m  mZ G dd„ dejƒZG dd„ deƒZG dd„ deƒZdS )é    Nc                       s€   e Zd ZdZddddddœZd‡ fd	d
„	Zd‡ fdd„	Zdd„ Zd‡ fdd„	Zdd„ Z	d dd„Z
dd„ Zdd„ Zdd„ Z‡  ZS )!Ú_CompatEndpointResolverzyEndpoint resolver which handles boto2 compatibility concerns.

    This is NOT intended for external use whatsoever.
    ÚlambdaZ
monitoringÚemailZecsÚconfig)Z	awslambdaZ
cloudwatchZsesZec2containerserviceZconfigserviceNc                    s@   t t| ƒ |¡ |dkr| j}|| _tdd„ | ¡ D ƒƒ| _dS )á.  
        :type endpoint_data: dict
        :param endpoint_data: Regions and endpoints data in the same format
            as is used by botocore / boto3.

        :type service_rename_map: dict
        :param service_rename_map: A mapping of boto2 service name to
            endpoint prefix.
        Nc                 s   s   | ]\}}||fV  qd S ©N© )Ú.0ÚkÚvr   r   ú2/tmp/pip-unpacked-wheel-dlxw5sjy/boto/endpoints.pyÚ	<genexpr>2   s    z3_CompatEndpointResolver.__init__.<locals>.<genexpr>)Úsuperr   Ú__init__Ú_DEFAULT_SERVICE_RENAMESÚ_endpoint_prefix_mapÚdictÚitemsÚ_service_name_map©ÚselfZendpoint_dataZservice_rename_map©Ú	__class__r   r   r   "   s    
ÿz _CompatEndpointResolver.__init__ÚawsFc                    s   |   |¡}tt| ƒ |||¡S r   )Ú_endpoint_prefixr   r   Úget_available_endpoints)r   Úservice_nameÚpartition_nameZallow_non_regionalÚendpoint_prefixr   r   r   r   5   s    

  ÿz/_CompatEndpointResolver.get_available_endpointsc                 C   sd   t ƒ }|  |¡}|  ¡ D ]B}|  ||¡rH|  |¡}| |d  ¡ ¡ qq| |  ||¡¡ qt|ƒS )z6Retrieve every region across partitions for a service.Úregions)	Úsetr   Zget_available_partitionsÚ_is_global_serviceÚ_get_partition_dataÚupdateÚkeysr   Úlist)r   r   r   r   r   Ú	partitionr   r   r   Úget_all_available_regions;   s    

 ÿÿz1_CompatEndpointResolver.get_all_available_regionsc                    s   |   |¡}tt| ƒ ||¡S r   )r   r   r   Úconstruct_endpoint)r   r   Úregion_namer   r   r   r   r(   P   s
    

 ÿz*_CompatEndpointResolver.construct_endpointc                    s:   t ƒ }ˆ jd D ]}| |d  ¡ ¡ q‡ fdd„|D ƒS )zAGet a list of all the available services in the endpoints file(s)Ú
partitionsÚservicesc                    s   g | ]}ˆ   |¡‘qS r   )Ú_service_name)r	   Ús©r   r   r   Ú
<listcomp>\   s     zB_CompatEndpointResolver.get_available_services.<locals>.<listcomp>)r    Ú_endpoint_datar#   r$   )r   r+   r&   r   r.   r   Úget_available_servicesU   s    z._CompatEndpointResolver.get_available_servicesc                 C   s,   |   |¡}|  |¡}|d  |i ¡}d|kS )zÕDetermines whether a service uses a global endpoint.

        In theory a service can be 'global' in one partition but regional in
        another. In practice, each service is all global or all regional.
        r+   ZpartitionEndpoint)r   r"   Úget)r   r   r   r   r&   Zservicer   r   r   r!   ^   s    

z*_CompatEndpointResolver._is_global_servicec                 C   s4   | j d D ]}|d |kr
|  S q
td| ƒ‚dS )aà  Get partition information for a particular partition.

        This should NOT be used to get service endpoint data because it only
        loads from the new endpoint format. It should only be used for
        partition metadata and partition specific service metadata.

        :type partition_name: str
        :param partition_name: The name of the partition to search for.

        :returns: Partition info from the new endpoints format.
        :rtype: dict or None
        r*   r&   z%Could not find partition data for: %sN)r0   Ú
ValueError)r   r   r&   r   r   r   r"   i   s    
ÿz+_CompatEndpointResolver._get_partition_datac                 C   s   | j  ||¡S )z4Given a boto2 service name, get the endpoint prefix.)r   r2   ©r   r   r   r   r   r   |   s    z(_CompatEndpointResolver._endpoint_prefixc                 C   s   | j  ||¡S )z5Given an endpoint prefix, get the boto2 service name.)r   r2   )r   r   r   r   r   r,   €   s    z%_CompatEndpointResolver._service_name)N)r   F)N)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r'   r(   r1   r!   r"   r   r,   Ú__classcell__r   r   r   r   r      s$   
÷  ÿ	
r   c                   @   s2   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZdS )ÚBotoEndpointResolverz^Resolves endpoint hostnames for AWS services.

    This is NOT intended for external use.
    Nc                 C   s   t ||ƒ| _dS )r   N)r   Ú	_resolverr   r   r   r   r   ‹   s    
 ÿzBotoEndpointResolver.__init__c                 C   s*   | j  ||¡}|dkrdS | d|d ¡S )aD  Resolve the hostname for a service in a particular region.

        :type service_name: str
        :param service_name: The service to look up.

        :type region_name: str
        :param region_name: The region to find the endpoint for.

        :return: The hostname for the given service in the given region.
        NZsslCommonNameÚhostname)r;   r(   r2   )r   r   r)   Zendpointr   r   r   Úresolve_hostname˜   s    z%BotoEndpointResolver.resolve_hostnamec                 C   s   | j  |¡S )zøGet all the regions a service is available in.

        :type service_name: str
        :param service_name: The service to look up.

        :rtype: list of str
        :return: A list of all the regions the given service is available in.
        )r;   r'   r4   r   r   r   r'   ¨   s    	z.BotoEndpointResolver.get_all_available_regionsc                 C   s
   | j  ¡ S )zßGet all the services supported by the endpoint data.

        :rtype: list of str
        :return: A list of all the services explicitly contained within the
            endpoint data provided during instantiation.
        )r;   r1   r.   r   r   r   r1   ³   s    z+BotoEndpointResolver.get_available_services)N)r5   r6   r7   r8   r   r=   r'   r1   r   r   r   r   r:   …   s
   
r:   c                   @   s2   e Zd ZdZdd„ Zddd„Zdd„ Zd	d
„ ZdS )ÚStaticEndpointBuilderz:Builds a static mapping of endpoints in the legacy format.c                 C   s
   || _ dS )ze
        :type resolver: BotoEndpointResolver
        :param resolver: An endpoint resolver.
        N)r;   )r   Úresolverr   r   r   r   À   s    zStaticEndpointBuilder.__init__Nc                 C   sD   |dkr| j  ¡ }i }|D ]}|  |¡}|r|||< q|  |¡ |S )a¯  Build a set of static endpoints in the legacy boto2 format.

        :param service_names: The names of the services to build. They must
            use the names that boto2 uses, not boto3, e.g "ec2containerservice"
            and not "ecs". If no service names are provided, all available
            services will be built.

        :return: A dict consisting of::
            {"service": {"region": "full.host.name"}}
        N)r;   r1   Ú_build_endpoints_for_serviceÚ_handle_special_cases)r   Zservice_namesÚstatic_endpointsÚnameZendpoints_for_servicer   r   r   Úbuild_static_endpointsÇ   s    



z,StaticEndpointBuilder.build_static_endpointsc                 C   s0   i }| j  |¡}|D ]}| j  ||¡||< q|S r   )r;   r'   r=   )r   r   Z	endpointsr   r)   r   r   r   r@   à   s     ÿ
z2StaticEndpointBuilder._build_endpoints_for_servicec                 C   s   d|kr|d }||d< d S )NZcloudsearchZcloudsearchdomainr   )r   rB   Zcloudsearch_endpointsr   r   r   rA   ê   s    z+StaticEndpointBuilder._handle_special_cases)N)r5   r6   r7   r8   r   rD   r@   rA   r   r   r   r   r>   ½   s
   

r>   )	Zboto.vendored.regions.regionsÚvendoredr   Z_regionsZEndpointResolverr   Úobjectr:   r>   r   r   r   r   Ú<module>   s   u8