a
   Œ%£Ý_ÿã                   @   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# 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 .d
¡Z/e .dej0¡Z1e .d¡Z2e .dej0¡j3Z4d 5¡ Z6g d¢Z7dZ8dZ9e9j:dj:ej;Ž edZ<dd„ Z=dd„ Z>dd„ Z?dBdd„Z@dCdd„ZAdDdd„ZBdedfd d!„ZCd"d#„ ZDe .d$ej0¡ZEeDd%d&„ ƒZFG d'd(„ d(ƒZGG d)d*„ d*eGƒZHG d+d,„ d,eƒZIe .d-¡jJZKd.d/„ ZLd0d1„ ZMdEd2d3„ZNd4d5„ ZOG d6d7„ d7ƒZPG d8d9„ d9ejQƒZRejSjTfd:d;„ZUd<d=„ ZVeNe8ƒeUƒZUd>d?„ ZWd@dA„ ZXdS )Fz#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)Ú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{}.{})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!   ú</usr/lib/python3.9/site-packages/setuptools/package_index.pyÚparse_requirement_arg6   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_verZplatr!   r!   r"   r   ?   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éþÿÿÿú#é   )Úurllibr   ÚurlparseÚunquoteÚsplit)	ÚurlÚpartsÚschemeÚserverÚpathÚ
parametersÚqueryÚfragmentr+   r!   r!   r"   Úegg_info_for_urlW   s    r?   c                 c   s\   t | ƒ\}}t| ||ƒD ]
}|V  q|rXt |¡}|rXt| | d¡|tdD ]
}|V  qLdS )zEYield egg or source distribution objects that might be found at a URLr2   )Ú
precedenceN)r?   Údistros_for_locationÚEGG_FRAGMENTÚmatchr   Úgroupr   )r7   Úmetadatar+   r>   ÚdistrC   r!   r!   r"   r   b   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.whlr2   )ÚlocationÚproject_nameÚversionr@   r$   )r(   r   Zfrom_locationr   Zis_compatiblerJ   rK   r   r   r   r   Ú
EXTENSIONSÚlen)rI   ÚbasenamerE   ZwheelZwin_baser,   ÚplatformÚextr!   r!   r"   rA   p   s2    
û
ÿ
rA   c                 C   s   t t| ƒtj | ¡|ƒS )zEYield possible egg or source distribution objects based on a filename)rA   r   Úosr;   rN   )ÚfilenamerE   r!   r!   r"   Údistros_for_filename‘   s    ÿrS   c              
   c   s|   |  d¡}|s,tdd„ |dd… D ƒƒr,dS tdt|ƒd ƒD ]8}t| |d |d|… ¡d ||d… ¡|||dV  q>dS )zØGenerate alternative interpretations 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!
    rH   c                 s   s   | ]}t  d |¡V  qdS )z	py\d\.\d$N)ÚrerC   )Ú.0Úpr!   r!   r"   Ú	<genexpr>¯   ó    z(interpret_distro_name.<locals>.<genexpr>é   Nr2   )Ú
py_versionr@   rO   )r6   ÚanyÚrangerM   r   Újoin)rI   rN   rE   rZ   r@   rO   r8   rV   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   )rb   rc   r!   ra   r"   Úunique_values»   s    rd   z(<([^>]*\srel\s*=\s*['"]?([^'">]+)[^>]*)>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homepager/   r2   )z<th>Home Pagez<th>Download URLr.   N)ÚRELÚfinditerÚgroupsÚsetÚmapÚstrÚstripr'   r6   ÚHREFr3   r   ÚurljoinÚ
htmldecoderD   ÚfindÚsearch)r7   ÚpagerC   ÚtagÚrelZrelsÚposr!   r!   r"   Úfind_external_linksÌ   s    
rv   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!   ©ry   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!   )ry   ÚreporterÚtemplater!   r!   r"   Úreportð   s    zContentChecker.reportN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r{   r}   r€   r!   r!   r!   r"   rw   ß   s   rw   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 r^   )Ú	hash_nameÚhashlibÚnewÚhashÚexpected)ry   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 URLr.   )r3   r   r4   rw   Úpatternrq   Ú	groupdict)Úclsr7   r>   rC   r!   r!   r"   Úfrom_url  s    zHashChecker.from_urlc                 C   s   | j  |¡ d S r^   )r‰   Úupdaterx   r!   r!   r"   r{     s    zHashChecker.feedc                 C   s   | j  ¡ | jkS r^   )r‰   Z	hexdigestrŠ   r|   r!   r!   r"   r}     s    zHashChecker.is_validc                 C   s   || j  }||ƒS r^   )r†   )ry   r~   r   Úmsgr!   r!   r"   r€     s    
zHashChecker.reportN)r   r‚   rƒ   rT   ÚcompilerŒ   r‹   Úclassmethodr   r{   r}   r€   r!   r!   r!   r"   r…   ø   s   ÿ

