3
zYðiœ  ã               @   s  d Z ddlmZ ddlZddlZddlmZ ddlZddlZ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mZmZmZmZ dd	lmZ dd
lmZ ddlm Z  ddl!m"Z"m#Z#m$Z$m%Z% ddl&m'Z'm(Z(m)Z)m*Z* ddl+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2m3Z3 ddl4mZ5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z;m<Z< ddl=m>Z> dddgZ?d3d4d5d6d7d8gZ@ejAeBƒZCG dd „ d eDƒZEG d!d„ deDƒZFe
jGd"e
jHƒfd#d$„ZIG d%d&„ d&eDƒZJG d'd(„ d(eDƒZKedd)ƒZLd*d„ ZMd+d,„ ZNd-d.„ ZOd/d0„ ZPed1d2ƒZQdS )9z!Routines related to PyPI, indexesé    )Úabsolute_importN)Ú
namedtuple)Úparse)Úrequest)Ú	ipaddress)Úcached_propertyÚsplitextÚnormalize_pathÚARCHIVE_EXTENSIONSÚSUPPORTED_EXTENSIONS)ÚRemovedInPip10Warning)Ú
indent_log)Úcheck_requires_python)ÚDistributionNotFoundÚBestVersionAlreadyInstalledÚInvalidWheelFilenameÚUnsupportedWheel)ÚHAS_TLSÚis_urlÚpath_to_urlÚurl_to_path)ÚWheelÚ	wheel_ext)Úget_supported)Úhtml5libÚrequestsÚsix)Úcanonicalize_name)Ú
specifiers)Ú	HTTPErrorÚSSLError)ÚunescapeÚFormatControlÚfmt_ctl_handle_mutual_excludeÚPackageFinderÚhttpsÚ*Ú	localhostú127.0.0.0/8ú::1/128ÚfileÚsshc               @   s\   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚInstallationCandidatec             C   s,   || _ t|ƒ| _|| _| j | j| jf| _d S )N)ÚprojectÚparse_versionÚversionÚlocationÚ_key)Úselfr-   r/   r0   © r3   ú(/tmp/pip-build-ue6tjl93/pip/pip/index.pyÚ__init__>   s    
zInstallationCandidate.__init__c             C   s   dj | j| j| jƒS )Nz,<InstallationCandidate({0!r}, {1!r}, {2!r})>)Úformatr-   r/   r0   )r2   r3   r3   r4   Ú__repr__D   s    zInstallationCandidate.__repr__c             C   s
   t | jƒS )N)Úhashr1   )r2   r3   r3   r4   Ú__hash__I   s    zInstallationCandidate.__hash__c             C   s   | j |dd„ ƒS )Nc             S   s   | |k S )Nr3   )ÚsÚor3   r3   r4   Ú<lambda>M   s    z.InstallationCandidate.__lt__.<locals>.<lambda>)Ú_compare)r2   Úotherr3   r3   r4   Ú__lt__L   s    zInstallationCandidate.__lt__c             C   s   | j |dd„ ƒS )Nc             S   s   | |kS )Nr3   )r:   r;   r3   r3   r4   r<   P   s    z.InstallationCandidate.__le__.<locals>.<lambda>)r=   )r2   r>   r3   r3   r4   Ú__le__O   s    zInstallationCandidate.__le__c             C   s   | j |dd„ ƒS )Nc             S   s   | |kS )Nr3   )r:   r;   r3   r3   r4   r<   S   s    z.InstallationCandidate.__eq__.<locals>.<lambda>)r=   )r2   r>   r3   r3   r4   Ú__eq__R   s    zInstallationCandidate.__eq__c             C   s   | j |dd„ ƒS )Nc             S   s   | |kS )Nr3   )r:   r;   r3   r3   r4   r<   V   s    z.InstallationCandidate.__ge__.<locals>.<lambda>)r=   )r2   r>   r3   r3   r4   Ú__ge__U   s    zInstallationCandidate.__ge__c             C   s   | j |dd„ ƒS )Nc             S   s   | |kS )Nr3   )r:   r;   r3   r3   r4   r<   Y   s    z.InstallationCandidate.__gt__.<locals>.<lambda>)r=   )r2   r>   r3   r3   r4   Ú__gt__X   s    zInstallationCandidate.__gt__c             C   s   | j |dd„ ƒS )Nc             S   s   | |kS )Nr3   )r:   r;   r3   r3   r4   r<   \   s    z.InstallationCandidate.__ne__.<locals>.<lambda>)r=   )r2   r>   r3   r3   r4   Ú__ne__[   s    zInstallationCandidate.__ne__c             C   s   t |tƒstS || j|jƒS )N)Ú
