
    ?wg                    r   d Z ddlm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mZ ddlm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/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5  ejl                  d      Z7 ejl                  dejp                        Z9 ejl                  d      Z: ejl                  dejp                        jv                  Z<dj{                         Z>g dZ?dZ@dej                   dej                  j                   dej                  j                   ZEd ZFd ZGd ZHd5dZId5dZJd5dZKde#dfdZLd ZM ejl                  d ejp                        ZN	 eMd!        ZO G d" d#      ZP G d$ d%eP      ZQ G d& d'e%      ZR ejl                  d(      j                  ZTd) ZUd* ZVd6d+ZWd, ZX G d- d.e      ZY G d/ d0ej                        Z[ej                  j                  fd1Z^d2 Z_  eWe@      e^      Z^d3 Z`d4 Zay)7z$PyPI and direct package downloading.    )annotationsN)	translatewraps)
NamedTupleunique_everseen)BINARY_DISTCHECKOUT_DISTDEVELOP_DISTEGG_DISTSOURCE_DISTDistributionEnvironmentRequirementfind_distributionsnormalize_pathparse_version	safe_namesafe_versionto_filename)Wheel   )_cfg_read_utf8_with_fallback_read_utf8_with_fallback)log)DistutilsErrorz^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/z Python-urllib/.c                n    	 t        j                  |       S # t        $ r}t        d|       |d }~ww xY w)Nz/Not a URL, existing file, or requirement spec: )r   parse
ValueErrorr   )speces     O/var/www/horilla/myenv/lib/python3.12/site-packages/setuptools/package_index.pyparse_requirement_argr*   H   sB      && =dXF
	s    	4/4c                8   | j                         }d\  }}}|j                  d      ro|j                  d      r| dd }d}nV|j                  dd      r| d	d
 }| dd }d}n7|j                  d      r| dd }d}n|j                  dd      r| 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plats        r)   r    r    Q   s     JJLE)D&$~~f>>,':DDk3/"R[F:DD^^,-:DDos3"R[F:DD    c                d   t         j                  j                  |       }|\  }}}}}}t         j                  j                  |j	                  d      d         }|dk(  r6|dk(  r1t         j                  j                  |j	                  d      d         }d|v r|j	                  dd      \  }}||fS )N/zsourceforge.netdownload#r   )urllibr%   urlparseunquotesplit)	urlparts_schemeserverpath_parameters_queryfragmentr3   s	            r)   egg_info_for_urlrI   i   s    LL!!#&E;@8GVT;<<

3 34D""tz'9||##DJJsOB$78
d{C+h>r6   c              #     K   t        |       \  }}t        | ||      E d{    |rCt        j                  |      }|r+t	        | |j                  d      |t              E d{    yyy7 J7 	w)zEYield egg or source distribution objects that might be found at a URLNr   )
precedence)rI   distros_for_locationEGG_FRAGMENTmatchr!   groupr   )rA   metadatar3   rH   rN   s        r)   r   r   t   st     %c*ND(#Cx888""8,,U[[^X-     9s"   A0A,AA0$A.%A0.A0c                &   |j                  d      r|dd }|j                  d      rd|v rt        j                  | ||      gS |j                  d      rLd|v rHt        |      }|j	                         sg S t        | |j
                  |j                  t        dz         gS |j                  d	      r%t        |      \  }}}|t        | |||t        |      S t        D ]1  }|j                  |      s|dt        |        }t        | ||      c S  g S )
z:Yield egg or source distribution objects based on basename.egg.zipNr.   z.egg-z.whlr   )locationproject_nameversionrK   r,   )r0   r   from_locationr   is_compatiblerU   rV   r   r    r!   r
   
