B
    =)H[v�  ã               @   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	m
Z
 ddlmZ ddlmZmZmZ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) ddl*m+Z+ ddl,m-Z- e.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<ej=dd… ed�Z>dd„ Z?dd„ Z@dd„ ZAdEd d„ZBdFd!d"„ZCdGd#d$„ZDdedfd%d„ZEdHd&d'„ZFd(d)„ ZGe 0d*ej2¡ZHeGd+d,„ ƒZIG d-d.„ d.ƒZJG d/d0„ d0eJƒZKG d1d„ deƒZLe 0d2¡jMZNd3d4„ ZOd5d6„ ZPdId7d8„ZQd9d:„ ZRG d;d<„ d<ƒZSG d=d>„ d>ejTƒZUejVjWfd?d@„ZXeQe:ƒeXƒZXdAdB„ ZYdCdD„ ZZdS )Jz#PyPI and direct package downloadingé    N)Úwraps)Úsix)ÚurllibÚhttp_clientÚconfigparserÚmap)ÚCHECKOUT_DISTÚDistributionÚBINARY_DISTÚnormalize_pathÚSOURCE_DISTÚEnvironmentÚfind_distributionsÚ	safe_nameÚsafe_versionÚto_filenameÚRequirementÚDEVELOP_DISTÚEGG_DIST)Ússl_support)Úlog)ÚDistutilsError)Ú	translate)Úget_all_headers)Úunescape)ÚWheelz^egg=([-A-Za-z0-9_.+!]+)$zhref\s*=\s*['"]?([^'"> ]+)zƒ<a href="([^"#]+)">([^<]+)</a>\n\s+\(<a (?:title="MD5 hash"\n\s+)href="[^?]+\?:action=show_md5&amp;digest=([0-9a-f]{32})">md5</a>\)z([-+.a-z0-9]{2,}):z.tar.gz .tar.bz2 .tar .zip .tgzÚPackageIndexÚdistros_for_urlÚparse_bdist_wininstÚinterpret_distro_nameé   z<setuptools/{setuptools.__version__} Python-urllib/{py_major}é   )Zpy_majorÚ
setuptoolsc             C   s2   y
t  | ¡S  tk
r,   td| f ƒ‚Y nX d S )Nz1Not a URL, existing file, or requirement spec: %r)r   ÚparseÚ
ValueErrorr   )Úspec© r&   ú`C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\setuptools\setuptools\package_index.pyÚparse_requirement_arg3   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   <   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éþÿÿÿú#é   )r   r#   ÚurlparseÚunquoteÚsplit)	ÚurlÚpartsÚschemeÚserverÚpathÚ
parametersÚqueryÚfragmentr/   r&   r&   r'   Úegg_info_for_urlT   s    rC   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 URLr7   )Ú
precedenceN)rC   Údistros_for_locationÚEGG_FRAGMENTÚmatchr   Úgroupr   )r;   Úmetadatar/   rB   ÚdistrG   r&   r&   r'   r   _   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.whlr7   )ÚlocationÚproject_nameÚversionrD   z.exe)r,   r	   Úfrom_locationr   Zis_compatiblerM   rN   r   r   r   r
   Ú
EXTENSIONSÚlen)rL   ÚbasenamerI   ÚwheelZwin_baser0   ÚplatformÚextr&   r&   r'   rE   m   s.    



rE   c             C   s   t t| ƒtj | ¡|ƒS )zEYield possible egg or source distribution objects based on a filename)rE   r   Úosr?   rR   )ÚfilenamerI   r&   r&   r'   Údistros_for_filenameŽ   s    rX   c          
   c   s€   |  d¡}|s,tdd„ |dd… D ƒƒr,dS xNtdt|ƒd ƒD ]8}t| |d |d|… ¡d ||d… ¡|||d�V  q@W 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!
    rK   c             s   s   | ]}t  d |¡V  qdS )z	py\d\.\d$N)ÚrerG   )Ú.0Úpr&   r&   r'   ú	<genexpr>¬   s    z(interpret_distro_name.<locals>.<genexpr>é   Nr7   )Ú
py_versionrD   rT   )r:   ÚanyÚrangerQ   r	   Újoin)rL   rR   rI   r^   rD   rT   r<   r[   r&   r&   r'   r   •   s    
$c             c   sn   t ƒ }|j}|dkr>xTtj |j| ¡D ]}||ƒ |V  q&W n,x*| D ]"}||ƒ}||krD||ƒ |V  qDW dS )zHList unique elements, preserving order. Remember all elements ever seen.N)ÚsetÚaddr   ÚmovesÚfilterfalseÚ__contains__)ÚiterableÚkeyÚseenZseen_addÚelementÚkr&   r&   r'   Úunique_everseen¹   s    
rl   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)rl   )ÚargsÚkwargs)Úfuncr&   r'   ÚwrapperÑ   s    zunique_values.<locals>.wrapper)r   )ro   rp   r&   )ro   r'   Úunique_valuesË   s    rq   z(<([^>]*\srel\s*=\s*['"]?([^'">]+)[^>]*)>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homepager4   r7   )z<th>Home Pagez<th>Download URLr3   N)ÚRELÚfinditerÚgroupsrb   r   ÚstrÚstripr+   r:   ÚHREFr   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 )N)Ú	hash_nameÚhashlibÚnewÚhashÚexpected)rƒ   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 URLr3   )r   r#   r8   r‚   Úpatternr|   Ú	groupdict)Úclsr;   rB   rG   r&   r&   r'   Úfrom_url  s    zHashChecker.from_urlc             C   s   | j  |¡ d S )N)r’   Úupdate)rƒ   r„   r&   r&   r'   r…     s    zHashChecker.feedc             C   s   | j  ¡ | jkS )N)r’   Ú	hexdigestr“   )rƒ   r&   r&   r'   r†   !  s    zHashChecker.is_validc             C   s   || j  }||ƒS )N)r�   )rƒ   r‡   rˆ   Úmsgr&   r&   r'   r‰   $  s    
zHashChecker.reportN)rŠ   r‹   rŒ   rY   Úcompiler•   r”   Úclassmethodr˜   r…   r†   r‰   r&   r&   r&   r'   rŽ     s   rŽ   c                   s<  e Zd ZdZdJdd„ZdKd	d
„ZdLdd„ZdMdd„Zdd„ Zdd„ Z	dd„ Z
dd„ ZdNdd„Zdd„ ZdO‡ fdd„	Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ ZdPd'd(„ZdQd)d*„Zd+d,„ Zd-Zd.d/„ Zd0d1„ ZdRd2d3„Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Ze dSd>d?„ƒZ!d@dA„ Z"dBdC„ Z#dDdE„ Z$dFdG„ Z%dHdI„ Z&‡  Z'S )Tr   z;A distribution index that scans web pages for download URLsúhttps://pypi.org/simple/©Ú*NTc             O   s”   t j| f|ž|Ž |dd | d¡ …  | _i | _i | _i | _t d 	t
t|ƒ¡¡j| _g | _|ortjor|prt ¡ }|r†t |¡| _n
tjj| _d S )Nr2   ú|)r   r”   r,   Ú	index_urlÚscanned_urlsÚfetched_urlsÚpackage_pagesrY   rœ   ra   r   r   rG   ÚallowsÚto_scanr   Zis_availableZfind_ca_bundleZ
opener_forÚopenerr   ÚrequestÚurlopen)rƒ   r¢   ÚhostsZ	ca_bundleZ
verify_sslrm   ÚkwZuse_sslr&   r&   r'   r”   ,  s    zPackageIndex.__init__Fc             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 d| j|j< d|j dd¡ ¡ k�r | ¡  dS |j}| ¡ }t|tƒ�sNt|tjjƒ�r0d	}n|j d
¡�p@d	}| |d¡}| ¡  x6t |¡D ](}	tj |t|	 d¡ƒ¡}
|  |
¡ �qbW |  | 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!Úhtmlzcontent-typeÚ zlatin-1ÚcharsetÚignorer7   Úcodei”  )$r£   Ú
URL_SCHEMEÚprocess_filenameÚlistr   Úurl_okÚdebugr¤   r   rc   ÚinfoÚopen_urlr;   ÚheadersÚgetr+   ÚcloseÚreadÚ
isinstancerv   r   ÚerrorÚ	HTTPErrorÚ	get_paramÚdecoderx   rt   r#   ry   rz   rH   Úprocess_urlr-   r¢   ÚgetattrÚprocess_index)rƒ   r;   ÚretrieveÚdistsÚtmplÚfr/   r}   r¯   rG   Úlinkr&   r&   r'   rÂ   A  sP    





 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)rV   r?   ÚexistsÚwarnÚisdirÚrealpathÚlistdirr³   ra   rX   r¶   r´   r   rc   )rƒ   ÚfnÚnestedr?   ÚitemrÆ   r&   r&   r'   r³   t  s    zPackageIndex.process_filenamec             C   sb   t |ƒ}|o| d¡ ¡ dk}|s8|  tj |¡d ¡r<dS d}|rRt|| ƒ‚n|  ||¡ d S )Nr7   ÚfileTzN
Note: Bypassing %s (disallowed host; see http://bit.ly/2hrImnY for details).
)	r²   rH   r+   r¦   r   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)rV   rÎ   r,   )rZ   r?   Úentryr&   r&   r'   r\   ”  s   z.PackageIndex.scan_egg_links.<locals>.<genexpr>)ÚfilterrV   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|ƒƒƒ}W d Q R X t	|ƒdkrDd S |\}}x>t
tj ||¡ƒD ](}tjj|f|žŽ |_t|_|  |¡ q`W d S )Nr]   )ÚopenrV   r?   ra   r´   r×   r   rv   rw   rQ   r   rL   r   rD   rc   )rƒ   r?   rÖ   Z	raw_linesÚlinesZegg_pathZ
setup_pathrJ   r&   r&   r'   rÚ   ›  s     zPackageIndex.scan_egg_linkc       
   	      sÖ   ‡ fdd„}xHt  |¡D ]:}y |tj |t| d¡ƒ¡ƒ W q tk