isinstancer,   ÚNotImplementedr1   )r2   r>   Úmethodr3   r3   r4   r=   ^   s    
zInstallationCandidate._compareN)Ú__name__Ú
__module__Ú__qualname__r5   r7   r9   r?   r@   rA   rB   rC   rD   r=   r3   r3   r3   r4   r,   <   s   r,   c            	   @   s’   e Zd ZdZd!dd„Zdd„ Zed"dd	„ƒZd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZejdƒZdd„ Zdd„ Zdd„ Zdd„ Zdd „ ZdS )#r$   z This finds packages.

    This is meant to match easy_install's technique for looking for
    packages, by reading pages and looking for appropriate links.
    FNc             C   sø   |dkrt dƒ‚g | _x:|D ]2}|jdƒrBt|ƒ}tjj|ƒrB|}| jj|ƒ qW || _g | _	t
ƒ | _|pvtt
ƒ t
ƒ ƒ| _dd„ |rˆ|ng D ƒ| _|| _|| _|| _t|	||
|d�| _tsôx8tj| j| jƒD ]$}tj|ƒ}|jdkrÌtjdƒ P qÌW dS )	a¯  Create a PackageFinder.

        :param format_control: A FormatControl object or None. Used to control
            the selection of source packages / binary packages when consulting
            the index and links.
        :param platform: A string or None. If None, searches for packages
            that are supported by the current system. Otherwise, will find
            packages that can be built on the platform passed in. These
            packages will only be downloaded for distribution: they will
            not be built locally.
        :param versions: A list of strings or None. This is passed directly
            to pep425tags.py in the get_supported() method.
        :param abi: A string or None. This is passed directly
            to pep425tags.py in the get_supported() method.
        :param implementation: A string or None. This is passed directly
            to pep425tags.py in the get_supported() method.
        Nz>PackageFinder() missing 1 required keyword argument: 'session'ú~c             S   s   g | ]}d |d f‘qS )r&   r3   )Ú.0Úhostr3   r3   r4   ú
