o
    xŸŽiÎ›  ã                   @   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@dBdd„ZAdBd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„ ZMdCd2d3„ZNd4d5„ ZOG d6d7„ d7ƒZPG d8d9„ d9ejQƒZRejSjTfd:d;„ZUd<d=„ ZVeNe8ƒeUƒZUd>d?„ ZWd@dA„ ZXdS )Dz#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   s6   zt  | ¡W S  ty } ztd| f ƒ|‚d }~ww )Nz1Not a URL, existing file, or requirement spec: %r)r   ÚparseÚ
ValueErrorr   )ÚspecÚe© r!   úbC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\setuptools/package_index.pyÚparse_requirement_arg6   s   ÿþ€ÿr#   c                 C   s°   |   ¡ }d\}}}| d¡rS| d¡r| dd… }d}n7| dd¡r1| d	d
… }| dd… }d}n"| d¡r?| dd… }d}n| dd¡rS| d	d
… }| dd… }d}|||fS )z=Return (base,pyversion) or (None,None) for possible .exe name)NNNú.exez
.win32.exeNiöÿÿÿÚwin32z	.win32-pyiðÿÿÿiùÿÿÿéüÿÿÿz.win-amd64.exeiòÿÿÿz	win-amd64z.win-amd64-pyiìÿÿÿ)ÚlowerÚendswithÚ
startswith)Únamer'   ÚbaseÚpy_verÚplatr!   r!   r"   r   ?   s$   




r   c           	      C   sx   t j | ¡}|\}}}}}}t j | d¡d ¡}|dkr,|dkr,t j | d¡d ¡}d|v r8| 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   sf   � t | ƒ\}}t| ||ƒD ]}|V  q|r-t |¡}|r/t| | d¡|td�D ]	}|V  q'dS dS dS )zEYield egg or source distribution objects that might be found at a URLr3   )Ú
precedenceN)r@   Údistros_for_locationÚEGG_FRAGMENTÚmatchr   Úgroupr   )r8   Úmetadatar+   r?   ÚdistrD   r!   r!   r"   r   b   s   €

ÿúr   c                 C   sä   |  d¡r|dd… }|  d¡rd|v rt | ||¡gS |  d¡r<d|v r<t|ƒ}| ¡ s/g S t| |j|jtd d�gS |  d	¡rUt|ƒ\}}}|durUt	| |||t
|ƒS tD ]}|  |¡ro|dt|ƒ … }t	| ||ƒ  S qWg S )
z:Yield egg or source distribution objects based on basenameú.egg.zipNr&   z.eggú-z.whlr3   )ÚlocationÚproject_nameÚversionrA   r$   )r(   r   Úfrom_locationr   Úis_compatiblerK   rL   r   r   r   r   Ú
EXTENSIONSÚlen)rJ   ÚbasenamerF   ÚwheelZwin_baser,   ÚplatformÚextr!   r!   r"   rB   p   s4   
û
ÿ
þrB   c                 C   s   t t| ƒtj | ¡|ƒS )zEYield possible egg or source distribution objects based on a filenameN)rB   r   Úosr<   rQ   )ÚfilenamerF   r!   r!   r"   Údistros_for_filename‘   s   ÿrW   c              
   c   s~   � |  d¡}|stdd„ |dd… D ƒƒrdS tdt|ƒd ƒD ]}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!
    rI   c                 s   s   � | ]	}t  d |¡V  qdS )z	py\d\.\d$N)ÚrerD   )Ú.0Úpr!   r!   r"   Ú	<genexpr>¯   s   € z(interpret_distro_name.<locals>.<genexpr>é   Nr3   )Ú