r…   c                       sD  e Zd ZdZdLdd„ZdMd	d
„ZdNdd„ZdOdd„Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdPdd„Zdd„ ZdQ‡ fdd„	Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ ZdRd)d*„ZdSd+d,„Zd-d.„ Zd/Zd0d1„ Zd2d3„ ZdTd4d5„Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Zd>d?„ Z e!dUd@dA„ƒZ"dBdC„ Z#dDdE„ Z$dFdG„ Z%dHdI„ Z&dJdK„ Z'‡  Z(S )Vr   z;A distribution index that scans web pages for download URLsúhttps://pypi.org/simple/©Ú*NTc                 O   sr   t j| g|¢R i |¤Ž |dd | d¡ …  | _i | _i | _i | _t d 	t
t|ƒ¡¡j| _g | _tjj| _d S )Nr-   ú|)r	   r‹   r(   Ú	index_urlÚscanned_urlsÚfetched_urlsÚpackage_pagesrT   r’   r]   rj   r   rC   ÚallowsÚto_scanr3   ÚrequestÚurlopenÚopener)ry   r˜   ZhostsZ	ca_bundleZ
verify_sslr_   Úkwr!   r!   r"   r‹     s    zPackageIndex.__init__Fc                 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Úignorer2   Úcodeé”  )&r™   Ú
URL_SCHEMEÚprocess_filenameÚlistr   Úurl_okÚdebugrš   rj   ÚaddÚinfoÚopen_urlÚ
isinstancer3   ÚerrorÚ	HTTPErrorr§   r‘   r7   ÚheadersÚgetr'   ÚcloseÚreadrk   Z	get_paramÚdecoderm   rg   r   rn   ro   rD   Úprocess_urlr)   r˜   ÚgetattrÚprocess_index)ry   r7   ZretrieveÚdistsÚtmplÚfr+   rr   r¥   rC   Úlinkr!   r!   r"   r¹   *  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)rQ   r;   ÚexistsÚwarnÚisdirÚrealpathÚlistdirrª   r]   rS   r­   r«   rj   r®   )ry   ÚfnÚnestedr;   Úitemr¼   r!   r!   r"   rª   _  s    zPackageIndex.process_filenamec                 C   sb   t |ƒ}|o| d¡ ¡ dk}|s8|  tj |¡d ¡r<dS d}|rRt|| ƒ‚n|  ||¡ d S )Nr2   ÚfileTzN
Note: Bypassing %s (disallowed host; see http://bit.ly/2hrImnY for details).
)	r©   rD   r'   rœ   r3   r   r4   r   rÁ   )ry   r7   ZfatalÚsÚis_filer‘   r!   r!   r"   r¬   o  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)rQ   rÄ   r(   )rU   r;   Úentryr!   r!   r"   rW   ~  s   
ýz.PackageIndex.scan_egg_links.<locals>.<genexpr>)ÚfilterrQ   r;   rÂ   r«   Ú	itertoolsÚstarmapÚscan_egg_link)ry   Ú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|ƒƒƒ}W d   ƒ n1 s>0    Y  t	|ƒdkrXd S |\}}t
tj ||¡ƒD ]*}tjj|g|¢R Ž |_t|_|  |¡ qrd S )NrY   )ÚopenrQ   r;   r]   r«   rÌ   rj   rk   rl   rM   r
   rI   r   r@   r®   )ry   r;   rË   Z	raw_linesÚlinesZegg_pathZ
