a
    ñ»j©˜  ã                   @   s   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. d
dl/m0Z0m1Z1 e 2d¡Z3e 2dej4¡Z5e 2d¡Z6e 2dej4¡j7Z8d 9¡ Z:g d¢Z;dZ<dZ=e=j>dj>ej?Ž ed�Z@dd„ ZAdd„ ZBdd„ ZCdDdd„ZDdEdd„ZEdFd d!„ZFdedfd"d#„ZGd$d%„ ZHe 2d&ej4¡ZIeHd'd(„ ƒZJG d)d*„ d*ƒZKG d+d,„ d,eKƒZLG d-d.„ d.eƒZMe 2d/¡jNZOd0d1„ ZPd2d3„ ZQdGd4d5„ZRd6d7„ ZSG d8d9„ d9ƒZTG d:d;„ d;ejUƒZVejWjXfd<d=„ZYd>d?„ ZZeRe<ƒeYƒZYd@dA„ Z[dBdC„ Z\dS )Hz$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_everseené   )Ú_read_utf8_with_fallbackÚ_cfg_read_utf8_with_fallbackz^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{}.{})Zpy_majorÚ
setuptoolsc              
   C   sF   zt  | ¡W S  ty@ } ztd| f ƒ|‚W Y d }~n
d }~0 0 d S )Nz1Not a URL, existing file, or requirement spec: %r)r   ÚparseÚ
ValueErrorr   )ÚspecÚe© r%   ú>E:\soccer\ml_env\Lib\site-packages\setuptools/package_index.pyÚparse_requirement_argG   s    ÿþr'   c                 C   s°   |   ¡ }d\}}}| d¡r¦| d¡r8| dd… }d}nn| dd¡rb| d	d
… }| dd… }d}nD| d¡r~| dd… }d}n(| 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-pyiðÿÿÿiùÿÿÿéüÿÿÿz.win-amd64.exeiòÿÿÿz	win-amd64z.win-amd64-pyiìÿÿÿ)ÚlowerÚendswithÚ
startswith)Únamer+   ÚbaseÚpy_verÚplatr%   r%   r&   r   P   s$    



r   c           	      C   sx   t j | ¡}|\}}}}}}t j | d¡d ¡}|dkrX|dkrXt j | d¡d ¡}d|v rp| dd¡\}}||fS )Nú/éÿÿÿÿzsourceforge.netÚdownloadéþÿÿÿú#r   )Úurllibr!   ÚurlparseÚunquoteÚsplit)	ÚurlÚpartsÚschemeÚserverÚpathÚ
parametersÚqueryÚfragmentr/   r%   r%   r&   Úegg_info_for_urlh   s    rC   c                 c   sP   t | ƒ\}}t| ||ƒE dH  |rLt |¡}|rLt| | d¡|td�E dH  dS )zEYield egg or source distribution objects that might be found at a URLNr   )Ú
precedence)rC   Údistros_for_locationÚEGG_FRAGMENTÚmatchr   Úgroupr   )r;   Úmetadatar/   rB   rG   r%   r%   r&   r   s   s    
ÿr   c                 C   sä   |  d¡r|dd… }|  d¡r8d|v r8t | ||¡gS |  d¡rxd|v rxt|ƒ}| ¡ s^g S t| |j|jtd d�gS |  d	¡rªt|ƒ\}}}|durªt	| |||t
|ƒS tD ]0}|  |¡r®|dt|ƒ … }t	| ||ƒ  S q®g S )
z:Yield egg or source distribution objects based on basenameú.egg.zipNr*   z.eggú-z.whlr   )ÚlocationÚproject_nameÚversionrD   r(   )r,   r   Úfrom_locationr   Úis_compatiblerM   rN   r   r   r   r   Ú
EXTENSIONSÚlen)rL   ÚbasenamerI   ÚwheelZwin_baser0   ÚplatformÚextr%   r%   r&   rE      s4    
ûÿ	
ÿ
rE   c                 C   s   t t| ƒtj | ¡|ƒS )zEYield possible egg or source distribution objects based on a filename)rE   r   Úosr?   rS   )ÚfilenamerI   r%   r%   r&   Údistros_for_filename¢   s    ÿrY   c              	   c   s–   |  d¡}|s,tdd„ |dd… D ƒƒr,dS tt|ƒƒD ]}|| dd…  ¡ r8 q^q8t|ƒ}t| |d |d|… ¡d ||d… ¡|||d�V  dS )zÏGenerate 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!
    rK   c                 s   s   | ]}t  d |¡V  qdS )z	py\d\.\d$N)ÚrerG   )Ú.0Úpr%   r%   r&   Ú	<genexpr>´   ó    z(interpret_distro_name.<locals>.<genexpr>é   Nr   )Ú