py_versionrA   rS   )r7   ÚanyÚrangerP   r   Újoin)rJ   rQ   rF   r]   rA   rS   r9   rZ   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>.wrapperNr   )re   rf   r!   rd   r"   Úunique_values»   s   rg   z(<([^>]*\srel\s*=\s*['"]?([^'">]+)[^>]*)>c              	   c   s¼   � t  |¡D ]2}| ¡ \}}tttj| ¡  d¡ƒƒ}d|v s#d|v r8t	 |¡D ]}t
j | t| d¡ƒ¡V  q(qdD ] }| |¡}|dkr[t	 ||¡}|r[t
j | t| d¡ƒ¡V  q;dS )zEFind rel="homepage" and rel="download" links in `page`, yielding URLsú,Zhomepager0   r3   )z<th>Home Pagez<th>Download URLr/   N)ÚRELÚfinditerÚgroupsÚsetÚmapÚstrÚstripr'   r7   ÚHREFr4   r   ÚurljoinÚ
htmldecoderE   ÚfindÚsearch)r8   ÚpagerD   ÚtagÚrelZrelsÚposr!   r!   r"   Úfind_external_linksÌ   s    €€
€ûry   c                   @   ó(   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   ó   dS )z3
        Feed a block of data to the hash.
        Nr!   ©ÚselfÚblockr!   r!   r"   Úfeedä   ó   zContentChecker.feedc                 C   r|   )zC
        Check the hash. Return False if validation fails.
        TNr!   ©r~   r!   r!   r"   Úis_validê   r�   zContentChecker.is_validc                 C   r|   )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 ra   )Ú	hash_nameÚhashlibÚnewÚhashÚexpected)r~   rŒ   r�   r!   r!   r"   Ú__init__þ   s   
zHashChecker.__init__c                 C   sB   t j |¡d }|stƒ S | j |¡}|stƒ S | di | ¡ ¤ŽS )z5Construct a (possibly null) ContentChecker from a URLr/   Nr!   )r4   r   r5   r{   Úpatternrt   Ú	groupdict)Úclsr8   r?   rD   r!   r!   r"   Úfrom_url  s   zHashChecker.from_urlc                 C   s   | j  |¡ d S ra   )r�   Úupdater}   r!   r!   r"   r€     ó   zHashChecker.feedc                 C   s   | j  ¡ | jkS ra   )r�   Ú	hexdigestr�   r‚   r!   r!   r"   rƒ     r—   zHashChecker.is_validc                 C   s   || j  }||ƒS ra   )rŒ   )r~   r„   r…   Úmsgr!   r!   r"   r†     s   
zHashChecker.reportN)r‡   rˆ   r‰   rX   Úcompiler’   r‘   Úclassmethodr•   r€   rƒ   r†   r!   r!   r!   r"   r‹   ø   s    ÿ

r‹   c                       sL  e Zd ZdZ		dLdd„ZdMd	d
„ZdMdd„ZdMdd„Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdNdd„Zdd„ ZdN‡ fdd„	Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Z		dOd)d*„ZdPd+d,„Zd-d.„ Zd/Zd0d1„ Zd2d3„ ZdNd4d5„Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Zd>d?„ Z e!dMd@dA„ƒZ"dBdC„ Z#dDdE„ Z$dFdG„ Z%dHdI„ Z&dJdK„ Z'‡  Z(S )Qr   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_pagesrX   rš   r`   rm   r   rD   ÚallowsÚto_scanr4   ÚrequestÚurlopenÚopener)r~   r    ÚhostsZ	ca_bundleZ
verify_sslrb   Úkwr!   r!   r"   r‘     s   zPackageIndex.__init__Fc                 C   sÜ  || j v r	|s	dS d| j |< t|ƒs|  |¡ dS tt|ƒƒ}|r.|  |¡s(dS |  d|¡ |s7|r7|| jv rAtt| j	|ƒƒ dS |  |¡sMd| j|< dS |  
d|¡ d| j|< d}|  ||| ¡}|du rhd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ƒs·t|tjjƒr©d}n|j d¡p°d}| |d¡}| ¡  t |¡D ]}	tj |t|	  d¡ƒ¡}
|  !|
¡ qÀ| "| j#¡rêt$|ddƒdkrì|  %||¡}dS dS 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Úignorer3   Úcodeé”  )&r¡   Ú
URL_SCHEMEÚprocess_filenameÚlistr   Úurl_okÚdebugr¢   rm   ÚaddÚinfoÚopen_urlÚ
isinstancer4   ÚerrorÚ	HTTPErrorr°   r™   r8   ÚheadersÚgetr'   ÚcloseÚreadrn   Ú	get_paramÚdecoderp   rj   r   rq   rr   rE   Úprocess_urlr)   r    ÚgetattrÚprocess_index)r~   r8   ÚretrieveÚdistsÚtmplÚfr+   ru   r®   rD   Úlinkr!   r!   r"   rÃ   *  sV   