EXTENSIONSlen)rT   basenamerP   wheelwin_baser4   platformexts           r)   rL   rL      s+   $CR= SH_**8XxHII SH_h""$I!"//#a<
 	
  %8%B"&(((Hfk8 
  GS!3s8),H(8XFFG Ir6   c                h    t        t        |       t        j                  j	                  |       |      S )zEYield possible egg or source distribution objects based on a filename)rL   r   osrE   r[   )filenamerP   s     r)   distros_for_filenamerc      s*    x "''"2"28"<h r6   c           
   #  F  K   |j                  d      }|st        d |dd D              ryt        t        |            D ]  }||   dd j	                         s n t        |      }t        | |dj                  |d|       dj                  ||d       |||       yw)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!
    rS   c              3  H   K   | ]  }t        j                  d |        yw)z	py\d\.\d$N)rerN   ).0ps     r)   	<genexpr>z(interpret_distro_name.<locals>.<genexpr>   s     KAbhh|Q7Ks    "   Nr   )
py_versionrK   r^   )r@   anyrangerZ   isdigitr   join)rT   r[   rP   rk   rK   r^   rB   rh   s           r)   r!   r!      s      NN3E#KqrKK 3u: 8BQ<! J
rqr s   AB!AB!c                .     t                fd       }|S )zs
    Wrap a function returning an iterable such that the resulting iterable
    only ever yields unique items.
    c                 &    t         | i |      S Nr   )argskwargsfuncs     r)   wrapperzunique_values.<locals>.wrapper   s    tT4V455r6   r   )ru   rv   s   ` r)   unique_valuesrw      s"     4[6 6 Nr6   z3<([^>]*\srel\s{0,10}=\s{0,10}['"]?([^'" >]+)[^>]*)>c           
   #    K   t         j                  |      D ]  }|j                         \  }}t        t	        t
        j                  |j                         j                  d                  }d|v sd|v s_t        j                  |      D ]<  }t        j                  j                  | t        |j                  d                   >  dD ]l  }|j                  |      }|dk7  st        j!                  ||      }|s3t        j                  j                  | t        |j                  d                   n yw)zEFind rel="homepage" and rel="download" links in `page`, yielding URLs,homepager:   r   )z<th>Home Pagez<th>Download URLr9   N)RELfinditergroupssetmapstrstripr/   r@   HREFr=   r%   urljoin
htmldecoderO   findsearch)rA   pagerN   tagrelrelsposs          r)   find_external_linksr      s     d# L<<>S3syy#))+"3"3C"89:t!3s+ Lll**3
5;;q>0JKKL	L 5 Liin"9KKc*Ell**3
5;;q>0JKKLs   A4D?7A1D?)D?=D?c                  "    e Zd ZdZd Zd Zd Zy)ContentCheckerzP
    A null content checker that defines the interface for checking content
    c                     y)z3
        Feed a block of data to the hash.
        N selfblocks     r)   feedzContentChecker.feed   s     	r6   c                     y)zC
        Check the hash. Return False if validation fails.
        Tr   r   s    r)   is_validzContentChecker.is_valid   s     r6   c                     y)zu
        Call reporter with information about the checker (hash name)
        substituted into the template.
        Nr   )r   reportertemplates      r)   reportzContentChecker.report  s    
 	r6   N)__name__
__module____qualname____doc__r   r   r   r   r6   r)   r   r      s    r6   r   c                  Z    e Zd Z ej                  d      ZddZed        Zd Z	d Z
d Zy)	HashCheckerzK(?P<hash_name>sha1|sha224|sha384|sha256|sha512|md5)=(?P<expected>[a-f0-9]+)c                T    || _         t        j                  |      | _        || _        y rr   )	hash_namehashlibnewhashexpected)r   r   r   s      r)   __init__zHashChecker.__init__  s     "KK	*	 r6   c                    t         j                  j                  |      d   }|s
t               S | j                  j                  |      }|s
t               S  | di |j                         S )z5Construct a (possibly null) ContentChecker from a URLr9   r   )r=   r%   r>   r   patternr   	groupdict)clsrA   rH   rN   s       r)   from_urlzHashChecker.from_url  s^     <<((-b1!##""8,!##'U__&''r6   c                :    | j                   j                  |       y rr   )r   updater   s     r)   r   zHashChecker.feed!  s    		r6   c                P    | j                   j                         | j                  k(  S rr   )r   	hexdigestr   r   s    r)   r   zHashChecker.is_valid$  s    yy""$55r6   c                0    || j                   z  } ||      S rr   )r   )r   r   r   msgs       r)   r   zHashChecker.report'  s    '}r6   NreturnNone)r   r   r   rf   compiler   r   classmethodr   r   r   r   r   r6   r)   r   r     s?    bjj	#G
!
 ( ( 6r6   r   c                  z    e Zd ZdZ	 	 	 	 d&	 	 	 	 	 d' fdZ fdZd(d)dZd(d*dZd(d+dZd,dZ	d,dZ
d	 Zd
 Zd,dZd-d,dZd,dZd- fd	Zd,dZd,dZd Zd,dZd Z	 	 	 	 d.	 	 	 	 	 	 	 d/dZ	 d0	 	 	 	 	 d1dZd ZdZd Zd,dZd-dZd Zed        Zd Z d Z!d,dZ"d  Z#d! Z$ed"        Z%d,d#Z&d,d$Z'd,d%Z( xZ)S )2r   z;A distribution index that scans web pages for download URLsc                V   t        |   |i | |dd |j                  d        z   | _        i | _        i | _        i | _        t        j                  dj                  t        t        |                  j                  | _        g | _        t        j                   j"                  | _        y )Nr8   |)superr   r0   	index_urlscanned_urlsfetched_urlspackage_pagesrf   r   ro   r   r   rN   allowsto_scanr=   requesturlopenopener)r   r   hosts	ca_bundle
verify_sslrs   kw	__class__s          r)   r   zPackageIndex.__init__/  s     	$%"%"S)Fy/A/A#/F+F%GG"$"$#%jj#i*?!@AGGnn,,r6   c                l    	 t        |j                         t        |   |      S # t        $ r Y y w xY wrr   )r   rV   	Exceptionr   add)r   distr   s     r)   r   zPackageIndex.addA  s9    	$,,' w{4    		s   ' 	33c           	        || j                   v r|syd| j                   |<   t        |      s| j                  |       yt        t	        |            }|r$| j                  |      sy| j                  d|       |s|r|| j                  v r t        t        | j                  |             y| j                  |      sd| j                  |<   y| j                  d|       d| j                  |<   d}| j                  |||z        }|yt        |t        j                  j                        r-|j                   dk(  r| j                  d|j"                          d| j                  |j$                  <   d|j&                  j)                  d	d
      j+                         vr|j-                          y|j$                  }|j/                         }t        |t0              sXt        |t        j                  j                        rd}n|j&                  j3                  d      xs d}|j5                  |d      }|j-                          t6        j9                  |      D ]K  }	t        j:                  j=                  |t?        |	jA                  d                  }
| jC                  |
       M |jE                  | jF                        r$tI        |dd      dk7  r| jK                  ||      }yyy)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: htmlcontent-type zlatin-1charsetignorer   code  )&r   
URL_SCHEMEprocess_filenamelistr   url_okdebugr   r   r   infoopen_url
isinstancer=   error	HTTPErrorr   r   rA   headersgetr/   closereadr   	get_paramdecoder   r|   r%   r   r   rO   process_urlr1   r   getattrprocess_index)r   rA   retrievediststmplfr3   r   r   rN   links              r)   r   zPackageIndex.process_urlJ  sX   $###H!%##!!#&-.E{{3'

+S1C4+<+<$<TXXu%&{{3%)Dc"		,$!%#MMM#tcz*9a//0QVVs]II.quug67#'!%% ~r:@@BBGGIuuvvx$$!V\\334#))--i8EI;;w1D		]]4( 	#E<<''jQ.HIDT"	# >>$..)ga.F#.M%%c40D /N)r6   c                   t         j                  j                  |      s| j                  d|       y t         j                  j	                  |      rk|sit         j                  j                  |      }t        j                  |      D ]2  }| j                  t         j                  j                  ||      d       4 t        |      }|r2| j                  d|       t        t        | j                  |             y y )NzNot found: %sTz	Found: %s)ra   rE   existswarnisdirrealpathlistdirr   ro   rc   r   r   r   r   )r   fnnestedrE   itemr   s         r)   r   zPackageIndex.process_filename  s    ww~~b!IIor*77==V77##B'D

4( F%%bggll4&>EF %R(JJ{B'TXXu%& r6   c                   t        |      }|xr" |j                  d      j                         dk(  }|s1| j                  t        j
                  j                  |      d         ryd}|rt        ||z        | j                  ||       y)Nr   fileTz
Note: Bypassing %s (disallowed host; see https://setuptools.pypa.io/en/latest/deprecated/easy_install.html#restricting-downloads-with-allow-hosts for details).
F)	r   rO   r/   r   r=   r%   r>   r   r   )r   rA   fatalsis_filer   s         r)   r   zPackageIndex.url_ok  s    sO4
((*f4dkk&,,"7"7"<Q"?@W 	
  s++IIc3r6   c                    t        t        j                  j                  |      }d |D        }t	        t        j                  | j                  |             y )Nc              3  z   K   | ]3  }t        j                  |      D ]  }|j                  d       r||f  5 yw)z	.egg-linkN)ra   r   r0   )rg   rE   entrys      r)   ri   z.PackageIndex.scan_egg_links.<locals>.<genexpr>  sF      
D)
 ~~k* 5M

s   9;)filterra   rE   r   r   	itertoolsstarmapscan_egg_link)r   search_pathdirs	egg_linkss       r)   scan_egg_linkszPackageIndex.scan_egg_links  sB    bggmm[1

	 	Yt119=>r6   c           
        t        t        j                  j                  ||            }t	        t        d t        t        j                  |j                                           }t        |      dk7  ry |\  }}t        t        j                  j                  ||            D ]C  }t        j                  j                  |g| |_        t        |_        | j                  |       E y )Nrj   )r   ra   rE   ro   r   r   r   r   r   
splitlinesrZ   r   rT   r   rK   r   )r   rE   r   contentlinesegg_path_setup_pathr   s           r)   r  zPackageIndex.scan_egg_link  s    *277<<e+DEVD#cii1C1C1E"FGHu:? %+&rww||D('CD 	DGGLL66DM)DOHHTN	r6   c           	        d}|j                  | j                        s|S t        t        t        j
                  j                  |t        | j                        d  j                  d                  }t        |      dk7  sd|d   v r|S t        |d         }t        |d         }d| j                  j                  |j                         i       |<   t        |      t        |      fS )NNNr8   rj   r<   r   r   T)r1   r   r   r   r=   r%   r?   rZ   r@   r   r   r   
setdefaultr/   r   )r   r   NO_MATCH_SENTINELrB   pkgvers         r)   _scanzPackageIndex._scan  s    &t~~.$$S--tC4G4I/J/P/PQT/UVWu:?cU1Xo$$ a!58$?C%%ciik26t<3S!111r6   c                   t         j                  |      D ]J  }	 | j                  t        j                  j                  |t        |j                  d                         L | j                  |      \  }}|syt        ||      D ]S  }t        |      \  }}|j                  d      r!|s|r|d| d| z  }n| j                  |       | j                  |       U t        j                  d |      S # t        $ r Y w xY w)z#Process the contents of a PyPI pager   r   .pyz#egg=rS   c                B     dj                   | j                  ddd       S )Nz<a href="{}#md5={}">{}</a>r      rj   )formatrO   )ms    r)   <lambda>z,PackageIndex.process_index.<locals>.<lambda>  s"    92991771a;KL r6   )r   r|   r  r=   r%   r   r   rO   r&   r   rI   r0   need_version_infoscan_urlPYPI_MD5sub)	r   rA   r   rN   r  r  new_urlr3   frags	            r)   r   zPackageIndex.process_index  s     ]]4( 	E

6<<//ZA5OPQ	 ::c?S +35 	#G)'2JD$}}U#Dse1SE22G**3/MM'"	# ||Ld
 	
%  s   AC33	C?>C?c                (    | j                  d|       y )NzPPage at %s links to .py file(s) without version info; an index scan is required.)scan_allr   rA   s     r)   r  zPackageIndex.need_version_info  s     	
r6   c                    | j                   | j                  vr&|r | j                  |g|  | j                  d       | j	                  | j                          y )Nz6Scanning index of all packages (this may take a while))r   r   r   r   r  r   r   rs   s      r)   r#  zPackageIndex.scan_all  sG    >>!2!22		#%%IINOdnn%r6   c                   | j                  | j                  |j                  z   dz          | j                  j	                  |j
                        s+| j                  | j                  |j                  z   dz          | j                  j	                  |j
                        s| j                  |       t        | j                  j	                  |j
                  d            D ]  }| j                  |        y )Nr8   r   )	r  r   unsafe_namer   r   keyrU   not_found_in_indexr   )r   requirementrA   s      r)   find_packageszPackageIndex.find_packages  s    dnn{'>'>>DE!!%%koo6MM$..;+C+CCcIJ!!%%koo6##K0**..{CD 	CMM#	r6   c                    | j                          | j                  |       | |j                     D ]  }||v r|c S | j                  d||        t        |   ||      S )Nz%s does not match %s)prescanr,  r)  r   r   obtain)r   r+  	installerr   r   s       r)   r/  zPackageIndex.obtain  se    ;') 	BD{"JJ-{DA	B w~k955r6   c                0   |j                  | j                  d|        |j                         sg|j                          t	        j
                  |       t        |j                  j                   dt        j                  j                  |       d      y)z-
        checker is a ContentChecker
        zValidating %s checksum for z validation failed for z; possible download problem?N)r   r   r   r   ra   unlinkr   r   r2   rE   r[   )r   checkerrb   tfps       r)   
check_hashzPackageIndex.check_hash  s     	tzz%@
#KL!IIKIIh <<$$%%<RWW=M=Mh=W<X Y- -  "r6   c                    |D ]k  }| j                   0t        |      r%|j                  d      st        t	        |            r| j                  |       Q| j                   j                  |       m y)z;Add `urls` to the list that will be prescanned for searchesNfile:)r   r   r1   r   r   r  append)r   urlsrA   s      r)   add_find_linkszPackageIndex.add_find_links  s]     	)C$!#>>'*,- c" ##C(	)r6   c                |    | j                   r)t        t        | j                  | j                                d| _         y)z7Scan urls scheduled for prescanning (e.g. --find-links)N)r   r   r   r  r   s    r)   r.  zPackageIndex.prescan(  s'    <<T]]DLL12r6   c                    | |j                      r| j                  d}}n| j                  d}} |||j                         | j	                          y )Nz#Couldn't retrieve index page for %rz3Couldn't find index page for %r (maybe misspelled?))r)  r   r   r(  r#  )r   r+  methr   s       r)   r*  zPackageIndex.not_found_in_index.  sC     		#H#D		#X#DS+))*r6   c                Z   t        |t              st        |      }|rF| j                  ||      }t	        |      \  }}|j                  d      r| j                  |||      }|S t        j                  j                  |      r|S t        |      }t        | j                  ||      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.
        r  rT   N)r   r   r   _download_urlrI   r0   	gen_setupra   rE   r   r*   r   fetch_distribution)r   r'   tmpdirschemefoundr3   rH   s          r)   r:   zPackageIndex.download6  s    $ $,%F**48!1$!7h==' NN5(FCE%,T2t..tV<j$OOr6   c                   	  j                  d|       t               	d}d	d
 	fd}|r) j                           j                  |        ||      }|s|	 |||      }|$ j                   j                           ||      }||s j                  |        ||      }| j                  dxr dxs d|       y j                  d|       |j                  |j                        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                   |}|| j                      D ]  }|j                  t        k(  r*s(|vr#j                  d|       j	                  |       @|| v xr |j                  t
        k  xs  }|saj                  |j                  	      }||_        t        j                  j                  |j                        s|c S  y )Nz&Skipping development or system egg: %s)r)  rK   r   r   r   r   r:   rT   download_locationra   rE   r   )
reqenvr   testloc
develop_okr   skippedsourcerB  s
        r)   r   z-PackageIndex.fetch_distribution.<locals>.findv  s    { CGG $??l2:7*		D   D)s{U;(F(Tf*--v>C-0D*ww~~d&<&<=#$" r6   z:No local packages or working download links found for %s%sza source distribution of r   zBest match: %s)rT   rr   )rI  zEnvironment | None)r   r~   r.  r,  r   r   clonerG  )
r   r+  rB  
force_scanrN  rL  local_indexr   r   rM  s
   ` ` ``   @r)   rA  zPackageIndex.fetch_distributionX  s    4 			$k2%	 	0 LLN{+$D/[1D<||'$D<
{+$D<IIL77=2
 II&-::t'='=:>>r6   c                H    | j                  ||||      }||j                  S y)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)rA  rT   )r   r+  rB  rP  rN  r   s         r)   fetchzPackageIndex.fetch  s-     &&{FJO== r6   c                   t         j                  |      }|xr6 t        ||j                  d      d       D cg c]  }|j                  r| c}xs g }t        |      dk(  rDt        j                  j                  |      }t        j                  j                  |      |k7  rwt        j                  j                  ||      }t        j                  j                  |      r t        j                  j                  ||      st        j                  ||       |}t        t        j                  j                  |d      dd      5 }	|	j!                  d|d   j"                  d|d   j                  d	t        j                  j%                  |      d   d
       d d d        |S |rt'        d|d|      t'        d      c c}w # 1 sw Y   |S xY w)Nr   zsetup.pywzutf-8)encodingz(from setuptools import setup
setup(name=r   z
, version=z, py_modules=[z])
z9Can't unambiguously interpret project/version identifier zI; any dashes in the name or version should be escaped using underscores. zpCan't process plain .py files without an '#egg=name-version' suffix to enable automatic setup script generation.)rM   rN   r!   rO   rV   rZ   ra   rE   r[   dirnamero   r   samefileshutilcopy2openwriterU   splitextr   )
r   rb   rH   rB  rN   dr   r[   dstr   s
             r)   r@  zPackageIndex.gen_setup  s   ""8,  /xQN99   	 u:?ww''1H wwx(F2ggll684s+0@0@30OLL3/"Hbggll6:6gN RV

""'("7"7!:*U1XEUEUDXXfgigngngwgw  yA  hB  CD  hE  gH  HLM
 O KH< X  %y*  !G A$
 Os   GAG

Gi    c                >   | j                  d|       d }	 t        j                  |      }| j                  |      }t	        |t
        j                  j                        r(t        d| d|j                   d|j                         |j                         }d}| j                  }d}d|v r?|j                  d      }	t        t        t        |	            }| j!                  |||||       t#        |d	      5 }
	 |j%                  |      }|r=|j'                  |       |
j)                  |       |d
z  }| j!                  |||||       nnR| j+                  |||
       d d d        ||r|j-                          S S # 1 sw Y   xY w# |r|j-                          w w xY w)NzDownloading %szCan't download :  r   r9   zcontent-lengthzContent-Lengthwbr   )r   r   r   r   r   r=   r   r   r   r   r   dl_blocksizeget_allmaxr   int
reporthookr[  r   r   r\  r5  r   )r   rA   rb   fpr3  r   blocknumbssizesizesr4  r   s               r)   _download_tozPackageIndex._download_to  s{   		"C(	!**3/Gs#B"fll445$se2bggYax%PQQggiGH""BD7*(893sE?+XxTBh% 
8GGBKEU+		%( AXxTJ  37
8 
 
8 
8 
 s%   C!F 7A'E;	F ;F F Fc                     y rr   r   )r   rA   rb   rj  blksizerl  s         r)   rh  zPackageIndex.reporthook  s    r6   c           	        |j                  d      rt        |      S 	 t        || j                        S # t        t
        j                  j                  f$ rh}dj                  |j                  D cg c]  }t        |       nc c}w c}      }|r| j                  ||       nt        | d|       |Y d }~y d }~wt        j                  j                  $ r}|cY d }~S d }~wt        j                  j                   $ rE}|r| j                  ||j"                         nt        d| d|j"                         |Y d }~y d }~wt
        j                  j$                  $ rD}|r| j                  ||j&                         nt        | d|j&                         |Y d }~y d }~wt
        j                  j(                  t*        f$ r1}|r| j                  ||       nt        d| d|       |Y d }~y d }~ww xY w)Nr7  rb  zDownload error for ra  z7 returned a bad status line. The server might be down, )r1   
local_openopen_with_authr   r&   httpclient
InvalidURLro   rs   r   r   r   r=   r   r   URLErrorreasonBadStatusLinelineHTTPExceptionOSError)r   rA   warningvargr   s         r)   r   zPackageIndex.open_url
  s   >>'"c?"	N!#t{{33DKK223 	<((7CH778C		'3'$uAcU^4!; ( ||%% 	H||$$ 	U		'188,$':3%r!((%LMSTT - {{(( 			'166*$e VVH&  + ))73 	N		'1%$':3%r!%EFAM &	NsW   4 #G7B:0B
3B:: G7C!G7! G7;E G7!:F  &G7'G22G7c                6   t        |      \  }}|r,d|v r*|j                  dd      j                  dd      }d|v r'nd}|j                  d      r|d d }t        j                  j                  ||      }| j                  ||      xs | j                  ||      S )Nz..r#   \___downloaded__rR   r.   )rI   replacer0   ra   rE   ro   _download_vcs_download_other)r   rA   rB  r2   	_fragmentrb   s         r)   r?  zPackageIndex._download_url*  s     +3/i$,||D#.66tSA $, $D==$9D77<<-!!#x0WD4H4Hh4WWr6   c                    t         j                  j                  |       j                  }|j	                  d      \  }}}t        ddgdgt        |      z  z         }t        t        |h|z        d      S )a  
        >>> rvcs = PackageIndex._resolve_vcs
        >>> rvcs('git+http://foo/bar')
        'git'
        >>> rvcs('hg+https://foo/bar')
        'hg'
        >>> rvcs('git:myhost')
        'git'
        >>> rvcs('hg:myhost')
        >>> rvcs('http://foo/bar')
        +svngithgN)	r=   r%   urlsplitrC  	partitionr~   boolnextiter)rA   rC  presep_postalloweds         r)   _resolve_vcszPackageIndex._resolve_vcs;  sj     &&s+22 **3/S%uenvS	'99:D#)400r6   c                   | j                  |      }|sy |dk(  rt        d|       |j                  d      \  }}}| j                  |      \  }}| j	                  d| d| d|        t        j                  |dd||g       t        |d	|d
d|g|d|dd	d|dg      }|,| j	                  d|        t        j                  ||          |S )Nr  z/Invalid config, SVN download is not supported: r<   zDoing z clone from z to rO  z--quietz-Ccheckoutz--cwdupz-rz-q)r  r  zChecking out )r  r   r  _vcs_split_rev_from_urlr   
subprocess
check_calldict)r   rA   spec_filenamevcsrb   r  revco_commandss           r)   r  zPackageIndex._download_vcsN  s    $%< A#G  '005!Q//4S		F3%|C5XJ?@sGYXFGdHj)SAWhdD#tD
 ?IIcU+,!!+c"23r6   c                2   t         j                  j                  |      j                  }|dk(  rFt         j                  j                  t         j                  j                  |      j                        S | j                  |d       | j                  ||      S )Nr   T)
r=   r%   r  rC  r   url2pathnamer>   rE   r   _attempt_download)r   rA   rb   rC  s       r)   r  zPackageIndex._download_otherg  so    &&s+22V>>..v||/D/DS/I/N/NOOC%%c844r6   c                (    | j                  |d       y )NT)r   r$  s     r)   r  zPackageIndex.scan_urlo  s    d#r6   c                    | j                  ||      }d|j                  dd      j                         v r| j                  |||      S |S )Nr   r   r   )rn  r   r/   _invalid_download_html)r   rA   rb   r   s       r)   r  zPackageIndex._attempt_downloadr  sJ    ##C2W[[4::<<..sGXFFOr6   c                H    t        j                  |       t        d|       )NzUnexpected HTML page found at )ra   r2  r   )r   rA   r   rb   s       r)   r  z#PackageIndex._invalid_download_htmly  s!    
		(=cUCDDr6   c                L   t         j                  j                  |       }|j                  j	                  dd      d   }|j
                  j                  d      \  }}}|j                  d      \  }}}|r||fn|df\  }}	|j                  ||d      j                         }
|
|	fS )	a  
        Given a possible VCS URL, return a clean URL and resolved revision if any.

        >>> vsrfu = PackageIndex._vcs_split_rev_from_url
        >>> vsrfu('git+https://github.com/pypa/setuptools@v69.0.0#egg-info=setuptools')
        ('https://github.com/pypa/setuptools', 'v69.0.0')
        >>> vsrfu('git+https://github.com/pypa/setuptools#egg-info=setuptools')
        ('https://github.com/pypa/setuptools', None)
        >>> vsrfu('http://foo/bar')
        ('http://foo/bar', None)
        r  r   r9   r<   @Nr   )rC  rE   rH   )
r=   r%   r  rC  r@   rE   r  
rpartition_replacegeturl)rA   rB   clean_schemeno_fragment_pathr  r  r  post
clean_pathr  resolveds              r)   r  z$PackageIndex._vcs_split_rev_from_url}  s     %%c*||))#q1"5 "'!5!5c!:!Q)44S9S$),3+4,
C>>	 " 

 &( 	 }r6   c                0    t        j                  |g|  y rr   )r   r   r&  s      r)   r   zPackageIndex.debug  s    		#r6   c                0    t        j                  |g|  y rr   )r   r   r&  s      r)   r   zPackageIndex.info      tr6   c                0    t        j                  |g|  y rr   )r   r   r&  s      r)   r   zPackageIndex.warn  r  r6   )zhttps://pypi.org/simple/)*NT)r   r   r   r  r   r   )F)r   r  r   r   )r   r  r   r   )r   r  r   r  r   rr   )FFFN)rP  r  rN  r  rL  r  r   zDistribution | None)FF)rP  r  rN  r  r   z
str | None)*r   r   r   r   r   r   r   r   r   r  r  r  r   r  r#  r,  r/  r5  r:  r.  r*  r:   rA  rS  r@  rd  rn  rh  r   r?  staticmethodr  r  r  r  r  r  r  r   r   r   __classcell__r   s   @r)   r   r   ,  sh   E 4--
 - 
-$!31j'  ? 2 
:
&6) PL ! P? 	P?
 P? P? 
P?f MR/3EI	'R L DN@X" 1 1$25$E  >r6   r   z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c                N    | j                  d      }t        j                  |      S )Nr   )rO   r   unescape)rN   whats     r)   decode_entityr    s    ;;q>D==r6   c                "    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_subr  )texts    r)   r   r     s     mT**r6   c                      fd}|S )Nc                      fd}|S )Nc                     t        j                         }t        j                         	  | i |t        j                  |       S # t        j                  |       w xY wrr   )socketgetdefaulttimeoutsetdefaulttimeout)rs   rt   old_timeoutru   timeouts      r)   _socket_timeoutz@socket_timeout.<locals>._socket_timeout.<locals>._socket_timeout  sN     224K$$W-6T,V,((5((5s   A	 	A r   )ru   r  r  s   ` r)   r  z'socket_timeout.<locals>._socket_timeout  s    	6 r6   r   )r  r  s   ` r)   socket_timeoutr    s    	 r6   c                    t         j                  j                  |       }|j                         }t	        j
                  |      }|j                         }|j                  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   )r=   r%   r?   encodebase64	b64encoder   r  )authauth_s
