
    dfT                     $   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j^                  d
      Z0 ej^                  dejb                        Z2 ej^                  d      Z3 ej^                  dejb                        jh                  Z5djm                         Z7g dZ8dZ9dZ:e:jw                   djv                  ejx                   e      Z=d Z>d Z?d Z@d1dZAd1dZBd1dZCdedfdZDd ZE ej^                  dejb                        ZFeEd        ZG G d d      ZH G d  d!eH      ZI G d" d#e      ZJ ej^                  d$      j                  ZLd% ZMd& ZNd2d'ZOd( ZP G d) d*      ZQ G d+ d,ej                        ZSej                  j                  fd-ZVd. ZW  eOe9      eV      ZVd/ ZXd0 ZYy)3z#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                 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     Q/home/api-vastappli/venv/lib/python3.12/site-packages/setuptools/package_index.pyparse_requirement_argr&   6   s>      && CGI
	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   ?   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#   )urllibr!   urlparseunquotesplit)	urlpartsschemeserverpath
parametersqueryfragmentr/   s	            r%   egg_info_for_urlrF   W   s    LL!!#&E8=5FFD*eX<<

3 34D""tz'9||##DJJsOB$78
d{C+h>r2   c              #      K   t        |       \  }}t        | ||      D ]  }|  |rDt        j                  |      }|r,t	        | |j                  d      |t              D ]  }|  yyyw)zEYield egg or source distribution objects that might be found at a URLr9   )
precedenceN)rF   distros_for_locationEGG_FRAGMENTmatchr   groupr   )r>   metadatar/   rE   distrK   s         r%   r   r   b   s}     %c*ND($S$9 
""8,-U[[^X-  
  s   A,A.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.whlr9   )locationproject_nameversionrH   r(   )r,   r   from_locationr   is_compatiblerS   rT   r   r   r   r   
EXTENSIONSlen)rR   basenamerM   wheelwin_baser0   platformexts           r%   rI   rI   p   s+   $CR= SH_**8XxHII SH_h""$I++MM!|
  	  %8%B"&(((Hfk8 
  GS!
#c(+H(8XFFG Ir2   c                 h    t        t        |       t        j                  j	                  |       |      S )zEYield possible egg or source distribution objects based on a filename)rI   r   osrB   rY   )filenamerM   s     r%   distros_for_filenamera      s*    x "''"2"28"<h r2   c              #     K   |j                  d      }|st        d |dd D              ryt        dt        |      dz         D ]:  }t	        | |dj                  |d|       dj                  ||d       |||       < yw)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!
    rQ   c              3   H   K   | ]  }t        j                  d |        yw)z	py\d\.\d$N)rerK   ).0ps     r%   	<genexpr>z(interpret_distro_name.<locals>.<genexpr>   s     KAbhh|Q7Ks    "   Nr9   )
py_versionrH   r\   )r=   anyrangerX   r   join)rR   rY   rM   ri   rH   r\   r?   rf   s           r%   r   r      s     , NN3E#KqrKK1c%j1n% 
hr 3SXXeABi5H!j
 	