rP   Y qX qW ||ƒ\}}|rÎxVt||ƒD ]H}t	|ƒ\}}	| 
d¡r°|	s°|r¦|d||f 7 }n
ˆ  |¡ ˆ  |¡ qrW t dd„ |¡S dS d	S )
z#Process the contents of a PyPI pagec                sŒ   |   ˆ j¡rˆtttjj| tˆ jƒd …  d¡ƒƒ}t|ƒdkrˆd|d krˆt	|d ƒ}t
|d ƒ}dˆ j | ¡ i ¡| < t|ƒt|ƒfS dS )Nr2   r]   r6   r7   r   T)NN)r-   r¢   r´   r   r   r#   r9   rQ   r:   r   r   r¥   Ú
setdefaultr+   r   )rÉ   r<   ÚpkgÚver)rƒ   r&   r'   Úscan®  s    "z(PackageIndex.process_index.<locals>.scanr7   z.pyz
#egg=%s-%sc             S   s   d|   ddd¡ S )Nz<a href="%s#md5=%s">%s</a>r7   r!   r]   )rH   )Úmr&   r&   r'   Ú<lambda>Ñ  s    z,PackageIndex.process_index.<locals>.<lambda>r®   N)rx   rt   r   r#   ry   rz   rH   r$   r�   rC   r,   Úneed_version_infoÚscan_urlÚPYPI_MD5Úsub)
rƒ   r;   r}   rã   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kr*|r | j|f|žŽ  |  d¡ |  | j ¡ d S )Nz6Scanning index of all packages (this may take a while))r¢   r¤   rË   r·   rç   )rƒ   r›   rm   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 )Nr2   r&   )	rç   r¢   Úunsafe_namer¥   rº   rh   rM   Únot_found_in_indexr´   )rƒ   Úrequirementr;   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ð   rh   r¶   Úsuperr   Úobtain)rƒ   rï   Ú	installerrJ   )Ú	__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»   rV   Úunlinkr   r’   r.   r?   rR   )rƒ   ÚcheckerrW   Ú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)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´   r   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?))rh   r·   rË   rí   rì   )rƒ   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.
        r7   z.pyrL   N)r½   r   r²   Ú_download_urlrH   rC   r,   Ú	gen_setuprV   r?   rÊ   r(   rÃ   Úfetch_distribution)rƒ   r%   Útmpdirr=   Úfoundr/   rB   r&   r&   r'   r4   ,  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: %sr7   )rh   rD   r   rË   r   r4   rL   Údownload_locationrV   r?   rÊ   )ÚreqÚenvrJ   ÚtestÚloc)Ú