setup_pathrF   r!   r!   r"   rÏ   †  s    4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)NNr-   rY   r1   r2   r   T)r)   r˜   r«   rj   r3   r   r5   rM   r6   r   r   r›   Ú
setdefaultr'   r   )ry   r¿   ZNO_MATCH_SENTINELr8   Ú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 pager2   r¤   ú.pyz
#egg=%s-%sc                 S   s   d|   ddd¡ S )Nz<a href="%s#md5=%s">%s</a>r2   é   rY   )rD   )Úmr!   r!   r"   Ú<lambda>Â  rX   z,PackageIndex.process_index.<locals>.<lambda>)rm   rg   rØ   r3   r   rn   ro   rD   r   rv   r?   r(   Úneed_version_infoÚscan_urlÚPYPI_MD5Úsub)	ry   r7   rr   rC   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©ry   r7   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Þ   ©ry   r‘   r_   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 )Nr-   r!   )	rÞ   r˜   Úunsafe_namer›   rµ   ÚkeyrJ   Únot_found_in_indexr«   )ry   Úrequirementr7   r!   r!   r"   Úfind_packagesÔ  s    
zPackageIndex.find_packagesc                    sR   |   ¡  |  |¡ | |j D ]"}||v r0|  S |  d||¡ qtt| ƒ ||¡S )Nz%s does not match %s)Úprescanrê   rç   r­   Úsuperr   Úobtain)ry   ré   Z	installerrF   ©Ú	__class__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¶   rQ   Úunlinkr   r‰   r*   r;   rN   )ry   ÚcheckerrR   Ú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)ry   Zurlsr7   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«   rj   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ã   )ry   ré   Úmethr‘   r!   r!   r"   rè     s    
þzPackageIndex.not_found_in_indexc                 C   s~   t |tƒsjt|ƒ}|rR|  | d¡||¡}t|ƒ\}}| d¡rN|  |||¡}|S tj	 
|¡rb|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.
        r2   rÙ   rI   N)r±   r   r©   Ú_download_urlrD   r?   r(   Ú	gen_setuprQ   r;   rÀ   r#   rº   Úfetch_distribution)ry   r   Útmpdirr9   Úfoundr+   r>   r!   r!   r"   r/     s    

zPackageIndex.downloadc           	         sÜ   ˆ  d|¡ i ‰d}d
‡ ‡‡‡‡fdd„	}|rHˆ ¡  ˆ |¡ ||ƒ}|s^|dur^|||ƒ}|du r€ˆjdurxˆ ¡  ||ƒ}|du rž|sžˆ |¡ ||ƒ}|du r¾ˆ dˆr´dp¶d|¡ nˆ  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 ]v}|jtkrFˆ sF|ˆvrˆ d|¡ dˆ|< q|| v o\|jtkp\ˆ }|rˆ |jˆ¡}||_tj	 
|j¡r|  S qd S )Nz&Skipping development or system egg: %sr2   )rç   r@   r   rÁ   r   r/   rI   Údownload_locationrQ   r;   rÀ   )ZreqÚenvrF   ÚtestÚloc©Ú
develop_okry   ZskippedÚsourcerû   r!   r"   rp   U  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)rI   )N)r¯   rë   rê   r   rÁ   Zclonerý   )	ry   ré   rû   Ú
force_scanr  r  Zlocal_indexrF   rp   r!   r  r"   rú   =  s2    




ý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ú   rI   )ry   ré   rû   r  r  rF   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 	||¡}ddl
m} |||ƒsŠt ||¡ |}ttj 	|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!   )rK   )rU   Údr!   r!   r"   Ú
<listcomp>˜  s   ÿz*PackageIndex.gen_setup.<locals>.<listcomp>r2   r   )Úsamefilezsetup.pyÚwzIfrom setuptools import setup
setup(name=%r, version=%r, py_modules=[%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.)rB   rC   r   rD   rM   rQ   r;   rN   Údirnamer]   Zsetuptools.command.easy_installr  ÚshutilÚcopy2rÓ   ÚwriterJ   rK   Úsplitextr   )
ry   rR   r>   rû   rC   r¼   rN   Údstr  rÈ   r!   r!   r"   rù   –  s@    

