B
    ©»ˆd œ  ã               @   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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.m/Z/ e 0d¡Z1e 0dej2¡Z3e 0d¡Z4e 0dej2¡j5Z6d 7¡ Z8ddddgZ9dZ:dZ;e;j<dj<ej=Ž edZ>dd„ Z?dd„ Z@dd„ ZAdBdd„ZBdCdd„ZCdDd d!„ZDdedfd"d„ZEd#d$„ ZFe 0d%ej2¡ZGeFd&d'„ ƒZHG d(d)„ d)ƒZIG d*d+„ d+eIƒZJG d,d„ deƒZKe 0d-¡jLZMd.d/„ ZNd0d1„ ZOdEd2d3„ZPd4d5„ ZQG d6d7„ d7ƒZRG d8d9„ d9e
jSƒZTejUjVfd:d;„ZWd<d=„ ZXePe:ƒeWƒZWd>d?„ ZYd@dA„ ZZd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Úparse_version)Úlog)ÚDistutilsError)Ú	translate)ÚWheel)Úunique_everseen)ÚSetuptoolsDeprecationWarningz^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   sB   y
t  | ¡S  tk
r< } ztd| f ƒ|‚W d d }~X Y nX d S )Nz1Not a URL, existing file, or requirement spec: %r)r   ÚparseÚ
ValueErrorr   )ÚspecÚe© r!   úJ/var/www/html/venv/lib/python3.7/site-packages/setuptools/package_index.pyÚparse_requirement_argE   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)NNNz.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   N   s$    



c       	      C   sx   t j | ¡}|\}}}}}}t j | d¡d ¡}|dkrX|dkrXt j | d¡d ¡}d|k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_urlf   s    r?   c             c   sd   t | ƒ\}}xt| ||ƒD ]
}|V  qW |r`t |¡}|r`x$t| | d¡|tdD ]
}|V  qRW d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   q   s    

c             C   sä   |  d¡r|dd… }|  d¡r8d|kr8t | ||¡gS |  d¡rxd|krxt|ƒ}| ¡ s^g S t| |j|jtd dgS |  d	¡rªt|ƒ\}}}|dk	rªt	| |||t
|ƒS x4tD ],}|  |¡r°|dt|ƒ … }t	| ||ƒS q°W g S )
z:Yield egg or source distribution objects based on basenamez.egg.zipNr%   z.eggú-z.whlr2   )ÚlocationÚproject_nameÚversionr@   z.exe)r'   r   Úfrom_locationr   Úis_compatiblerI   rJ   r   r   r   r   Ú
EXTENSIONSÚlen)rH   ÚbasenamerE   ÚwheelZwin_baser+   ÚplatformÚextr!   r!   r"   rA      s.    



rA   c             C   s   t t| ƒtj | ¡|ƒS )zEYield possible egg or source distribution objects based on a filename)rA   r   Úosr;   rO   )ÚfilenamerE   r!   r!   r"   Údistros_for_filename¢   s    rU   c          	   c   s˜   |  d¡}|s,tdd„ |dd… D ƒƒr,dS x2tt|ƒƒD ]}|| dd…  ¡ r:P q:W t|ƒ}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!
    rG   c             s   s   | ]}t  d |¡V  qdS )z	py\d\.\d$N)ÚrerC   )Ú.0Úpr!   r!   r"   ú	<genexpr>´   s    z(interpret_distro_name.<locals>.<genexpr>é   Nr2   )Ú
