
b]c           @@  s  d  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	 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 d d	 l m Z m Z m Z d d l m Z d d
 l m Z d d l m Z m  Z  d d l! 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- d d l. m/ Z/ d d l0 m1 Z1 d d l2 m3 Z3 d d l4 m5 Z5 m6 Z6 m7 Z7 m8 Z8 m9 Z9 d d l: m; Z; d d l< m= Z= d d l> m? Z? e= r9d d l m@ Z@ d d lA mB ZB mC ZC mD ZD mE ZE mF ZF mG ZG mH ZH mI ZI mJ ZJ mK ZK mL ZL mM ZM mN ZN d d lO ZP d d l mQ ZQ d d lR mS ZS d d lT mU ZU d d lV mW ZW d d l mX ZX d d lY mZ ZZ d d  l[ m\ Z\ eM eB d! f Z] eM e^ e^ e^ eQ e] eI e^ f Z_ eP j` ja jb Zc eM ed ed eI ed f Ze n  d" d# d$ g Zf d% d& d& f d& d' d& f d& d( d& f d& d) d& f d* d& eg f d+ d& d& f g Zh e ji ej  Zk d,   Zl d-   Zm d. en f d/     YZo d0   Zp d1 en f d2     YZq d3   Zr d4   Zs eg d5  Zt eg d6  Zu ev d7  Zw d8 ex f d9     YZy d:   Zz d; ex f d<     YZ{ d= ex f d>     YZ| d# ex f d?     YZ} d$ ex f d@     YZ~ dA   Z dB   Z dC   Z dD   Z dE   Z dF   Z dG ex f dH     YZ d S(I   s!   Routines related to PyPI, indexesi    (   t   absolute_importN(   t   html5libt   requestst   six(   t   unescape(   t
   specifiers(   t   canonicalize_name(   t   parse(   t	   HTTPErrort
   RetryErrort   SSLError(   t   request(   t   is_urlt   url_to_path(   t   BestVersionAlreadyInstalledt   DistributionNotFoundt   InvalidWheelFilenamet   UnsupportedWheel(   t   InstallationCandidate(   t   FormatControl(   t   Link(   t   SelectionPreferences(   t   TargetPython(   t	   ipaddress(   t
   indent_log(   t   ARCHIVE_EXTENSIONSt   SUPPORTED_EXTENSIONSt   WHEEL_EXTENSIONt   path_to_urlt   redact_password_from_url(   t   check_requires_python(   t   MYPY_CHECK_RUNNING(   t   Wheel(   t   Logger(   t   Anyt   Callablet	   FrozenSett   Iterablet   Iteratort   Listt   MutableMappingt   Optionalt   Sequencet   Sett   Textt   Tuplet   Union(   t   _BaseVersion(   t   Response(   t   SearchScope(   t   InstallRequirement(   t
   PipSession(   t	   Pep425Tag(   t   Hashes.R   t   FoundCandidatest   PackageFindert   httpst   *t	   localhosts   127.0.0.0/8s   ::1/128t   filet   sshc         C@  sW   d d l  m } x@ | j D]5 } |  j   j |  r |  t |  d k r | Sq Wd S(   sg   Look for VCS schemes in the URL.

    Returns the matched VCS scheme, or None if there's no match.
    i    (   t   vcss   +:N(   t   pip._internal.vcsR=   t   schemest   lowert
   startswitht   lent   None(   t   urlR=   t   scheme(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _match_vcs_schemeR   s
    +c         C@  s7   t  |   j } x! t D] } | j |  r t Sq Wt S(   s2   Return whether the URL looks like an archive.
    (   R   t   filenameR   t   endswitht   Truet   False(   RD   RG   t   bad_ext(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _is_url_like_archive_   s
    t   _NotHTMLc           B@  s   e  Z d    Z RS(   c         C@  s/   t  t |   j | |  | |  _ | |  _ d  S(   N(   t   superRM   t   __init__t   content_typet   request_desc(   t   selfRP   RQ   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyRO   k   s    	(   t   __name__t
   __module__RO   (    (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyRM   j   s   c         C@  sF   |  j  j d d  } | j   j d  sB t | |  j j   n  d S(   s   Check the Content-Type header to ensure the response contains HTML.

    Raises `_NotHTML` if the content type is not text/html.
    s   Content-Typet    s	   text/htmlN(   t   headerst   getR@   RA   RM   R   t   method(   t   responseRP   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _ensure_html_headerr   s    t   _NotHTTPc           B@  s   e  Z RS(    (   RS   RT   (    (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR[   }   s   c         C@  si   t  j |   \ } } } } } | d d h k r< t    n  | j |  d t } | j   t |  d S(   s   Send a HEAD request to the URL, and ensure the response contains HTML.

    Raises `_NotHTTP` if the URL is not available for a HEAD request, or
    `_NotHTML` if the content type is not text/html.
    t   httpR8   t   allow_redirectsN(   t   urllib_parset   urlsplitR[   t   headRI   t   raise_for_statusRZ   (   RD   t   sessionRE   t   netloct   patht   queryt   fragmentt   resp(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _ensure_html_response   s    
c         C@  sp   t  |   r t |  d | n  t j d t |    | j |  d i d d 6d d 6} | j   t |  | S(   s  Access an HTML page with GET, and return the response.

    This consists of three parts:

    1. If the URL looks suspiciously like an archive, send a HEAD first to
       check the Content-Type is HTML, to avoid downloading a large file.
       Raise `_NotHTTP` if the content type cannot be determined, or
       `_NotHTML` if it is not HTML.
    2. Actually perform the request. Raise HTTP exceptions on network failures.
    3. Check the Content-Type header to make sure we got HTML, and raise
       `_NotHTML` otherwise.
    Rb   s   Getting page %sRV   s	   text/htmlt   Accepts	   max-age=0s   Cache-Control(   RL   Rh   t   loggert   debugR   RW   Ra   RZ   (   RD   Rb   Rg   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _get_html_response   s    

c         C@  s,   | d  k r t j } n  | d |  |  d  S(   Ns%   Could not fetch URL %s: %s - skipping(   RC   Rj   Rk   (   t   linkt   reasont   meth(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _handle_get_page_fail   s    c   
      C@  s-  | d  k r t d   n  |  j j d d  d } t |  } | r] t j d | |   d  St j |  \ } } } } } } | d k r t	 j
 j t j |   r | j d  s | d 7} n  t j | d  } t j d	 |  n  y t | d
 | } Wnt k
 rt j d |   n
t k
 rM} t j d |  | j | j  n t k
 rl} t |  |  n t k
 r} t |  |  n t k
 r} d }	 |	 t |  7}	 t |  |	 d t j n` t j k
 r} t |  d |  n: t j k
 rt |  d  n Xt | j | j | j   Sd  S(   Ns?   _get_html_page() missing 1 required keyword argument: 'session't   #i   i    s   Cannot look at %s URL %sR;   t   /s
   index.htmls#    file: URL is directory, getting %sRb   sQ   Skipping page %s because it looks like an archive, and cannot be checked by HEAD.s<   Skipping page %s because the %s request got Content-Type: %ss4   There was a problem confirming the ssl certificate: Ro   s   connection error: %ss	   timed out(!   RC   t	   TypeErrorRD   t   splitRF   Rj   Rk   R^   t   urlparset   osRd   t   isdirt   urllib_requestt   url2pathnameRH   t   urljoinRl   R[   RM   RQ   RP   R   Rp   R	   R
   t   strt   infoR   t   ConnectionErrort   Timeoutt   HTMLPaget   contentRV   (
   Rm   Rb   RD   t
   vcs_schemeRE   t   _Rd   Rg   t   excRn   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _get_html_page   sL    !'
c         C@  s   y t  |  j d | } Wn* t j k
 rE t j d |  j |   n^ X| s d j t t |   } | s t j d | |  j |   t	 St j d | |  j |   n  t
 S(   sa  
    Return whether the given Python version is compatible with a link's
    "Requires-Python" value.

    :param version_info: A 3-tuple of ints representing the Python
        major-minor-micro version to check.
    :param ignore_requires_python: Whether to ignore the "Requires-Python"
        value if the given Python version isn't compatible.
    t   version_infos2   Ignoring invalid Requires-Python (%r) for link: %st   .s4   Link requires a different Python (%s not in: %r): %ssB   Ignoring failed Requires-Python check (%s not in: %r) for link: %s(   R   t   requires_pythonR   t   InvalidSpecifierRj   Rk   t   joint   mapR{   RJ   RI   (   Rm   R   t   ignore_requires_pythont   is_compatiblet   version(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _check_link_requires_python  s$    t   LinkEvaluatorc           B@  s2   e  Z d  Z e j d  Z d d  Z d   Z RS(   sD   
    Responsible for evaluating links for a particular project.
    s   -py([123]\.?[0-9]?)$c         C@  sO   | d k r t } n  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d S(   s  
        :param project_name: The user supplied package name.
        :param canonical_name: The canonical package name.
        :param formats: The formats allowed for this package. Should be a set
            with 'binary' or 'source' or both in it.
        :param target_python: The target Python interpreter to use when
            evaluating link compatibility. This is used, for example, to
            check wheel compatibility, as well as when checking the Python
            version, e.g. the Python version embedded in a link filename
            (or egg fragment) and against an HTML link's optional PEP 503
            "data-requires-python" attribute.
        :param allow_yanked: Whether files marked as yanked (in the sense
            of PEP 592) are permitted to be candidates for install.
        :param ignore_requires_python: Whether to ignore incompatible
            PEP 503 "data-requires-python" values in HTML links. Defaults
            to False.
        N(   RC   RJ   t   _allow_yankedt   _canonical_namet   _ignore_requires_pythont   _formatst   _target_pythont   project_name(   RR   R   t   canonical_namet   formatst   target_pythont   allow_yankedR   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyRO   =  s    						c         C@  s  d } | j r; |  j r; | j p% d } t d j |  f S| j rY | j } | j } nT| j   \ } } | s{ t d f S| t	 k r t d | f Sd |  j
 k r | t k r d |  j } t | f Sd | j k r | d k r t d	 f S| t k ry t | j  } Wn t k
 r%t d
 f SXt | j  |  j k rUd |  j } t | f S|  j j   } | j |  s| j   } d j d j |   } t | f S| j } n  d |  j
 k r| t k rt d |  j f S| st | |  j  } n  | st d |  j f S|  j j |  }	 |	 ra| |	 j    } |	 j d  }
 |
 |  j j k rat d f Sn  t  | d |  j j! d |  j" } | st d f St# j$ d | |  t% | f S(   sG  
        Determine whether a link is a candidate for installation.

        :return: A tuple (is_candidate, result), where `result` is (1) a
            version string if `is_candidate` is True, and (2) if
            `is_candidate` is False, an optional string to log the reason
            the link fails to qualify.
        s   <none given>u   yanked for reason: {}s
   not a files   unsupported archive format: %st   binarys   No binaries permitted for %st   macosx10s   .zips   macosx10 ones   invalid wheel filenames   wrong project name (not %s)s"   none of the wheel's tags match: {}s   , t   sources   No sources permitted for %ss   Missing project version for %si   s   Python version is incorrectR   R   s   Found link %s, version: %sN(&   RC   t	   is_yankedR   t   yanked_reasonRJ   t   formatt   egg_fragmentt   extt   splitextR   R   R   R   Rd   R    RG   R   R   t   nameR   R   t   get_tagst	   supportedt   get_formatted_file_tagsR   R   t   _extract_version_from_fragmentt   _py_version_ret   searcht   startt   groupt
   py_versionR   t   py_version_infoR   Rj   Rk   RI   (   RR   Rm   R   Rn   t   egg_infoR   t   wheelt   supported_tagst	   file_tagst   matchR   t   supports_python(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   evaluate_linkc  sh    
		





N(	   RS   RT   t   __doc__t   ret   compileR   RC   RO   R   (    (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR   1  s   c   
      C@  s:  | s) t  j d t |   |  t |   Sg  } g  } d } x_ |  D]W } | j } | j s] n/ | j d |  r| | d 7} n | j |  qB | j |  qB W| r | } n t |   } t |  t |   k r d }	 n+ d j t |  d j	 d   | D   }	 t  j d	 t |   | | j
 | t |  | |	  | S(
   s  
    Filter out candidates whose hashes aren't allowed, and return a new
    list of candidates.

    If at least one candidate has an allowed hash, then all candidates with
    either an allowed hash or no hash specified are returned.  Otherwise,
    the given candidates are returned.

    Including the candidates with no hash specified when there is a match
    allows a warning to be logged if there is a more preferred candidate
    with no hash specified.  Returning all candidates in the case of no
    matches lets pip report the hash of the candidate that would otherwise
    have been installed (e.g. permitting the user to more easily update
    their requirements file with the desired hash).
    sJ   Given no hashes to check %s links for project %r: discarding no candidatesi    t   hashesi   s   discarding no candidatess   discarding {} non-matches:
  {}s   
  c         s@  s   |  ] } t  | j  Vq d  S(   N(   R{   Rm   (   t   .0t	   candidate(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pys	   <genexpr>  s    sP   Checked %s links for project %r against %s hashes (%s matches, %s no digest): %s(   Rj   Rk   RB   t   listRm   t   has_hasht   is_hash_allowedt   appendR   R   t   digest_count(
   t
   candidatesR   R   t   matches_or_no_digestt   non_matchest   match_countR   Rm   t   filteredt   discard_message(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   filter_unallowed_hashes  sF    	
						t   CandidatePreferencesc           B@  s   e  Z d  Z e e d  Z RS(   sk   
    Encapsulates some of the preferences for filtering and sorting
    InstallationCandidate objects.
    c         C@  s   | |  _  | |  _ d S(   sR   
        :param allow_all_prereleases: Whether to allow all pre-releases.
        N(   t   allow_all_prereleasest   prefer_binary(   RR   R   R   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyRO     s    		(   RS   RT   R   RJ   RO   (    (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR     s   t   CandidateEvaluatorc           B@  sb   e  Z d  Z e d e e d d d   Z e e d d  Z d   Z d   Z	 d   Z
 d   Z RS(   sm   
    Responsible for filtering and sorting candidates for installation based
    on what tags are valid.
    c         C@  sj   | d k r t   } n  | d k r3 t j   } n  | j   } |  d | d | d | d | d | d |  S(   s@  Create a CandidateEvaluator object.

        :param target_python: The target Python interpreter to use when
            checking compatibility. If None (the default), a TargetPython
            object will be constructed from the running Python.
        :param hashes: An optional collection of allowed hashes.
        R   R   t	   specifierR   R   R   N(   RC   R   R   t   SpecifierSetR   (   t   clsR   R   R   R   R   R   R   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   create"  s    c         C@  s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d S(   s   
        :param supported_tags: The PEP 425 tags supported by the target
            Python in order of preference (most preferred first).
        N(   t   _allow_all_prereleasest   _hashest   _prefer_binaryt   _project_namet
   _specifiert   _supported_tags(   RR   R   R   R   R   R   R   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyRO   D  s    					c         C@  s   |  j  p d } |  j } d   | j d   | D d | D } g  | D]! } t | j  | k rH | ^ qH } t d | d |  j d |  j  S(   sM   
        Return the applicable candidates from a list of candidates.
        c         S@  s   h  |  ] } t  |   q S(    (   R{   (   R   t   v(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pys	   <setcomp>e  s   	 c         s@  s   |  ] } t  | j  Vq d  S(   N(   R{   R   (   R   t   c(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pys	   <genexpr>m  s    t   prereleasesR   R   R   N(	   R   RC   R   t   filterR{   R   R   R   R   (   RR   R   t   allow_prereleasesR   t   versionsR   t   applicable_candidates(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   get_applicable_candidatesY  s    		.	c         C@  s%   |  j  |  } t | d | d |  S(   s   
        Create and return a `FoundCandidates` instance.

        :param specifier: An optional object implementing `filter`
            (e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
            versions.
        R   t	   evaluator(   R   R6   (   RR   R   R   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   make_found_candidates}  s
    c         C@  s'  |  j  } t |  } t   } d } | j } | j r t | j  } | j |  sj t d | j   n  |  j	 r| d } n  | j
 |  } | j d k	 r t j d | j  }	 |	 j   }
 t |
 d  |
 d f } q n | } t | j |  j   } d t | j  } | | | | j | | f S(   s)  
        Function to pass as the `key` argument to a call to sorted() to sort
        InstallationCandidates by preference.

        Returns a tuple such that tuples sorting as greater using Python's
        default comparison operator are more preferred.

        The preference is as follows:

        First and foremost, candidates with allowed (matching) hashes are
        always preferred over candidates without matching hashes. This is
        because e.g. if the only candidate with an allowed hash is yanked,
        we still want to use that candidate.

        Second, excepting hash considerations, candidates that have been
        yanked (in the sense of PEP 592) are always less preferred than
        candidates that haven't been yanked. Then:

        If not finding wheels, they are 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._supported_tags)
          3. source archives
        If prefer_binary was set, then all wheels are sorted above sources.

        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
        i    sB   %s is not a supported wheel for this platform. It can't be sorted.i   s   ^(\d+)(.*)$iN(   R   RB   t   tupleRm   t   is_wheelR    RG   R   R   R   t   support_index_mint	   build_tagRC   R   R   t   groupst   intR   R   R   R   (   RR   R   t
   valid_tagst   support_numR   t   binary_preferenceRm   R   t   priR   t   build_tag_groupst   has_allowed_hasht
   yank_value(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt	   _sort_key  s.    						 c         C@  sl   | s
 d St | d |  j } | j } | j rh | j p= d } d j d | d |  } t j |  n  | S(   sy   
        Return the best candidate per the instance's sort order, or None if
        no candidate is acceptable.
        t   keys   <none given>uq   The candidate selected for download or install is a yanked version: {candidate}
Reason for being yanked: {reason}R   Rn   N(	   RC   t   maxR   Rm   R   R   R   Rj   t   warning(   RR   R   t   best_candidateRm   Rn   t   msg(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   get_best_candidate  s    				N(   RS   RT   R   t   classmethodRC   RJ   R   RO   R   R   R   R   (    (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR     s   	$		<c           B@  s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s   A collection of candidates, returned by `PackageFinder.find_candidates`.

    This class is only intended to be instantiated by CandidateEvaluator's
    `make_found_candidates()` method.
    c         C@  s   | |  _  | |  _ | |  _ d S(   s  
        :param candidates: A sequence of all available candidates found.
        :param applicable_candidates: The applicable candidates.
        :param evaluator: A CandidateEvaluator object to sort applicable
            candidates by order of preference.
        N(   t   _applicable_candidatest   _candidatest
   _evaluator(   RR   R   R   R   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyRO     s    		c         C@  s   t  |  j  S(   s(   Iterate through all candidates.
        (   t   iterR   (   RR   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   iter_all  s    c         C@  s   t  |  j  S(   s3   Iterate through the applicable candidates.
        (   R   R   (   RR   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   iter_applicable
  s    c         C@  s"   t  |  j    } |  j j |  S(   sd   Return the best candidate available, or None if no applicable
        candidates are found.
        (   R   R   R   R   (   RR   R   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   get_best  s    (   RS   RT   R   RO   R   R   R   (    (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR6     s
   			c           B@  s  e  Z d  Z d d d d d  Z e d d d d   Z e d    Z e d    Z	 e d    Z
 d   Z d d  Z d   Z e e d	   Z d
   Z d   Z d   Z d d d  Z d d d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s   This finds packages.

    This is meant to match easy_install's technique for looking for
    packages, by reading pages and looking for appropriate links.
    c	   	      C@  s   | d k r g  } n  | d k r- t   } n  | pE t t   t    } | |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 | |  _ t   |  _ d S(   s  
        This constructor is primarily meant to be used by the create() class
        method and from tests.

        :param session: The Session to use to make requests.
        :param format_control: A FormatControl object, used to control
            the selection of source packages / binary packages when consulting
            the index and links.
        :param candidate_prefs: Options to use when creating a
            CandidateEvaluator object.
        N(   RC   R   R   t   setR   t   _candidate_prefsR   R   t   search_scopeRb   t   format_controlt   trusted_hostst   _logged_links(	   RR   R   Rb   R   R   R   R   t   candidate_prefsR   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyRO      s    									c         C@  s   | d k r t d   n  | d k r3 t   } n  t d | j d | j  } |  d | d | d | d | d | j d	 | j d
 | d | j  S(   s  Create a PackageFinder.

        :param selection_prefs: The candidate selection preferences, as a
            SelectionPreferences object.
        :param trusted_hosts: Domains not to emit warnings for when not using
            HTTPS.
        :param session: The Session to use to make requests.
        :param target_python: The target Python interpreter to use when
            checking compatibility. If None (the default), a TargetPython
            object will be constructed from the running Python.
        sE   PackageFinder.create() missing 1 required keyword argument: 'session'R   R   R  R   Rb   R   R   R   R   R   N(	   RC   Rs   R   R   R   R   R   R   R   (   R   R   t   selection_prefsR   Rb   R   R  (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR   O  s"    			c         C@  s
   |  j  j S(   N(   R   t
   find_links(   RR   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR  |  s    c         C@  s
   |  j  j S(   N(   R   t
   index_urls(   RR   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR    s    c         C@  s
   |  j  j S(   N(   R   R   (   RR   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR     s    c         C@  s   t  |  j _ d  S(   N(   RI   R   R   (   RR   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   set_allow_all_prereleases  s    c         C@  su   d j  |  } | d k	 r1 | d j  |  7} n  t j |  |  j j |  | |  j k ra d S|  j j |  d S(   st   
        :param source: An optional source string, for logging where the host
            string came from.
        s   adding trusted host: {!r}s
    (from {})N(   R   RC   Rj   R|   Rb   t   add_insecure_hostR   R   (   RR   t   hostR   R   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   add_trusted_host  s    c         c@  s<   x t  D] } | Vq Wx |  j D] } d | d f Vq  Wd  S(   NR9   (   t   SECURE_ORIGINSR   (   RR   t   secure_originR  (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   iter_secure_origins  s    	c         @  sn  g    g      f d   } xC|  D];} t  j j |  } | j d  } | sX | r4| rg | } n t |  } t  j j |  r| r t  j j |  } x_ t  j |  D] } | t  j j | |   q Wq1| r  j	 |  q1t
 j d j |   q`t  j j |  r!| |  q`t
 j d |  q% t |  rP j	 |  q% t
 j d |  q% W   f S(   st   
        Sort locations into "files" (archives) and "urls", and return
        a pair of lists (files,urls)
        c         @  sL   t  |   } t j | d t d d k r;  j |  n   j |  d  S(   Nt   stricti    s	   text/html(   R   t	   mimetypest
   guess_typeRJ   R   (   Rd   RD   (   t   filest   urls(    s2   lib/python2.7/site-packages/pip/_internal/index.pyt	   sort_path  s    s   file:s)   Path '{0}' is ignored: it is a directory.s:   Url '%s' is ignored: it is neither a file nor a directory.sQ   Url '%s' is ignored. It is either a non-existing path or lacks a specific scheme.(   Rv   Rd   t   existsRA   R   Rw   t   realpatht   listdirR   R   Rj   R   R   t   isfileR   (   t	   locationst
   expand_dirR  RD   t   is_local_patht   is_file_urlRd   t   item(    (   R  R  s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _sort_locations  s>    	 
c   	      C@  s  t  j t |   } | j | j | j f } | d j d d  d } xg|  j   D]Y} | | d k r | d d k r qT n  y t 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   } WnQ t k
 r_| d rr| d j   | d j   k rr| d d k rrqT qrn X| | k rrqT n  | d | d k r| d d k r| d d  k	 rqT n  t SW| j d | j | j  t S(	   Ni    t   +i   iR9   t   utf8i   s   The repository located at %s is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host %s'.(   R^   Ru   R{   RE   t   hostnamet   portt   rsplitR  R   t
   ip_addresst
   isinstanceR   t	   text_typeRC   t   decodet
   ip_networkt
   ValueErrorR@   RI   R   RJ   (	   RR   Rj   t   locationt   parsedt   origint   protocolR
  t   addrt   network(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _validate_secure_origin  s>      
 

c         C@  sR   t  |  } |  j j |  } t d | d | d | d |  j d |  j d |  j  S(   NR   R   R   R   R   R   (   R   R   t   get_allowed_formatsR   R   R   R   (   RR   R   R   R   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   make_link_evaluator,  s    		c      	   C@  s  |  j  } | j |  } |  j |  \ } } |  j |  j d t \ } } d   t j | |  D } g  t j d   | D d   | D  D] }	 |  j t |	  r |	 ^ q }
 t j	 d t
 |
  |  x |
 D] } t j	 d |  q W|  j |  } |  j | d   |  j D  } g  } x\ |  j |
 |  D]H } t j	 d | j  t   $ | j |  j | | j     Wd	 QXq3W|  j | |  } | r| j d
 t  t j	 d d j g  | D] } t | j j  ^ q  n  | | | S(   s  Find all available InstallationCandidate for project_name

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

        See LinkEvaluator.evaluate_link() for details on which files
        are accepted.
        R  c         s@  s   |  ] } t  |  Vq d  S(   N(   R   (   R   RD   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pys	   <genexpr>K  s    c         s@  s   |  ] } t  |  Vq d  S(   N(   R   (   R   RD   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pys	   <genexpr>T  s    c         s@  s   |  ] } t  |  Vq d  S(   N(   R   (   R   RD   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pys	   <genexpr>U  s    s,   %d location(s) to search for versions of %s:s   * %sc         s@  s   |  ] } t  | d   Vq d S(   s   -fN(   R   (   R   RD   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pys	   <genexpr>d  s    s   Analyzing links from page %sNt   reverses   Local files found: %ss   , (   R   t   get_index_urls_locationsR  R  RI   t	   itertoolst   chainR-  Rj   Rk   RB   R/  t   _package_versionst
   _get_pagesRD   R   t   extendt
   iter_linkst   sortR   R   Rm   (   RR   R   R   t   index_locationst   index_file_loct   index_url_loct   fl_file_loct
   fl_url_loct   file_locationsRm   t   url_locationsR'  t   link_evaluatort   find_links_versionst   page_versionst   paget   file_versionsR   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   find_all_candidates:  sD    
			
#)c         C@  s@   |  j  } t j d | d |  j d | j d | j d | d |  S(   s3   Create a CandidateEvaluator object to use.
        R   R   R   R   R   R   (   R   R   R   R   R   R   (   RR   R   R   R   R  (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   make_candidate_evaluator}  s    						c         C@  s:   |  j  |  } |  j d | d | d |  } | j |  S(   s  Find matches for the given project and specifier.

        :param specifier: An optional object implementing `filter`
            (e.g. `packaging.specifiers.SpecifierSet`) to filter applicable
            versions.

        :return: A `FoundCandidates` instance.
        R   R   R   (   RE  RF  R   (   RR   R   R   R   R   t   candidate_evaluator(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   find_candidates  s    		c   	      C@  s  | j  d t  } |  j | j d | j d | } | j   } d } | j d k	 ri t | j j	  } n  d   } | d k r | d k r t
 j d | | | j     t d |   n  t } | r | d k s | j	 | k r t } n  | r2| d k	 r2| rt
 j d |  n t
 j d | | j	  d S| r`t
 j d	 | | | j     t  n  t
 j d
 | j	 | | j     | j S(   s   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
        t   trust_internetR   R   c         S@  s)   d j  t d   |  D d t  p( d S(   Ns   , c         S@  s   h  |  ] } t  | j   q S(    (   R{   R   (   R   R   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pys	   <setcomp>  s   	 R   t   none(   R   t   sortedt   parse_version(   t	   cand_iter(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _format_versions  s    	sN   Could not find a version that satisfies the requirement %s (from versions: %s)s%   No matching distribution found for %ssL   Existing installed version (%s) is most up-to-date and satisfies requirementsU   Existing installed version (%s) satisfies requirement (most up-to-date version is %s)s=   Installed version (%s) is most up-to-date (past versions: %s)s)   Using version %s (newest of versions: %s)N(   R   RJ   RH  R   R   R   RC   t   satisfied_byRL  R   Rj   t   criticalR   R   RI   Rk   R   R   Rm   (	   RR   t   reqt   upgradeR   R   R   t   installed_versionRN  t   best_installed(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   find_requirement  sR    	
	

	c         c@  si   t    } xY | D]Q } | | k r( q n  | j |  t | d |  j } | d k r\ q n  | Vq Wd S(   sp   
        Yields (page, page_url) from the given locations, skipping
        locations that have errors.
        Rb   N(   R   t   addR   Rb   RC   (   RR   R  R   t   seenR'  RC  (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR5    s    	c         C@  sq   g  g  } } t    } xP | D]H } | | k r | j |  | j rU | j |  qe | j |  q q W| | S(   s   
        Returns elements of links in order, non-egg links first, egg links
        second, while eliminating duplicates
        (   R   RV  R   R   (   RR   t   linkst   eggst   no_eggsRW  Rm   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _sort_links  s    		c         C@  s9   | |  j  k r5 t j d | |  |  j  j |  n  d  S(   Nu   Skipping link: %s: %s(   R   Rj   Rk   RV  (   RR   Rm   Rn   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _log_skipped_link  s    c         C@  s]   | j  |  \ } } | s; | r7 |  j | d | n  d St d | j d | d t |   S(   s   
        If the link is a candidate for install, convert it to an
        InstallationCandidate and return it. Otherwise, return None.
        Rn   t   projectRm   R   N(   R   R\  RC   R   R   R{   (   RR   R@  Rm   t   is_candidatet   result(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   get_install_candidate$  s    	c         C@  sR   g  } xE |  j  |  D]4 } |  j | |  } | d  k	 r | j |  q q W| S(   N(   R[  R`  RC   R   (   RR   R@  RX  R_  Rm   R   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR4  8  s    N(   RS   RT   R   RC   RO   R   R   t   propertyR  R  R   R  R  R  t   staticmethodRJ   R  R-  R/  RE  RF  RH  RU  R5  R[  R\  R`  R4  (    (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR7     s<   &&		9	J		F	O				c         C@  se   xF t  |   D]8 \ } } | d k r+ q n  t |  |   | k r | Sq Wt d j |  |    d S(   s  Find the separator's index based on the package's canonical name.

    :param fragment: A <package>+<version> filename "fragment" (stem) or
        egg fragment.
    :param canonical_name: The package's canonical name.

    This function is needed since the canonicalized name does not necessarily
    have the same length as the egg info's name part. An example::

    >>> fragment = 'foo__bar-1.0'
    >>> canonical_name = 'foo-bar'
    >>> _find_name_version_sep(fragment, canonical_name)
    8
    t   -s   {} does not match {}N(   t	   enumerateR   R&  R   (   Rf   R   t   iR   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _find_name_version_sepB  s    c         C@  sD   y t  |  |  d } Wn t k
 r+ d SX|  | } | s@ d S| S(   s   Parse the version string from a <package>+<version> filename
    "fragment" (stem) or egg fragment.

    :param fragment: The string to parse. E.g. foo-2.1
    :param canonical_name: The canonicalized name of the package this
        belongs to.
    i   N(   Rf  R&  RC   (   Rf   R   t   version_startR   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR   ]  s    	
c         C@  s=   x6 |  j  d  D]% } | j d  } | d k	 r | Sq W| S(   s  Determine the HTML document's base URL.

    This looks for a ``<base>`` tag in the HTML document. If present, its href
    attribute denotes the base URL of anchor tags in the document. If there is
    no such tag (or if it does not have a valid href attribute), the HTML
    file's URL is used as the base URL.

    :param document: An HTML document representation. The current
        implementation expects the result of ``html5lib.parse()``.
    :param page_url: The URL of the HTML document.
    s   .//baset   hrefN(   t   findallRW   RC   (   t   documentt   page_urlt   baseRh  (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _determine_base_urlp  s
    c         C@  sF   |  rB d |  k rB t  j |  d  \ } } d | k rB | d Sn  d S(   sB   Determine if we have any encoding information in our headers.
    s   Content-Typet   charsetN(   t   cgit   parse_headerRC   (   RV   RP   t   params(    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _get_encoding_from_headers  s
    c         C@  sv   t  j |   } | j d k r< t j t j | j   } n! t  j t  j | j  d d } t  j	 | j
 d |   S(   s   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).RU   t   safes   /@Rd   (   R^   Ru   Rc   Rx   t   pathname2urlRy   Rd   t   quotet   unquotet
   urlunparset   _replace(   RD   R_  Rd   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _clean_link  s    	!c         C@  s   |  j  d  } | s d St t j | |   } |  j  d  } | rR t |  n d } |  j  d  } | r| t |  } n  t | d | d | d | } | S(   sJ   
    Convert an anchor element in a simple repository page to a Link.
    Rh  s   data-requires-pythons   data-yankedt
   comes_fromR   R   N(   RW   RC   Ry  R^   Rz   R   R   (   t   anchorRk  t   base_urlRh  RD   t	   pyrequireR   Rm   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   _create_link_from_element  s    		R   c           B@  s,   e  Z d  Z d d  Z d   Z d   Z RS(   s'   Represents one page, along with its URLc         C@  s   | |  _  | |  _ | |  _ d  S(   N(   R   RD   RV   (   RR   R   RD   RV   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyRO     s    		c         C@  s   t  |  j  S(   N(   R   RD   (   RR   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   __str__  s    c         c@  s   t  j |  j d t |  j  d t } t | |  j  } xI | j d  D]8 } t	 | d |  j d | } | d k r| qI n  | VqI Wd S(   s   Yields all links in the paget   transport_encodingt   namespaceHTMLElementss   .//aRk  R|  N(   R   R   R   Rr  RV   RJ   Rm  RD   Ri  R~  RC   (   RR   Rj  R|  R{  Rm   (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR7    s    				N(   RS   RT   R   RC   RO   R  R7  (    (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyR     s   	(   R   t
   __future__R    Ro  R2  t   loggingR  Rv   R   t   pip._vendorR   R   R   t   pip._vendor.distlib.compatR   t   pip._vendor.packagingR   t   pip._vendor.packaging.utilsR   t   pip._vendor.packaging.versionR   RL  t   pip._vendor.requests.exceptionsR   R	   R
   t   pip._vendor.six.moves.urllibR^   R   Rx   t   pip._internal.downloadR   R   t   pip._internal.exceptionsR   R   R   R   t   pip._internal.models.candidateR   t#   pip._internal.models.format_controlR   t   pip._internal.models.linkR   t$   pip._internal.models.selection_prefsR   t"   pip._internal.models.target_pythonR   t   pip._internal.utils.compatR   t   pip._internal.utils.loggingR   t   pip._internal.utils.miscR   R   R   R   R   t   pip._internal.utils.packagingR   t   pip._internal.utils.typingR   t   pip._internal.wheelR    R!   t   typingR"   R#   R$   R%   R&   R'   R(   R)   R*   R+   R,   R-   R.   t   xml.etree.ElementTreet   xmlR/   t   pip._vendor.requestsR0   t!   pip._internal.models.search_scopeR1   t   pip._internal.reqR2   R3   t   pip._internal.pep425tagsR4   t   pip._internal.utils.hashesR5   t   BuildTagR   t   CandidateSortingKeyt   etreet   ElementTreet   Elementt   HTMLElementR{   t   SecureOrigint   __all__RC   R	  t	   getLoggerRS   Rj   RF   RL   t	   ExceptionRM   RZ   R[   Rh   Rl   Rp   R   RJ   R   t   objectR   R   R   R   R6   R7   Rf  R   Rm  Rr  Ry  R~  R   (    (    (    s2   lib/python2.7/site-packages/pip/_internal/index.pyt   <module>   s   "(X 					69(	K-  +				
		 