<listcomp>ž   s   z*PackageFinder.__init__.<locals>.<listcomp>)ÚversionsÚplatformÚabiÚimplr%   zipip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.)Ú	TypeErrorÚ
find_linksÚ
startswithr	   ÚosÚpathÚexistsÚappendÚ
index_urlsÚdependency_linksÚsetÚlogged_linksr"   Úformat_controlÚsecure_originsÚallow_all_prereleasesÚprocess_dependency_linksÚsessionr   Ú
valid_tagsr   Ú	itertoolsÚchainÚurllib_parseÚurlparseÚschemeÚloggerÚwarning)r2   rT   rZ   r`   Útrusted_hostsra   rb   r^   rP   rO   rQ   ÚimplementationÚlinkÚnew_linkÚparsedr3   r3   r4   r5   l   s>    	




zPackageFinder.__init__c             C   s"   | j rtjdtƒ | jj|ƒ d S )NzXDependency Links processing has been deprecated and will be removed in a future release.)ra   ÚwarningsÚwarnr   r[   Úextend)r2   Úlinksr3   r3   r4   Úadd_dependency_linksÀ   s
    z"PackageFinder.add_dependency_linksc                sô   g ‰ g ‰‡ ‡fdd„}xÔ| D ]Ì}t jj|ƒ}|jdƒ}|s>|rÈ|rH|}nt|ƒ}t jj|ƒr¤|r”t jj|ƒ}x4t j|ƒD ]}|t jj||ƒƒ qxW qÆ|rÆˆj	|ƒ qèt jj
|ƒrº||ƒ qètjd|ƒ qt|ƒrÜˆj	|ƒ qtjd|ƒ qW ˆ ˆfS )zt
        Sort locations into "files" (archives) and "urls", and return
        a pair of lists (files,urls)
        c                s8   t | ƒ}tj|dd�d dkr*ˆj|ƒ n
ˆ j|ƒ d S )NF)Ústrictr   z	text/html)r   Ú	mimetypesÚ
guess_typerY   )rW   Úurl)ÚfilesÚurlsr3   r4   Ú	sort_path×   s    z0PackageFinder._sort_locations.<locals>.sort_pathzfile:z:Url '%s' is ignored: it is neither a file nor a directory.zQUrl '%s' is ignored. It is either a non-existing path or lacks a specific scheme.)rV   rW   rX   rU   r   ÚisdirÚrealpathÚlistdirÚjoinrY   Úisfileri   rj   r   )Ú	locationsÚ
expand_dirr{   rx   Úis_local_pathÚis_file_urlrW   Úitemr3   )ry   rz   r4   Ú_sort_locationsÍ   s8    



zPackageFinder._sort_locationsc             C   sX   t | jƒ}|jjrHt|jjƒ}|j| jƒs8td|j ƒ‚|j| jƒ }n| }|j	|fS )a[  
        Function used to generate link sort key for link tuples.
        The greater the return value, the more preferred it is.
        If not finding wheels, then sorted by version only.
        If finding wheels, then the sort order is by version, then:
          1. existing installs
          2. wheels ordered via Wheel.support_index_min(self.valid_tags)
          3. source archives
        Note: it was considered to embed this logic into the Link
              comparison operators, but then different sdist links
              with the same version, would have to be considered equal
        zB%s is not a supported wheel for this platform. It can't be sorted.)
Úlenrc   r0   Úis_wheelr   ÚfilenameÚ	supportedr   Úsupport_index_minr/   )r2   Ú	candidateÚsupport_numÚwheelÚprir3   r3   r4   Ú_candidate_sort_keyÿ   s    

z!PackageFinder._candidate_sort_keyc       	      C   sl  t jt|ƒƒ}|j|j|jf}|d jddƒd
 }�x t| j D �]}||d kr`|d dkr`q@yht	j
t|d tjƒs‚|d d krŠ|d n|d jdƒƒ}t	jt|d tjƒr¶|d n|d jdƒƒ}W nJ tk
�r   |d �r|d jƒ |d jƒ k�r|d dk�rw@Y nX ||k�r q@|d |d k�rP|d dk�rP|d d k	�rPq@dS W |jd|j|jƒ d	S )Nr   ú+é   r&   Úutf8é   TzúThe repository located at %s is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwise you may silence this warning and allow it anyways with '--trusted-host %s'.Féÿÿÿÿ)rf   rg   Ústrrh   ÚhostnameÚportÚrsplitÚSECURE_ORIGINSr_   r   Ú
ip_addressrE   r   Ú	text_typeÚdecodeÚ
ip_networkÚ
ValueErrorÚlowerrj   )	r2   ri   r0   ro   ÚoriginÚprotocolÚsecure_originÚaddrÚnetworkr3   r3   r4   Ú_validate_secure_origin  s>    

z%PackageFinder._validate_secure_originc                s    ‡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
        c                s,   t j| tjtˆ ƒƒƒ}|jdƒs(|d }|S )Nú/)Ú	posixpathr   rf   Úquoter   Úendswith)rx   Úloc)Úproject_namer3   r4   Úmkurl_pypi_urlh  s    
z?PackageFinder._get_index_urls_locations.<locals>.mkurl_pypi_urlc                s   g | ]}ˆ |ƒ‘qS r3   r3   )rL   rx   )r­   r3   r4   rN   u  s    z;PackageFinder._get_index_urls_locations.<locals>.<listcomp>)rZ   )r2   r¬   r3   )r­   r¬   r4   Ú_get_index_urls_locationsa  s    z'PackageFinder._get_index_urls_locationsc                sÆ  ˆ j |ƒ}ˆ j|ƒ\}}ˆ jˆ jdd�\}}ˆ jˆ jƒ\}}dd„ tj|||ƒD ƒ}	‡ fdd„tjdd„ |D ƒdd„ |D ƒd	d„ |D ƒƒD ƒ}
tjd
t|
ƒ|ƒ x|
D ]}tjd|ƒ q¦W t	|ƒ}t
ˆ j|ƒ}t|||ƒ}ˆ jdd„ ˆ jD ƒ|ƒ}g }xJˆ j|
|ƒD ]:}tjd|jƒ tƒ � |jˆ j|j|ƒƒ W dQ R X �qW ˆ jdd„ ˆ jD ƒ|ƒ}|�r|tjddjdd„ |D ƒƒƒ ˆ j|	|ƒ}|�r¶|jdd� tjddjdd„ |D ƒƒƒ || | | S )a  Find all available InstallationCandidate for project_name

        This checks index_urls, find_links and dependency_links.
        All versions found are returned as an InstallationCandidate list.

        See _link_package_versions for details on which files are accepted
        T)r‚   c             s   s   | ]}t |ƒV  qd S )N)ÚLink)rL   rx   r3   r3   r4   ú	<genexpr>†  s    z4PackageFinder.find_all_candidates.<locals>.<genexpr>c                s   g | ]}ˆ j t|ƒr|‘qS r3   )r¦   ri   )rL   rm   )r2   r3   r4   rN   �  s    z5PackageFinder.find_all_candidates.<locals>.<listcomp>c             s   s   | ]}t |ƒV  qd S )N)r¯   )rL   rx   r3   r3   r4   r°   �  s    c             s   s   | ]}t |ƒV  qd S )N)r¯   )rL   rx   r3   r3   r4   r°   ‘  s    c             s   s   | ]}t |ƒV  qd S )N)r¯   )rL   rx   r3   r3   r4   r°   ’  s    z,%d location(s) to search for versions of %s:z* %sc             s   s   | ]}t |d ƒV  qdS )z-fN)r¯   )rL   rx   r3   r3   r4   r°   ¢  s    zAnalyzing links from page %sNc             s   s   | ]}t |ƒV  qd S )N)r¯   )rL   rx   r3   r3   r4   r°   ¯  s    zdependency_links found: %sz, c             S   s   g | ]}|j j‘qS r3   )r0   rx   )rL   r/   r3   r3   r4   rN   µ  s    )ÚreversezLocal files found: %sc             S   s   g | ]}t |jjƒ‘qS r3   )r   r0   rx   )rL   rŒ   r3   r3   r4   rN   ¿  s   )r®   r†   rT   r[   rd   re   ri   Údebugr‡   r   Úfmt_ctl_formatsr^   ÚSearchÚ_package_versionsÚ
_get_pagesrx   r   rr   rs   r   Úsort)r2   r¬   Úindex_locationsÚindex_file_locÚindex_url_locÚfl_file_locÚ
fl_url_locÚdep_file_locÚdep_url_locÚfile_locationsÚurl_locationsr0   Úcanonical_nameÚformatsÚsearchÚfind_links_versionsÚpage_versionsÚpageÚdependency_versionsÚfile_versionsr3   )r2   r4   Úfind_all_candidatesw  sX    


 
z!PackageFinder.find_all_candidatesc                sh  | j |jƒ}t|jjdd„ |D ƒ| jr,| jndd�ƒ‰ ‡ fdd„|D ƒ}|r\t|| jd�}nd}|jdk	rxt	|jj
ƒ}nd}|dkrÂ|dkrÂtjd|djttd	d
„ |D ƒƒt	d�ƒƒ td| ƒ‚d}|rà|dksÜ|j
|kràd}| oì|dk	�r|�rtjd|ƒ ntjd||j
ƒ dS |�rDtjd|djtˆ t	d�ƒ�p<dƒ t‚tjd|j
djtˆ t	d�ƒƒ |jS )zÙTry to find a Link matching req

        Expects req, an InstallRequirement and upgrade, a boolean
        Returns a Link if found,
        Raises DistributionNotFound or BestVersionAlreadyInstalled otherwise
        c             S   s   g | ]}t |jƒ‘qS r3   )r–   r/   )rL   Úcr3   r3   r4   rN   Ý  s    z2PackageFinder.find_requirement.<locals>.<listcomp>N)Úprereleasesc                s   g | ]}t |jƒˆ kr|‘qS r3   )r–   r/   )rL   rÊ   )Úcompatible_versionsr3   r4   rN   æ  s    )ÚkeyzNCould not find a version that satisfies the requirement %s (from versions: %s)z, c             s   s   | ]}t |jƒV  qd S )N)r–   r/   )rL   rÊ   r3   r3   r4   r°   û  s    z1PackageFinder.find_requirement.<locals>.<genexpr>z%No matching distribution found for %sFTzLExisting installed version (%s) is most up-to-date and satisfies requirementzUExisting installed version (%s) satisfies requirement (most up-to-date version is %s)z=Installed version (%s) is most up-to-date (past versions: %s)Únonez)Using version %s (newest of versions: %s))rÉ   Únamer\   Ú	specifierÚfilterr`   Úmaxr�   Úsatisfied_byr.   r/   ri   Úcriticalr   Úsortedr   r²   r   r0   )r2   ÚreqÚupgradeÚall_candidatesÚapplicable_candidatesÚbest_candidateÚinstalled_versionÚbest_installedr3   )rÌ   r4   Úfind_requirementÊ  sd    