auth_bytesencoded_bytesencodeds        r)   _encode_authr    sR     \\!!$'FJ$$Z0M""$G??4$$r6   c                  .    e Zd ZU dZded<   ded<   ddZy)
Credentialz
    A username/password pair.

    Displayed separated by `:`.
    >>> str(Credential('username', 'password'))
    'username:password'
    r   usernamepasswordc                8    | j                    d| j                   S )N:)r  r  r   s    r)   __str__zCredential.__str__  s    --$--11r6   N)r   r   )r   r   r   r   __annotations__r  r   r6   r)   r  r    s     MM2r6   r  c                  :     e Zd Z fdZed        Zd Zd Z xZS )
PyPIConfigc                &   t         j                  g dd      }t        |   |       t        j
                  j                  t        j
                  j                  d      d      }t        j
                  j                  |      rt        | |       yy)z%
        Load from ~/.pypirc
        )r  r  
repositoryr   ~z.pypircN)
r  fromkeysr   r   ra   rE   ro   
expanduserr   r   )r   defaultsrcr   s      r)   r   zPyPIConfig.__init__  se     ==!GL"WW\\"'',,S19=77>>"(r2 r6   c                    | j                         D cg c]$  }| j                  |d      j                         r|& }}t        t	        | j
                  |            S c c}w )Nr  )sectionsr   r   r  r   _get_repo_cred)r   sectionsections_with_repositoriess      r)   creds_by_repositoryzPyPIConfig.creds_by_repository  s_      ==?&
