o
    ȷe&                     @   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.
    lambda
monitoringemailecsconfig)	awslambda
cloudwatchsesec2containerserviceconfigserviceNc                    s@   t t| | |du 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   E/var/www/ideatree/venv/lib/python3.10/site-packages/boto/endpoints.py	<genexpr>2   s    
z3_CompatEndpointResolver.__init__.<locals>.<genexpr>)superr   __init___DEFAULT_SERVICE_RENAMES_endpoint_prefix_mapdictitems_service_name_mapselfendpoint_data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_nameallow_non_regionalendpoint_prefixr    r   r   r$   5   s   

z/_CompatEndpointResolver.get_available_endpointsc                 C   sb   t  }| |}|  D ] }| ||r#| |}||d   q|| || qt|S )z6Retrieve every region across partitions for a service.regions)	setr#   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   r3   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   r6   r1   r   r9   r   get_available_servicesU   s   z._CompatEndpointResolver.get_available_servicesc                 C   s,   |  |}| |}|d |i }d|v S )zDetermines 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.
        r6   partitionEndpoint)r#   r-   get)r   r%   r&   r(   r1   servicer   r   r   r,   ^   s   

z*_CompatEndpointResolver._is_global_servicec                 C   s0   | j d D ]}|d |kr|  S qtd| )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
        r5   r1   z%Could not find partition data for: %s)r;   
ValueError)r   r&   r1   r   r   r   r-   i   s   z+_CompatEndpointResolver._get_partition_datac                 C      | j ||S )z4Given a boto2 service name, get the endpoint prefix.)r   r>   r   r%   r   r   r   r#   |      z(_CompatEndpointResolver._endpoint_prefixc                 C   rA   )z5Given an endpoint prefix, get the boto2 service name.)r   r>   )r   r(   r   r   r   r7      rC   z%_CompatEndpointResolver._service_namer   )r"   F)r"   )__name__
__module____qualname____doc__r   r   r$   r2   r3   r<   r,   r-   r#   r7   __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u 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.
        NsslCommonNamehostname)rJ   r3   r>   )r   r%   r4   endpointr   r   r   resolve_hostname   s   z%BotoEndpointResolver.resolve_hostnamec                 C   s   | j |S )zGet 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.
        )rJ   r2   rB   r   r   r   r2      s   	z.BotoEndpointResolver.get_all_available_regionsc                 C   s
   | j  S )zGet 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.
        )rJ   r<   r9   r   r   r   r<      s   
z+BotoEndpointResolver.get_available_servicesr   )rD   rE   rF   rG   r   rN   r2   r<   r   r   r   r   rI      s    
rI   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)rJ   )r   resolverr   r   r   r      s   
zStaticEndpointBuilder.__init__Nc                 C   sD   |du 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)rJ   r<   _build_endpoints_for_service_handle_special_cases)r   service_namesstatic_endpointsnameendpoints_for_servicer   r   r   build_static_endpoints   s   


z,StaticEndpointBuilder.build_static_endpointsc                 C   s0   i }| j |}|D ]}| j ||||< q
|S r   )rJ   r2   rN   )r   r%   	endpointsr)   r4   r   r   r   rQ      s   
z2StaticEndpointBuilder._build_endpoints_for_servicec                 C   s    d|v r|d }||d< d S d S )Ncloudsearchcloudsearchdomainr   )r   rT   cloudsearch_endpointsr   r   r   rR      s   z+StaticEndpointBuilder._handle_special_casesr   )rD   rE   rF   rG   r   rW   rQ   rR   r   r   r   r   rO      s    

rO   )	boto.vendored.regions.regionsvendoredr)   _regionsEndpointResolverr   objectrI   rO   r   r   r   r   <module>   s   u8