py_versionr@   rQ   )r6   ÚanyÚrangerN   Úisdigitr   Újoin)rH   rO   rE   r[   r@   rQ   r8   rX   r!   r!   r"   r   ©   s    

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 ˆ | |ŽƒS )N)r   )ÚargsÚkwargs)Úfuncr!   r"   ÚwrapperÑ   s    zunique_values.<locals>.wrapper)r   )rb   rc   r!   )rb   r"   Úunique_valuesË   s    rd   z3<([^>]*\srel\s{0,10}=\s{0,10}['"]?([^'" >]+)[^>]*)>c          	   c   sÆ   xvt  |¡D ]h}| ¡ \}}tttj| ¡  d¡ƒƒ}d|ksFd|krx,t	 |¡D ]}t
j | t| d¡ƒ¡V  qRW qW xHdD ]@}| |¡}|dkr~t	 ||¡}|r~t
j | t| d¡ƒ¡V  q~W d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!   )rx   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!   )rx   ÚreporterÚtemplater!   r!   r"   Úreport  s    zContentChecker.reportN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rz   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 )N)Ú	hash_nameÚhashlibÚnewÚhashÚexpected)rx   r„   rˆ   r!   r!   r"   Ú__init__  s    zHashChecker.__init__c             C   s>   t j |¡d }|stƒ S | j |¡}|s0tƒ S | f | ¡ Ž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 )N)r‡   Úupdate)rx   ry   r!   r!   r"   rz      s    zHashChecker.feedc             C   s   | j  ¡ | jkS )N)r‡   Ú	hexdigestrˆ   )rx   r!   r!   r"   r{   #  s    zHashChecker.is_validc             C   s   || j  }||ƒS )N)r„   )rx   r|   r}   Úmsgr!   r!   r"   r~   &  s    
zHashChecker.reportN)r   r€   r   rV   ÚcompilerŠ   r‰   Úclassmethodr   rz   r{   r~   r!   r!   r!   r"   rƒ   
  s   rƒ   c                   sT  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d:d;„ Zd<d=„ Zd>d?„ Z d@dA„ Z!e"dWdBdC„ƒZ#dDdE„ Z$dFdG„ Z%dHdI„ Z&dJdK„ Z'dLdM„ Z(‡  Z)S )Xr   z;A distribution index that scans web pages for download URLsúhttps://pypi.org/simple/©Ú*NTc                sh   t ƒ j||Ž |dd | d¡ …  | _i | _i | _i | _t d 	t
t|ƒ¡¡j| _g | _tjj| _d S )Nr-   ú|)Úsuperr‰   r'   Ú	index_urlÚscanned_urlsÚfetched_urlsÚpackage_pagesrV   r‘   r_   rj   r   rC   ÚallowsÚto_scanr3   ÚrequestÚurlopenÚopener)rx   r˜   ÚhostsZ	ca_bundleZ
verify_sslr`   Úkw)Ú	__class__r!   r"   r‰   .  s    	zPackageIndex.__init__c                s0   yt |jƒ W n tk
r"   d S X tƒ  |¡S )N)r   rJ   Ú	Exceptionr—   Úadd)rx   rF   )r£   r!   r"   r¥   @  s
    zPackageIndex.addFc             C   sæ  || j kr|sdS d| j |< t|ƒs2|  |¡ dS tt|ƒƒ}|r\|  |¡sPdS |  d|¡ |sn|rn|| jkr‚tt| j	|ƒƒ dS |  |¡sšd| j|< dS |  
d|¡ d| j|< d}|  ||| ¡}|dkrÐdS t|tjjƒrø|jdkrø|  
d|j ¡ d| j|j< d|j d	d
¡ ¡ kr(| ¡  dS |j}| ¡ }t|tƒsvt|tjjƒrXd}n|j d¡phd}| |d¡}| ¡  x6t |¡D ](}	tj |t|	  d¡ƒ¡}
|  !|
¡ qŠW | "| 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Úhtmlzcontent-typeÚ zlatin-1ÚcharsetÚignorer2   Úcodei”  )&r™   Ú
URL_SCHEMEÚprocess_filenameÚlistr   Úurl_okÚdebugrš   rj   r¥   ÚinfoÚopen_urlÚ
isinstancer3   ÚerrorÚ	HTTPErrorrª   r   r7   ÚheadersÚgetr&   ÚcloseÚreadrk   Ú	get_paramÚdecoderm   rg   r   rn   ro   rD   Úprocess_urlr(   r˜   ÚgetattrÚprocess_index)rx   r7   ÚretrieveÚdistsÚtmplÚfr*   rr   r¨   rC   Úlinkr!   r!   r"   r»   I  sT    





 zPackageIndex.process_urlc             C   sŽ   t j |¡s|  d|¡ d S t j |¡rb|sbt j |¡}x(t  |¡D ]}|  t j ||¡d¡ qDW t	|ƒ}|rŠ|  
d|¡ tt| j|ƒƒ d S )NzNot found: %sTz	Found: %s)rS   r;   ÚexistsÚwarnÚisdirÚrealpathÚlistdirr¬   r_   rU   r¯   r­   rj   r¥   )rx   Ú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   Ú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«   rD   r&   rœ   r3   r   r4   r   rÄ   )rx   r7   Ú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)rS   rÇ   r'   )rW   r;   Úentryr!   r!   r"   rY      s   z.PackageIndex.scan_egg_links.<locals>.<genexpr>)ÚfilterrS   r;   rÅ   r­   Ú	itertoolsÚstarmapÚscan_egg_link)rx   Ú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 Q R X t	|ƒdkrDd S |\}}x>t
tj ||¡ƒD ](}tjj|f|žŽ |_t|_|  |¡ q`W d S )NrZ   )ÚopenrS   r;   r_   r­   rÐ   rj   rk   rl   rN   r	   rH   r   r@   r¥   )rx   r;   rÏ   Z	raw_linesÚlinesZegg_pathZ
setup_pathrF   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 krV|S t	|d ƒ}t
|d ƒ}d| j | ¡ i ¡|< t|ƒt|ƒfS )N)NNr-   rZ   r1   r2   r   T)r(   r˜   r­   rj   r3   r   r5   rN   r6   r
   r   r›   Ú
setdefaultr&   r   )rx   rÂ   ZNO_MATCH_SENTINELr8   ÚpkgÚverr!   r!   r"   Ú_scan·  s    &zPackageIndex._scanc       	   
   C   sÊ   xJt  |¡D ]<}y"|  tj |t| d¡ƒ¡¡ W q tk