develop_okrƒ   ÚskippedÚsourcer  r&   r'   r{   f  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·   rñ   rð   r§   rË   Úcloner  )	rƒ   rï   r  Ú
force_scanr
  r  Zlocal_indexrJ   r{   r&   )r  rƒ   r	  r
  r  r'   r   N  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   rL   )rƒ   rï   r  r  r
  rJ   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ƒ�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&   )rN   )rZ   Údr&   r&   r'   ú
<listcomp>ª  s    z*PackageIndex.gen_setup.<locals>.<listcomp>r7   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.)rF   rG   r   rH   rQ   rV   r?   rR   Údirnamera   Zsetuptools.command.easy_installr  ÚshutilÚcopy2rÞ   ÚwriterM   rN   Úsplitextr   )
rƒ   rW   rB   r  rG   rÆ   rR   Údstr  rÒ   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’t|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   r3   zcontent-lengthzContent-LengthÚwbr7   )r·   rŽ   r˜   r¸   r½   r   r¾   r¿   r   r±   r›   Údl_blocksizer   Úmaxr   ÚintÚ
reporthookrÞ   r¼   r…   r  rù   r»   )rƒ   r;   rW   Úfpr÷   r¹   ÚblocknumÚbsÚsizeÚsizesrø   r„   r&   r&   r'   Ú_download_toÒ  s:    