py_versionrD   rU   )r:   ÚanyÚrangerR   Úisdigitr   Újoin)rL   rS   rI   r`   rD   rU   r<   r\   r%   r%   r&   r   ©   s     

ùr   c                    s   t ˆ ƒ‡ fdd„ƒ}|S )zs
    Wrap a function returning an iterable such that the resulting iterable
    only ever yields unique items.
    c                     s   t ˆ | i |¤ŽƒS ©Nr   )ÚargsÚkwargs©Úfuncr%   r&   ÚwrapperÑ   s    zunique_values.<locals>.wrapperr   )ri   rj   r%   rh   r&   Úunique_valuesË   s    rk   z3<([^>]*\srel\s{0,10}=\s{0,10}['"]?([^'" >]+)[^>]*)>c              	   c   sº   t  |¡D ]d}| ¡ \}}tttj| ¡  d¡ƒƒ}d|v sDd|v r
t	 |¡D ]}t
j | t| d¡ƒ¡V  qNq
dD ]@}| |¡}|dkrtt	 ||¡}|rtt
j | t| d¡ƒ¡V  qtdS )zEFind rel="homepage" and rel="download" links in `page`, yielding URLsú,Zhomepager4   r   )z<th>Home Pagez<th>Download URLr3   N)ÚRELÚfinditerÚgroupsÚsetÚmapÚstrÚstripr+   r:   ÚHREFr7   r!   ÚurljoinÚ
htmldecoderH   ÚfindÚsearch)r;   ÚpagerG   ÚtagÚrelZrelsÚposr%   r%   r&   Úfind_external_linksÞ   s    
r}   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚContentCheckerzP
    A null content checker that defines the interface for checking content
    c                 C   s   dS )z3
        Feed a block of data to the hash.
        Nr%   ©ÚselfÚblockr%   r%   r&   Úfeedö   s    zContentChecker.feedc                 C   s   dS )zC
        Check the hash. Return False if validation fails.
        Tr%   ©r€   r%   r%   r&   Úis_validü   s    zContentChecker.is_validc                 C   s   dS )zu
        Call reporter with information about the checker (hash name)
        substituted into the template.
        Nr%   )r€   ÚreporterÚtemplater%   r%   r&   Úreport  s    zContentChecker.reportN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r‚   r„   r‡   r%   r%   r%   r&   r~   ñ   s   r~   c                   @   sB   e Zd Ze d¡Zdd„ Zedd„ ƒZdd„ Z	dd	„ Z
d
d„ ZdS )ÚHashCheckerzK(?P<hash_name>sha1|sha224|sha384|sha256|sha512|md5)=(?P<expected>[a-f0-9]+)c                 C   s   || _ t |¡| _|| _d S re   )Ú	hash_nameÚhashlibÚnewÚhashÚexpected)r€   r�   r‘   r%   r%   r&   Ú__init__  s    zHashChecker.__init__c                 C   sB   t j |¡d }|stƒ S | j |¡}|s0tƒ S | f i | ¡ ¤ŽS )z5Construct a (possibly null) ContentChecker from a URLr3   )r7   r!   r8   r~   Úpatternrx   Ú	groupdict)Úclsr;   rB   rG   r%   r%   r&   Úfrom_url  s    zHashChecker.from_urlc                 C   s   | j  |¡ d S re   )r�   Úupdater   r%   r%   r&   r‚      s    zHashChecker.feedc                 C   s   | j  ¡ | jkS re   )r�   Ú	hexdigestr‘   rƒ   r%   r%   r&   r„   #  s    zHashChecker.is_validc                 C   s   || j  }||ƒS re   )r�   )r€   r…   r†   Úmsgr%   r%   r&   r‡   &  s    
zHashChecker.reportN)rˆ   r‰   rŠ   rZ   Úcompiler“   r’   Úclassmethodr–   r‚   r„   r‡   r%   r%   r%   r&   rŒ   
  s   ÿ

rŒ   c                       sV  e Zd ZdZdN‡ fdd„	Z‡ fdd	„ZdOdd„ZdPdd„ZdQdd„Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdRdd„Zdd„ ZdS‡ fdd „	Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ ZdTd+d,„ZdUd-d.„Zd/d0„ Zd1Zd2d3„ Zd4d5„ ZdVd6d7„Zd8d9„ Zed:d;„ ƒZd<d=„ Z d>d?„ Z!d@dA„ Z"dBdC„ Z#dDdE„ Z$edFdG„ ƒZ%dHdI„ Z&dJdK„ Z'dLdM„ Z(‡  Z)S )Wr   z;A distribution index that scans web pages for download URLsúhttps://pypi.org/simple/©Ú*NTc                    sl   t ƒ j|i |¤Ž |dd | d¡ …  | _i | _i | _i | _t d 	t
t|ƒ¡¡j| _g | _tjj| _d S )Nr2   ú|)Úsuperr’   r,   Ú	index_urlÚscanned_urlsÚfetched_urlsÚpackage_pagesrZ   rš   rd   rq   r   rG   ÚallowsÚto_scanr7   ÚrequestÚurlopenÚopener)r€   r¡   ÚhostsZ	ca_bundleZ
verify_sslrf   Úkw©Ú	__class__r%   r&   r’   .  s    	zPackageIndex.__init__c                    s0   zt |jƒ W n ty"   Y d S 0 tƒ  |¡S re   )r   rN   Ú	Exceptionr    Úadd)r€   Údistr¬   r%   r&   r¯   @  s
    zPackageIndex.addFc                 C   sâ  || j v r|sdS d| j |< t|ƒs2|  |¡ dS tt|ƒƒ}|r\|  |¡sPdS |  d|¡ |sn|rn|| jv r‚tt| j	|ƒƒ dS |  |¡sšd| j|< dS |  
d|¡ d| j|< d}|  ||| ¡}|du rÐdS t|tjjƒrø|jdkrø|  
d|j ¡ d| j|j< d|j d	d
¡ ¡ v�r(| ¡  dS |j}| ¡ }t|tƒ�svt|tjjƒ�rXd}n|j d¡�phd}| |d¡}| ¡  t |¡D ](}	tj |t|	  d¡ƒ¡}
|  !|
¡ �qˆ| "| j#¡�rÞt$|ddƒdk�rÞ|  %||¡}dS )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Úignorer   Úcodeé”  )&r¢   Ú
URL_SCHEMEÚprocess_filenameÚlistr   Úurl_okÚdebugr£   rq   r¯   ÚinfoÚopen_urlÚ
isinstancer7   ÚerrorÚ	HTTPErrorr¶   r™   r;   ÚheadersÚgetr+   ÚcloseÚreadrr   Ú	get_paramÚdecodert   rn   r!   ru   rv   rH   Úprocess_urlr-   r¡   ÚgetattrÚprocess_index)r€   r;   ÚretrieveÚdistsÚtmplÚfr/   ry   r´   rG   Úlinkr%   r%   r&   rÈ   I  sT    





 zPackageIndex.process_urlc                 C   sŠ   t j |¡s|  d|¡ d S t j |¡r^|s^t j |¡}t  |¡D ]}|  t j ||¡d¡ qBt	|ƒ}|r†|  
d|¡ tt| j|ƒƒ d S )NzNot found: %sTz	Found: %s)rW   r?   ÚexistsÚwarnÚisdirÚrealpathÚlistdirr¹   rd   rY   r¼   rº   rq   r¯   )r€   ÚfnÚnestedr?   ÚitemrÌ   r%   r%   r&   r¹   ~  s    zPackageIndex.process_filenamec                 C   sf   t |ƒ}|o| d¡ ¡ dk}|s8|  tj |¡d ¡r<dS d}|rRt|| ƒ‚n|  ||¡ dS d S )Nr   ÚfileTz¡
Note: Bypassing %s (disallowed host; see https://setuptools.pypa.io/en/latest/deprecated/easy_install.html#restricting-downloads-with-allow-hosts for details).
F)	r¸   rH   r+   r¥   r7   r!   r8   r   rÑ   )r€   r;   ÚfatalÚsÚis_filer™   r%   r%   r&   r»   Ž  s    ÿzPackageIndex.url_okc                 C   s2   t tjj|ƒ}dd„ |D ƒ}tt | j|¡ƒ d S )Nc                 s   s0   | ](}t  |¡D ]}| d ¡r||fV  qqdS )z	.egg-linkN)rW   rÔ   r,   )r[   r?   Úentryr%   r%   r&   r]      s   
ýz.PackageIndex.scan_egg_links.<locals>.<genexpr>)ÚfilterrW   r?   rÒ   rº   Ú	itertoolsÚstarmapÚscan_egg_link)r€   Úsearch_pathÚdirsZ	egg_linksr%   r%   r&   Úscan_egg_linksž  s
    þzPackageIndex.scan_egg_linksc                 C   s†   t tj ||¡ƒ}ttd ttj| 	¡ ƒƒƒ}t
|ƒdkr<d S |\}}ttj ||¡ƒD ]*}tjj|g|¢R Ž |_t|_|  |¡ qVd S )Nr_   )r   rW   r?   rd   rº   rÝ   rq   rr   rs   Ú
splitlinesrR   r
   rL   r   rD   r¯   )r€   r?   rÜ   ÚcontentÚlinesZegg_pathZ
setup_pathr°   r%   r%   r&   rà   ¨  s    zPackageIndex.scan_egg_linkc                 C   s”   d}|  | j¡s|S tttjj|t| jƒd …  d¡ƒƒ}t|ƒdksRd|d v rV|S t	|d ƒ}t
|d ƒ}d| j | ¡ i ¡|< t|ƒt|ƒfS )N)NNr2   r_   r6   r   r   T)r-   r¡   rº   rq   r7   r!   r9   rR   r:   r   r   r¤   Ú
setdefaultr+   r   )r€   rÏ   ZNO_MATCH_SENTINELr<   ÚpkgÚverr%   r%   r&   Ú_scan¸  s    &zPackageIndex._scanc           	   
   C   sÀ   t  |¡D ]:}z"|  tj |t| d¡ƒ¡¡ W q
 tyB   Y q
0 q
|  |¡\}}|s\dS t	||ƒD ]H}t
|ƒ\}}| d¡r¤|s¤|rš|d||f 7 }n
|  |¡ |  |¡ qft dd„ |¡S )z#Process the contents of a PyPI pager   r³   ú.pyz
#egg=%s-%sc                 S   s   d|   ddd¡ S )Nz<a href="%s#md5=%s">%s</a>r   é   r_   )rH   )Úmr%   r%   r&   Ú<lambda>â  r^   z,PackageIndex.process_index.<locals>.<lambda>)rt   rn   rê   r7   r!   ru   rv   rH   r"   r}   rC   r,   Úneed_version_infoÚscan_urlÚPYPI_MD5Úsub)	r€   r;   ry   rG   rè   ré   Únew_urlr/   Úfragr%   r%   r&   rÊ   È  s$    "
ÿzPackageIndex.process_indexc                 C   s   |   d|¡ d S )NzPPage at %s links to .py file(s) without version info; an index scan is required.)Úscan_all©r€   r;   r%   r%   r&   rï   å  s    ýzPackageIndex.need_version_infoc                 G   s<   | j | jvr,|r"| j|g|¢R Ž  |  d¡ |  | j ¡ d S )Nz6Scanning index of all packages (this may take a while))r¡   r£   rÑ   r½   rð   ©r€   r™   rf   r%   r%   r&   rõ   ì  s
    
zPackageIndex.scan_allc                 C   sz   |   | j|j d ¡ | j |j¡s:|   | j|j d ¡ | j |j¡sR|  |¡ t| j |jd¡ƒD ]}|   |¡ qfd S )Nr2   r%   )	rð   r¡   Úunsafe_namer¤   rÃ   ÚkeyrM   Únot_found_in_indexrº   )r€   Úrequirementr;   r%   r%   r&   Úfind_packagesó  s    
zPackageIndex.find_packagesc                    sN   |   ¡  |  |¡ | |j D ]"}||v r0|  S |  d||¡ qtƒ  ||¡S )Nz%s does not match %s)Úprescanrü   rù   r¼   r    Úobtain)r€   rû   Ú	installerr°   r¬   r%   r&   rþ     s    
zPackageIndex.obtainc                 C   sL   |  | jd| ¡ | ¡ sH| ¡  t |¡ td|jjtj	 
|¡f ƒ‚dS )z-
        checker is a ContentChecker
        zValidating %%s checksum for %sz7%s validation failed for %s; possible download problem?N)r‡   r¼   r„   rÄ   rW   Úunlinkr   r�   r.   r?   rS   )r€   ÚcheckerrX   Útfpr%   r%   r&   Ú
check_hash  s    
þÿzPackageIndex.check_hashc                 C   sN   |D ]D}| j du s0t|ƒr0| d¡s0tt|ƒƒr<|  |¡ q| j  |¡ qdS )z;Add `urls` to the list that will be prescanned for searchesNúfile:)r¦   r¸   r-   rº   r   rð   Úappend)r€   Úurlsr;   r%   r%   r&   Úadd_find_links  s    ÿþý
üzPackageIndex.add_find_linksc                 C   s"   | j rtt| j| j ƒƒ d| _ dS )z7Scan urls scheduled for prescanning (e.g. --find-links)N)r¦   rº   rq   rð   rƒ   r%   r%   r&   rý   (  s    zPackageIndex.prescanc                 C   s<   | |j  r| jd }}n| jd }}|||jƒ |  ¡  d S )Nz#Couldn't retrieve index page for %rz3Couldn't find index page for %r (maybe misspelled?))rù   r½   rÑ   rø   rõ   )r€   rû   Úmethr™   r%   r%   r&   rú   .  s    
þzPackageIndex.not_found_in_indexc                 C   sv   t |tƒsbt|ƒ}|rJ|  ||¡}t|ƒ\}}| d¡rF|  |||¡}|S tj 	|¡rZ|S t
|ƒ}t|  ||¡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ë   rL   N)r¿   r   r¸   Ú_download_urlrC   r,   Ú	gen_setuprW   r?   rÐ   r'   rÉ   Úfetch_distribution)r€   r#   Útmpdirr=   Úfoundr/   rB   r%   r%   r&   r4   9  s    

zPackageIndex.downloadc           	         sà   ˆ  d|¡ tƒ ‰d}d
‡ ‡‡‡‡fdd„	}|rJˆ ¡  ˆ |¡ ||ƒ}|s`|dur`|||ƒ}|du r‚ˆjdurzˆ ¡  ||ƒ}|du r |s ˆ |¡ ||ƒ}|du rÂˆ dˆr¶dp¸d|¡ dS ˆ  d|¡ |j|jd	�S d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                    s”   |d u rˆ}|| j  D ]x}|jtkrHˆ sH|ˆvrˆ d|¡ ˆ |¡ q|| v o^|jtkp^ˆ }|rˆ |jˆ¡}||_t	j
 |j¡r|  S qd S )Nz&Skipping development or system egg: %s)rù   rD   r   rÑ   r¯   r   r4   rL   Údownload_locationrW   r?   rÐ   )ÚreqÚenvr°   ÚtestÚloc©Ú
develop_okr€   ZskippedÚsourcer  r%   r&   rw   y  s$    þ

z-PackageIndex.fetch_distribution.<locals>.findz:No local packages or working download links found for %s%sza source distribution of r³   zBest match: %s)rL   )N)r½   rp   rý   rü   r¦   rÑ   Úcloner  )	r€   rû   r  Ú
force_scanr  r  Zlocal_indexr°   rw   r%   r  r&   r  [  s4    




ýzPackageIndex.fetch_distributionc                 C   s"   |   ||||¡}|dur|jS dS )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)r  rL   )r€   rû   r  r  r  r°   r%   r%   r&   Úfetch­  s    zPackageIndex.fetchc           	   	   C   s  t  |¡}|r*dd„ t|| d¡d ƒD ƒp,g }t|ƒdkrötj |¡}tj |¡|krŽtj 	||¡}tj 
|¡r~tj ||¡sŽt ||¡ |}ttj 	|d¡ddd��<}| d|d	 j|d	 jtj |¡d	 f ¡ W d   ƒ n1 sè0    Y  |S |�rtd
||f ƒ‚ntdƒ‚d S )Nc                 S   s   g | ]}|j r|‘qS r%   )rN   )r[   Údr%   r%   r&   Ú
<listcomp>¾  s   þz*PackageIndex.gen_setup.<locals>.<listcomp>r   zsetup.pyÚwzutf-8)ÚencodingzIfrom setuptools import setup
setup(name=%r, version=%r, py_modules=[%r])
r   z†Can't unambiguously interpret project/version identifier %r; any dashes in the name or version should be escaped using underscores. %rzpCan't process plain .py files without an '#egg=name-version' suffix to enable automatic setup script generation.)rF   rG   r   rH   rR   rW   r?   rS   Údirnamerd   rÐ   ÚsamefileÚshutilÚcopy2ÚopenÚwriterM   rN   Úsplitextr   )	r€   rX   rB   r  rG   rÌ   rS   ÚdstrØ   r%   r%   r&   r
  º  sD    
þÿù
ýþÿ"	þÿÿzPackageIndex.gen_setupi    c                 C   s:  |   d|¡ d }�zt |¡}|  |¡}t|tjjƒrLtd||j	|j
f ƒ‚|  ¡ }d}| j}d}d|v r”| d¡}	ttt|	ƒƒ}|  |||||¡ t|dƒ�`}
| |¡}|râ| |¡ |
 |¡ |d7 }|  |||||¡ q qâq |  |||