rF   Y qX qW |  |¡\}}|sbdS xVt	||ƒD ]H}t
|ƒ\}}| d¡r¬|s¬|r¢|d||f 7 }n
|  |¡ |  |¡ qnW t dd„ |¡S )z#Process the contents of a PyPI pager2   r§   z.pyz
#egg=%s-%sc             S   s   d|   ddd¡ S )Nz<a href="%s#md5=%s">%s</a>r2   é   rZ   )rD   )Úmr!   r!   r"   Ú<lambda>á  ó    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)	rx   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)rx   r7   r!   r!   r"   rá   ä  s    zPackageIndex.need_version_infoc             G   s:   | j | jkr*|r | j|f|žŽ  |  d¡ |  | j ¡ d S )Nz6Scanning index of all packages (this may take a while))r˜   rš   rÄ   r°   râ   )rx   r   r`   r!   r!   r"   rç   ë  s
    
zPackageIndex.scan_allc             C   s~   |   | j|j d ¡ | j |j¡s:|   | j|j d ¡ | j |j¡sR|  |¡ x&t| j |jd¡ƒD ]}|   |¡ qhW d S )Nr-   r!   )	râ   r˜   Úunsafe_namer›   r¶   ÚkeyrI   Únot_found_in_indexr­   )rx   Úrequirementr7   r!   r!   r"   Úfind_packagesò  s    
zPackageIndex.find_packagesc                sR   |   ¡  |  |¡ x,| |j D ]}||kr.|S |  d||¡ qW tt| ƒ ||¡S )Nz%s does not match %s)Úprescanrì   ré   r¯   r—   r   Úobtain)rx   rë   Ú	installerrF   )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·   rS   Úunlinkr   r‡   r)   r;   rO   )rx   ÚcheckerrT   Útfpr!   r!   r"   Ú
check_hash
  s    
