o
    ^+)hT                     @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlZddlmZ ddlZddlmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, dd	l-m.Z. e/d
Z0e/dej1Z2e/dZ3e/dej1j4Z5d6 Z7g dZ8dZ9dZ:e:j;dj;ej< edZ=dd Z>dd Z?dd Z@dBddZAdBddZBdBddZCdedfd d!ZDd"d# ZEe/d$ej1ZFeEd%d& ZGG d'd( d(ZHG d)d* d*eHZIG d+d, d,eZJe/d-jKZLd.d/ ZMd0d1 ZNdCd2d3ZOd4d5 ZPG d6d7 d7ZQG d8d9 d9ejRZSejTjUfd:d;ZVd<d= ZWeOe9eVZVd>d? ZXd@dA ZYd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parse_version)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"   WC:\Users\User\Downloads\Proyecto_IoT\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-pyiiz.win-amd64.exeiz	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   rA   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 URLr4   )
precedenceN)rA   distros_for_locationEGG_FRAGMENTmatchr   groupr   )r9   metadatar,   r@   distrE   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.whlr4   )locationproject_nameversionrB   r%   )r)   r   from_locationr   is_compatiblerL   rM   r   r   r   r   
EXTENSIONSlen)rK   basenamerG   wheelZwin_baser-   platformextr"   r"   r#   rC   p   s4   


rC   c                 C   s   t t| tj| |S )zEYield possible egg or source distribution objects based on a filename)rC   r   osr=   rR   )filenamerG   r"   r"   r#   distros_for_filename   s   rX   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 )zGenerate 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!
    rJ   c                 s   s    | ]	}t d |V  qdS )z	py\d\.\d$N)rerE   ).0pr"   r"   r#   	<genexpr>   s    z(interpret_distro_name.<locals>.<genexpr>   Nr4   )
py_versionrB   rT   )r8   anyrangerQ   r   join)rK   rR   rG   r^   rB   rT   r:   r[   r"   r"   r#   r      s   
$
r   c                    s   t   fdd}|S )zs
    Wrap a function returning an iterable such that the resulting iterable
    only ever yields unique items.
    c                     s   t  | i |S Nr   )argskwargsfuncr"   r#   wrapper   s   zunique_values.<locals>.wrapperr   )rf   rg   r"   re   r#   unique_values   s   rh   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homepager1   r4   )z<th>Home Pagez<th>Download URLr0   N)RELfinditergroupssetmapstrstripr(   r8   HREFr5   r   urljoin
htmldecoderF   findsearch)r9   pagerE   tagrelZrelsposr"   r"   r#   find_external_links   s    
rz   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.
        Tr"   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 rb   )	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 URLr0   Nr"   )r5   r   r6   r|   patternru   	groupdict)clsr9   r@   rE   r"   r"   r#   from_url  s   zHashChecker.from_urlc                 C   s   | j | d S rb   )r   updater~   r"   r"   r#   r        zHashChecker.feedc                 C   s   | j  | jkS rb   )r   	hexdigestr   r   r"   r"   r#   r     r   zHashChecker.is_validc                 C   s   || j  }||S rb   )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		dN fdd	Z fdd	ZdOddZdOddZdOddZdd Z	dd Z
dd Zdd Zdd ZdPddZdd ZdP fdd 	Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Z	
	dQd+d,ZdRd-d.Zd/d0 Zd1Zd2d3 Zd4d5 ZdPd6d7Zd8d9 Zd:d; Zd<d= Zd>d? Z d@dA Z!e"dOdBdCZ#dDdE Z$dFdG Z%dHdI Z&dJdK Z'dLdM Z(  Z)S )Sr   z;A distribution index that scans web pages for download URLshttps://pypi.org/simple/*NTc                    sl   t  j|i | |dd |d   | _i | _i | _i | _td	t