þý
þþÿ"þÿÿ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   r.   zcontent-lengthzContent-LengthÚwbr2   )r¯   r…   r   r°   r±   r3   r²   r³   r   r§   r‘   Údl_blocksizeZget_allÚmaxrj   ÚintÚ
reporthookrÓ   r·   r{   r  ró   r¶   )ry   r7   rR   Úfprñ   r´   ÚblocknumÚbsÚsizeZsizesrò   rz   r!   r!   r"   Ú_download_toÁ  sD    

ÿ



.ý ÿzPackageIndex._download_toc                 C   s   d S r^   r!   )ry   r7   rR   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j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!   )rk   )rU   Úargr!   r!   r"   r  ï  rX   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Ú
InvalidURLr]   r_   rÁ   r   r3   r²   r³   ZURLErrorÚreasonZBadStatusLineÚlineZHTTPExceptionÚsocket)ry   r7   ZwarningÚvr‘   r!   r!   r"   r°   é  sJ    
(ÿÿþÿüÿÿzPackageIndex.open_urlc                 C   sæ   t |ƒ\}}|r0d|v r4| dd¡ dd¡}qnd}| d¡rJ|d d… }tj ||¡}|dksj| d	¡rv|  ||¡S |d
ksˆ| d¡r”|  ||¡S | d¡rª|  	||¡S |dkrÊt
j t
j |¡d ¡S |  |d¡ |  ||¡S d S )Nz..Ú.ú\Ú_Z__downloaded__rG   r&   Úsvnzsvn+Úgitzgit+zhg+rÈ   rY   T)r?   Úreplacer(   rQ   r;   r]   r)   Ú_download_svnÚ_download_gitÚ_download_hgr3   rž   Úurl2pathnamer   r4   r¬   Ú_attempt_download)ry   r9   r7   rû   r*   r>   rR   r!   r!   r"   rø     s$    

zPackageIndex._download_urlc                 C   s   |   |d¡ d S )NT)r¹   rä   r!   r!   r"   rÞ   )  s    zPackageIndex.scan_urlc                 C   s6   |   ||¡}d| dd¡ ¡ v r.|  |||¡S |S d S )Nr¢   r£   r¤   )r  rµ   r'   Ú_download_html)ry   r7   rR   r´   r!   r!   r"   r/  ,  s    zPackageIndex._attempt_downloadc                 C   sn   t |ƒ}|D ]>}| ¡ rt d|¡rF| ¡  t |¡ |  ||¡  S  qLq| ¡  t |¡ td| ƒ‚d S )Nz <title>([^- ]+ - )?Revision \d+:zUnexpected HTML page found at )	rÓ   rl   rT   rq   r¶   rQ   rð   r+  r   )ry   r7   r´   rR   rÈ   r"  r!   r!   r"   r0  3  s    

zPackageIndex._download_htmlc                 C   s  t  dt¡ | dd¡d }d}| ¡  d¡râd|v râtj |¡\}}}}}}	|sâ| d¡râd	|d
d … v râ|d
d …  d	d¡\}}t	|ƒ\}
}|
râd|
v rº|
 dd¡\}}d||f }nd|
 }|}||||||	f}tj 
