
    0A7hۛ                     &   d 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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ZddlmZ ddlZddlmZmZmZmZmZmZmZmZmZ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, dd	l-m.Z.  ej^                  d
      Z0 ej^                  dejb                        Z2 ej^                  d      Z3 ej^                  dejb                        jh                  Z5djm                         Z7g dZ8dZ9dZ:e:jw                   djv                  ejx                   e      Z=d Z>d Z?d Z@d1dZAd1dZBd1dZCdedfdZDd ZE ej^                  dejb                        ZF	 eEd        ZG G d d      ZH G d  d!eH      ZI G d" d#e      ZJ ej^                  d$      j                  ZLd% ZMd& ZNd2d'ZOd( ZP G d) d*      ZQ G d+ d,ej                        ZSej                  j                  fd-ZVd. ZW  eOe9      eV      ZVd/ ZXd0 ZYy)3z$PyPI and direct package downloading.    Nwraps)CHECKOUT_DISTDistributionBINARY_DISTnormalize_pathSOURCE_DISTEnvironmentfind_distributions	safe_namesafe_versionto_filenameRequirementDEVELOP_DISTEGG_DISTparse_version)log)DistutilsError)	translate)Wheelunique_everseenz^egg=([-A-Za-z0-9_.+!]+)$zhref\s*=\s*['"]?([^'"> ]+)z<a href="([^"#]+)">([^<]+)</a>\n\s+\(<a (?:title="MD5 hash"\n\s+)href="[^?]+\?:action=show_md5&amp;digest=([0-9a-f]{32})">md5</a>\)z([-+.a-z0-9]{2,}):z.tar.gz .tar.bz2 .tar .zip .tgz)PackageIndexdistros_for_urlparse_bdist_wininstinterpret_distro_name   z<setuptools/{setuptools.__version__} Python-urllib/{py_major}z{}.{})py_major
setuptoolsc                 n    	 t        j                  |       S # t        $ r}t        d|       |d }~ww xY w)Nz/Not a URL, existing file, or requirement spec: )r   parse
ValueErrorr   )speces     :/usr/lib/python3/dist-packages/setuptools/package_index.pyparse_requirement_argr&   E   s>      && CGI
	s    	4/4c                 8   | j                         }d\  }}}|j                  d      ro|j                  d      r| dd }d}nV|j                  dd      r| d	d
 }| dd }d}n7|j                  d      r| dd }d}n|j                  dd      r| d	d
 }| dd }d}|||fS )z=Return (base,pyversion) or (None,None) for possible .exe name)NNN.exez
.win32.exeNiwin32z	.win32-pyiiz.win-amd64.exeiz	win-amd64z.win-amd64-pyi)lowerendswith
startswith)namer+   basepy_verplats        r%   r   r   N   s     JJLE)D&$~~f>>,':DDk3/"R[F:DD^^,-:DDos3"R[F:DD    c                 d   t         j                  j                  |       }|\  }}}}}}t         j                  j                  |j	                  d      d         }|dk(  r6|dk(  r1t         j                  j                  |j	                  d      d         }d|v r|j	                  dd      \  }}||fS )N/zsourceforge.netdownload#   )urllibr!   urlparseunquotesplit)	urlpartsschemeserverpath
parametersqueryfragmentr/   s	            r%   egg_info_for_urlrF   f   s    LL!!#&E8=5FFD*eX<<

3 34D""tz'9||##DJJsOB$78
d{C+h>r2   c              #      K   t        |       \  }}t        | ||      D ]  }|  |rDt        j                  |      }|r,t	        | |j                  d      |t              D ]  }|  yyyw)zEYield egg or source distribution objects that might be found at a URLr9   )
precedenceN)rF   distros_for_locationEGG_FRAGMENTmatchr   groupr   )r>   metadatar/   rE   distrK   s         r%   r   r   q   s}     %c*ND($S$9 
""8,-U[[^X-  
  s   A,A.c                 &   |j                  d      r|dd }|j                  d      rd|v rt        j                  | ||      gS |j                  d      rLd|v rHt        |      }|j	                         sg S t        | |j
                  |j                  t        dz         gS |j                  d	      r%t        |      \  }}}|t        | |||t        |      S t        D ]1  }|j                  |      s|dt        |        }t        | ||      c S  g S )