t|j| _g | _tjj| _d S )Nr/   |)superr   r)   	index_urlscanned_urlsfetched_urlspackage_pagesrY   r   ra   rn   r   rE   allowsto_scanr5   requesturlopenopener)r   r   hostsZ	ca_bundleZ
verify_sslrc   kw	__class__r"   r#   r     s   zPackageIndex.__init__c                    s0   zt |j W n
 ty   Y d S w t |S rb   )r   rM   	Exceptionr   add)r   rH   r   r"   r#   r   )  s   zPackageIndex.addFc                 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st|tjjrd}n|jdpd}||d}|  t|D ]}	tj|t|	 d}
| !|
 q|"| j#rt$|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ignorer4   code  )&r   
URL_SCHEMEprocess_filenamelistr   url_okdebugr   rn   r   infoopen_url
isinstancer5   error	HTTPErrorr   r   r9   headersgetr(   closereadro   	get_paramdecoderq   rk   r   rr   rs   rF   process_urlr*   r   getattrprocess_index)r   r9   retrievediststmplfr,   rv   r   rE   linkr"   r"   r#   r   2  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)rV   r=   existswarnisdirrealpathlistdirr   ra   rX   r   r   rn   r   )r   fnnestedr=   itemr   r"   r"   r#   r   g  s   zPackageIndex.process_filenamec                 C   s`   t |}|o|d dk}|s| tj|d rdS d}|r(t|| | || d S )Nr4   fileTzN
Note: Bypassing %s (disallowed host; see http://bit.ly/2hrImnY for details).
)	r   rF   r(   r   r5   r   r6   r   r   )r   r9   fatalsis_filer   r"   r"   r#   r   w  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)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    n1 sw   Y  t	|dkr,d S |\}}t
tj||D ]}tjj|g|R  |_t|_| | q9d S )Nr]   )openrV   r=   ra   r   r   rn   ro   rp   rQ   r
   rK   r   rB   r   )r   r=   r   Z	raw_lineslinesZegg_pathZ
setup_pathrH   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]   r3   r4   r   T)r*   r   r   rn   r5   r   r7   rQ   r8   r   r   r   
setdefaultr(   r   )r   r   ZNO_MATCH_SENTINELr:   pkgverr"   r"   r#   _scan  s   zPackageIndex._scanc           	   
   C   s   t |D ]}z| tj|t|d W q t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 pager4   r   .pyz
#egg=%s-%sc                 S   s   d|  ddd S )Nz<a href="%s#md5=%s">%s</a>r4      r]   )rF   )mr"   r"   r#   <lambda>  s    z,PackageIndex.process_index.<locals>.<lambda>)rq   rk   r   r5   r   rr   rs   rF   r   rz   rA   r)   need_version_infoscan_urlPYPI_MD5sub)	r   r9   rv   rE   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   r9   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   rc   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   keyrL   not_found_in_indexr   )r   requirementr9   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   r   r   obtain)r   r   	installerrH   r   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   rV   unlinkr   r   r+   r=   rR   )r   checkerrW   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   urlsr9   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   rn   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.
        r4   r   rK   N)r   r   r   _download_urlrF   rA   r)   	gen_setuprV   r=   r   r$   r   fetch_distribution)r   r    tmpdirr;   foundr,   r@   r"   r"   r#   r1   #  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: %sr4   )r   rB   r   r   r   r1   rK   download_locationrV   r=   r   )reqenvrH   testloc
develop_okr   Zskippedsourcer  r"   r#   rt   ]  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)rK   rb   )r   r   r   r   r   cloner  )	r   r   r  
force_scanr  r  Zlocal_indexrH   rt   r"   r  r#   r
  E  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
  rK   )r   r   r  r  r  rH   r"   r"   r#   fetch  s   zPackageIndex.fetchc           	   	   C   s  t |}|rdd t||dd D pg }t|dkrztj|}tj||krGtj	||}tj