s   B 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5r2   r   )rr   rs   s   ` r%   unique_valuesrt      s"     4[6 6 Nr2   z(<([^>]*\srel\s*=\s*['"]?([^'">]+)[^>]*)>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,homepager6   r9   )z<th>Home Pagez<th>Download URLr5   N)RELfinditergroupssetmapstrstripr+   r=   HREFr:   r!   urljoin
htmldecoderL   findsearch)r>   pagerK   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     	r2   c                      y)zC
        Check the hash. Return False if validation fails.
        Tr   r   s    r%   is_validzContentChecker.is_valid   s     r2   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    
 	r2   N)__name__
__module____qualname____doc__r   r   r   r   r2   r%   r   r      s    r2   r   c                   X    e Zd Z ej                  d      Z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 ro   )	hash_namehashlibnewhashexpected)r   r   r   s      r%   __init__zHashChecker.__init__   s     "KK	*	 r2   c                     t         j                  j                  |      d   }|s
t               S | j                  j                  |      }|s
t               S  | di |j                         S )z5Construct a (possibly null) ContentChecker from a URLr5   r   )r:   r!   r;   r   patternr   	groupdict)clsr>   rE   rK   s       r%   from_urlzHashChecker.from_url  s^     <<((-b1!##""8,!##'U__&''r2   c                 :    | j                   j                  |       y ro   )r   updater   s     r%   r   zHashChecker.feed  s    		r2   c                 P    | j                   j                         | j                  k(  S ro   )r   	hexdigestr   r   s    r%   r   zHashChecker.is_valid  s    yy""$55r2   c                 0    || j                   z  } ||      S ro   )r   )r   r   r   msgs       r%   r   zHashChecker.report  s    '}r2   N)r   r   r   rd   compiler   r   classmethodr   r   r   r   r   r2   r%   r   r      s?    bjj	#G
!
 ( ( 6r2   r   c                        e Zd ZdZ	 	 d& fd	Z fdZd'dZd'dZd'dZd Z	d Z
d	 Zd
 Zd Zd(dZd Zd( fd	Zd Zd Zd Zd Zd Z	 	 d)dZd*dZd ZdZd Zd Zd(dZd Zd Zd Zd Z d Z!e"d'd        Z#d! Z$d" Z%d# Z&d$ Z'd% Z( xZ)S )+r   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 )Nr4   |)superr   r,   	index_urlscanned_urlsfetched_urlspackage_pagesrd   r   rl   r|   r   rK   allowsto_scanr:   requesturlopenopener)r   r   hosts	ca_bundle
verify_sslrp   kw	__class__s          r%   r   zPackageIndex.__init__  s     	$%"%"S*Fy/A/A#/F+F%GGjj#i*?!@AGGnn,,r2   c                 l    	 t        |j                         t        |   |      S # t        $ r Y y w xY wro   )r   rT   	Exceptionr   add)r   rN   r   s     r%   r   zPackageIndex.add)  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"                  z         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: %shtmlcontent-type zlatin-1charsetignorer9   code  )&r   
URL_SCHEMEprocess_filenamelistr   url_okdebugr   r|   r   infoopen_url
isinstancer:   error	HTTPErrorr   r   r>   headersgetr+   closereadr}   	get_paramdecoder   ry   r!   r   r   rL   process_urlr-   r   getattrprocess_index)r   r>   retrievediststmplfr/   r   r   rK   links              r%   r   zPackageIndex.process_url2  sV   $###H!%##!!#&-.E{{3'

+S1C4+<+<$<TXXu%&{{3%)Dc"		,$!%#MMM#tcz*9a//0QVVs]II015589#'!%% ~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)r2   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)r_   rB   existswarnisdirrealpathlistdirr   rl   ra   r   r   r|   r   )r   fnnestedrB   itemr   s         r%   r   zPackageIndex.process_filenameg  s    ww~~b!IIor*77==V77##B'D

4( F%%bggll4&>EF %R(JJ{B'TXXu%& r2   c                    t        |      }|xr" |j                  d      j                         dk(  }|s1| j                  t        j
                  j                  |      d         ryd}|rt        ||z        | j                  ||       y )Nr9   fileTzN
Note: Bypassing %s (disallowed host; see http://bit.ly/2hrImnY for details).
)	r   rL   r+   r   r:   r!   r;   r   r   )r   r>   fatalsis_filer   s         r%   r   zPackageIndex.url_okw  s|    sO4
((*f4dkk&,,"7"7"<Q"?@4 	  s++IIc3r2   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)r_   r   r,   )re   rB   entrys      r%   rg   z.PackageIndex.scan_egg_links.<locals>.<genexpr>  sF      
D)
 ~~k* 5M

s   9;)filterr_   rB   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=>r2   c           
         t        t        j                  j                  ||            5 }t	        t        d t        t        j                  |                  }d d d        t              dk7  ry |\  }}t        t        j                  j                  ||            D ]C  }t        j                  j                  |g| |_        t        |_        | j                  |       E y # 1 sw Y   xY w)Nrh   )openr_   rB   rl   r   r   r|   r}   r~   rX   r   rR   r	   rH   r   )r   rB   r   	raw_lineslinesegg_path
setup_pathrN   s           r%   r   zPackageIndex.scan_egg_link  s    "'',,tU+, 	B	c#))Y&?@AE	B u:?$*&rww||D('CD 	DGGLL66DM)DOHHTN		B 	Bs   .C$$C-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)NNr4   rh   r8   r9   r   T)r-   r   r   r|   r:   r!   r<   rX   r=   r   r   r   
setdefaultr+   r   )r   r   NO_MATCH_SENTINELr?   pkgvers         r%   _scanzPackageIndex._scan  s    &t~~.$$SLL  $s4>>':';"<"B"B3"G
  u:?cU1Xo$$ a!58$?C%%ciik26t<3S!111r2   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 pager9   r   .pyz#egg=rQ   c                 .    d| j                  ddd      z  S )Nz<a href="%s#md5=%s">%s</a>r9      rh   )rL   )ms    r%   <lambda>z,PackageIndex.process_index.<locals>.<lambda>  s    2QWWQ15EE r2   )r   ry   r  r:   r!   r   r   rL   r"   r   rF   r,   need_version_infoscan_urlPYPI_MD5sub)	r   r>   r   rK   r
  r  new_urlr/   frags	            r%   r   zPackageIndex.process_index  s     ]]4( 	E

6<<//ZA5OPQ	 ::c?S +35 	#G)'2JD$}}U#DsC88G**3/MM'"	# ||Et
 	
%  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   r>   s     r%   r  zPackageIndex.need_version_info  s     !$	
r2   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   rp   s      r%   r  zPackageIndex.scan_all  sK    >>!2!22		#%%IIH 	dnn%r2   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 )Nr4   r   )	r  r   unsafe_namer   r   keyrS   not_found_in_indexr   )r   requirementr>   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#	r2   c                     | j                          | j                  |       | |j                     D ]  }||v r|c S | j                  d||        t        t
        |   ||      S )Nz%s does not match %s)prescanr#  r   r   r   r   obtain)r   r"  	installerrN   r   s       r%   r&  zPackageIndex.obtain  sh    ;') 	BD{"JJ-{DA	B \4/YGGr2   c                 0   |j                  | j                  d|z         |j                         sg|j                          t	        j
                  |       t        |j                  j                  dt        j                  j                  |      d      y)z-
        checker is a ContentChecker
        zValidating %%s checksum for %sz validation failed for z; possible download problem?N)r   r   r   r   r_   unlinkr   r   r.   rB   rY   )r   checkerr`   tfps       r%   