zPackageIndex.check_hashc             C   sR   xL|D ]D}| j dks2t|ƒr2| d¡s2tt|ƒƒr>|  |¡ q| j  |¡ qW dS )z;Add `urls` to the list that will be prescanned for searchesNzfile:)r   r«   r(   r­   r   râ   Úappend)rx   Ú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â   )rx   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ç   )rx   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   z.pyrH   N)r²   r   r«   Ú_download_urlrD   r?   r'   Ú	gen_setuprS   r;   rÃ   r#   r¼   Úfetch_distribution)rx   r   Útmpdirr9   Úfoundr*   r>   r!   r!   r"   r/   8  s    

zPackageIndex.downloadc       	         sÜ   ˆ  d|¡ i ‰d}d
‡ ‡‡‡‡fdd„	}|rHˆ ¡  ˆ |¡ ||ƒ}|s^|dk	r^|||ƒ}|dkr€ˆjdk	rxˆ ¡  ||ƒ}|dkrž|sžˆ |¡ ||ƒ}|dk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 krˆ}x€|| j  D ]r}|jtkrHˆ sH|ˆkrˆ d|¡ dˆ|< q|| ko^|jtkp^ˆ }|rˆ |jˆ¡}||_tj	 
|j¡r|S qW d S )Nz&Skipping development or system egg: %sr2   )ré   r@   r   rÄ   r   r/   rH   Údownload_locationrS   r;   rÃ   )ÚreqÚenvrF   ÚtestÚloc)Ú
develop_okrx   ÚskippedÚsourcerû   r!   r"   rp   x  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)rH   )N)r°   rí   rì   r   rÄ   Úclonerý   )	rx   rë   rû   Ú
force_scanr  r  Zlocal_indexrF   rp   r!   )r  rx   r  r  rû   r"   rú   Z  s0    




zPackageIndex.fetch_distributionc             C   s"   |   ||||¡}|dk	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ú   rH   )rx   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 	||¡}tj 
|¡r~tj ||¡sŽt ||¡ |}ttj 	|d¡dƒ2}| d|d j|d jtj |¡d f ¡ W d Q R X |S |rôtd||f ƒ‚ntd	ƒ‚d S )
Nc             S   s   g | ]}|j r|‘qS r!   )rJ   )rW   Údr!   r!   r"   ú
<listcomp>¼  s   z*PackageIndex.gen_setup.<locals>.<listcomp>r2   zsetup.pyÚwzIfrom 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.)rB   rC   r   rD   rN   rS   r;   rO   Údirnamer_   rÃ   ÚsamefileÚshutilÚcopy2r×   ÚwriterI   rJ   Úsplitextr   )	rx   rT   r>   rû   rC   r¿   rO   ÚdstrË   r!   r!   r"   rù   ·  s2    
 zPackageIndex.gen_setupi    c          	   C   s  |   d|¡ d }zît |¡}|  |¡}t|tjjƒrJtd||j	|j
f ƒ‚|  ¡ }d}| j}d}d|kr’| d¡}	ttt|	ƒƒ}|  |||||¡ t|dƒZ}
xD| |¡}|rÞ| |¡ |
 |¡ |d7 }|  |||||¡ q P q W |  |||
¡ W d Q R X |S |r| ¡  X 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_blocksizeÚget_allÚmaxrj   ÚintÚ
reporthookr×   r¸   rz   r  ró   r·   )rx   r7   rT   Úfprñ   rµ   ÚblocknumÚbsÚsizeÚsizesrò   ry   r!   r!   r"   Ú_download_toç  s:    





zPackageIndex._download_toc             C   s   d S )Nr!   )rx   r7   rT   r  Zblksizer  r!   r!   r"   r    s    zPackageIndex.reporthookc          
   C   sœ  |  d¡rt|ƒS yt|| jƒS  ttjjfk
