3
ûâde¨  ã               @   s„   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZ ejeƒZG dd„ dƒZdS )	é    N)ÚList)Úcanonicalize_name)ÚPyPI)Úhas_tls)Únormalize_pathÚredact_auth_from_urlc               @   sr   e Zd ZdZddgZeee ee d dœdd„ƒZee ee ddœdd	„Z	ed
œdd„Z
eee dœdd„ZdS )ÚSearchScopezF
    Encapsulates the locations that pip is configured to search.
    Ú
find_linksÚ
index_urls)r	   r
   Úreturnc             C   sˆ   g }x8|D ]0}|j dƒr0t|ƒ}tjj|ƒr0|}|j|ƒ q
W tƒ s|x6tj||ƒD ]&}t	j
j|ƒ}|jdkrRtjdƒ P qRW | ||d�S )zQ
        Create a SearchScope object after normalizing the `find_links`.
        ú~Úhttpszipip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.)r	   r
   )Ú
startswithr   ÚosÚpathÚexistsÚappendr   Ú	itertoolsÚchainÚurllibÚparseÚurlparseÚschemeÚloggerÚwarning)Úclsr	   r
   Zbuilt_find_linksÚlinkÚnew_linkÚparsed© r   ú@/tmp/pip-build-red6nood/pip/pip/_internal/models/search_scope.pyÚcreate   s"    


zSearchScope.createNc             C   s   || _ || _d S )N)r	   r
   )Úselfr	   r
   r   r   r    Ú__init__A   s    zSearchScope.__init__)r   c             C   s®   g }g }| j r|| j tjgkr|xH| j D ]>}t|ƒ}tjj|ƒ}|j rX|j rXt	j
d|ƒ |j|ƒ q$W |jdjdj|ƒƒƒ | jr¤|jdjdjdd„ | jD ƒƒƒƒ dj|ƒS )Nz:The index url "%s" seems invalid, please provide a scheme.zLooking in indexes: {}z, zLooking in links: {}c             s   s   | ]}t |ƒV  qd S )N)r   )Ú.0Úurlr   r   r    ú	<genexpr>h   s    z6SearchScope.get_formatted_locations.<locals>.<genexpr>Ú
)r
   r   Ú
simple_urlr   r   r   Úurlsplitr   Únetlocr   r   r   ÚformatÚjoinr	   )r"   ÚlinesZredacted_index_urlsr%   Zredacted_index_urlÚpurlr   r   r    Úget_formatted_locationsI   s$    z#SearchScope.get_formatted_locations)Úproject_namer   c                s(   t t dœ‡fdd„‰ ‡ fdd„| jD ƒS )z²Returns the locations found via self.index_urls

        Checks the url_name on the main (first in the list) index and
        use this url_name to produce all locations
        )r%   r   c                s.   t j| tjjtˆ ƒƒƒ}|jdƒs*|d }|S )Nú/)Ú	posixpathr,   r   r   Úquoter   Úendswith)r%   Úloc)r0   r   r    Úmkurl_pypi_urlt   s
    
z<SearchScope.get_index_urls_locations.<locals>.mkurl_pypi_urlc                s   g | ]}ˆ |ƒ‘qS r   r   )r$   r%   )r6   r   r    ú
<listcomp>�   s    z8SearchScope.get_index_urls_locations.<locals>.<listcomp>)Ústrr
   )r"   r0   r   )r6   r0   r    Úget_index_urls_locationsm   s    z$SearchScope.get_index_urls_locations)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__Úclassmethodr   r8   r!   r#   r/   r9   r   r   r   r    r      s   %$r   )r   Úloggingr   r2   Úurllib.parser   Útypingr   Úpip._vendor.packaging.utilsr   Zpip._internal.models.indexr   Zpip._internal.utils.compatr   Zpip._internal.utils.miscr   r   Ú	getLoggerr:   r   r   r   r   r   r    Ú<module>   s   