z:Yield egg or source distribution objects based on basename.egg.zipNr*   z.egg-z.whlr9   )locationproject_nameversionrH   r(   )r,   r   from_locationr   is_compatiblerS   rT   r   r   r   r   
EXTENSIONSlen)rR   basenamerM   wheelwin_baser0   platformexts           r%   rI   rI      s+   $CR= SH_**8XxHII SH_h""$I!"//#a<
 	
  %8%B"&(((Hfk8 
  GS!3s8),H(8XFFG Ir2   c                 h    t        t        |       t        j                  j	                  |       |      S )zEYield possible egg or source distribution objects based on a filename)rI   r   osrB   rY   )filenamerM   s     r%   distros_for_filenamera      s*    x "''"2"28"<h r2   c           
   #   F  K   |j                  d      }|st        d |dd D              ryt        t        |            D ]  }||   dd j	                         s n t        |      }t        | |dj                  |d|       dj                  ||d       |||       yw)zGenerate the interpretation of a source distro name

    Note: if `location` is a filesystem filename, you should call
    ``pkg_resources.normalize_path()`` on it before passing it to this
    routine!
    rQ   c              3   H   K   | ]  }t        j                  d |        yw)z	py\d\.\d$N)rerK   ).0ps     r%   	<genexpr>z(interpret_distro_name.<locals>.<genexpr>   s     KAbhh|Q7Ks    "   Nr9   )
py_versionrH   r\   )r=   anyrangerX   isdigitr   join)rR   rY   rM   ri   rH   r\   r?   rf   s           r%   r   r      s      NN3E#KqrKK 3u: 8BQ<! J
rqr s   AB!AB!c                 .     t                fd       }|S )zs
    Wrap a function returning an iterable such that the resulting iterable
    only ever yields unique items.
    c                  &    t         | i |      S Nr   )argskwargsfuncs     r%   wrapperzunique_values.<locals>.wrapper   s    tT4V455r2   r   )rs   rt   s   ` r%   unique_valuesru      s"     4[6 6 Nr2   z3<([^>]*\srel\s{0,10}=\s{0,10}['"]?([^'" >]+)[^>]*)>c           
   #     K   t         j                  |      D ]  }|j                         \  }}t        t	        t
        j                  |j                         j                  d                  }d|v sd|v s_t        j                  |      D ]<  }t        j                  j                  | t        |j                  d                   >  dD ]l  }|j                  |      }|dk7  st        j!                  ||      }|s3t        j                  j                  | t        |j                  d                   n yw)zEFind rel="homepage" and rel="download" links in `page`, yielding URLs,homepager6   r9   )z<th>Home Pagez<th>Download URLr5   N)RELfinditergroupssetmapstrstripr+   r=   HREFr:   r!   urljoin
htmldecoderL   findsearch)r>   pagerK   tagrelrelsposs          r%   find_external_linksr      s     d# L<<>S3syy#))+"3"3C"89:t!3s+ Lll**3
5;;q>0JKKL	L 5 Liin"9KKc*Ell**3
5;;q>0JKKLs   A4D?7A1D?)D?=D?c                   "    e Zd ZdZd Zd Zd Zy)ContentCheckerzP
    A null content checker that defines the interface for checking content
    c                      y)z3
        Feed a block of data to the hash.
        N selfblocks     r%   feedzContentChecker.feed   s     	r2   c                      y)zC
        Check the hash. Return False if validation fails.
        Tr   r   s    r%   is_validzContentChecker.is_valid   s     r2   c                      y)zu
        Call reporter with information about the checker (hash name)
        substituted into the template.
        Nr   )r   reportertemplates      r%   reportzContentChecker.report  s    
 	r2   N)__name__
__module____qualname____doc__r   r   r   r   r2   r%   r   r      s    r2   r   c                   X    e Zd Z ej                  d      Zd Zed        Zd Z	d Z
d Zy)HashCheckerzK(?P<hash_name>sha1|sha224|sha384|sha256|sha512|md5)=(?P<expected>[a-f0-9]+)c                 T    || _         t        j                  |      | _        || _        y rp   )	hash_namehashlibnewhashexpected)r   r   r   s      r%   __init__zHashChecker.__init__  s     "KK	*	 r2   c                     t         j                  j                  |      d   }|s
t               S | j                  j                  |      }|s
t               S  | di |j                         S )z5Construct a (possibly null) ContentChecker from a URLr5   r   )r:   r!   r;   r   patternr   	groupdict)clsr>   rE   rK   s       r%   from_urlzHashChecker.from_url  s^     <<((-b1!##""8,!##'U__&''r2   c                 :    | j                   j                  |       y rp   )r   updater   s     r%   r   zHashChecker.feed   s    		r2   c                 P    | j                   j                         | j                  k(  S rp   )r   	hexdigestr   r   s    r%   r   zHashChecker.is_valid#  s    yy""$55r2   c                 0    || j                   z  } ||      S rp   )r   )r   r   r   msgs       r%   r   zHashChecker.report&  s    '}r2   N)r   r   r   rd   compiler   r   classmethodr   r   r   r   r   r2   r%   r   r   
  s?    bjj	#G
!
 ( ( 6r2   r   c                   @    e Zd ZdZ	 	 	 	 d' fd	Z fdZd(dZd(dZd(dZd Z	d Z
d	 Zd
 Zd Zd)dZd Zd) fd	Zd Zd Zd Zd Zd Z	 	 	 	 d*dZd+dZd ZdZd Zd Zd)dZed        Zd Zed        Z d Z!d Z"d  Z#d! Z$d" Z%ed#        Z&d$ Z'd% Z(d& Z) xZ*S ),r   z;A distribution index that scans web pages for download URLsc                 V   t        |   |i | |dd |j                  d        z   | _        i | _        i | _        i | _        t        j                  dj                  t        t        |                  j                  | _        g | _        t        j                   j"                  | _        y )Nr4   |)superr   r,   	index_urlscanned_urlsfetched_urlspackage_pagesrd   r   rm   r}   r   rK   allowsto_scanr:   requesturlopenopener)r   r   hosts	ca_bundle
verify_sslrq   kw	__class__s          r%   r   zPackageIndex.__init__.  s     	$%"%"S)Fy/A/A#/F+F%GGjj#i*?!@AGGnn,,r2   c                 l    	 t        |j                         t        |   |      S # t        $ r Y y w xY wrp   )r   rT   	Exceptionr   add)r   rN   r   s     r%   r   zPackageIndex.add@  s9    	$,,' w{4    		s   ' 	33c           	         || j                   v r|syd| j                   |<   t        |      s| j                  |       yt        t	        |            }|r$| j                  |      sy| j                  d|       |s|r|| j                  v r t        t        | j                  |             y| j                  |      sd| j                  |<   y| j                  d|       d| j                  |<   d}| j                  |||z        }|yt        |t        j                  j                        r-|j                   dk(  r| j                  d|j"                  z         d| j                  |j$                  <   d|j&                  j)                  d	d
      j+                         vr|j-                          y|j$                  }|j/                         }t        |t0              sXt        |t        j                  j                        rd}n|j&                  j3                  d      xs d}|j5                  |d      }|j-                          t6        j9                  |      D ]K  }	t        j:                  j=                  |t?        |	jA                  d                  }
| jC                  |
       M |jE                  | jF                        r$tI        |dd      dk7  r| jK                  ||      }yyy)z<Evaluate a URL as a possible download, and maybe retrieve itNTzFound link: %sz
Reading %sz<Download error on %s: %%s -- Some packages may not be found!i  zAuthentication error: %shtmlcontent-type zlatin-1charsetignorer9   code  )&r   
URL_SCHEMEprocess_filenamelistr   url_okdebugr   r}   r   infoopen_url
isinstancer:   error	HTTPErrorr   r   r>   headersgetr+   closereadr~   	get_paramdecoder   rz   r!   r   r   rL   process_urlr-   r   getattrprocess_index)r   r>   retrievediststmplfr/   r   r   rK   links              r%   r   zPackageIndex.process_urlI  sV   $###H!%##!!#&-.E{{3'

+S1C4+<+<$<TXXu%&{{3%)Dc"		,$!%#MMM#tcz*9a//0QVVs]II015589#'!%% ~r:@@BBGGIuuvvx$$!V\\334#))--i8EI;;w1D		]]4( 	#E<<''jQ.HIDT"	# >>$..)ga.F#.M%%c40D /N)r2   c                    t         j                  j                  |      s| j                  d|       y t         j                  j	                  |      rk|sit         j                  j                  |      }t        j                  |      D ]2  }| j                  t         j                  j                  ||      d       4 t        |      }|r2| j                  d|       t        t        | j                  |             y y )NzNot found: %sTz	Found: %s)r_   rB   existswarnisdirrealpathlistdirr   rm   ra   r   r   r}   r   )r   fnnestedrB   itemr   s         r%   r   zPackageIndex.process_filename~  s    ww~~b!IIor*77==V77##B'D

4( F%%bggll4&>EF %R(JJ{B'TXXu%& r2   c                    t        |      }|xr" |j                  d      j                         dk(  }|s1| j                  t        j
                  j                  |      d         ryd}|rt        ||z        | j                  ||       y )Nr9   fileTz
Note: Bypassing %s (disallowed host; see https://setuptools.pypa.io/en/latest/deprecated/easy_install.html#restricting-downloads-with-allow-hosts for details).
)	r   rL   r+   r   r:   r!   r;   r   r   )r   r>   fatalsis_filer   s         r%   r   zPackageIndex.url_ok  s}    sO4
((*f4dkk&,,"7"7"<Q"?@W 	
  s++IIc3r2   c                     t        t        j                  j                  |      }d |D        }t	        t        j                  | j                  |             y )Nc              3   z   K   | ]3  }t        j                  |      D ]  }|j                  d       r||f  5 yw)z	.egg-linkN)r_   r   r,   )re   rB   entrys      r%   rg   z.PackageIndex.scan_egg_links.<locals>.<genexpr>  sF      
D)
 ~~k* 5M

s   9;)filterr_   rB   r   r   	itertoolsstarmapscan_egg_link)r   search_pathdirs	egg_linkss       r%   scan_egg_linkszPackageIndex.scan_egg_links  sB    bggmm[1

	 	Yt119=>r2   c           
         t        t        j                  j                  ||            5 }t	        t        d t        t        j                  |                  }d d d        t              dk7  ry |\  }}t        t        j                  j                  ||            D ]C  }t        j                  j                  |g| |_        t        |_        | j                  |       E y # 1 sw Y   xY w)Nrh   )openr_   rB   rm   r   r   r}   r~   r   rX   r   rR   r	   rH   r   )r   rB   r   	raw_lineslinesegg_path
setup_pathrN   s           r%   r   zPackageIndex.scan_egg_link  s    "'',,tU+, 	B	c#))Y&?@AE	B u:?$*&rww||D('CD 	DGGLL66DM)DOHHTN		B 	Bs   .C$$C-c           	         d}|j                  | j                        s|S t        t        t        j
                  j                  |t        | j                        d  j                  d                  }t        |      dk7  sd|d   v r|S t        |d         }t        |d         }d| j                  j                  |j                         i       |<   t        |      t        |      fS )N)NNr4   rh   r8   r9   r   T)r-   r   r   r}   r:   r!   r<   rX   r=   r   r   r   
setdefaultr+   r   )r   r   NO_MATCH_SENTINELr?   pkgvers         r%   _scanzPackageIndex._scan  s    &t~~.$$S--tC4G4I/J/P/PQT/UVWu:?cU1Xo$$ a!58$?C%%ciik26t<3S!111r2   c                    t         j                  |      D ]J  }	 | j                  t        j                  j                  |t        |j                  d                         L | j                  |      \  }}|syt        ||      D ]S  }t        |      \  }}|j                  d      r!|s|r|d|d|z  }n| j                  |       | j                  |       U t        j                  d |      S # t        $ r Y w xY w)z#Process the contents of a PyPI pager9   r   .pyz#egg=rQ   c                 .    d| j                  ddd      z  S )Nz<a href="%s#md5=%s">%s</a>r9      rh   )rL   )ms    r%   <lambda>z,PackageIndex.process_index.<locals>.<lambda>  s    2QWWQ15EE r2   )r   rz   r  r:   r!   r   r   rL   r"   r   rF   r,   need_version_infoscan_urlPYPI_MD5sub)	r   r>   r   rK   r  r  new_urlr/   frags	            r%   r   zPackageIndex.process_index  s     ]]4( 	E

6<<//ZA5OPQ	 ::c?S +35 	#G)'2JD$}}U#DsC88G**3/MM'"	# ||Et
 	
%  s   AC33	C?>C?c                 (    | j                  d|       y )NzPPage at %s links to .py file(s) without version info; an index scan is required.)scan_allr   r>   s     r%   r  zPackageIndex.need_version_info  s     	
r2   c                     | j                   | j                  vr&|r | j                  |g|  | j                  d       | j	                  | j                          y )Nz6Scanning index of all packages (this may take a while))r   r   r   r   r  r   r   rq   s      r%   r  zPackageIndex.scan_all  sG    >>!2!22		#%%IINOdnn%r2   c                    | j                  | j                  |j                  z   dz          | j                  j	                  |j
                        s+| j                  | j                  |j                  z   dz          | j                  j	                  |j
                        s| j                  |       t        | j                  j	                  |j
                  d            D ]  }| j                  |        y )Nr4   r   )	r  r   unsafe_namer   r   keyrS   not_found_in_indexr   )r   requirementr>   s      r%   find_packageszPackageIndex.find_packages  s    dnn{'>'>>DE!!%%koo6MM$..;+C+CCcIJ!!%%koo6##K0**..{CD 	CMM#	r2   c                     | j                          | j                  |       | |j                     D ]  }||v r|c S | j                  d||        t        t
        |   ||      S )Nz%s does not match %s)prescanr$  r!  r   r   r   obtain)r   r#  	installerrN   r   s       r%   r'  zPackageIndex.obtain  sh    ;') 	BD{"JJ-{DA	B \4/YGGr2   c                 0   |j                  | j                  d|z         |j                         sg|j                          t	        j
                  |       t        |j                  j                  dt        j                  j                  |      d      y)z-
        checker is a ContentChecker
        zValidating %%s checksum for %sz validation failed for z; possible download problem?N)r   r   r   r   r_   unlinkr   r   r.   rB   rY   )r   checkerr`   tfps       r%   