ÿzPackageIndex.process_urlc                 C   sŽ   t j |¡s|  d|¡ d S t j |¡r/|s/t j |¡}t  |¡D ]}|  t j ||¡d¡ q!t	|ƒ}|rE|  
d|¡ tt| j|ƒƒ d S d S )NzNot found: %sTz	Found: %s)rU   r<   ÚexistsÚwarnÚisdirÚrealpathÚlistdirr³   r`   rW   r¶   r´   rm   r·   )r~   ÚfnÚnestedr<   ÚitemrÇ   r!   r!   r"   r³   _  s   þzPackageIndex.process_filenamec                 C   s`   t |ƒ}|o| d¡ ¡ dk}|s|  tj |¡d ¡rdS d}|r(t|| ƒ‚|  ||¡ d S )Nr3   ÚfileTzN
Note: Bypassing %s (disallowed host; see http://bit.ly/2hrImnY for details).
)	r²   rE   r'   r¤   r4   r   r5   r   rÌ   )r~   r8   Ú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   s2   � | ]}t  |¡D ]}| d ¡r	||fV  q	qdS )z	.egg-linkN)rU   rÏ   r(   )rY   r<   Úentryr!   r!   r"   r[   ~  s   € ýüÿz.PackageIndex.scan_egg_links.<locals>.<genexpr>)ÚfilterrU   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   ƒ n1 sw   Y  t	|ƒdkr,d S |\}}t
tj ||¡ƒD ]}tjj|g|¢R Ž |_t|_|  |¡ q9d S )Nr\   )ÚopenrU   r<   r`   r´   rØ   rm   rn   ro   rP   r
   rJ   r   rA   r·   )r~   r<   r×   Z	raw_linesÚlinesZegg_pathZ
setup_pathrG   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s)d|d v r+|S t	|d ƒ}t
|d ƒ}d| j | ¡ i ¡|< t|ƒt|ƒfS )N)NNr.   r\   r2   r3   r   T)r)   r    r´   rm   r4   r   r6   rP   r7   r   r   r£   Ú
setdefaultr'   r   )r~   rÊ   ZNO_MATCH_SENTINELr9   ÚpkgÚverr!   r!   r"   Ú_scan–  s   ÿzPackageIndex._scanc           	   
   C   s¾   t  |¡D ]}z|  tj |t| d¡ƒ¡¡ W q ty!   Y qw |  |¡\}}|s-dS t	||ƒD ]$}t
|ƒ\}}| d¡rQ|sQ|rL|d||f 7 }n|  |¡ |  |¡ q2t dd„ |¡S )z#Process the contents of a PyPI pager3   r­   ú.pyz
#egg=%s-%sc                 S   s   d|   ddd¡ S )Nz<a href="%s#md5=%s">%s</a>r3   é   r\   )rE   )Úmr!   r!   r"   Ú<lambda>Â  s    z,PackageIndex.process_index.<locals>.<lambda>N)rp   rj   rä   r4   r   rq   rr   rE   r   ry   r@   r(   Úneed_version_infoÚscan_urlÚPYPI_MD5Úsub)	r~   r8   ru   rD   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~   r8   r!   r!   r"   ré   Å  s   þzPackageIndex.need_version_infoc                 G   s<   | j | jvr|r| j|g|¢R Ž  |  d¡ |  | j ¡ d S )Nz6Scanning index of all packages (this may take a while))r    r¢   rÌ   r¸   rê   ©r~   r™   rb   r!   r!   r"   rï   Ë  s   ÿzPackageIndex.scan_allc                 C   sz   |   | j|j d ¡ | j |j¡s|   | j|j d ¡ | j |j¡s)|  |¡ t| j |jd¡ƒD ]}|   |¡ q3d S )Nr.   r!   )	rê   r    Úunsafe_namer£   r¾   ÚkeyrK   Únot_found_in_indexr´   )r~   Úrequirementr8   r!   r!   r"   Úfind_packagesÔ  s   
þzPackageIndex.find_packagesc                    sR   |   ¡  |  |¡ | |j D ]}||v r|  S |  d||¡ qtt| ƒ ||¡S )Nz%s does not match %s)Úprescanrö   ró   r¶   Úsuperr   Úobtain)r~   rõ   Ú	installerrG   ©Ú	__class__r!   r"   rù   ã  s   
zPackageIndex.obtainc                 C   sL   |  | jd| ¡ | ¡ s$| ¡  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¿   rU   Úunlinkr   r�   r*   r<   rQ   )r~   ÚcheckerrV   Útfpr!   r!   r"   Ú
check_hashì  s   þ
þÿýzPackageIndex.check_hashc                 C   sN   |D ]"}| j du st|ƒr| d¡stt|ƒƒr|  |¡ q| j  |¡ qdS )z;Add `urls` to the list that will be prescanned for searchesNúfile:)r¥   r²   r)   r´   r   rê   Úappend)r~   Úurlsr8   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´   rm   rê   r‚   r!   r!   r"   r÷     s   
zPackageIndex.prescanc                 C   s<   | |j  r| jd}}n| jd}}|||jƒ |  ¡  d S )Nz#Couldn't retrieve index page for %rz3Couldn't find index page for %r (maybe misspelled?))ró   r¸   rÌ   rò   rï   )r~   rõ   Úmethr™   r!   r!   r"   rô     s   
þzPackageIndex.not_found_in_indexc                 C   s~   t |tƒs5t|ƒ}|r)|  | d¡||¡}t|ƒ\}}| d¡r'|  |||¡}|S tj	 
|¡r1|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.
        r3   rå   rJ   N)rº   r   r²   Ú_download_urlrE   r@   r(   Ú	gen_setuprU   r<   rË   r#   rÄ   Úfetch_distribution)r~   r   Útmpdirr:   Úfoundr+   r?   r!   r!   r"   r0     s   

zPackageIndex.downloadc           	         sÚ   ˆ  d|¡ i ‰d}d
‡ ‡‡‡‡fdd„	}|r$ˆ ¡  ˆ |¡ ||ƒ}|s/|dur/|||ƒ}|du r@ˆjdur<ˆ ¡  ||ƒ}|du rO|sOˆ |¡ ||ƒ}|du r`ˆ dˆrZdp[d|¡ dS ˆ  d|¡ |j|j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 ];}|jtkr#ˆ s#|ˆvr"ˆ d|¡ dˆ|< q|| v o.|jtkp.ˆ }|rFˆ |jˆ¡}||_tj	 
|j¡rF|  S qd S )Nz&Skipping development or system egg: %sr3   )ró   rA   r   rÌ   r   r0   rJ   Údownload_locationrU   r<   rË   )ÚreqÚenvrG   ÚtestÚloc©Ú
develop_okr~   ÚskippedÚsourcer	  r!   r"   rs   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)rJ   ra   )r¸   r÷   rö   r¥   rÌ   Úcloner  )	r~   rõ   r	  Ú
force_scanr  r  Zlocal_indexrG   rs   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  rJ   )r~   rõ   r	  r  r  rG   r!   r!   r"   Úfetch‰  s   zPackageIndex.fetchc           
   	   C   s  t  |¡}|rdd„ t|| d¡d ƒD ƒpg }t|ƒdkrxtj |¡}tj |¡|krEtj 	||¡}ddl