check_hashzPackageIndex.check_hash  sz     	JJ,x7	9 !IIKIIh  <<$$bgg&6&6x&@B  "r2   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   r-   r   r   r  append)r   urlsr>   s      r%   add_find_linkszPackageIndex.add_find_links  s]     	)C$!#>>'*,- c" ##C(	)r2   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r2   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  sJ     		#H#D 		E D 	S+))*r2   c                 z   t        |t              st        |      }|rV| j                  |j	                  d      ||      }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.
        r9   r  rR   N)r   r   r   _download_urlrL   rF   r,   	gen_setupr_   rB   r   r&   r   fetch_distribution)r   r#   tmpdirr@   foundr/   rE   s          r%   r6   zPackageIndex.download#  s    $ $,%F**6<<?D&I!1$!7h==' NN5(FCE%,T2t..tV<j$OOr2   c                    	  j                  d|       i 	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                 z   |}|| j                      D ]  }|j                  t        k(  rs|vrj                  d|       d|<   4|| v xr |j                  t        k  xs  }|sUj                  |j                  	      }||_        t        j                  j                  |j                        s|c S  y )Nz&Skipping development or system egg: %sr9   )r   rH   r   r   r	   r6   rR   download_locationr_   rB   r   )
reqenvrN   testloc
develop_okr   skippedsourcer9  s
        r%   r   z-PackageIndex.fetch_distribution.<locals>.find]  s    { CGG $??l2:7*		Dd )* CK GK7Ev:  --v>C-0D*ww~~d&<&<=#%$r2   z:No local packages or working download links found for %s%sza source distribution of r   zBest match: %s)rR   ro   )r   r%  r#  r   r   cloner=  )