zPackageIndex._download_toc             C   s   d S )Nr&   )rƒ   r;   rW   r  Zblksizer   r&   r&   r'   r  ö  s    zPackageIndex.reporthookc          
   C   sŽ  |  d¡rt|ƒS yt|| jƒS  tt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k
�r: } z,|�r|  	||j¡ nt
d||jf ƒ‚W d d }~X Y nP tjtjfk
�rˆ } z(|�rh|  	||¡ nt
d||f ƒ‚W d d }~X Y nX d S )Nzfile:ú c             S   s   g | ]}t |ƒ‘qS r&   )rv   )rZ   Ú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$   r   Ú
InvalidURLra   rm   rË   r   r   r¾   r¿   ÚURLErrorÚreasonÚBadStatusLineÚlineÚHTTPExceptionÚsocket)rƒ   r;   ÚwarningÚvr›   r&   r&   r'   r¸   ù  s6    
"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Ò   r]   T)rC   Úreplacer,   rV   r?   ra   r-   Ú_download_svnÚ_download_gitÚ_download_hgr   r©   Úurl2pathnamer#   r8   rµ   Ú_attempt_download)rƒ   r=   r;   r  r.   rB   rW   r&   r&   r'   rþ     s$    


zPackageIndex._download_urlc             C   s   |   |d¡ d S )NT)rÂ   )rƒ   r;   r&   r&   r'   rç   9  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)rƒ   r;   rW   r¹   r&   r&   r'   r:  <  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Þ   rw   rY   r|   r»   rV   rö   r6  r   )rƒ   r;   r¹   rW   rÒ   r+  r&   r&   r'   r;  C  s    