m} |||ƒsEt ||¡ |}ttj 	|d¡dƒ�}	|	 d|d j|d jtj |¡d f ¡ W d   ƒ |S 1 sqw   Y  |S |r‚td	||f ƒ‚td
ƒ‚)Nc                 S   s   g | ]}|j r|‘qS r!   )rL   )rY   Údr!   r!   r"   Ú
<listcomp>˜  s    þÿz*PackageIndex.gen_setup.<locals>.<listcomp>r3   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.)rC   rD   r   rE   rP   rU   r<   rQ   Údirnamer`   Zsetuptools.command.easy_installr  ÚshutilÚcopy2rß   ÚwriterK   rL   Úsplitextr   )
r~   rV   r?   r	  rD   rÇ   rQ   Údstr  rÓ   r!   r!   r"   r  –  sF   

þý
þþÿ
ÿ	÷	þÿÿzPackageIndex.gen_setupi    c                 C   s2  |   d|¡ d }zˆt |¡}|  |¡}t|tjjƒr%td||j	|j
f ƒ‚|  ¡ }d}| j}d}d|v rI| d¡}	ttt|	ƒƒ}|  |||||¡ t|dƒ�1}
	 | |¡}|ro| |¡ |
 |¡ |d	7 }|  |||||¡ nqqqP|  |||
¡ W d   ƒ n1 s‚w   Y  |W |r�| ¡  S S |r˜| ¡  w w )
NzDownloading %szCan't download %s: %s %sr   r/   zcontent-lengthzContent-LengthÚwbTr3   )r¸   r‹   r•   r¹   rº   r4   r»   r¼   r   r°   r™   Údl_blocksizeÚget_allÚmaxrm   ÚintÚ
reporthookrß   rÀ   r€   r  r   r¿   )r~   r8   rV   Úfprþ   r½   ÚblocknumÚbsÚsizeÚsizesrÿ   r   r!   r!   r"   Ú_download_toÁ  sF   

ÿ



ø	ö
ÿ
ÿzPackageIndex._download_toc                 C   s   d S ra   r!   )r~   r8   rV   r(  Zblksizer*  r!   r!   r"   r&  å  ó   zPackageIndex.reporthookc              
   C   s¦  |  d¡r	t|ƒS zt|| jƒW S  ttjjfyD } z$d dd„ |j	D ƒ¡}|r0|  
||¡ n	td||f ƒ|‚W Y d }~d S d }~w tjjyY } z|W  Y d }~S d }~w tjjy� } z|rl|  
||j¡ n
td||jf ƒ|‚W Y d }~d S d }~w tjjy© } z|r”|  
||j¡ n
td||jf ƒ|‚W Y d }~d S d }~w tjjtjfyÒ } z|r¾|  
||¡ n	td||f ƒ|‚W Y d }~d S d }~ww )Nr  ú c                 S   s   g | ]}t |ƒ‘qS r!   )rn   )rY   Ú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`   rb   rÌ   r   r4   r»   r¼   ÚURLErrorÚreasonÚBadStatusLineÚlineÚHTTPExceptionÚsocket)r~   r8   ÚwarningÚvr™   r!   r!   r"   r¹   é  s^   
þ€€ÿÿþ€þÿüþ€ÿÿþ€þzPackageIndex.open_urlc                 C   sè   t |ƒ\}}|rd|v r| dd¡ dd¡}d|v snd}| d¡r(|d d… }tj ||¡}|dks8| d	¡r>|  ||¡S |d
ksG| d¡rM|  ||¡S | d¡rX|  	||¡S |dkrht
j t
j |¡d ¡S |  |d¡ |  ||¡S )Nz..Ú.ú\Ú_Z__downloaded__rH   r&   Úsvnzsvn+Úgitzgit+zhg+rÓ   r\   T)r@   Úreplacer(   rU   r<   r`   r)   Ú_download_svnÚ_download_gitÚ_download_hgr4   r¦   Úurl2pathnamer   r5   rµ   Ú_attempt_download)r~   r:   r8   r	  r*   r?   rV   r!   r!   r"   r    s(   ÿ€

zPackageIndex._download_urlc                 C   s   |   |d¡ d S )NT)rÃ   rð   r!   r!   r"   rê   )  r—   zPackageIndex.scan_urlc                 C   s2   |   ||¡}d| dd¡ ¡ v r|  |||¡S |S )Nr«   r¬   r­   )r,  r¾   r'   Ú_download_html)r~   r8   rV   r½   r!   r!   r"   rG  ,  s   zPackageIndex._attempt_downloadc                 C   sj   t |ƒ}|D ]}| ¡ r%t d|¡r#| ¡  t |¡ |  ||¡  S  q&q| ¡  t |¡ td| ƒ‚)Nz <title>([^- ]+ - )?Revision \d+:zUnexpected HTML page found at )	rß   ro   rX   rt   r¿   rU   rý   rC  r   )r~   r8   r½   rV   rÓ   r8  r!   r!   r"   rH  3  s   
ù
zPackageIndex._download_htmlc                 C   s  t  dt¡ | dd¡d }d}| ¡  d¡rqd|v rqtj |¡\}}}}}}	|sq| d¡rqd	|d
d … v rq|d
d …  d	d¡\}}t	|ƒ\}
}|
rqd|
v r]|
 dd¡\}}d||f }nd|
 }|}||||||	f}tj 
|¡}|  d||¡ t d|||f ¡ |S )Nz"SVN download support is deprecatedr2   r3   r   r­   zsvn:ú@z//r.   r\   ú:z --username=%s --password=%sz --username=z'Doing subversion checkout from %s to %szsvn checkout%s -q %s %s)ÚwarningsrÌ   ÚUserWarningr7   r'   r)   r4   r   r5   Ú
_splituserÚ
urlunparser¸   rU   Úsystem)r~   r8   rV   Úcredsr:   Únetlocr<   rZ   ÚqrÉ   ÚauthÚhostÚuserÚpwr9   r!   r!   r"   rC  B  s&   zPackageIndex._download_svnc                 C   sp   t j | ¡\}}}}}| dd¡d }| dd¡d }d }d|v r)| dd¡\}}t j ||||df¡} | |fS )Nú+r3   r/   r2   r   rI  r­   )r4   r   Úurlsplitr7   ÚrsplitÚ
urlunsplit)r8   Ú
pop_prefixr:   rQ  r<   r>   rî   Úrevr!   r!   r"   Ú_vcs_split_rev_from_urlX  s   z$PackageIndex._vcs_split_rev_from_urlc                 C   ól   |  dd¡d }| j|dd�\}}|  d||¡ t d||f ¡ |d ur4|  d|¡ t d	||f ¡ |S )
Nr2   r3   r   T©r[  zDoing git clone from %s to %szgit clone --quiet %s %szChecking out %szgit -C %s checkout --quiet %s©r7   r]  r¸   rU   rO  ©r~   r8   rV   r\  r!   r!   r"   rD  j  ó   þzPackageIndex._download_gitc                 C   r^  )
Nr2   r3   r   Tr_  zDoing hg clone from %s to %szhg clone --quiet %s %szUpdating to %szhg --cwd %s up -C -r %s -qr`  ra  r!   r!   r"   rE  z  rb  zPackageIndex._download_hgc                 G   ó   t j|g|¢R Ž  d S ra   )r   r¶   rñ   r!   r!   r"   r¶   Š  ó   zPackageIndex.debugc                 G   rc  ra   )r   r¸   rñ   r!   r!   r"   r¸   �  rd  zPackageIndex.infoc                 G   rc  ra   )r   rÌ   rñ   r!   r!   r"   rÌ   �  rd  zPackageIndex.warn)rœ   r�   NT)Fra   )FFFN)FF))r‡   rˆ   r‰   rŠ   r‘   rÃ   r³   rµ   rÞ   rÛ   rä   rÅ   ré   rï   rö   rù   r   r  r÷   rô   r0   r  r  r  r"  r,  r&  r¹   r  rê   rG  rH  rC  Ústaticmethodr]  rD  rE  r¶   r¸   rÌ   Ú__classcell__r!   r!   rû   r"   r     sT    
þ