zPackageFinder.find_requirementc             c   sF   t ƒ }x:|D ]2}||krq|j|ƒ | j|ƒ}|dkr8q|V  qW dS )zp
        Yields (page, page_url) from the given locations, skipping
        locations that have errors.
        N)r\   ÚaddÚ	_get_page)r2   r�   r¬   Úseenr0   rÆ   r3   r3   r4   r¶   -  s    


zPackageFinder._get_pagesz-py([123]\.?[0-9]?)$c             C   sT   g g  }}t ƒ }x:|D ]2}||kr|j|ƒ |jr>|j|ƒ q|j|ƒ qW || S )z�
        Returns elements of links in order, non-egg links first, egg links
        second, while eliminating duplicates
        )r\   rÞ   Úegg_fragmentrY   )r2   rs   ÚeggsÚno_eggsrà   rm   r3   r3   r4   Ú_sort_links@  s    


zPackageFinder._sort_linksc             C   s:   g }x0| j |ƒD ]"}| j||ƒ}|d k	r|j|ƒ qW |S )N)rä   Ú_link_package_versionsrY   )r2   rs   rÃ   Úresultrm   Úvr3   r3   r4   rµ   P  s    zPackageFinder._package_versionsc             C   s(   || j kr$tjd||ƒ | j j|ƒ d S )NzSkipping link %s; %s)r]   ri   r²   rÞ   )r2   rm   Úreasonr3   r3   r4   Ú_log_skipped_linkX  s    
zPackageFinder._log_skipped_linkc       
      C   sJ  d}|j r|j }|j}�n|jƒ \}}|s:| j|dƒ dS |tkrV| j|d| ƒ dS d|jkr~|tkr~| j|d|j ƒ dS d|jkr |dkr | j|dƒ dS |tk�r&yt	|j
