o
    Eeɕ                     @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlmZ ddlZddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+ dd	l,m-Z- 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ZE	 eDd%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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{}.{})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$   Y/var/www/bmteknikk.ddns.net/venv/lib/python3.10/site-packages/setuptools/package_index.pyparse_requirement_argD   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   M   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_urle   s   rC   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 URLr6   )
precedenceN)rC   distros_for_locationEGG_FRAGMENTmatchr   groupr   )r;   metadatar.   rB   distrG   r$   r$   r%   r   p   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.whlr6   )locationproject_nameversionrD   r'   )r+   r   from_locationr   is_compatiblerN   rO   r   r   r   r   
EXTENSIONSlen)rM   basenamerI   wheelwin_baser/   platformextr$   r$   r%   rE   ~   s6   

	
rE   c                 C   s   t t| tj| |S )zEYield possible egg or source distribution objects based on a filename)rE   r   osr?   rT   )filenamerI   r$   r$   r%   distros_for_filename   s   r[   c              	   c   s    | d}|stdd |dd D rdS tt|D ]}|| dd  r+ nqt|}t| |d|d| d||d |||dV  dS )zGenerate the interpretation of a source distro name

    Note: if `location` is a filesystem filename, you should call
    ``pkg_resources.normalize_path()`` on it before passing it to this
    routine!
    rL   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>   Nr6   )
py_versionrD   rW   )r:   anyrangerS   isdigitr   join)rM   rT   rI   ra   rD   rW   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   )rj   rk   r$   ri   r%   unique_values   s   rl   z3<([^>]*\srel\s{0,10}=\s{0,10}['"]?([^'" >]+)[^>]*)>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,homepager3   r6   )z<th>Home Pagez<th>Download URLr2   N)RELfinditergroupssetmapstrstripr*   r:   HREFr7   r    urljoin
htmldecoderH   findsearch)r;   pagerG   tagrelrelsposr$   r$   r%   find_external_links   s    
r   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 rf   )	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 URLr2   Nr$   )r7   r    r8   r   patternrz   	groupdict)clsr;   rB   rG   r$   r$   r%   from_url  s   zHashChecker.from_urlc                 C   s   | j | d S rf   )r   updater   r$   r$   r%   r        zHashChecker.feedc                 C   s   | j  | jkS rf   )r   	hexdigestr   r   r$   r$   r%   r   "  r   zHashChecker.is_validc                 C   s   || j  }||S rf   )r   )r   r   r   msgr$   r$   r%   r   %  s   
zHashChecker.reportN)r   r   r   r\   compiler   r   classmethodr   r   r   r   r$   r$   r$   r%   r   	  s    

r   c                       sd  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 )Nr1   |)superr   r+   	index_urlscanned_urlsfetched_urlspackage_pagesr\   r   re   rs   r   rG   allowsto_scanr7   requesturlopenopener)r   r   hosts	ca_bundle
verify_sslrg   kw	__class__r$   r%   r   -  s   	zPackageIndex.__init__c                    s0   zt |j W n
 ty   Y d S w t |S rf   )r   rO   	Exceptionr   add)r   rJ   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ignorer6   code  )&r   
URL_SCHEMEprocess_filenamelistr   url_okdebugr   rs   r   infoopen_url
isinstancer7   error	HTTPErrorr   r   r;   headersgetr*   closereadrt   	get_paramdecoderv   rp   r    rw   rx   rH   process_urlr,   r   getattrprocess_index)r   r;   retrievediststmplfr.   r{   r   rG   linkr$   r$   r%   r   H  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)rY   r?   existswarnisdirrealpathlistdirr   re   r[   r   r   rs   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 )Nr6   fileTz
Note: Bypassing %s (disallowed host; see https://setuptools.pypa.io/en/latest/deprecated/easy_install.html#restricting-downloads-with-allow-hosts for details).
)	r   rH   r*   r   r7   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   s2    | ]}t |D ]}|d r	||fV  q	qdS )z	.egg-linkN)rY   r   r+   )r]   r?   entryr$   r$   r%   r_     s    z.PackageIndex.scan_egg_links.<locals>.<genexpr>)filterrY   r?   r   r   	itertoolsstarmapscan_egg_link)r   search_pathdirs	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`   )openrY   r?   re   r   r   rs   rt   ru   rS   r
   rM   r   rD   r   )r   r?   r   	raw_lineslinesegg_path
setup_pathrJ   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)NNr1   r`   r5   r6   r   T)r,   r   r   rs   r7   r    r9   rS   r:   r   r   r   
setdefaultr*   r   )r   r   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 pager6   r   .pyz
#egg=%s-%sc                 S   s   d|  ddd S )Nz<a href="%s#md5=%s">%s</a>r6      r`   )rH   )mr$   r$   r%   <lambda>  s    z,PackageIndex.process_index.<locals>.<lambda>)rv   rp   r   r7   r    rw   rx   rH   r!   r   rC   r+   need_version_infoscan_urlPYPI_MD5sub)	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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   rg   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 )Nr1   r$   )	r   r   unsafe_namer   r   keyrN   not_found_in_indexr   )r   requirementr;   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  	installerrJ   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   rY   unlinkr   r   r-   r?   rT   )r   checkerrZ   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   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   rs   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.
        r6   r   rM   N)r   r   r   _download_urlrH   rC   r+   	gen_setuprY   r?   r   r&   r   fetch_distribution)r   r"   tmpdirr=   foundr.   rB   r$   r$   r%   r3   7  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: %sr6   )r  rD   r   r   r   r3   rM   download_locationrY   r?   r   )reqenvrJ   testloc