zPackageIndex._download_htmlc             C   s   |  dd¡d }d}| ¡  d¡rÚd|krÚtj |¡\}}}}}}	|sÚ| d¡rÚd|d	d … krÚ|d	d …   dd¡\}}tj |¡\}
}|
rÚd
|
kr²|
  d
d¡\}}d||f }nd|
 }|}||||||	f}tj |¡}|  d||¡ t	 
d|||f ¡ |S )Nr6   r7   r   r®   zsvn:ú@z//r2   r]   ú:z --username=%s --password=%sz --username=z'Doing subversion checkout from %s to %szsvn checkout%s -q %s %s)r:   r+   r-   r   r#   r8   Ú	splituserÚ
urlunparser·   rV   Úsystem)rƒ   r;   rW   Úcredsr=   Únetlocr?   r[   ÚqrÈ   ÚauthÚhostÚuserÚpwr<   r&   r&   r'   r6  R  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ú+r7   r3   r6   r   r<  r®   )r   r#   Úurlsplitr:   ÚrsplitÚ
urlunsplit)r;   Ú
pop_prefixr=   rB  r?   rA   rë   Úrevr&   r&   r'   Ú_vcs_split_rev_from_urlg  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 )
Nr6   r7   r   T)rL  zDoing git clone from %s to %szgit clone --quiet %s %szChecking out %sz"(cd %s && git checkout --quiet %s))r:   rN  r·   rV   r@  )rƒ   r;   rW   rM  r&   r&   r'   r7  y  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 )
Nr6   r7   r   T)rL  zDoing hg clone from %s to %szhg clone --quiet %s %szUpdating to %sz(cd %s && hg up -C -r %s -q))r:   rN  r·   rV   r@  )rƒ   r;   rW   rM  r&   r&   r'   r8  ‰  s    
zPackageIndex._download_hgc             G   s   t j|f|žŽ  d S )N)r   r¶   )rƒ   r›   rm   r&   r&   r'   r¶   ™  s    zPackageIndex.debugc             G   s   t j|f|žŽ  d S )N)r   r·   )rƒ   r›   rm   r&   r&   r'   r·   œ  s    zPackageIndex.infoc             G   s   t j|f|žŽ  d S )N)r   rË   )rƒ   r›   rm   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î   r4   r   r  rÿ   r  r"  r  r¸   rþ   rç   r:  r;  r6  ÚstaticmethodrN  r7  r8  r¶   r·   rË   Ú__classcell__r&   r&   )rõ   r'   r   )  sL    

3


+
		
# 
J
)$
#z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c             C   s   |   d¡}t|ƒS )Nr   )rH   r   )rG   Ú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'   rz   ­  s    	rz   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)rm   rn   Zold_timeout)ro   Útimeoutr&   r'   Ú_socket_timeout»  s
    

z@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeoutr&   )ro   rX  )rW  )ro   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 )aq  
    A function compatible with Python 2.3-3.3 that will encode
    auth from a URL suitable for an HTTP header.
    >>> str(_encode_auth('username%3Apassword'))
    'dXNlcm5hbWU6cGFzc3dvcmQ='

    Long auth strings should not cause a newline to be inserted.
    >>> long_auth = 'username:' + 'password'*10
    >>> chr(10) in str(_encode_auth(long_auth))
    False
    Ú
r®   )r   r#   r9   ÚencodeÚbase64ÚencodestringrÁ   r5  )rD  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)rƒ   ra  rb  r&   r&   r'   r”   ä  s    zCredential.__init__c             c   s   | j V  | jV  d S )N)ra  rb  )rƒ   r&   r&   r'   Ú__iter__è  s    zCredential.__iter__c             C   s   dt | ƒ S )Nz%(username)s:%(password)s)Úvars)rƒ   r&   r&   r'   Ú__str__ì  s    zCredential.__str__N)rŠ   r‹   rŒ   r�   r”   rc  re  r&   r&   r&   r'   r`  ß  s   r`  c               @   s0   e Zd Zdd„ Zedd„ ƒZdd„ Zdd„ Zd	S )
Ú
PyPIConfigc             C   sP   t  dddgd¡}tj | |¡ tj tj d¡d¡}tj 	|¡rL|  
|¡ dS )z%
        Load from ~/.pypirc
        ra  rb  Ú