check_hashzPackageIndex.check_hash
  su     	tzz#Ch#NO!IIKIIh  <<$$bgg&6&6x&@B  "r2   c                     |D ]k  }| j                   0t        |      r%|j                  d      st        t	        |            r| j                  |       Q| j                   j                  |       m y)z;Add `urls` to the list that will be prescanned for searchesNfile:)r   r   r-   r   r   r  append)r   urlsr>   s      r%   add_find_linkszPackageIndex.add_find_links  s]     	)C$!#>>'*,- c" ##C(	)r2   c                 |    | j                   r)t        t        | j                  | j                                d| _         y)z7Scan urls scheduled for prescanning (e.g. --find-links)N)r   r   r}   r  r   s    r%   r&  zPackageIndex.prescan'  s'    <<T]]DLL12r2   c                     | |j                      r| j                  d}}n| j                  d}} |||j                         | j	                          y )Nz#Couldn't retrieve index page for %rz3Couldn't find index page for %r (maybe misspelled?))r!  r   r   r   r  )r   r#  methr   s       r%   r"  zPackageIndex.not_found_in_index-  sJ     		#H#D 		E D 	S+))*r2   c                 Z   t        |t              st        |      }|rF| j                  ||      }t	        |      \  }}|j                  d      r| j                  |||      }|S t        j                  j                  |      r|S t        |      }t        | j                  ||      dd      S )a  Locate and/or download `spec` to `tmpdir`, returning a local path

        `spec` may be a ``Requirement`` object, or a string containing a URL,
        an existing local filename, or a project/version requirement spec
        (i.e. the string form of a ``Requirement`` object).  If it is the URL
        of a .py file with an unambiguous ``#egg=name-version`` tag (i.e., one
        that escapes ``-`` as ``_`` throughout), a trivial ``setup.py`` is
        automatically created alongside the downloaded file.

        If `spec` is a ``Requirement`` object or a string containing a
        project/version requirement spec, this method returns the location of
        a matching distribution (possibly after downloading it to `tmpdir`).
        If `spec` is a locally existing file or directory name, it is simply
        returned unchanged.  If `spec` is a URL, it is downloaded to a subpath
        of `tmpdir`, and the local filename is returned.  Various errors may be
        raised if a problem occurs during downloading.
        r  rR   N)r   r   r   _download_urlrF   r,   	gen_setupr_   rB   r   r&   r   fetch_distribution)r   r#   tmpdirr@   foundr/   rE   s          r%   r6   zPackageIndex.download8  s    $ $,%F**48!1$!7h==' NN5(FCE%,T2t..tV<j$OOr2   c                    	  j                  d|       i 	d}d	 	fd	}|r) j                           j                  |        ||      }|s|	 |||      }|$ j                   j                           ||      }||s j                  |        ||      }| j	                  dxr dxs d|       y j                  d|       |j                  |j                        S )