develop_okr   skippedsourcer  r$   r%   ry   w  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)rM   rf   )r   r	  r  r   r   cloner  )	r   r  r  
force_scanr"  r   local_indexrJ   ry   r$   r  r%   r  Y  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  rM   )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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$   )rO   )r]   dr$   r$   r%   
<listcomp>  s    z*PackageIndex.gen_setup.<locals>.<listcomp>r6   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.)rF   rG   r   rH   rS   rY   r?   rT   dirnamere   r   samefileshutilcopy2r   writerN   rO   splitextr   )	r   rZ   rB   r  rG   r   rT   dstr   r$   r$   r%   r    sJ   




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   r2   zcontent-lengthzContent-LengthwbTr6   )r   r   r   r   r   r7   r   r   r   r   r   dl_blocksizeget_allmaxrs   int
reporthookr   r   r   r.  r  r   )r   r;   rZ   fpr  r   blocknumbssizesizesr  r   r$   r$   r%   _download_to  sF   





	

zPackageIndex._download_toc                 C   s   d S rf   r$   )r   r;   rZ   r8  blksizer:  r$   r$   r%   r6  	     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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$   )rt   )r]   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
InvalidURLre   rg   r   r   r7   r   r   URLErrorreasonBadStatusLinelineHTTPExceptionOSError)r   r;   warningvr   r$   r$   r%   r     sV   
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...\___downloaded__rK   r)   svnzsvn+gitzgit+zhg+r   r`   T)rC   replacer+   rY   r?   re   r,   _download_svn_download_git_download_hgr7   r   url2pathnamer    r8   r   _attempt_download)r   r=   r;   r  r-   rB   rZ   r$   r$   r%   r  /  s(   

zPackageIndex._download_urlc                 C   s   |  |d d S )NT)r   r  r$   r$   r%   r   L  r   zPackageIndex.scan_urlc                 C   s2   |  ||}d|dd v r| |||S |S )Nr   r   r   )r<  r   r*   _invalid_download_html)r   r;   rZ   r   r$   r$   r%   rY  O  s   zPackageIndex._attempt_downloadc                 C   s   t | td| )NzUnexpected HTML page found at )rY   r  r   )r   r;   r   rZ   r$   r$   r%   rZ  V  s   
z#PackageIndex._invalid_download_htmlc                 C   s   t d| )Nz/Invalid config, SVN download is not supported: r   )r   r;   	_filenamer$   r$   r%   rU  Z  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+r6   r2   r5   r   @r   )r7   r    urlsplitr:   rsplit
urlunsplit)r;   
pop_prefixr=   netlocr?   rA   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 )
Nr5   r6   r   Tra  zDoing git clone from %s to %szgit clone --quiet %s %szChecking out %szgit -C %s checkout --quiet %sr:   rd  r   rY   systemr   r;   rZ   rc  r$   r$   r%   rV  o     zPackageIndex._download_gitc                 C   re  )
Nr5   r6   r   Trf  zDoing hg clone from %s to %szhg clone --quiet %s %szUpdating to %szhg --cwd %s up -C -r %s -qrg  ri  r$   r$   r%   rW    rj  zPackageIndex._download_hgc                 G      t j|g|R   d S rf   )r   r   r  r$   r$   r%   r        zPackageIndex.debugc                 G   rk  rf   )r   r   r  r$   r$   r%   r     rl  zPackageIndex.infoc                 G   rk  rf   )r   r   r  r$   r$   r%   r     rl  zPackageIndex.warn)r   r   NT)Frf   )FFFN)FF)*r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r
  r  r  r	  r  r3   r  r&  r  r2  r<  r6  r   r  r   rY  rZ  rU  staticmethodrd  rV  rW  r   r   r   __classcell__r$   r$   r   r%   r   *  s^    
	
5


	&

O.$
"r   z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c                 C   s   |  d}t|S )Nr   )rH   r   unescape)rG   whatr$   r$   r%   decode_entity  s   

rq  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_subrq  )textr$   r$   r%   rx     s   
	rx   c                    s    fdd}|S )Nc                    s    fdd}|S )Nc               	      s:   t  }t  z | i |W t | S t | w rf   )socketgetdefaulttimeoutsetdefaulttimeout)rg   rh   old_timeout)rj   timeoutr$   r%   _socket_timeout  s
   
z@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeoutr$   )rj   ry  rx  ri   r%   ry    s   z'socket_timeout.<locals>._socket_timeoutr$   )rx  ry  r$   rz  r%   socket_timeout  s   r{  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   )r7   r    r9   encodebase64	b64encoder   rT  )authauth_s
auth_bytesencoded_bytesencodedr$   r$   r%   _encode_auth  s
   
r  c                   @   r   )	
Credentialz:
    A username/password pair. Use like a namedtuple.
    c                 C   s   || _ || _d S rf   usernamepassword)r   r  r  r$   r$   r%   r     s   
zCredential.__init__c                 c   s    | j V  | jV  d S rf   r  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%   r    s
    r  c                       s8   e Zd Z fddZedd Zdd Zdd Z  ZS )	
PyPIConfigc                    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   rY   r?   re   
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   ru   )r]   sectionr   r$   r%   r(    s    z2PyPIConfig.creds_by_repository.<locals>.<listcomp>)sectionsr  rs   _get_repo_cred)r   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   ru   r  )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   r;   r  credr$   r$   r%   find_credential  s
   
zPyPIConfig.find_credential)	r   r   r   r   propertyr  r  r  rn  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 authentication:znonnumeric port: '')rC  httpsNz*Authenticating as %s for %s (from .pypirc)zBasic Authorizationz
User-Agent)r7   r    r8   r+   rC  rD  rE  
_splituserr  r  rt   r  r   r   r  
urlunparser   Request
add_header
user_agentr;   )r;   r   parsedr=   rb  r?   paramsrA   r   r  addressr  r   r<   r   r   r7  s2h2path2param2query2frag2r$   r$   r%   rB    s8   

rB  c                 C   s$   |  d\}}} |r|| fS d| fS )zNsplituser('user[:passwd]@host[:port]')
    --> 'user[:passwd]', 'host[:port]'.r]  N)
rpartition)hostuserdelimr$   r$   r%   r  @  s   r  c                 C   s   | S rf   r$   )r;   r$   r$   r%   
fix_sf_urlK  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 directoriesr1   z
index.htmlrNz<a href="{name}">{name}</a>)r-   zB<html><head><title>{url}</title></head><body>{files}</body></html>r|  )r;   files)   OK)r   zPath not foundz	Not foundr   z	text/html)r7   r    r8   r   rX  rY   r?   isfiler   r+   r   r   re   r   r   r  formatioStringIOr   r   )r;   r=   r>   r?   paramrA   r   rZ   r  r   filepathr7  bodyr   statusmessager   body_streamr$   r$   r%   rA  O  s0   



rA  rf   )r   )Yr   sysrY   r\   r  r,  rt  r~  r   r   configparserr   http.clientrC  urllib.parser7   urllib.requesturllib.error	functoolsr   r   pkg_resourcesr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   	distutilsr   distutils.errorsr   fnmatchr   setuptools.wheelr    setuptools.extern.more_itertoolsr   r   rF   Irv   r   rG   r   r:   rR   __all___SOCKET_TIMEOUT_tmplr  version_infor  r&   r   rC   r   rE   r[   r   rl   ro   r   r   r   r   r   rr  rq  rx   r{  r  r  RawConfigParserr  r   r   rB  r  r  rA  r$   r$   r$   r%   <module>   s    @
	


#
"
!    {
'/