5


		
#
þ
L)$
#r   z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c                 C   s   |   d¡}t |¡S )Nr   )rE   r«   Úunescape)rD   Ú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'
    N)Ú
entity_subri  )Útextr!   r!   r"   rr   ž  s   
	rr   c                    s   ‡ fdd„}|S )Nc                    s   ‡ ‡fdd„}|S )Nc               	      s:   t  ¡ }t  ˆ¡ zˆ | i |¤ŽW t  |¡ S t  |¡ w ra   )r:  ÚgetdefaulttimeoutÚsetdefaulttimeout)rb   rc   Zold_timeout)re   Útimeoutr!   r"   Ú_socket_timeout¬  s
   
z@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeoutr!   )re   ro  ©rn  rd   r"   ro  «  s   z'socket_timeout.<locals>._socket_timeoutr!   )rn  ro  r!   rp  r"   Úsocket_timeoutª  s   rq  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­   N)r4   r   r6   ÚencodeÚbase64Ú	b64encoderÂ   rB  )rS  Zauth_sZ
auth_bytesZencoded_bytesÚencodedr!   r!   r"   Ú_encode_auth¹  s
   
rw  c                   @   rz   )	Ú
Credentialz:
    A username/password pair. Use like a namedtuple.
    c                 C   s   || _ || _d S ra   ©ÚusernameÚpassword)r~   rz  r{  r!   r!   r"   r‘   Ó  s   
zCredential.__init__c                 c   s   � | j V  | jV  d S ra   ry  r‚   r!   r!   r"   Ú__iter__×  s   €zCredential.__iter__c                 C   s   dt | ƒ S )Nz%(username)s:%(password)s)Úvarsr‚   r!   r!   r"   Ú__str__Û  s   zCredential.__str__N)r‡   rˆ   r‰   rŠ   r‘   r|  r~  r!   r!   r!   r"   rx  Î  s
    rx  c                   @   s0   e Zd Zdd„ Zedd„ ƒZdd„ Zdd„ Zd	S )