¡ W d   ƒ n1 �s0    Y  |W |�r"| ¡  S n|�r4| ¡  0 d S )	NzDownloading %szCan't download %s: %s %sr   r3   zcontent-lengthzContent-LengthÚwbr   )r½   rŒ   r–   r¾   r¿   r7   rÀ   rÁ   r   r¶   r™   Údl_blocksizeÚget_allÚmaxrq   ÚintÚ
reporthookr!  rÅ   r‚   r"  r  rÄ   )r€   r;   rX   Úfpr  rÂ   ÚblocknumÚbsÚsizeÚsizesr  r�   r%   r%   r&   Ú_download_toê  sD    

ÿ



.ý ÿzPackageIndex._download_toc                 C   s   d S re   r%   )r€   r;   rX   r,  Zblksizer.  r%   r%   r&   r*    s    zPackageIndex.reporthookc              
   C   s¬  |  d¡rt|ƒS zt|| jƒW S  ttjjfyˆ } zHd dd„ |j	D ƒ¡}|r`|  
||¡ ntd||f ƒ|‚W Y d }~�n(d }~0  tjjy² } z|W  Y d }~S d }~0  tjj�y } z4|rÚ|  
||j¡ ntd||jf ƒ|‚W Y d }~n®d }~0  tjj�yT } z6|�r,|  
||j¡ ntd||jf ƒ|‚W Y d }~n\d }~0  tjjtf�y¦ } z2|�r€|  
||¡ ntd||f ƒ|‚W Y d }~n
d }~0 0 d S )Nr  ú c                 S   s   g | ]}t |ƒ‘qS r%   )rr   )r[   Úargr%   r%   r&   r    r^   z)PackageIndex.open_url.<locals>.<listcomp>z%s %szDownload error for %s: %sz;%s returned a bad status line. The server might be down, %s)r-   Ú
local_openÚopen_with_authr©   r"   ÚhttpÚclientÚ
InvalidURLrd   rf   rÑ   r   r7   rÀ   rÁ   ÚURLErrorÚreasonÚBadStatusLineÚlineÚHTTPExceptionÚOSError)r€   r;   ÚwarningÚvr™   r%   r%   r&   r¾     sB    
(ÿþÿÿýzPackageIndex.open_urlc                 C   sp   t |ƒ\}}|r0d|v r4| dd¡ dd¡}qnd}| d¡rJ|d d… }tj ||¡}|  ||¡pn|  ||¡S )Nz..Ú.ú\Ú_Z__downloaded__rJ   r*   )rC   Úreplacer,   rW   r?   rd   Ú_download_vcsÚ_download_other)r€   r;   r  r.   rB   rX   r%   r%   r&   r	  4  s    
zPackageIndex._download_urlc                 C   sL   t j | ¡j}| d¡\}}}tddgdgt|ƒ  ƒ}tt|h|@ ƒ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)	r7   r!   Úurlsplitr=   Ú	partitionrp   ÚboolÚnextÚiter)r;   r=   ÚpreÚsepÚpostÚallowedr%   r%   r&   Ú_resolve_vcsE  s    zPackageIndex._resolve_vcsc              
   C   sÈ   |   |¡}|sd S |dkr(td|› �ƒ‚| d¡\}}}|  |¡\}}|  d|› d|› d|› �¡ t |dd||g¡ t|d	|d
d|g|d|dd	d|dgd�}|d urÄ|  d|› �¡ t || ¡ |S )NrG  z/Invalid config, SVN download is not supported: r6   zDoing z clone from z to r  z--quietz-CÚcheckoutz--cwdÚupz-rz-q)rH  rI  zChecking out )rS  r   rK  Ú_vcs_split_rev_from_urlr½   Ú
subprocessÚ
check_callÚdict)r€   r;   Zspec_filenameÚvcsrX   rB  ÚrevZco_commandsr%   r%   r&   rD  X  s&    
ÿþzPackageIndex._download_vcsc                 C   sD   t j |¡j}|dkr,t j t j |¡j¡S |  |d¡ |  	||¡S )NrØ   T)
r7   r!   rJ  r=   r§   Úurl2pathnamer8   r?   r»   Ú_attempt_download)r€   r;   rX   r=   r%   r%   r&   rE  q  s
    zPackageIndex._download_otherc                 C   s   |   |d¡ d S )NT)rÈ   rö   r%   r%   r&   rð   y  s    zPackageIndex.scan_urlc                 C   s6   |   ||¡}d| dd¡ ¡ v r.|  |||¡S |S d S )Nr±   r²   r³   )r0  rÃ   r+   Ú_invalid_download_html)r€   r;   rX   rÂ   r%   r%   r&   r]  |  s    zPackageIndex._attempt_downloadc                 C   s   t  |¡ td|› �ƒ‚d S )NzUnexpected HTML page found at )rW   r   r   )r€   r;   rÂ   rX   r%   r%   r&   r^  ƒ  s    
z#PackageIndex._invalid_download_htmlc                 C   st   t j | ¡}|j dd¡d }|j d¡\}}}| d¡\}}}|rL||fn|df\}}	|j||dd� 	¡ }
|
|	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)
        rF  r   r3   r6   ú@Nr³   )r=   r?   rB   )
r7   r!   rJ  r=   r:   r?   rK  Ú
rpartitionÚ_replaceÚgeturl)r;   r<   Zclean_schemeZno_fragment_pathrB  rO  rP  rQ  Z
clean_pathr[  Zresolvedr%   r%   r&   rV  ‡  s    ü
z$PackageIndex._vcs_split_rev_from_urlc                 G   s   t j|g|¢R Ž  d S re   )r   r¼   r÷   r%   r%   r&   r¼   §  s    zPackageIndex.debugc                 G   s   t j|g|¢R Ž  d S re   )r   r½   r÷   r%   r%   r&   r½   ª  s    zPackageIndex.infoc                 G   s   t j|g|¢R Ž  d S re   )r   rÑ   r÷   r%   r%   r&   rÑ   ­  s    zPackageIndex.warn)rœ   r�   NT)F)F)F)N)N)FFFN)FF)N)*rˆ   r‰   rŠ   r‹   r’   r¯   rÈ   r¹   r»   rã   rà   rê   rÊ   rï   rõ   rü   rþ   r  r  rý   rú   r4   r  r  r
  r&  r0  r*  r¾   r	  ÚstaticmethodrS  rD  rE  rð   r]  r^  rV  r¼   r½   rÑ   Ú__classcell__r%   r%   r¬   r&   r   +  s^       û	
5



	&    ù
R
.$
"

r   z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c                 C   s   |   d¡}t |¡S )Nr   )rH   r±   Úunescape)rG   Úwhatr%   r%   r&   Údecode_entity¶  s    
rg  c                 C   s
   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_subrg  )Útextr%   r%   r&   rv   »  s    	rv   c                    s   ‡ fdd„}|S )Nc                    s   ‡ ‡fdd„}|S )Nc               	      s>   t  ¡ }t  ˆ¡ zˆ | i |¤ŽW t  |¡ S t  |¡ 0 d S re   )ÚsocketÚgetdefaulttimeoutÚsetdefaulttimeout)rf   rg   Zold_timeout)ri   Útimeoutr%   r&   Ú_socket_timeoutÉ  s    

þz@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeoutr%   )ri   rn  ©rm  rh   r&   rn  È  s    z'socket_timeout.<locals>._socket_timeoutr%   )rm  rn  r%   ro  r&   Úsocket_timeoutÇ  s    rp  c                 C   s2   t j | ¡}| ¡ }t |¡}| ¡ }| 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³   )r7   r!   r9   ÚencodeÚbase64Ú	b64encoderÇ   rC  )ÚauthZauth_sZ
auth_bytesZencoded_bytesÚencodedr%   r%   r&   Ú_encode_authÖ  s
    
rw  c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú
Credentialz:
    A username/password pair. Use like a namedtuple.
    c                 C   s   || _ || _d S re   ©ÚusernameÚpassword)r€   rz  r{  r%   r%   r&   r’   ð  s    zCredential.__init__c                 c   s   | j V  | jV  d S re   ry  rƒ   r%   r%   r&   Ú__iter__ô  s    zCredential.__iter__c                 C   s   dt | ƒ S )Nz%(username)s:%(password)s)Úvarsrƒ   r%   r%   r&   Ú__str__ø  s    zCredential.__str__N)rˆ   r‰   rŠ   r‹   r’   r|  r~  r%   r%   r%   r&   rx  ë  s   rx  c                       s8   e Zd Z‡ fdd„Zedd„ ƒZdd„ Zdd„ Z‡  ZS )	Ú
PyPIConfigc                    sL   t  g d¢d¡}tƒ  |¡ tj tj d¡d¡}tj |¡rHt	| |ƒ dS )z%
        Load from ~/.pypirc
        )rz  r{  Ú
repositoryr³   ú~z.pypircN)
rY  Úfromkeysr    r’   rW   r?   rd   Ú
expanduserrÐ   r   )r€   ÚdefaultsÚrcr¬   r%   r&   r’   ý  s
    zPyPIConfig.__init__c                    s&   ‡ fdd„ˆ   ¡ D ƒ}ttˆ j|ƒƒS )Nc                    s    g | ]}ˆ   |d ¡ ¡ r|‘qS )r€  )rÃ   rs   )r[   Úsectionrƒ   r%   r&   r  
  s   þz2PyPIConfig.creds_by_repository.<locals>.<listcomp>)ÚsectionsrY  rq   Ú_get_repo_cred)r€   Zsections_with_repositoriesr%   rƒ   r&   Úcreds_by_repository  s    
þzPyPIConfig.creds_by_repositoryc                 C   s6   |   |d¡ ¡ }|t|   |d¡ ¡ |   |d¡ ¡ ƒfS )Nr€  rz  r{  )rÃ   rs   rx  )r€   r†  Úrepor%   r%   r&   rˆ    s
    þzPyPIConfig._get_repo_credc                 C   s*   | j  ¡ D ]\}}| |¡r
|  S q
dS )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€  Úcredr%   r%   r&   Úfind_credential  s    

zPyPIConfig.find_credential)	rˆ   r‰   rŠ   r’   Úpropertyr‰  rˆ  r�  rd  r%   r%   r¬   r&   r  ü  s
   
	r  c                 C   s@  t j | ¡}|\}}}}}}| d¡r2tj d¡‚|dv rHt|ƒ\}	}
nd}	|	s„tƒ  	| ¡}|r„t
|ƒ}	|j| f}tjdg|¢R Ž  |	rÊdt|	ƒ }	||
||||f}t j |¡}t j |¡}| d|	¡ nt j | ¡}| dt¡ ||ƒ}|	�r<t j |j¡\}}}}}}||k�r<||
k�r<||||||f}t j |¡|_|S )	z4Open a urllib2 request, handling HTTP authenticationú:znonnumeric port: '')r5  ÚhttpsNz*Authenticating as %s for %s (from .pypirc)zBasic ÚAuthorizationz
User-Agent)r7   r!   r8   r,   r5  r6  r7  Ú
_splituserr  r�  rr   rz  r   r½   rw  Ú
urlunparser§   ÚRequestÚ
add_headerÚ
user_agentr;   )r;   r©   Úparsedr=   Únetlocr?   ÚparamsrA   rô   ru  ÚaddressrŒ  r½   r<   ró   r§   r+  Ús2Zh2Zpath2Zparam2Zquery2Zfrag2r%   r%   r&   r4  $  s8    

r4  c                 C   s    |   d¡\}}} |r|nd| fS )zNsplituser('user[:passwd]@host[:port]')
    --> 'user[:passwd]', 'host[:port]'.r_  N)r`  )ÚhostÚuserÚdelimr%   r%   r&   r’  S  s    r’  c                 C   s   | S re   r%   )r;   r%   r%   r&   Ú