r   r"  r9  
force_scanrD  rB  local_indexrN   r   rC  s
   ` ` ``   @r%   r8  zPackageIndex.fetch_distributionE  s    ( 			$k2	$ 	$2 LLN{+$D/[1D<||'$D<
{+$D<IIL77=2 II&-::t'='=:>>r2   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)r8  rR   )r   r"  r9  rF  rD  rN   s         r%   fetchzPackageIndex.fetch  s-     &&{FJO== r2   c                    t         j                  |      }|xr6 t        ||j                  d      d       D cg c]  }|j                  r| c}xs g }t        |      dk(  rBt        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      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)Nr9   zsetup.pywz(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.)rJ   rK   r   rL   rT   rX   r_   rB   rY   dirnamerl   r   samefileshutilcopy2r  writerS   splitextr   )
r   r`   rE   r9  rK   dr   rY   dstr   s
             r%   r7  zPackageIndex.gen_setup  s   ""8, 
!(EKKNDA
EFYY 
   	
 u:?ww''1H wwx(F2ggll684s+0@0@30OLL3/"Hbggll6:6< 

 a--uQx/?/?((215	 O  &.u6  !G C
 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   r5   zcontent-lengthzContent-Lengthwbr9   )r   r   r   r   r   r:   r   r   r   r   r   dl_blocksizeget_allmaxr|   int
reporthookr  r   r   rP  r,  r   )r   r>   r`   fpr*  r   blocknumbssizesizesr+  r   s               r%   _download_tozPackageIndex._download_to  sv   		"C(	!**3/Gs#B"fll445$25rwwG  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 ro   r   )r   r>   r`   r^  blksizer`  s         r%   r\  zPackageIndex.reporthook  s    r2   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*        j                  f$ r1}|r| j                  ||       nt        d|d|      |Y d }~y d }~ww xY w)Nr.  rV  zDownload error for rU  z7 returned a bad status line. The server might be down, )r-   
local_openopen_with_authr   r"   httpclient
InvalidURLrl   rp   r}   r   r   r:   r   r   URLErrorreasonBadStatusLinelineHTTPExceptionsocket)r   r>   warningvargr   s         r%   r   zPackageIndex.open_url  s   >>'"c?"	8!#t{{33DKK223 	B((7CH778C		'3'$S%9:A ( ||%% 	H||$$ 	?		'188,$(+QXX&7 8=>? - {{(( 			'166*$ !&&" 	 + ))6<<8 	8		'1%$(+Q&0 1678 &	8sW   4 #HB:0B
3B:: HC!H! H;E H!:F  0H'G<<Hc                    t        |      \  }}|r,d|v r*|j                  dd      j                  dd      }d|v r'nd}|j                  d      r|d d }t        j                  j                  ||      }|dk(  s|j                  d	      r| j                  ||      S |d
k(  s|j                  d      r| j                  ||      S |j                  d      r| j                  ||      S |dk(  r?t        j                  j                  t        j                  j                  |      d         S | j                  |d       | j!                  ||      S )Nz...\___downloaded__rP   r*   svnzsvn+gitzgit+zhg+r   rh   T)rF   replacer,   r_   rB   rl   r-   _download_svn_download_git_download_hgr:   r   url2pathnamer!   r;   r   _attempt_download)r   r@   r>   r9  r.   rE   r`   s          r%   r6  zPackageIndex._download_url  s7    *#.h$,||D#.66tSA $, $D==$9D77<<- U?f//7%%c844u_ 1 1& 9%%c844u%$$S(33v>>..v||/D/DS/I!/LMMKKT"))#x88r2   c                 (    | j                  |d       y )NT)r   r  s     r%   r  zPackageIndex.scan_url0  s    d#r2   c                     | j                  ||      }d|j                  dd      j                         v r| j                  |||      S |S )Nr   r   r   )rb  r   r+   _download_html)r   r>   r`   r   s       r%   r  zPackageIndex._attempt_download3  sJ    ##C2W[[4::<<&&sGX>>Or2   c                 N   t        |      }|D ]c  }|j                         st        j                  d|      r9|j	                          t        j                  |       | j                  ||      c S  n |j	                          t        j                  |       t        d|z         )Nz <title>([^- ]+ - )?Revision \d+:zUnexpected HTML page found at )	r  r~   rd   r   r   r_   r)  r|  r   )r   r>   r   r`   r   rn  s         r%   r  zPackageIndex._download_html:  s    H~ 	Dzz|99@$GJJLIIh'--c8<<	 	


		(=CDDr2   c                    t        j                  dt               |j                  dd      d   }d}|j	                         j                  d      rd|v rt        j                  j                  |      \  }}}}}}	|s|j                  d      rd	|d