a|  Obtain a distribution suitable for fulfilling `requirement`

        `requirement` must be a ``pkg_resources.Requirement`` instance.
        If necessary, or if the `force_scan` flag is set, the requirement is
        searched for in the (online) package index as well as the locally
        installed packages.  If a distribution matching `requirement` is found,
        the returned distribution's ``location`` is the value you would have
        gotten from calling the ``download()`` method with the matching
        distribution's URL or filename.  If no matching distribution is found,
        ``None`` is returned.

        If the `source` flag is set, only source distributions and source
        checkout links will be considered.  Unless the `develop_ok` flag is
        set, development and system eggs (i.e., those using the ``.egg-info``
        format) will be ignored.
        zSearching for %sNc                 z   |}|| j                      D ]  }|j                  t        k(  rs|vrj                  d|       d|<   4|| v xr |j                  t        k  xs  }|sUj                  |j                  	      }||_        t        j                  j                  |j                        s|c S  y )Nz&Skipping development or system egg: %sr9   )r!  rH   r   r   r	   r6   rR   download_locationr_   rB   r   )
reqenvrN   testloc
develop_okr   skippedsourcer:  s
        r%   r   z-PackageIndex.fetch_distribution.<locals>.findx  s    { CGG $??l2:7*		D  )*s{U;(F(Tf*--v>C-0D*ww~~d&<&<=#$r2   z:No local packages or working download links found for %s%sza source distribution of r   zBest match: %s)rR   rp   )r   r&  r$  r   r   cloner>  )
r   r#  r:  
force_scanrE  rC  local_indexrN   r   rD  s
   ` ` ``   @r%   r9  zPackageIndex.fetch_distributionZ  s    4 			$k2	$ 	$, LLN{+$D/[1D<||'$D<
{+$D<IIL77=2 II&-::t'='=:>>r2   c                 H    | j                  ||||      }||j                  S y)a3  Obtain a file suitable for fulfilling `requirement`

        DEPRECATED; use the ``fetch_distribution()`` method now instead.  For
        backward compatibility, this routine is identical but returns the
        ``location`` of the downloaded distribution instead of a distribution
        object.
        N)r9  rR   )r   r#  r:  rG  rE  rN   s         r%   fetchzPackageIndex.fetch  s-     &&{FJO== r2   c                    t         j                  |      }|xr6 t        ||j                  d      d       D cg c]  }|j                  r| c}xs g }t        |      dk(  rBt        j                  j                  |      }t        j                  j                  |      |k7  rwt        j                  j                  ||      }t        j                  j                  |      r t        j                  j                  ||      st        j                  ||       |}t        t        j                  j                  |d      d      5 }	|	j!                  d|d   j"                  d|d   j                  dt        j                  j%                  |      d   d       d d d        |S |rt'        d	|d
|      t'        d      c c}w # 1 sw Y   |S xY w)Nr9   zsetup.pywz(from setuptools import setup
setup(name=r   z
, version=z, py_modules=[z])
z9Can't unambiguously interpret project/version identifier zI; any dashes in the name or version should be escaped using underscores. zpCan't process plain .py files without an '#egg=name-version' suffix to enable automatic setup script generation.)rJ   rK   r   rL   rT   rX   r_   rB   rY   dirnamerm   r   samefileshutilcopy2r  writerS   splitextr   )
r   r`   rE   r:  rK   dr   rY   dstr   s
             r%   r8  zPackageIndex.gen_setup  s   ""8,  /xQN99   	 u:?ww''1H wwx(F2ggll684s+0@0@30OLL3/"Hbggll6:6< 	

 a--a((((215	 O  &.u6  !G K$	 Os   GAGGi    c                 >   | j                  d|       d }	 t        j                  |      }| j                  |      }t	        |t
        j                  j                        r(t        d|d|j                  d|j                        |j                         }d}| j                  }d}d|v r?|j                  d      }	t        t        t        |	            }| j!                  |||||       t#        |d	      5 }
	 |j%                  |      }|r=|j'                  |       |
j)                  |       |d
z  }| j!                  |||||       nnR| j+                  |||
       d d d        ||r|j-                          S S # 1 sw Y   xY w# |r|j-                          w w xY w)NzDownloading %szCan't download :  r   r5   zcontent-lengthzContent-Lengthwbr9   )r   r   r   r   r   r:   r   r   r   r   r   dl_blocksizeget_allmaxr}   int
reporthookr  r   r   rQ  r-  r   )r   r>   r`   fpr+  r   blocknumbssizesizesr,  r   s               r%   _download_tozPackageIndex._download_to  sv   		"C(	!**3/Gs#B"fll445$25rwwG  ggiGH""BD7*(893sE?+XxTBh% 
8GGBKEU+		%( AXxTJ  37
8 
 
8 
8 
 s%   C!F 7A'E;	F ;F F Fc                      y rp   r   )r   r>   r`   r_  blksizera  s         r%   r]  zPackageIndex.reporthook
  s    r2   c           	         |j                  d      rt        |      S 	 t        || j                        S # t        t
        j                  j                  f$ rh}dj                  |j                  D cg c]  }t        |       nc c}w c}      }|r| j                  ||       nt        |d|      |Y d }~y d }~wt        j                  j                  $ r}|cY d }~S d }~wt        j                  j                   $ rE}|r| j                  ||j"                         nt        d|d|j"                        |Y d }~y d }~wt
        j                  j$                  $ rD}|r| j                  ||j&                         nt        |d|j&                        |Y d }~y d }~wt
        j                  j(                  t*        j                  f$ r1}|r| j                  ||       nt        d|d|      |Y d }~y d }~ww xY w)Nr/  rW  zDownload error for rV  z7 returned a bad status line. The server might be down, )r-   