|¡}|  d||¡ t d|||f ¡ |S )Nz"SVN download support is deprecatedr1   r2   r   r¤   zsvn:ú@z//r-   rY   ú:z --username=%s --password=%sz --username=z'Doing subversion checkout from %s to %szsvn checkout%s -q %s %s)ÚwarningsrÁ   ÚUserWarningr6   r'   r)   r3   r   r4   Ú
_splituserÚ
urlunparser¯   rQ   Úsystem)ry   r7   rR   Zcredsr9   Únetlocr;   rV   Úqr¾   ÚauthÚhostÚuserZpwr8   r!   r!   r"   r+  B  s&    zPackageIndex._download_svnc                 C   sp   t j | ¡\}}}}}| dd¡d }| dd¡d }d }d|v rR| dd¡\}}t j ||||df¡} | |fS )Nú+r2   r.   r1   r   r1  r¤   )r3   r   Úurlsplitr6   ÚrsplitÚ
urlunsplit)r7   Ú
pop_prefixr9   r8  r;   r=   râ   Úrevr!   r!   r"   Ú_vcs_split_rev_from_urlX  s    z$PackageIndex._vcs_split_rev_from_urlc                 C   sl   |  dd¡d }| j|dd\}}|  d||¡ t d||f ¡ |d urh|  d|¡ t d	||f ¡ |S )
Nr1   r2   r   T©rA  zDoing git clone from %s to %szgit clone --quiet %s %szChecking out %szgit -C %s checkout --quiet %s©r6   rC  r¯   rQ   r7  ©ry   r7   rR   rB  r!   r!   r"   r,  j  s    þzPackageIndex._download_gitc                 C   sl   |  dd¡d }| j|dd\}}|  d||¡ t d||f ¡ |d urh|  d|¡ t d	||f ¡ |S )
Nr1   r2   r   TrD  zDoing hg clone from %s to %szhg clone --quiet %s %szUpdating to %szhg --cwd %s up -C -r %s -qrE  rF  r!   r!   r"   r-  z  s    þzPackageIndex._download_hgc                 G   s   t j|g|¢R Ž  d S r^   )r   r­   rå   r!   r!   r"   r­   Š  s    zPackageIndex.debugc                 G   s   t j|g|¢R Ž  d S r^   )r   r¯   rå   r!   r!   r"   r¯     s    zPackageIndex.infoc                 G   s   t j|g|¢R Ž  d S r^   )r   rÁ   rå   r!   r!   r"   rÁ     s    zPackageIndex.warn)r”   r•   NT)F)F)F)N)N)FFFN)FF)N)F))r   r‚   rƒ   r„   r‹   r¹   rª   r¬   rÒ   rÏ   rØ   r»   rÝ   rã   rê   rí   ró   rö   rë   rè   r/   rú   r  rù   r  r  r  r°   rø   rÞ   r/  r0  r+  ÚstaticmethodrC  r,  r-  r­   r¯   rÁ   Ú__classcell__r!   r!   rî   r"   r     sR     þ

5



		
#  þ
L
)$
#r   z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c                 C   s   |   d¡}t |¡S )Nr   )rD   r¢   Zunescape)rC   Zwhatr!   r!   r"   Údecode_entity™  s    
rI  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_subrI  )Útextr!   r!   r"   ro   ž  s    	ro   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 r^   )r#  ZgetdefaulttimeoutZsetdefaulttimeout)r_   r`   Zold_timeout)rb   Útimeoutr!   r"   Ú_socket_timeout¬  s    

þz@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeoutr!   )rb   rM  ©rL  ra   r"   rM  «  s    z'socket_timeout.<locals>._socket_timeoutr!   )rL  rM  r!   rN  r"   Úsocket_timeoutª  s    rO  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¤   )r3   r   r5   ÚencodeÚbase64Z	b64encoder¸   r*  )r:  Zauth_sZ
auth_bytesZencoded_bytesZencodedr!   r!   r"   Ú_encode_auth¹  s
    
rS  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 r^   ©ÚusernameÚpassword)ry   rV  rW  r!   r!   r"   r‹   Ó  s    zCredential.__init__c                 c   s   | j V  | jV  d S r^   rU  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‹   rX  rZ  r!   r!   r!   r"   rT  Î  s   rT  c                   @   s0   e Zd Zdd„ Zedd„ ƒZdd„ Zdd„ Zd	S )
Ú
PyPIConfigc                 C   sN   t  g d¢d¡}tj | |¡ tj tj d¡d¡}tj 	|¡rJ|  
|¡ dS )z%
        Load from ~/.pypirc
        )rV  rW  Ú