r„ } z>d dd„ |j	D ƒ¡}|r`|  
||¡ ntd||f ƒ|‚W d d }~X Y n tjjk
r¨ } z|S d }~X Y nð tjjk
rô } z,|rÐ|  
||j¡ ntd||jf ƒ|‚W d d }~X Y n¤ tjjk
rD } z.|r |  
||j¡ ntd||jf ƒ|‚W d d }~X Y nT tjjtjfk
r– } z*|rt|  
||¡ ntd||f ƒ|‚W d d }~X Y nX d S )Nzfile:ú c             S   s   g | ]}t |ƒ‘qS r!   )rk   )rW   Úargr!   r!   r"   r	    s    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´   ÚURLErrorÚreasonÚBadStatusLineÚlineÚHTTPExceptionÚsocket)rx   r7   ÚwarningÚvr   r!   r!   r"   r±     s8    
$zPackageIndex.open_urlc             C   sê   t |ƒ\}}|r4x&d|kr0| dd¡ dd¡}qW nd}| d¡rN|d d… }tj ||¡}|dksn| d	¡rz|  ||¡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__z.egg.zipr%   Úsvnzsvn+Úgitzgit+zhg+rË   rZ   T)r?   Úreplacer'   rS   r;   r_   r(   Ú_download_svnÚ_download_gitÚ_download_hgr3   rž   Úurl2pathnamer   r4   r®   Ú_attempt_download)rx   r9   r7   rû   r)   r>   rT   r!   r!   r"   rø   1  s$    


zPackageIndex._download_urlc             C   s   |   |d¡ d S )NT)r»   )rx   r7   r!   r!   r"   râ   N  s    zPackageIndex.scan_urlc             C   s6   |   ||¡}d| dd¡ ¡ kr.|  |||¡S |S d S )Nr¦   zcontent-typer§   )r  r¶   r&   Ú_download_html)rx   r7   rT   rµ   r!   r!   r"   r7  Q  s    zPackageIndex._attempt_downloadc             C   sl   t |ƒ}x@|D ]8}| ¡ rt d|¡rD| ¡  t |¡ |  ||¡S P qW | ¡  t |¡ td| ƒ‚d S )Nz <title>([^- ]+ - )?Revision \d+:zUnexpected HTML page found at )	r×   rl   rV   rq   r·   rS   rð   r3  r   )rx   r7   rµ   rT   rË   r(  r!   r!   r"   r8  X  s    


zPackageIndex._download_htmlc             C   s  t jdd|› dd | dd¡d }d}| ¡  d	¡rìd
|krìtj |¡\}}}}}}	|sì| d¡rìd|dd … krì|dd …  dd¡\}}t|ƒ\}
}|
rìd|
krÄ|
 dd¡\}}d||f }nd|
 }|}||||||	f}tj 	|¡}|  
d||¡ t d|||f ¡ |S )NzInvalid configz$SVN download support is deprecated: )iç  é   r2   )Zdue_dater1   r2   r   r§   zsvn:ú@z//r-   rZ   ú:z --username=%s --password=%sz --username=z'Doing subversion checkout from %s to %szsvn checkout%s -q %s %s)r   Úemitr6   r&   r(   r3   r   r4   Ú
_splituserÚ
urlunparser°   rS   Úsystem)rx   r7   rT   Úcredsr9   Únetlocr;   rX   ÚqrÁ   ÚauthÚhostÚuserÚpwr8   r!   r!   r"   r3  g  s,    zPackageIndex._download_svnc             C   sp   t j | ¡\}}}}}| dd¡d }| dd¡d }d }d|krR| dd¡\}}t j ||||df¡} | |fS )Nú+r2   r.   r1   r   r:  r§   )r3   r   Úurlsplitr6   ÚrsplitÚ
urlunsplit)r7   Ú
pop_prefixr9   rA  r;   r=   ræ   Úrevr!   r!   r"   Ú_vcs_split_rev_from_url  s    z$PackageIndex._vcs_split_rev_from_urlc             C   sl   |  dd¡d }| j|dd\}}|  d||¡ t d||f ¡ |d k	rh|  d|¡ t d	||f ¡ |S )
Nr1   r2   r   T)rK  zDoing git clone from %s to %szgit clone --quiet %s %szChecking out %szgit -C %s checkout --quiet %s)r6   rM  r°   rS   r?  )rx   r7   rT   rL  r!   r!   r"   r4  “  s    
zPackageIndex._download_gitc             C   sl   |  dd¡d }| j|dd\}}|  d||¡ t d||f ¡ |d k	rh|  d|¡ t d	||f ¡ |S )
Nr1   r2   r   T)rK  zDoing hg clone from %s to %szhg clone --quiet %s %szUpdating to %szhg --cwd %s up -C -r %s -q)r6   rM  r°   rS   r?  )rx   r7   rT   rL  r!   r!   r"   r5  ¦  s    
zPackageIndex._download_hgc             G   s   t j|f|žŽ  d S )N)r   r¯   )rx   r   r`   r!   r!   r"   r¯   ¹  s    zPackageIndex.debugc             G   s   t j|f|žŽ  d S )N)r   r°   )rx   r   r`   r!   r!   r"   r°   ¼  s    zPackageIndex.infoc             G   s   t j|f|žŽ  d S )N)r   rÄ   )rx   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â   r7  r8  r3  ÚstaticmethodrM  r4  r5  r¯   r°   rÄ   Ú__classcell__r!   r!   )r£   r"   r   +  sX      	
5



	&   