d  v rx|d
d  j                  d	d      \  }}t        |      \  }
}|
rPd|
v r|
j                  dd      \  }}d|d|}nd|
z   }|}||||||	f}t        j                  j                  |      }| j                  d||       t        j                  d|d|d|       |S )Nz"SVN download support is deprecatedr8   r9   r   r   zsvn:@z//r4   rh   :z --username=z --password=z'Doing subversion checkout from %s to %szsvn checkoutz -q rV  )warningsr   UserWarningr=   r+   r-   r:   r!   r;   
_splituser
urlunparser   r_   system)r   r>   r`   credsr@   netlocrB   rf   qr   authhostuserpwr?   s                  r%   r|  zPackageIndex._download_svnI  s.   :KHiiQ"99;!!&)cSj,2LL,A,A#,F)FFD!Qdood3tABx#ABx~~c15'/
dd{#'::c1#5bBF K . 5!F"FCAq8E ,,11%8C		;S(K
		uc8DEr2   c                 &   t         j                  j                  |       \  }}}}}|j                  dd      d   }|j                  dd      d   }d }d|v r|j	                  dd      \  }}t         j                  j                  ||||df      } | |fS )N+r9   r5   r8   r   r  r   )r:   r!   urlsplitr=   rsplit
urlunsplit)r>   
pop_prefixr@   r  rB   rD   r  revs           r%   _vcs_split_rev_from_urlz$PackageIndex._vcs_split_rev_from_url_  s    ,2LL,A,A#,F)eTc1%b) zz#q!!$$;C+ID# ll%%vvtUB&GHCxr2   c                    |j                  dd      d   }| j                  |d      \  }}| j                  d||       t        j                  d|d|       |-| j                  d	|       t        j                  d
|d|       |S )Nr8   r9   r   Tr  zDoing git clone from %s to %szgit clone --quiet rV  zChecking out %szgit -C z checkout --quiet r=   r  r   r_   r  r   r>   r`   r  s       r%   r}  zPackageIndex._download_gitq  s    >>#q)!,///ES		13A
		sH=>?II'-II 
 r2   c                    |j                  dd      d   }| j                  |d      \  }}| j                  d||       t        j                  d|d|       |.| j                  d	|       t        j                  d
|d|d       |S )Nr8   r9   r   Tr  zDoing hg clone from %s to %szhg clone --quiet rV  zUpdating to %sz	hg --cwd z
 up -C -r z -qr  r  s       r%   r~  zPackageIndex._download_hg  s    >>#q)!,///ES		0#x@
		c8<=?II&,II 
 r2   c                 0    t        j                  |g|  y ro   )r   r   r  s      r%   r   zPackageIndex.debug  s    		#r2   c                 0    t        j                  |g|  y ro   )r   r   r  s      r%   r   zPackageIndex.info      tr2   c                 0    t        j                  |g|  y ro   )r   r   r  s      r%   r   zPackageIndex.warn  r  r2   )zhttps://pypi.org/simple/)*NT)Fro   )FFFN)FF)*r   r   r   r   r   r   r   r   r   r   r   r  r   r  r  r#  r&  r,  r1  r%  r!  r6   r8  rI  r7  rX  rb  r\  r   r6  r  r  r  r|  staticmethodr  r}  r~  r   r   r   __classcell__r   s   @r%   r   r     s    E ?E'+-!31j'  ? 2$
:
&H ) PF AF*.J?X&P L"H!8F9:$E,  "  r2   r   z!&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?c                 N    | j                  d      }t        j                  |      S )Nr   )rL   r   unescape)rK   whats     r%   decode_entityr    s    ;;q>D==r2   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**r2   c                       fd}|S )Nc                       fd}|S )Nc                      t        j                         }t        j                         	  | i |t        j                  |       S # t        j                  |       w xY wro   )rp  getdefaulttimeoutsetdefaulttimeout)rp   rq   old_timeoutrr   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   )rr   r  r  s   ` r%   r  z'socket_timeout.<locals>._socket_timeout  s    	6 r2   r   )r  r  s   ` r%   socket_timeoutr    s    	 r2   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{  )r  auth_s
auth_bytesencoded_bytesencodeds        r%   _encode_authr    sR     \\!!$'FJ$$Z0M""$G??4$$r2   c                   "    e Zd ZdZd Zd Zd Zy)
Credentialz:
    A username/password pair. Use like a namedtuple.
    c                      || _         || _        y ro   usernamepassword)r   r  r  s      r%   r   zCredential.__init__  s      r2   c              #   D   K   | j                    | j                   y wro   r  r   s    r%   __iter__zCredential.__iter__  s     mmmms    c                     dt        |       z  S )Nz%(username)s:%(password)s)varsr   s    r%   __str__zCredential.__str__  s    *T$Z77r2   N)r   r   r   r   r   r  r  r   r2   r%   r  r    s    !8r2   r  c                   :     e Zd Z fdZed        Zd Zd Z xZS )