local_openopen_with_authr   r"   httpclient
InvalidURLrm   rq   r~   r   r   r:   r   r   URLErrorreasonBadStatusLinelineHTTPExceptionsocket)r   r>   warningvargr   s         r%   r   zPackageIndex.open_url  s   >>'"c?"	T!#t{{33DKK223 	B((7CH778C		'3'$S%9:A ( ||%% 	H||$$ 			'188,$36A -
 {{(( 			'166*$"%qvv/  + ))6<<8 	T		'1%$C%KLRSS &	TsW   4 #HB:0B
3B:: HC!H! H;E H!:F  0H'G<<Hc                 >   t        |       \  }}|r,d|v r*|j                  dd      j                  dd      }d|v r'nd}|j                  d      r|dd }t        j                  j                  ||      }|j                  t        |            st        d	|       |S )
aB  
        >>> import pathlib
        >>> du = PackageIndex._resolve_download_filename
        >>> root = getfixture('tmp_path')
        >>> url = 'https://files.pythonhosted.org/packages/a9/5a/0db.../setuptools-78.1.0.tar.gz'
        >>> str(pathlib.Path(du(url, root)).relative_to(root))
        'setuptools-78.1.0.tar.gz'

        Ensures the target is always in tmpdir.

        >>> url = 'https://anyhost/%2fhome%2fuser%2f.ssh%2fauthorized_keys'
        >>> du(url, root)
        Traceback (most recent call last):
        ...
        ValueError: Invalid filename...
        z...\___downloaded__rP   Nr*   zInvalid filename )	rF   replacer,   r_   rB   rm   r-   r~   r"   )r>   r:  r.   rE   r`   s        r%   _resolve_download_filenamez'PackageIndex._resolve_download_filename0  s    $ *#.h$,||D#.66tSA $, $D==$9D77<<- ""3v;/0