ƒ}W n  tk
rØ   | j|d	ƒ dS X t|jƒ|jk�r| j|d
|j ƒ dS |j| jƒ�s | j|dƒ dS |j}d|jk�rR|tk�rR| j|d|j ƒ dS |�sft||j|ƒ}|dk�r†| j|d
|j ƒ dS | jj|ƒ}|�rÖ|d|jƒ … }|jdƒ}|tjdd… k�rÖ| j|dƒ dS yt|jƒ}	W n. tjk
�r   tjd|j
|jƒ d}	Y nX |	�s.tjd||jƒ dS tjd||ƒ t|j||ƒS )z'Return an InstallationCandidate or NoneNz
not a filezunsupported archive format: %sÚbinaryzNo binaries permitted for %sÚmacosx10z.zipzmacosx10 onezinvalid wheel filenamezwrong project name (not %s)z%it is not compatible with this PythonÚsourcezNo sources permitted for %sr’   é   zPython version is incorrectz3Package %s has an invalid Requires-Python entry: %sTz_The package %s is incompatible with the pythonversion in use. Acceptable python versions are:%szFound link %s, version: %s)rá   Úextr   ré   r   rÂ   r   ÚsuppliedrW   r   r‰   r   r   rÏ   Ú	canonicalrŠ   rc   r/   Úegg_info_matchesÚ_py_version_rerÃ   ÚstartÚgroupÚsysr   Úrequires_pythonr   ÚInvalidSpecifierri   r²   r,   )
r2   rm   rÃ   r/   Úegg_inforî   rŽ   ÚmatchÚ
py_versionÚsupport_this_pythonr3   r3   r4   rå   ]  s€    





z$PackageFinder._link_package_versionsc             C   s   t j|| jd�S )N)rb   )ÚHTMLPageÚget_pagerb   )r2   rm   r3   r3   r4   rß   ª  s    zPackageFinder._get_page)	FNFNNNNNN)F)rH   rI   rJ   Ú__doc__r5   rt   Ústaticmethodr†   r�   r¦   r®   rÉ   rÝ   r¶   ÚreÚcompilerò   rä   rµ   ré   rå   rß   r3   r3   r3   r4   r$   e   s(      
Q1GSc
Mz([a-z0-9_.]+)-([a-z0-9_.!+-]+)c             C   s�   |j | ƒ}|stjd|ƒ dS |dkrB|jdƒ}||jdƒd… S |jdƒjƒ }|jddƒ}|jƒ d }|j|ƒrˆ|jdƒt|ƒd… S dS dS )ax  Pull the version part out of a string.

    :param egg_info: The string to parse. E.g. foo-2.1
    :param search_name: The name of the package this belongs to. None to
        infer the name. Note that this cannot unambiguously parse strings
        like foo-2-2 which might be foo, 2-2 or foo-2, 2.
    :param link: The link the string came from, for logging on failure.
    z%Could not parse version from link: %sNr   ú-Ú_)	rÃ   ri   r²   rô   Úindexr    ÚreplacerU   r‡   )rø   Úsearch_namerm   Ú_egg_info_rerù   Ú
full_matchrÏ   Úlook_forr3   r3   r4   rñ   ®  s    