|r?tj||sGt|| |}ttj	|dd}|d|d j|d jtj|d f  W d    |S 1 ssw   Y  |S |rtd||f td	)
Nc                 S   s   g | ]}|j r|qS r"   )rM   )rZ   dr"   r"   r#   
<listcomp>  s    z*PackageIndex.gen_setup.<locals>.<listcomp>r4   zsetup.pywzIfrom setuptools import setup
setup(name=%r, version=%r, py_modules=[%r])
r   zCan'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.)rD   rE   r   rF   rQ   rV   r=   rR   dirnamera   r   samefileshutilcopy2r   writerL   rM   splitextr   )	r   rW   r@   r  rE   r   rR   dstr   r"   r"   r#   r	    sD   


		zPackageIndex.gen_setupi    c                 C   s2  |  d| d }zt|}| |}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nqP| |||
 W d    n1 sw   Y  |W |r|  S S |r|  w w )
NzDownloading %szCan't download %s: %s %sr   r0   zcontent-lengthzContent-LengthwbTr4   )r   r   r   r   r   r5   r   r   r   r   r   dl_blocksizeget_allmaxrn   int
reporthookr   r   r   r  r  r   )r   r9   rW   fpr   r   blocknumbssizesizesr  r   r"   r"   r#   _download_to  sF   





	

zPackageIndex._download_toc                 C   s   d S rb   r"   )r   r9   rW   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"   )ro   )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   httpclient
InvalidURLra   rc   r   r   r5   r   r   URLErrorreasonBadStatusLinelineHTTPExceptionsocket)r   r9   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__rI   r'   svnzsvn+gitzgit+zhg+r   r]   T)rA   replacer)   rV   r=   ra   r*   _download_svn_download_git_download_hgr5   r   url2pathnamer   r6   r   _attempt_download)r   r;   r9   r  r+   r@   rW   r"   r"   r#   r    s(   

zPackageIndex._download_urlc                 C   s   |  |d d S )NT)r   r   r"   r"   r#   r   0  r   zPackageIndex.scan_urlc                 C   s2   |  ||}d|dd v r| |||S |S )Nr   r   r   )r-  r   r(   _download_html)r   r9   rW   r   r"   r"   r#   rH  3  s   zPackageIndex._attempt_downloadc                 C   sj   t |}|D ]}| r%td|r#|  t| | ||  S  nq|  t| td| )Nz <title>([^- ]+ - )?Revision \d+:zUnexpected HTML page found at )	r   rp   rY   ru   r   rV   r   rD  r   )r   r9   r   rW   r   r9  r"   r"   r#   rI  :  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 deprecatedr3   r4   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   UserWarningr8   r(   r*   r5   r   r6   
_splituser
urlunparser   rV   system)r   r9   rW   credsr;   netlocr=   r[   qr   authhostuserpwr:   r"   r"   r#   rD  I  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+r4   r0   r3   r   rJ  r   )r5   r   urlsplitr8   rsplit
urlunsplit)r9   
pop_prefixr;   rR  r=   r?   r   revr"   r"   r#   _vcs_split_rev_from_url_  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 )
Nr3   r4   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r8   r^  r   rV   rP  r   r9   rW   r]  r"   r"   r#   rE  q     zPackageIndex._download_gitc                 C   r_  )
Nr3   r4   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 -qra  rb  r"   r"   r#   rF    rc  zPackageIndex._download_hgc                 G      t j|g|R   d S rb   )r   r   r   r"   r"   r#   r        zPackageIndex.debugc                 G   rd  rb   )r   r   r   r"   r"   r#   r     re  zPackageIndex.infoc                 G   rd  rb   )r   r   r   r"   r"   r#   r     re  zPackageIndex.warn)r   r   NT)Frb   )FFFN)FF)*r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r   r1   r
  r  r	  r#  r-  r'  r   r  r   rH  rI  rD  staticmethodr^  rE  rF  r   r   r   __classcell__r"   r"   r   r#   r     sV    
	
5


		
#