;<<r2   c                 r    | j                  ||      }| j                  ||      xs | j                  ||      S )z2
        Determine the download filename.
        )r{  _download_vcs_download_other)r   r>   r:  r`   s       r%   r7  zPackageIndex._download_urlT  s;     223?!!#x0WD4H4Hh4WWr2   c                     t         j                  j                  |       j                  }|j	                  d      \  }}}t        ddgdgt        |      z  z         }t        t        |h|z        d      S )a  
        >>> rvcs = PackageIndex._resolve_vcs
        >>> rvcs('git+http://foo/bar')
        'git'
        >>> rvcs('hg+https://foo/bar')
        'hg'
        >>> rvcs('git:myhost')
        'git'
        >>> rvcs('hg:myhost')
        >>> rvcs('http://foo/bar')
        +svngithgN)	r:   r!   urlsplitr@   	partitionr|   boolnextiter)r>   r@   preseppostalloweds         r%   _resolve_vcszPackageIndex._resolve_vcs[  sj     &&s+22))#.S$uenvS	'99:D#)400r2   c                    | j                  |      }|sy |dk(  rt        d|       |j                  d      \  }}}| j                  |      \  }}| j	                  d| d| d|        t        j                  |dd||g       t        |d	|d
d|g|d|dd	d|dg      }|,| j	                  d|        t        j                  ||          |S )Nr  z/Invalid config, SVN download is not supported: r8   zDoing z clone from z to rF  z--quietz-Ccheckoutz--cwdupz-rz-q)r  r  zChecking out )r  r   r  _vcs_split_rev_from_urlr   
subprocess
check_calldict)r   r>   spec_filenamevcsr`   rx  revco_commandss           r%   r}  zPackageIndex._download_vcsn  s    $%< A#G  '005!Q//4S		F3%|C5XJ?@sGYXFGdHj)SAWhdD#tD
 ?IIcU+,!!+c"23r2   c                 2   t         j                  j                  |      j                  }|dk(  rFt         j                  j                  t         j                  j                  |      j                        S | j                  |d       | j                  ||      S )Nr   T)
r:   r!   r  r@   r   url2pathnamer;   rB   r   _attempt_download)r   r>   r`   r@   s       r%   r~  zPackageIndex._download_other  so    &&s+22V>>..v||/D/DS/I/N/NOOC%%c844r2   c                 (    | j                  |d       y )NT)r   r  s     r%   r  zPackageIndex.scan_url  s    d#r2   c                     | j                  ||      }d|j                  dd      j                         v r| j                  |||      S |S )Nr   r   r   )rc  r   r+   _invalid_download_html)r   r>   r`   r   s       r%   r  zPackageIndex._attempt_download  sJ    ##C2W[[4::<<..sGXFFOr2   c                 H    t        j                  |       t        d|       )NzUnexpected HTML page found at )r_   r*  r   )r   r>   r   r`   s       r%   r  z#PackageIndex._invalid_download_html  s!    
		(=cUCDDr2   c                 L   t         j                  j                  |       }|j                  j	                  dd      d   }|j
                  j                  d      \  }}}|j                  d      \  }}}|r||fn|df\  }}	|j                  ||d      j                         }