fix_sf_url^  s    rŸ  c                 C   s  t j | ¡\}}}}}}t j |¡}tj |¡r<t j | ¡S | 	d¡rÒtj 
|¡rÒg }t |¡D ]N}	tj ||	¡}
|	dkrˆt|
ƒ} qÈntj 
|
¡rœ|	d7 }	| dj|	d�¡ q`d}|j| d |¡d�}d\}}n
d	\}}}d
di}t |¡}t j | ||||¡S )z7Read a local path, with special support for directoriesr2   z
index.htmlz<a href="{name}">{name}</a>)r.   zB<html><head><title>{url}</title></head><body>{files}</body></html>rq  )r;   Úfiles)éÈ   ÚOK)r·   zPath not foundz	Not foundr²   z	text/html)r7   r!   r8   r§   r\  rW   r?   Úisfiler¨   r,   rÒ   rÔ   rd   r   r  ÚformatÚioÚStringIOrÀ   rÁ   )r;   r=   r>   r?   ÚparamrA   rô   rX   r   rÎ   ÚfilepathÚbodyrÍ   ÚstatusÚmessagerÂ   Zbody_streamr%   r%   r&   r3  b  s*    


r3  )N)N)N)r   )]r‹   ÚsysrW  rW   rZ   r¥  r  rj  rs  rŽ   rÞ   Úconfigparserr±   Úhttp.clientr5  Úurllib.parser7   Ú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   Zsetuptools.wheelr   Z setuptools.extern.more_itertoolsr   Zunicode_utilsr   r   rš   rF   ÚIrt   rñ   rG   r¸   r:   rQ   Ú__all__Z_SOCKET_TIMEOUTZ_tmplr¤  Úversion_infor–  r'   r   rC   r   rE   rY   r   rk   rm   r}   r~   rŒ   r   rò   rh  rg  rv   rp  rw  rx  ÚRawConfigParserr  r§   r¨   r4  r’  rŸ  r3  r%   r%   r%   r&   Ú<module>   sŒ   @
ÿÿ	

#
ÿ
"
!     
(/