xx.446 &
" &
 C++-GHII&
s   )Ac                    | j                  |d      j                         }|t        | j                  |d      j                         | j                  |d      j                               fS )Nr  r  r  )r   r   r  )r   r  repos      r)   r  zPyPIConfig._get_repo_cred  s]    xx.446ZHHWj)//1HHWj)//1
 
 	
r6   c                r    | j                   j                         D ]  \  }}|j                  |      s|c S  y)z
        If the URL indicated appears to be a repository defined in this
        config, return the credential for that repository.
        N)r  itemsr1   )r   rA   r  creds       r)   find_credentialzPyPIConfig.find_credential  s=    
 !% 8 8 > > @ 	J~~j)	 r6   )	r   r   r   r   propertyr  r  r  r  r  s   @r)   r  r    s(    	3 J J
r6   r  c                   t         j                  j                  |       }|\  }}}}}}|j                  d      rt        j
                  j                  d      |dv rt        |      \  }	}
nd\  }	}
|	sJt               j                  |       }|r/t        |      }	|j                  | f}t        j                  dg|  |	rgdt        |	      z   }	||
||||f}t         j                  j                  |      }t         j                   j#                  |      }|j%                  d|	       nt         j                   j#                  |       }|j%                  dt&                ||      }|	rft         j                  j                  |j(                        \  }}}}}}||k(  r1||
k(  r,||||||f}t         j                  j                  |      |_        |S )	z4Open a urllib2 request, handling HTTP authenticationr  znonnumeric port: '')rt  httpsr  z*Authenticating as %s for %s (from .pypirc)zBasic Authorizationz
User-Agent)r=   r%   r>   r0   rt  ru  rv  
_splituserr  r  r   r  r   r   r  
urlunparser   Request
add_header
user_agentrA   )rA   r   parsedrC  netlocrE   paramsqueryr!  r  addressr  r   rB   r   r   ri  s2h2path2param2query2frag2s                          r)   rs  rs    s    \\""3'F06-FFD&% skk$$%:;;"""6*g$g|++C0t9D==#%DHHAIDI,t,,vud:,,))%0..((1?D1..((-|Z0	B 06||/D/DRVV/L,Bvvu<B'Mvvu<E\\,,U3BFIr6   c                @    | j                  d      \  }}} |r|| fS d| fS )zNsplituser('user[:passwd]@host[:port]')
    --> 'user[:passwd]', 'host[:port]'.r  N)r  )hostuserdelims      r)   r  r  I  s0     ,D%Dd**td**r6   c                    | S rr   r   )rA   s    r)   