|
|	fS )	a  
        Given a possible VCS URL, return a clean URL and resolved revision if any.

        >>> vsrfu = PackageIndex._vcs_split_rev_from_url
        >>> vsrfu('git+https://github.com/pypa/setuptools@v69.0.0#egg-info=setuptools')
        ('https://github.com/pypa/setuptools', 'v69.0.0')
        >>> vsrfu('git+https://github.com/pypa/setuptools#egg-info=setuptools')
        ('https://github.com/pypa/setuptools', None)
        >>> vsrfu('http://foo/bar')
        ('http://foo/bar', None)
        r  r9   r5   r8   @Nr   )r@   rB   rE   )
r:   r!   r  r@   r=   rB   r  
rpartition_replacegeturl)r>   r?   clean_schemeno_fragment_pathrx  r  r  r  
clean_pathr  resolveds              r%   r  z$PackageIndex._vcs_split_rev_from_url  s     %%c*||))#q1"5 "'!5!5c!:!Q)44S9S$),3+4,
C>>	 " 

 &( 	 }r2   c                 0    t        j                  |g|  y rp   )r   r   r  s      r%   r   zPackageIndex.debug  s    		#r2   c                 0    t        j                  |g|  y rp   )r   r   r  s      r%   r   zPackageIndex.info      tr2   c                 0    t        j                  |g|  y rp   )r   r   r  s      r%   r   zPackageIndex.warn  r  r2   )zhttps://pypi.org/simple/)*NT)Frp   )FFFN)FF)+r   r   r   r   r   r   r   r   r   r  r   r  r   r  r  r$  r'  r-  r2  r&  r"  r6   r9  rJ  r8  rY  rc  r]  r   staticmethodr{  r7  r  r}  r~  r  r  r  r  r   r   r   __classcell__r   s   @r%   r   r   +  s   E --$!31j'  ? 2 
:
&H)	 PL M?^,\ L"H TD ! !FX 1 1$25$E  >r2   r   z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c                 N    | j                  d      }t        j                  |      S )Nr   )rL   r   unescape)rK   whats     r%   decode_entityr    s    ;;q>D==r2   c                 "    t        t        |       S )a  
    Decode HTML entities in the given text.

    >>> htmldecode(
    ...     'https://../package_name-0.1.2.tar.gz'
    ...     '?tokena=A&amp;tokenb=B">package_name-0.1.2.tar.gz')
    'https://../package_name-0.1.2.tar.gz?tokena=A&tokenb=B">package_name-0.1.2.tar.gz'
    )
entity_subr  )texts    r%   r   r     s     mT**r2   c                       fd}|S )Nc                       fd}|S )Nc                      t        j                         }t        j                         	  | i |t        j                  |       S # t        j                  |       w xY wrp   )rq  getdefaulttimeoutsetdefaulttimeout)rq   rr   old_timeoutrs   timeouts      r%   _socket_timeoutz@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeout  sN     224K$$W-6T,V,((5((5s   A	 	A r   )rs   r  r  s   ` r%   r  z'socket_timeout.<locals>._socket_timeout  s    	6 r2   r   )r  r  s   ` r%   socket_timeoutr    s    	 r2   c                     t         j                  j                  |       }|j                         }t	        j
                  |      }|j                         }|j                  dd      S )a9  
    Encode auth from a URL suitable for an HTTP header.
    >>> str(_encode_auth('username%3Apassword'))
    'dXNlcm5hbWU6cGFzc3dvcmQ='

    Long auth strings should not cause a newline to be inserted.
    >>> long_auth = 'username:' + 'password'*10
    >>> chr(10) in str(_encode_auth(long_auth))
    False
    
r   )r:   r!   r<   encodebase64	b64encoder   rz  )authauth_s
auth_bytesencoded_bytesencodeds        r%   _encode_authr    sR     \\!!$'FJ$$Z0M""$G??4$$r2   c                   "    e Zd ZdZd Zd Zd Zy)
Credentialz:
    A username/password pair. Use like a namedtuple.
    c                      || _         || _        y rp   usernamepassword)r   r  r  s      r%   r   zCredential.__init__  s      r2   c              #   D   K   | j                    | j                   y wrp   r  r   s    r%   __iter__zCredential.__iter__
  s     mmmms    c                     dt        |       z  S )Nz%(username)s:%(password)s)varsr   s    r%   __str__zCredential.__str__  s    *T$Z77r2   N)r   r   r   r   r   r  r  r   r2   r%   r  r    s    !8r2   r  c                   :     e Zd Z fdZed        Zd Zd Z xZS )
PyPIConfigc                 0   t         j                  g dd      }t        |   |       t        j
                  j                  t        j
                  j                  d      d      }t        j
                  j                  |      r| j                  |       yy)z%
        Load from ~/.pypirc
        )r  r  