repositoryr®   ú~z.pypircN)ÚdictÚfromkeysr   ÚRawConfigParserr”   rV   r?   ra   Ú
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 )rg  )rº   rw   )rZ   Úsection)rƒ   r&   r'   r  ÿ  s    z2PyPIConfig.creds_by_repository.<locals>.<listcomp>)Úsectionsri  r   Ú_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 )Nrg  ra  rb  )rº   rw   r`  )rƒ   ro  Úrepor&   r&   r'   rq    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)rr  Úitemsr-   )rƒ   r;   rg  Úcredr&   r&   r'   Úfind_credential  s    
zPyPIConfig.find_credentialN)rŠ   r‹   rŒ   r”   Úpropertyrr  rq  rv  r&   r&   r&   r'   rf  ð  s   	rf  c             C   s:  t j | ¡\}}}}}}| d¡r,t d¡‚|dkrFt j |¡\}}	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¡ ||ƒ}|�r6t j |j¡\}}}}}}||k�r6||	k�r6||||||f}t j |¡|_|S )
z4Open a urllib2 request, handling HTTP authenticationr=  znonnumeric port: '')ÚhttpÚhttpsNú*Authenticating as %s for %s (from .pypirc)zBasic ÚAuthorizationz
User-Agent)rz  )r   r#   r8   r,   r   r'  r>  rf  rv  rv   ra  r   r·   r_  r?  r©   ÚRequestÚ
add_headerÚ
user_agentr;   )r;   r¨   r=   rB  r?   ÚparamsrA   rë   rD  rE  ru  r·   r<   rê   r©   r  Ús2Úh2Úpath2Zparam2Zquery2Zfrag2r&   r&   r'   r&    s6    


r&  c             C   s   | S )Nr&   )r;   r&   r&   r'   Ú
fix_sf_urlG  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 directoriesr2   z
index.htmlÚrNz<a href="{name}">{name}</a>)r.   zB<html><head><title>{url}</title></head><body>{files}</body></html>rZ  )r;   Úfiles)éÈ   ÚOK)i”  zPath not foundz	Not foundzcontent-typez	text/html)r   r#   r8   r©   r9  rV   r?   Úisfilerª   r,   rÌ   rÎ   ra   rÞ   r¼   rú   Úformatr   ÚStringIOr¾   r¿   )r;   r=   r>   r?   ÚparamrA   rë   rW   r…  rÈ   Úfilepathr  ÚbodyrÇ   ÚstatusÚmessager¹   Zbody_streamr&   r&   r'   r%  K  s,    


r%  )N)N)N)N)r    )[r�   ÚsysrV   rY   r  r-  r\  r�   rØ   Ú	functoolsr   Zsetuptools.externr   Zsetuptools.extern.six.movesr   r   r   r   r"   Úpkg_resourcesr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   Ú	distutilsr   Údistutils.errorsr   Úfnmatchr   Zsetuptools.py27compatr   Zsetuptools.py33compatr   Zsetuptools.wheelr   ÚtypeZ__metaclass__rœ   rF   ÚIrx   rè   rG   r²   r:   rP   Ú__all__Z_SOCKET_TIMEOUTZ_tmplr‰  rN   r~  r(   r   rC   r   rE   rX   r   rl   rq   rs   r�   r‚   rŽ   r   ré   rS  rR  rz   rY  r_  r`  rk  rf  r©   rª   r&  rƒ  r%  r&   r&   r&   r'   Ú<module>   s~   <
	

!
"
!     
&.