rñ   c               @   sx   e Zd ZdZddd„Zdd„ Zeddd	„ƒZedd
d„ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZejdejƒZdd„ ZdS )rü   z'Represents one page, along with its URLNc             C   s\   d }|r2d|kr2t j|d ƒ\}}d|kr2|d }|| _tj| j|dd�| _|| _|| _d S )NzContent-TypeÚcharsetF)Útransport_encodingÚnamespaceHTMLElements)ÚcgiÚparse_headerÚcontentr   r   ro   rx   Úheaders)r2   r  rx   r  ÚencodingÚcontent_typeÚparamsr3   r3   r4   r5   Î  s    
zHTMLPage.__init__c             C   s   | j S )N)rx   )r2   r3   r3   r4   Ú__str__à  s    zHTMLPage.__str__Tc             C   sj  |d krt dƒ‚|j}|jddƒd }ddlm} x>|jD ]4}|jƒ j|ƒr:|t|ƒ dkr:t	j
d||ƒ d S q:W �y"|rÊ|j}xHtD ]@}|j|ƒr†| j||d�}	|	jƒ jd	ƒr´P q†t	j
d
||	ƒ d S q†W t	j
d|ƒ tj|ƒ\}}
}}}}|dk�r6tjjtj|ƒƒ�r6|jdƒ�s|d7 }tj|dƒ}t	j
d|ƒ |j|d	ddœd�}|jƒ  |jjddƒ}	|	jƒ jd	ƒ�s‚t	j
d
||	ƒ d S | |j|j|jƒ}W nÊ tk
�rÈ } z| j|||ƒ W Y d d }~X nž tk
�r } z"d| }| j|||t	jd� W Y d d }~X n` tj k
�r< } z| j|d| |ƒ W Y d d }~X n* tj!k
�r`   | j|d|ƒ Y nX |S d S )Nz9get_page() missing 1 required keyword argument: 'session'ú#r’   r   )Ú
VcsSupportz+:zCannot look at %s URL %s)rb   z	text/htmlz,Skipping page %s because of Content-Type: %szGetting page %sr*   r§   z
index.htmlz# file: URL is directory, getting %szmax-age=600)ÚAcceptzCache-Control)r  zContent-TypeÚunknownz6There was a problem confirming the ssl certificate: %s)Úmethzconnection error: %sz	timed out)"rS   rx   ÚsplitÚpip.vcsr  Úschemesr    rU   r‡   ri   r²   r‰   r
   rª   Ú_get_content_typerf   rg   rV   rW   r|   Úurllib_requestÚurl2pathnameÚurljoinÚgetÚraise_for_statusr  r  r   Ú_handle_failr    Úinfor   ÚConnectionErrorÚTimeout)Úclsrm   Úskip_archivesrb   rx   r  rh   r‰   Úbad_extr  ÚnetlocrW   r  ÚqueryÚfragmentÚrespÚinstÚexcrè   r3   r3   r4   rý   ã  sp    



$"zHTMLPage.get_pagec             C   s   |d krt j}|d| |ƒ d S )Nz%Could not fetch URL %s: %s - skipping)ri   r²   )rm   rè   rx   r  r3   r3   r4   r#  9  s    zHTMLPage._handle_failc             C   sD   t j| ƒ\}}}}}|dkr dS |j| dd�}|jƒ  |jjddƒS )z;Get the Content-Type of the given url, using a HEAD requestÚhttpr%   Ú T)Úallow_redirectszContent-Type)r0  r%   )rf   ÚurlsplitÚheadr"  r  r!  )rx   rb   rh   r*  rW   r+  r,  r-  r3   r3   r4   r  @  s    zHTMLPage._get_content_typec             C   s@   dd„ | j jdƒD ƒ}|r6|d jdƒr6|d jdƒS | jS d S )Nc             S   s   g | ]}|j d ƒdk	r|‘qS )ÚhrefN)r!  )rL   Úxr3   r3   r4   rN   Q  s    z%HTMLPage.base_url.<locals>.<listcomp>z.//baser   r5  )ro   Úfindallr!  rx   )r2   Úbasesr3   r3   r4   Úbase_urlN  s    zHTMLPage.base_urlc             c   sl   xf| j jdƒD ]V}|jdƒr|jdƒ}| jtj| j|ƒƒ}|jdƒ}|rPt|ƒnd}t|| |d�V  qW dS )zYields all links in the pagez.//ar5  zdata-requires-pythonN)rö   )	ro   r7  r!  Ú
clean_linkrf   r   r9  r!   r¯   )r2   Úanchorr5  rx   Ú	pyrequirer3   r3   r4   rs   Y  s    


zHTMLPage.linksz[^a-z0-9$&+,/:;=?@.#%_\\|-]c             C   s   | j jdd„ |ƒS )z¨Makes sure a link is fully encoded.  That is, if a ' ' shows up in
        the link, it will be rewritten to %20 (while not over-quoting
        % or other characters).c             S   s   dt | jdƒƒ S )Nz%%%2xr   )Úordrô   )rù   r3   r3   r4   r<   m  s    z%HTMLPage.clean_link.<locals>.<lambda>)Ú	_clean_reÚsub)r2   rx   r3   r3   r4   r:  h  s    zHTMLPage.clean_link)N)TN)N)rH   rI   rJ   rþ   r5   r  Úclassmethodrý   rÿ   r#  r  r   r9  Úpropertyrs   r   r  ÚIr>  r:  r3   r3   r3   r4   rü   Ë  s   
Urü   c               @   s   e Zd Zd5dd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zed d!„ ƒZed"d#„ ƒZejd$ƒZed%d&„ ƒZejd'ƒZed(d)„ ƒZejd*ƒZed+d,„ ƒZed-d.„ ƒZed/d0„ ƒZed1d2„ ƒZed3d4„ ƒZ dS )6r¯   Nc             C   s0   |j dƒrt|ƒ}|| _|| _|r&|nd| _dS )aó  
        Object representing a parsed link from https://pypi.python.org/simple/*

        url:
            url of the resource pointed to (href of the link)
        comes_from:
            instance of HTMLPage where the link was found, or string.
        requires_python:
            String containing the `Requires-Python` metadata field, specified
            in PEP 345. This may be specified by a data-requires-python
            attribute in the HTML link tag, as described in PEP 503.
        z\\N)rU   r   rx   Ú
comes_fromrö   )r2   rx   rC  rö   r3   r3   r4   r5   r  s
    
zLink.__init__c             C   s<   | j rd| j  }nd}| jr.d| j| j|f S t| jƒS d S )Nz (requires-python:%s)r1  z%s (from %s)%s)rö   rC  rx   r–   )r2   Úrpr3   r3   r4   r  ˆ  s    zLink.__str__c             C   s   d|  S )Nz	<Link %s>r3   )r2   r3   r3   r4   r7   ’  s    zLink.__repr__c             C   s   t |tƒstS | j|jkS )N)rE   r¯   rF   rx   )r2   r>   r3   r3   r4   rA   •  s    
zLink.__eq__c             C   s   t |tƒstS | j|jkS )N)rE   r¯   rF   rx   )r2   r>   r3   r3   r4   rD   š  s    
zLink.__ne__c             C   s   t |tƒstS | j|jk S )N)rE   r¯   rF   rx   )r2   r>   r3   r3   r4   r?   Ÿ  s    
zLink.__lt__c             C   s   t |tƒstS | j|jkS )N)rE   r¯   rF   rx   )r2   r>   r3   r3   r4   r@   ¤  s    
zLink.__le__c             C   s   t |tƒstS | j|jkS )N)rE   r¯   rF   rx   )r2   r>   r3   r3   r4   rC   ©  s    
zLink.__gt__c             C   s   t |tƒstS | j|jkS )N)rE   r¯   rF   rx   )r2   r>   r3   r3   r4   rB   ®  s    
zLink.__ge__c             C   s
   t | jƒS )N)r8   rx   )r2   r3   r3   r4   r9   ³  s    zLink.__hash__c             C   sJ   t j| jƒ\}}}}}tj|jdƒƒp(|}t j|ƒ}|sFtd| j ƒ‚|S )Nr§   zURL %r produced no filename)rf   r3  rx   r¨   ÚbasenameÚrstripÚunquoteÚAssertionError)r2   r  r*  rW   rÏ   r3   r3   r4   r‰   ¶  s
    
zLink.filenamec             C   s   t j| jƒd S )Nr   )rf   r3  rx   )r2   r3   r3   r4   rh   ¾  s    zLink.schemec             C   s   t j| jƒd S )Nr’   )rf   r3  rx   )r2   r3   r3   r4   r*  Â  s    zLink.netlocc             C   s   t jt j| jƒd ƒS )Nr”   )rf   rG  r3  rx   )r2   r3   r3   r4   rW   Æ  s    z	Link.pathc             C   s   t tj| jjdƒƒƒS )Nr§   )r   r¨   rE  rW   rF  )r2   r3   r3   r4   r   Ê  s    zLink.splitextc             C   s   | j ƒ d S )Nr’   )r   )r2   r3   r3   r4   rî   Í  s    zLink.extc             C   s*   t j| jƒ\}}}}}t j||||d fƒS )N)rf   r3  rx   Ú
urlunsplit)r2   rh   r*  rW   r+  r,  r3   r3   r4   Úurl_without_fragmentÑ  s    zLink.url_without_fragmentz[#&]egg=([^&]*)c             C   s    | j j| jƒ}|sd S |jdƒS )Nr’   )Ú_egg_fragment_rerÃ   rx   rô   )r2   rù   r3   r3   r4   rá   Ø  s    zLink.egg_fragmentz[#&]subdirectory=([^&]*)c             C   s    | j j| jƒ}|sd S |jdƒS )Nr’   )Ú_subdirectory_fragment_rerÃ   rx   rô   )r2   rù   r3   r3   r4   Úsubdirectory_fragmentá  s    zLink.subdirectory_fragmentz2(sha1|sha224|sha384|sha256|sha512|md5)=([a-f0-9]+)c             C   s    | j j| jƒ}|r|jdƒS d S )Nr”   )Ú_hash_rerÃ   rx   rô   )r2   rù   r3   r3   r4   r8   ì  s    
z	Link.hashc             C   s    | j j| jƒ}|r|jdƒS d S )Nr’   )rN  rÃ   rx   rô   )r2   rù   r3   r3   r4   Ú	hash_nameó  s    
zLink.hash_namec             C   s$   t j| jjddƒd jddƒd ƒS )Nr  r’   r   ú?)r¨   rE  rx   r  )r2   r3   r3   r4   Úshow_urlú  s    zLink.show_urlc             C   s
   | j tkS )N)rî   r   )r2   r3   r3   r4   rˆ   þ  s    zLink.is_wheelc             C   s    ddl m} | j|jkrdS dS )z 
        Determines if this points to an actual artifact (e.g. a tarball) or if
        it points to an "abstract" thing like a path or a VCS location.
        r   )ÚvcsFT)r  rR  rh   Úall_schemes)r2   rR  r3   r3   r4   Úis_artifact  s    zLink.is_artifact)NN)!rH   rI   rJ   r5   r  r7   rA   rD   r?   r@   rC   rB   r9   rA  r‰   rh   r*  rW   r   rî   rJ  r   r  rK  rá   rL  rM  rN  r8   rO  rQ  rˆ   rT  r3   r3   r3   r4   r¯   p  s8   



r¯   zno_binary only_binaryc             C   s’   | j dƒ}xFd|krP|jƒ  |jƒ  |jdƒ |d |jdƒd …= d|krd S qW x:|D ]2}|dkrn|jƒ  qXt|ƒ}|j|ƒ |j|ƒ qXW d S )Nú,z:all:r’   z:none:)r  ÚclearrÞ   r  r   Údiscard)ÚvalueÚtargetr>   ÚnewrÏ   r3   r3   r4   r#     s    




c             C   sj   t ddgƒ}|| jkr"|jdƒ n@|| jkr8|jdƒ n*d| jkrN|jdƒ nd| jkrb|jdƒ t|ƒS )Nrê   rì   z:all:)r\   Úonly_binaryrW  Ú	no_binaryÚ	frozenset)Úfmt_ctlrÁ   ræ   r3   r3   r4   r³   -  s    




r³   c             C   s   t d| j| jƒ d S )Nz:all:)r#   r\  r[  )r^  r3   r3   r4   Úfmt_ctl_no_binary:  s    r_  c             C   s   t | ƒ tjdtdd� d S )Nzf--no-use-wheel is deprecated and will be removed in the future.  Please use --no-binary :all: instead.r”   )Ú
stacklevel)r_  rp   rq   r   )r^  r3   r3   r4   Úfmt_ctl_no_use_wheel?  s
    ra  r´   zsupplied canonical formats)r%   r&   r&   )r&   r'   r&   )r&   r(   r&   )r&   r)   r&   )r*   r&   N)r+   r&   r&   )Rrþ   Ú
__future__r   Úloggingr  Úcollectionsr   rd   rõ   rV   r   rv   r¨   rp   Zpip._vendor.six.moves.urllibr   rf   r   r  Ú
pip.compatr   Ú	pip.utilsr   r   r	   r
   r   Zpip.utils.deprecationr   Úpip.utils.loggingr   Úpip.utils.packagingr   Úpip.exceptionsr   r   r   r   Úpip.downloadr   r   r   r   Ú	pip.wheelr   r   Zpip.pep425tagsr   Úpip._vendorr   r   r   Zpip._vendor.packaging.versionr.   Úpip._vendor.packaging.utilsr   Zpip._vendor.packagingr   Zpip._vendor.requests.exceptionsr   r    Zpip._vendor.distlib.compatr!   Ú__all__rš   Ú	getLoggerrH   ri   Úobjectr,   r$   r  rB  rñ   rü   r¯   r"   r#   r³   r_  ra  r´   r3   r3   r3   r4   Ú<module>   sl   

)    O & !