L($
#r   z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c                 C   s   |  d}t|S )Nr   )rF   r   unescape)rE   whatr"   r"   r#   decode_entity  s   

rj  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_subrj  )textr"   r"   r#   rs     s   
	rs   c                    s    fdd}|S )Nc                    s    fdd}|S )Nc               	      s:   t  }t  z | i |W t | S t | w rb   )r;  getdefaulttimeoutsetdefaulttimeout)rc   rd   Zold_timeout)rf   timeoutr"   r#   _socket_timeout  s
   
z@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeoutr"   )rf   rp  ro  re   r#   rp    s   z'socket_timeout.<locals>._socket_timeoutr"   )ro  rp  r"   rq  r#   socket_timeout  s   rr  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   )r5   r   r7   encodebase64	b64encoder   rC  )rT  Zauth_sZ
auth_bytesZencoded_bytesencodedr"   r"   r#   _encode_auth  s
   
rx  c                   @   r{   )	
Credentialz:
    A username/password pair. Use like a namedtuple.
    c                 C   s   || _ || _d S rb   usernamepassword)r   r{  r|  r"   r"   r#   r     s   
zCredential.__init__c                 c   s    | j V  | jV  d S rb   rz  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#   ry    s
    ry  c                       s8   e Zd Z fddZedd Zdd Zdd Z  ZS )	
PyPIConfigc                    sP   t g dd}t | tjtjdd}tj|r&| 	| dS dS )z%
        Load from ~/.pypirc
        )r{  r|  
repositoryr   ~z.pypircN)
dictfromkeysr   r   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 )r  )r   rp   )rZ   sectionr   r"   r#   r    s    z2PyPIConfig.creds_by_repository.<locals>.<listcomp>)sectionsr  rn   _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  r{  r|  )r   rp   ry  )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   r9   r  credr"   r"   r#   find_credential  s
   
zPyPIConfig.find_credential)	r   r   r   r   propertyr  r  r  rg  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 ||}|	rt j|j\}}}}}}||kr||
kr||||||f}t j||_|S )	z4Open a urllib2 request, handling HTTP authenticationrK  znonnumeric port: '')r3  httpsNz*Authenticating as %s for %s (from .pypirc)zBasic Authorizationz
User-Agent)r5   r   r6   r)   r3  r4  r5  rN  r  r  ro   r{  r   r   rx  rO  r   Request
add_header
user_agentr9   )r9   r   parsedr;   rR  r=   paramsr?   r   rT  addressr  r   r:   r   r   r(  s2h2Zpath2Zparam2Zquery2Zfrag2r"   r"   r#   r2    s8   

r2  c                 C   s$   |  d\}}} |r|| fS d| fS )zNsplituser('user[:passwd]@host[:port]')
    --> 'user[:passwd]', 'host[:port]'.rJ  N)
rpartition)rU  rV  delimr"   r"   r#   rN  ;  s   rN  c                 C   s   | S rb   r"   )r9   r"   r"   r#   
fix_sf_urlF  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   n t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>rs  )r9   files)   OK)r   zPath not foundz	Not foundr   z	text/html)r5   r   r6   r   rG  rV   r=   isfiler   r)   r   r   ra   r   r   r  formatioStringIOr   r   )r9   r;   r<   r=   paramr?   r   rW   r  r   filepathr(  bodyr   statusmessager   Zbody_streamr"   r"   r#   r1  J  s0   



r1  rb   )r   )Zr   sysrV   rY   r  r  r;  ru  r   r   rL  configparserr   http.clientr3  urllib.parser5   urllib.requesturllib.error	functoolsr   r   pkg_resourcesr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   	distutilsr   Zdistutils.errorsr   fnmatchr   Zsetuptools.wheelr   Z setuptools.extern.more_itertoolsr   r   rD   Irq   r   rE   r   r8   rP   __all__Z_SOCKET_TIMEOUTZ_tmplr  version_infor  r$   r   rA   r   rC   rX   r   rh   rj   rz   r|   r   r   r   rk  rj  rs   rr  rx  ry  RawConfigParserr  r   r   r2  rN  r  r1  r"   r"   r"   r#   <module>   s    @
	


!
#
!     	
&/