repositoryr   ~z.pypircN)
r  fromkeysr   r   r_   rB   rm   
expanduserr   r   )r   defaultsrcr   s      r%   r   zPyPIConfig.__init__  sf     ==!GL"WW\\"'',,S19=77>>"IIbM r2   c                     | j                         D cg c]$  }| j                  |d      j                         r|& }}t        t	        | j
                  |            S c c}w )Nr  )sectionsr   r   r  r}   _get_repo_cred)r   sectionsections_with_repositoriess      r%   creds_by_repositoryzPyPIConfig.creds_by_repository  s_      ==?&
xx.446 &
" &
 C++-GHII&
s   )Ac                     | j                  |d      j                         }|t        | j                  |d      j                         | j                  |d      j                               fS )Nr  r  r  )r   r   r  )r   r  repos      r%   r  zPyPIConfig._get_repo_cred(  s]    xx.446ZHHWj)//1HHWj)//1
 
 	
r2   c                 r    | j                   j                         D ]  \  }}|j                  |      s|c S  y)z
        If the URL indicated appears to be a repository defined in this
        config, return the credential for that repository.
        N)r  itemsr-   )r   r>   r  creds       r%   find_credentialzPyPIConfig.find_credential/  s8    
 !% 8 8 > > @ 	J~~j)	r2   )	r   r   r   r   propertyr  r  r  r  r  s   @r%   r  r    s(    	 J J
r2   r  c                    t         j                  j                  |       }|\  }}}}}}|j                  d      rt        j
                  j                  d      |dv rt        |      \  }	}
nd}	|	sJt               j                  |       }|r/t        |      }	|j                  | f}t        j                  dg|  |	rgdt        |	      z   }	|
||||f}t         j                  j                  |      }t         j                   j#                  |      }|j%                  d|	       nt         j                   j#                  |       }|j%                  dt&                ||      }|	rft         j                  j                  |j(                        \  }}}}}}||k(  r1|
k(  r,||||||f}t         j                  j                  |      |_        |S )	z4Open a urllib2 request, handling HTTP authentication:znonnumeric port: '')ri  httpsNz*Authenticating as %s for %s (from .pypirc)zBasic Authorizationz
User-Agent)r:   r!   r;   r,   ri  rj  rk  
_splituserr  r  r~   r  r   r   r  
urlunparser   Request
add_header
user_agentr>   )r>   r   parsedr@   netlocrB   paramsrD   r  r  addressr  r   r?   r  r   r^  s2h2path2param2query2frag2s                          r%   rh  rh  9  s    \\""3'F06-FFD&% skk$$%:;;"""6*g|++C0t9D==#%DHHAIDI,t,,vud:,,))%0..((1?D1..((-|Z0	B 06||/D/DRVV/L,Bvvu<B'Mvvu<E\\,,U3BFIr2   c                 @    | j                  d      \  }}} |r|| fS d| fS )zNsplituser('user[:passwd]@host[:port]')
    --> 'user[:passwd]', 'host[:port]'.r  N)r  )hostuserdelims      r%   r  r  h  s0     ,D%Dd**td**r2   c                     | S rp   r   )r>   s    r%   
fix_sf_urlr  s  s    Jr2   c                    t         j                  j                  |       \  }}}}}}t         j                  j	                  |      }t
        j                  j                  |      rt         j                  j                  |       S |j                  d      rt
        j                  j                  |      rg }t        j                  |      D ]  }	t
        j                  j                  ||	      }
|	dk(  r't        |
d      5 }|j                         }ddd        nkt
        j                  j                  |
      r|	dz  }	|j                  dj!                  |	              d}|j!                  | dj                  |      	      }d
\  }}nd\  }}}ddi}t#        j$                        }t         j&                  j)                  | ||||      S # 1 sw Y   xY w)z7Read a local path, with special support for directoriesr4   z
index.htmlrNz<a href="{name}">{name}</a>)r.   zB<html><head><title>{url}</title></head><body>{files}</body></html>r  )r>   files)   OK)r   zPath not foundz	Not foundr   z	text/html)r:   r!   r;   r   r  r_   rB   isfiler   r,   r   r   rm   r  r   r0  formatioStringIOr   r   )r>   r@   rA   rB   paramrD   r  r`   r  r   filepathr^  bodyr   statusmessager   body_streams                     r%   rg  rg  w  s   /5||/D/DS/I,FFD%~~**40H	ww~~h~~%%c**	s	h 7H% 	@Aww||Ha0HL (C( %B779D%x(SLL6==1=EF	@ X  ;;3dii.>;?D# B{+G++d#K<<!!#vwMM#% %s   ?GG	rp   )r   )Zr   sysr  r_   rd   r  rO  rq  r  r   r   configparserr   http.clientri  urllib.parser:   urllib.requesturllib.error	functoolsr   r   pkg_resourcesr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   	distutilsr   distutils.errorsr   fnmatchr   setuptools.wheelr    setuptools.extern.more_itertoolsr   r   rJ   Ir   r  rK   r   r=   rW   __all___SOCKET_TIMEOUT_tmplr  version_infor  r&   r   rF   r   rI   ra   r   ru   ry   r   r   r   r   r  r  r  r   r  r  r  RawConfigParserr  r   r   rh  r  r  rg  r   r2   r%   <module>r(     s   * 
  	 	 	                   +  " < rzz67rzz3RTT:2::J RZZ,bdd399
.446
 F\\W^^S--.:  

0 F .2kTXD
 bjjKRTTR
 L L$ 2. BY
; Y
| RZZ<=AA

	+%*8 8"$-- $N  &~~55 +^+ 10@Nr2   