I
.$
"z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c             C   s   |   d¡}t |¡S )Nr   )rD   r¦   Úunescape)rC   Úwhatr!   r!   r"   Údecode_entityÈ  s    
rR  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_subrR  )Útextr!   r!   r"   ro   Í  s    	ro   c                s   ‡ fdd„}|S )Nc                s   ‡ ‡fdd„}|S )Nc           	      s.   t  ¡ }t  ˆ¡ z
ˆ | |ŽS t  |¡ X d S )N)r*  ÚgetdefaulttimeoutÚsetdefaulttimeout)r`   ra   Zold_timeout)rb   Útimeoutr!   r"   Ú_socket_timeoutÛ  s
    

z@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeoutr!   )rb   rX  )rW  )rb   r"   rX  Ú  s    z'socket_timeout.<locals>._socket_timeoutr!   )rW  rX  r!   )rW  r"   Úsocket_timeoutÙ  s    rY  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Úbase64Ú	b64encoderº   r2  )rC  Zauth_sZ
auth_bytesZencoded_bytesÚencodedr!   r!   r"   Ú_encode_authè  s
    
r_  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 )N)ÚusernameÚpassword)rx   ra  rb  r!   r!   r"   r‰     s    zCredential.__init__c             c   s   | j V  | jV  d S )N)ra  rb  )rx   r!   r!   r"   Ú__iter__  s    zCredential.__iter__c             C   s   dt | ƒ S )Nz%(username)s:%(password)s)Úvars)rx   r!   r!   r"   Ú__str__
  s    zCredential.__str__N)r   r€   r   r‚   r‰   rc  re  r!   r!   r!   r"   r`  ý  s   r`  c                   s8   e Zd Z‡ fdd„Zedd„ ƒZdd„ Zdd„ Z‡  ZS )	Ú
PyPIConfigc                sN   t  dddgd¡}tƒ  |¡ tj tj d¡d¡}tj |¡rJ|  	|¡ dS )z%
        Load from ~/.pypirc
        ra  rb  Ú
repositoryr§   ú~z.pypircN)
ÚdictÚfromkeysr—   r‰   rS   r;   r_   Ú
expanduserrÃ   r¸   )rx   ÚdefaultsÚrc)r£   r!   r"   r‰     s
    zPyPIConfig.__init__c                s&   ‡ fdd„ˆ   ¡ D ƒ}ttˆ j|ƒƒS )Nc                s    g | ]}ˆ   |d ¡ ¡ r|‘qS )rg  )r¶   rl   )rW   Úsection)rx   r!   r"   r	    s   z2PyPIConfig.creds_by_repository.<locals>.<listcomp>)Úsectionsri  rj   Ú_get_repo_cred)rx   Zsections_with_repositoriesr!   )rx   r"   Úcreds_by_repository  s    
zPyPIConfig.creds_by_repositoryc             C   s6   |   |d¡ ¡ }|t|   |d¡ ¡ |   |d¡ ¡ ƒfS )Nrg  ra  rb  )r¶   rl   r`  )rx   rn  Úrepor!   r!   r"   rp  $  s    zPyPIConfig._get_repo_credc             C   s*   x$| j  ¡ D ]\}}| |¡r|S qW dS )zŒ
        If the URL indicated appears to be a repository defined in this
        config, return the credential for that repository.
        N)rq  Úitemsr(   )rx   r7   rg  Úcredr!   r!   r"   Úfind_credential+  s    