fix_sf_urlr  T  s    Jr6   c                T   t         j                  j                  |       \  }}}}}}t         j                  j	                  |      }t
        j                  j                  |      rt         j                  j                  |       S |j                  d      rt
        j                  j                  |      rg }t        j                  |      D ]p  }	t
        j                  j                  ||	      }
|	dk(  rt        |
      } nbt
        j                  j                  |
      r|	dz  }	|j                  d|	 d|	 d       r d}|j                  | dj                  |            }d	\  }}nd
\  }}}ddi}t!        j"                  |      }t         j$                  j'                  | ||||      S )z7Read a local path, with special support for directoriesr8   z
index.htmlz	<a href="z">z</a>zB<html><head><title>{url}</title></head><body>{files}</body></html>r  )rA   files)   OK)r   zPath not foundz	Not foundr   z	text/html)r=   r%   r>   r   r  ra   rE   isfiler   r0   r   r   ro   r   r8  r  ioStringIOr   r   )rA   rC   _serverrE   _paramrG   _fragrb   r  r   filepathbodyr   statusmessager   body_streams                    r)   rr  rr  X  s`   4:LL4I4I#4N1GWdFFE~~**40H	ww~~h~~%%c**	s	h 7H% 
	@Aww||Ha0HL /9x(SLL9QCr!D12
	@ XD;;3dii.>;?D# B{+G++d#K<<!!#vwMMr6   rr   )r"   )br   
__future__r   r  configparserr   r   http.clientrt  r  r  ra   rf   rY  r  r  sysurllib.errorr=   urllib.parseurllib.requestfnmatchr   	functoolsr   typingr   more_itertoolsr	   
setuptoolspkg_resourcesr
   r   r   r   r   r   r   r   r   r   r   r   r   r   setuptools.wheelr   unicode_utilsr   r   	distutilsr   distutils.errorsr   r   rM   Ir   r  rN   r   r@   rY   __all___SOCKET_TIMEOUT__version__version_infomajorminorr  r*   r    rI   r   rL   rc   r!   rw   r{   r   r   r   r   r  r  r  r   r  r  r  RawConfigParserr  r   r   rs  r  r  rr  r   r6   r)   <module>r6     s2   * "      	  	 	    
       *      # Q  +rzz67rzz3RTT:2::J RZZ,bdd399
.446
 :112/#BRBRBXBXAYYZ[^[k[k[q[qZrs
0	 F .2kTXD
 bjjKRTTR
 L L$ 2. Bx	; x	z RZZ<=AA

	+%*2 2 %-- %P  &~~55 +`+ 10@Nr6   