Ú
PyPIConfigc                 C   sR   t  g d¢d¡}tj | |¡ tj tj d¡d¡}tj 	|¡r'|  
|¡ dS dS )z%
        Load from ~/.pypirc
        )rz  r{  Ú
repositoryr­   ú~z.pypircN)ÚdictÚfromkeysÚconfigparserÚRawConfigParserr‘   rU   r<   r`   Ú
expanduserrË   rÀ   )r~   ÚdefaultsÚrcr!   r!   r"   r‘   à  s   ÿzPyPIConfig.__init__c                    s&   ‡ fdd„ˆ   ¡ D ƒ}ttˆ j|ƒƒS )Nc                    s    g | ]}ˆ   |d ¡ ¡ r|‘qS )r€  )r¾   ro   )rY   Úsectionr‚   r!   r"   r  í  s    þÿz2PyPIConfig.creds_by_repository.<locals>.<listcomp>)Úsectionsr‚  rm   Ú_get_repo_cred)r~   Zsections_with_repositoriesr!   r‚   r"   Úcreds_by_repositoryë  s   
ÿzPyPIConfig.creds_by_repositoryc                 C   s6   |   |d¡ ¡ }|t|   |d¡ ¡ |   |d¡ ¡ ƒfS )Nr€  rz  r{  )r¾   ro   rx  )r~   r‰  Úrepor!   r!   r"   r‹  ô  s
   þzPyPIConfig._get_repo_credc                 C   s*   | j  ¡ D ]\}}| |¡r|  S qdS )zŒ
        If the URL indicated appears to be a repository defined in this
        config, return the credential for that repository.
        N)rŒ  Úitemsr)   )r~   r8   r€  Úcredr!   r!   r"   Úfind_credentialû  s
   
ÿÿzPyPIConfig.find_credentialN)r‡   rˆ   r‰   r‘   ÚpropertyrŒ  r‹  r�  r!   r!   r!   r"   r  ß  s    
r  c                 C   s:  t j | ¡}|\}}}}}}| d¡rtj d¡‚|dv r$t|ƒ\}	}
nd}	|	sBtƒ  	| ¡}|rBt
|ƒ}	|j| f}tjdg|¢R Ž  |	red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 authenticationrJ  znonnumeric port: '')r2  ÚhttpsNz*Authenticating as %s for %s (from .pypirc)zBasic ÚAuthorizationz
User-Agent)r4   r   r5   r(   r2  r3  r4  rM  r  r�  rn   rz  r   r¸   rw  rN  r¦   ÚRequestÚ
add_headerÚ
user_agentr8   )r8   r¨   Úparsedr:   rQ  r<   Úparamsr>   rî   rS  Úaddressr�  r¸   r9   rí   r¦   r'  Ús2Úh2Zpath2Zparam2Zquery2Zfrag2r!   r!   r"   r1    s8   

r1  c                 C   s$   |   d¡\}}} |r|| fS d| fS )zNsplituser('user[:passwd]@host[:port]')
    --> 'user[:passwd]', 'host[:port]'.rI  N)Ú
rpartition)rT  rU  Údelimr!   r!   r"   rM  4  s   rM  c                 C   s   | S ra   r!   )r8   r!   r!   r"   Ú
fix_sf_url?  r-  rž  c              	   C   s*  t j | ¡\}}}}}}t j |¡}tj |¡rt j | ¡S | 	d¡r}tj 
|¡r}g }t |¡D ];}	tj ||	¡}
|	dkrXt|
dƒ�}| ¡ }W d  ƒ n1 sQw   Y   qxtj 
|
¡rb|	d7 }	| dj|	d�¡ q0d}|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>rr  )r8   Úfiles)éÈ   ÚOK)r±   zPath not foundz	Not foundr¬   z	text/html)r4   r   r5   r¦   rF  rU   r<   Úisfiler§   r(   rÍ   rÏ   r`   rß   rÀ   r  ÚformatÚioÚStringIOr»   r¼   )r8   r:   r;   r<   Úparamr>   rî   rV   r   rÉ   Úfilepathr'  ÚbodyrÈ   ÚstatusÚmessager½   Zbody_streamr!   r!   r"   r0  C  s0   
ÿÿ


r0  ra   )r   )YrŠ   ÚsysrU   rX   r¥  r  r:  rt  r�   rÙ   rK  r„  r«   Úhttp.clientr2  Úurllib.parser4   Úurllib.requestÚurllib.errorÚ	functoolsr   r   Úpkg_resourcesr   r   r   r   r   r	   r
   r   r   r   r   r   r   Ú	distutilsr   Údistutils.errorsr   Úfnmatchr   Zsetuptools.wheelr   Z setuptools.extern.more_itertoolsr   rš   rC   ÚIrp   rë   rD   r²   r7   rO   Ú__all__Z_SOCKET_TIMEOUTZ_tmplr¤  Úversion_infor–  r#   r   r@   r   rB   rW   r   rg   ri   ry   r{   r‹   r   rì   rj  ri  rr   rq  rw  rx  r…  r  r¦   r§   r1  rM  rž  r0  r!   r!   r!   r"   Ú<module>   sŽ    <
ÿÿ	


!
þ#
!     
&/