repositoryr¤   ú~z.pypircN)ÚdictÚfromkeysÚconfigparserÚRawConfigParserr‹   rQ   r;   r]   Ú
expanduserrÀ   r·   )ry   Ú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µ   rl   )rU   Úsectionr|   r!   r"   r  í  s   ÿz2PyPIConfig.creds_by_repository.<locals>.<listcomp>)Zsectionsr^  rj   Ú_get_repo_cred)ry   Zsections_with_repositoriesr!   r|   r"   Úcreds_by_repositoryë  s    
ÿzPyPIConfig.creds_by_repositoryc                 C   s6   |   |d¡ ¡ }|t|   |d¡ ¡ |   |d¡ ¡ ƒfS )Nr\  rV  rW  )rµ   rl   rT  )ry   re  Zrepor!   r!   r"   rf  ô  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)rg  Úitemsr)   )ry   r7   r\  Úcredr!   r!   r"   Úfind_credentialû  s    
zPyPIConfig.find_credentialN)r   r‚   rƒ   r‹   Úpropertyrg  rf  rj  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 authenticationr2  znonnumeric port: '')r  ÚhttpsNz*Authenticating as %s for %s (from .pypirc)zBasic ZAuthorizationz
User-Agent)r3   r   r4   r(   r  r  r   r5  r[  rj  rk   rV  r   r¯   rS  r6  rž   ZRequestZ
add_headerÚ
user_agentr7   )r7   r    Úparsedr9   r8  r;   Úparamsr=   râ   r:  Zaddressri  r¯   r8   rá   rž   r  Ús2Zh2Zpath2Zparam2Zquery2Zfrag2r!   r!   r"   r    s8    

r  c                 C   s    |   d¡\}}} |r|nd| fS )zNsplituser('user[:passwd]@host[:port]')
    --> 'user[:passwd]', 'host[:port]'.r1  N)Ú
rpartition)r;  r<  Údelimr!   r!   r"   r5  4  s    r5  c                 C   s   | S r^   r!   )r7   r!   r!   r"   Ú
fix_sf_url?  s    rs  c              	   C   s,  t j | ¡\}}}}}}t j |¡}tj |¡r<t j | ¡S | 	d¡rütj 
|¡rüg }t |¡D ]x}	tj ||	¡}
|	dkr²t|
dƒ}| ¡ }W d  ƒ n1 s¢0    Y   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 directoriesr-   z
index.htmlÚrNz<a href="{name}">{name}</a>)r*   zB<html><head><title>{url}</title></head><body>{files}</body></html>rP  )r7   Úfiles)éÈ   ZOK)r¨   zPath not foundz	Not foundr£   z	text/html)r3   r   r4   rž   r.  rQ   r;   ÚisfilerŸ   r(   rÂ   rÄ   r]   rÓ   r·   rõ   ÚformatÚioÚStringIOr²   r³   )r7   r9   r:   r;   Zparamr=   râ   rR   ru  r¾   Úfilepathr  Úbodyr½   ÚstatusÚmessager´   Zbody_streamr!   r!   r"   r  C  s.    &ÿ


r  )N)N)N)r   )Yr„   ÚsysrQ   rT   ry  r  r#  rR  r‡   rÍ   r3  r`  r¢   Zhttp.clientr  Úurllib.parser3   Zurllib.requestZurllib.errorÚ	functoolsr   r   Zpkg_resourcesr   r   r   r   r   r	   r
   r   r   r   r   r   r   Z	distutilsr   Zdistutils.errorsr   Úfnmatchr   Zsetuptools.wheelr   Z setuptools.extern.more_itertoolsr   r’   rB   ÚIrm   rß   rC   r©   r6   rL   Ú__all__Z_SOCKET_TIMEOUTZ_tmplrx  Úversion_inform  r#   r   r?   r   rA   rS   r   rd   rf   rv   rw   r…   r   rà   rJ  rI  ro   rO  rS  rT  ra  r[  rž   rŸ   r  r5  rs  r  r!   r!   r!   r"   Ú<module>   sŒ   <
ÿÿ	

!
þ
#
!     
&/