PyPIConfigc                 0   t         j                  g dd      }t        |   |       t        j
                  j                  t        j
                  j                  d      d      }t        j
                  j                  |      r| j                  |       yy)z%
        Load from ~/.pypirc
        )r  r  
repositoryr   ~z.pypircN)
dictfromkeysr   r   r_   rB   rl   
expanduserr   r   )r   defaultsrcr   s      r%   r   zPyPIConfig.__init__  sf     ==!GL"WW\\"'',,S19=77>>"IIbM r2   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
 
 	
r2   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  itemsr-   )r   r>   r  creds       r%   find_credentialzPyPIConfig.find_credential  s8    
 !% 8 8 > > @ 	J~~j)	r2   )	r   r   r   r   propertyr  r  r  r  r  s   @r%   r  r    s(    	 J J
r2   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: '')rh  httpsNz*Authenticating as %s for %s (from .pypirc)zBasic Authorizationz
User-Agent)r:   r!   r;   r,   rh  ri  rj  r  r  r  r}   r  r   r   r  r  r   Request
add_header
user_agentr>   )r>   r   parsedr@   r  rB   paramsrD   r  r  addressr  r   r?   r  r   r]  s2h2path2param2query2frag2s                          r%   rg  rg    s    \\""3'F06-FFD&% skk$$%:;;"""6*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Ir2   c                 @    | j                  d      \  }}} |r|| fS d| fS )zNsplituser('user[:passwd]@host[:port]')
    --> 'user[:passwd]', 'host[:port]'.r  N)
rpartition)r  r  delims      r%   r  r  ;  s0     ,D%Dd**td**r2   c                     | S ro   r   )r>   s    r%   
fix_sf_urlr  F  s    Jr2   c                    t         j                  j                  |       \  }}}}}}t         j                  j	                  |      }t
        j                  j                  |      rt         j                  j                  |       S |j                  d      rt
        j                  j                  |      rg }t        j                  |      D ]  }	t
        j                  j                  ||	      }
|	dk(  r't        |
d      5 }|j                         }ddd        nkt
        j                  j                  |
      r|	dz  }	|j                  dj!                  |	              d}|j!                  | dj                  |      	      }d
\  }}nd\  }}}ddi}t#        j$                        }t         j&                  j)                  | ||||      S # 1 sw Y   xY w)z7Read a local path, with special support for directoriesr4   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)r:   r!   r;   r   r  r_   rB   isfiler   r,   r   r   rl   r  r   r/  formatioStringIOr   r   )r>   r@   rA   rB   paramrD   r  r`   r  r   filepathr]  bodyr   statusmessager   body_streams                     r%   rf  rf  J  s   /5||/D/DS/I,FFD%~~**40H	ww~~h~~%%c**	s	h 7H% 	@Aww||Ha0HL (C( %B779D%x(SLL6==1=EF	@5  ;;3dii.>;?D# B{+G++d#K<<!!#vwMM#% %s   ?GG	ro   )r   )Zr   sysr_   rd   r   rN  rp  r  r   r   r  configparserr   http.clientrh  urllib.parser:   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   rJ   Ir   r  rK   r   r=   rW   __all___SOCKET_TIMEOUT_tmplr  version_infor  r&   r   rF   r   rI   ra   r   rt   rx   r   r   r   r   r  r  r  r   r  r  r  RawConfigParserr  r   r   rg  r  r  rf  r   r2   r%   <module>r     s   ) 
 	 	 	                 
  +  " < rzz67rzz3RTT:2::J RZZ,bdd399
.446

 F\\W^^S--.:  G
0B 26+ 
F
 bjj@"$$G L L$ 2. B	; 	H RZZ<=AA

	+%*8 8"#-- #L  &~~55 +^+ 10@Nr2   