zPyPIConfig.find_credential)	r   r€   r   r‰   Úpropertyrq  rp  ru  rO  r!   r!   )r£   r"   rf    s   
rf  c             C   s<  t j | ¡}|\}}}}}}| d¡r2tj d¡‚|dkrHt|ƒ\}	}
nd}	|	s€tƒ  	| ¡}|r€t
|ƒ}	|j| f}tjd	|žŽ  |	rÆdt|	ƒ }	||
||||f}t j |¡}t j |¡}| d|	¡ nt j | ¡}| dt¡ ||ƒ}|	r8t j |j¡\}}}}}}||kr8||
kr8||||||f}t j |¡|_|S )
z4Open a urllib2 request, handling HTTP authenticationr;  znonnumeric port: '')r"  ÚhttpsNú*Authenticating as %s for %s (from .pypirc)zBasic ÚAuthorizationz
User-Agent)rx  )r3   r   r4   r'   r"  r#  r$  r=  rf  ru  rk   ra  r   r°   r_  r>  rž   ÚRequestÚ
add_headerÚ
user_agentr7   )r7   r    Úparsedr9   rA  r;   Úparamsr=   ræ   rC  Úaddressrt  r°   r8   rå   rž   r  Ús2Zh2Zpath2Zparam2Zquery2Zfrag2r!   r!   r"   r!  5  s8    

r!  c             C   s    |   d¡\}}} |r|nd| fS )zNsplituser('user[:passwd]@host[:port]')
    --> 'user[:passwd]', 'host[:port]'.r:  N)Ú
rpartition)rD  rE  Údelimr!   r!   r"   r=  d  s    r=  c             C   s   | S )Nr!   )r7   r!   r!   r"   Ú
fix_sf_urlo  s    rƒ  c          
   C   s  t j | ¡\}}}}}}t j |¡}tj |¡r<t j | ¡S | 	d¡rêtj 
|¡rêg }xˆt |¡D ]b}	tj ||	¡}
|	dkržt|
dƒ}| ¡ }W dQ R X P ntj 
|
¡r²|	d7 }	| dj|	d¡ qbW 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>rZ  )r7   Úfiles)éÈ   ÚOK)i”  zPath not foundz	Not foundzcontent-typez	text/html)r3   r   r4   rž   r6  rS   r;   ÚisfilerŸ   r'   rÅ   rÇ   r_   r×   r¸   rô   ÚformatÚioÚStringIOr³   r´   )r7   r9   r:   r;   Úparamr=   ræ   rT   r…  rÁ   Úfilepathr  ÚbodyrÀ   ÚstatusÚmessagerµ   Zbody_streamr!   r!   r"   r   s  s,    


r   )N)N)N)r   )[r‚   ÚsysrS   rV   rŠ  r  r*  r\  r…   rÑ   Úconfigparserr¦   Úhttp.clientr"  Úurllib.parser3   Ú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setuptools.warningsr   r‘   rB   ÚIrm   rã   rC   r«   r6   rM   Ú__all__Z_SOCKET_TIMEOUTZ_tmplr‰  Úversion_infor|  r#   r   r?   r   rA   rU   r   rd   rf   rv   rw   rƒ   r   rä   rS  rR  ro   rY  r_  r`  ÚRawConfigParserrf  rž   rŸ   r!  r=  rƒ  r   r!   r!   r!   r"   Ú<module>   sˆ   @
	

#
!!     
'/