
    ,hB                       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mZ d dlZd dlZd dlmZmZmZ d dlZd dlZ G d de      Z G d d      Z G d	 d
      Zd Zd Zd Zej:                  j=                  dddefddefg      ej:                  j?                  e	j@                  dd dk(  xr e	j@                  jB                  dk7  d      d               Z"ej:                  j?                  e	j@                  dd dk(  xr e	j@                  jB                  dk7  d      d        Z#ej:                  j=                  dddg      d        Z$d Z% G d d       Z& G d! d"      Z'y)#    )annotationsN)mock)DistInfoDistributionDistributionEggInfoDistributionc                      e Zd Zd Zy)
EggRemoverc                    | t         j                  v rt         j                  j                  |        t        j                  j	                  |       rt        j                  |        y y N)syspathremoveosexists)selfs    h/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/pkg_resources/tests/test_pkg_resources.py__call__zEggRemover.__call__   s>    388HHOOD!77>>$IIdO      N)__name__
__module____qualname__r    r   r   r	   r	      s    r   r	   c                  x    e Zd ZU g Zded<    ej
                  dddddd      Z	 ed	        Zed
        Z	d Z
d Zy)TestZipProviderzlist[EggRemover]
finalizersi              r   c                   t        j                  dd      }t        j                  |d      }t        j                         }d|_        | j                  j                         |_        |j                  |d       t        j                         }d|_        | j                  j                         |_        |j                  |d       t        j                         }d	|_        | j                  j                         |_        |j                  |d
       t        j                         }d|_        | j                  j                         |_        |j                  |d       |j                          |j                          t        j                  j                  |j                         t        j                  j!                  |j                  d      }t        j                  j                  |       | j"                  j                  t%        |             | j"                  j                  t%        |j                               y)z'create a zip egg and add it to sys.pathz.eggF)suffixdeletewmod.pyzx = 3
data.dathello, world!zsubdir/mod2.pyzx = 6
zsubdir/data2.datzgoodbye, world!subdirN)tempfileNamedTemporaryFilezipfileZipFileZipInfofilenameref_time	timetuple	date_timewritestrcloser   r   appendnamer   joinr   r	   )clseggzip_eggzip_infor'   s        r   setup_classzTestZipProvider.setup_class&   s    ))F//#s+??$$ \\3359-??$& \\335?3??$, \\3359-??$. \\335#45		!chh1j01j23r   c                4    | j                   D ]	  } |         y r   )r   )r6   	finalizers     r   teardown_classzTestZipProvider.teardown_classD   s     	IK	r   c                    dd l }t        j                  |      }g d}t        |j	                  d            |k(  sJ ddg}t        |j	                  d            |k(  sJ t        |j	                  d            |k(  sJ |j	                  d      g k(  sJ |j	                  d	      g k(  sJ dd l}t        j                  |      }t        |j	                  d            |k(  sJ |j	                  d      g k(  sJ |j	                  d      g k(  sJ y )
Nr   )r%   r$   r'    z	data2.datzmod2.pyr'   zsubdir/nonexistentznonexistent/)modpkg_resourcesZipProvidersortedresource_listdirmod2)r   rA   zpexpected_rootexpected_subdirrF   zp2s          r   test_resource_listdirz%TestZipProvider.test_resource_listdirI   s    &&s+8b))"-.-??&	2b))(34GGb)))45HH""=1R77"">2b88''-c**2./?BB##H-33##I."444r   c                   ddl }t        j                         }t        j                  |      }|j	                  |d      }t
        j
                  j                  t        j                  |      j                        }|| j                  k(  sJ t        |dd      }|j                  d       |j                          | j                  j                         }t        j                  |||f       |j	                  |d      }t        |d      5 }|j!                         dk(  sJ 	 ddd       |j#                          y# 1 sw Y   xY w)	a  
        If a previous call to get_resource_filename has saved the file, but
        the file has been subsequently mutated with different file of the
        same size and modification time, it should not be overwritten on a
        subsequent call to get_resource_filename.
        r   Nr%   r#   utf-8encodingzhello, world?r&   )rA   rB   ResourceManagerrC   get_resource_filenamedatetimefromtimestampr   statst_mtimer.   openwriter2   	timestamputimereadcleanup_resources)r   rA   managerrG   r-   actualftss           r   )test_resource_filename_rewrites_on_changez9TestZipProvider.test_resource_filename_rewrites_on_changea   s    	//1&&s+++GZ@""001B1K1KL&&31	 		]]$$&
B8$++GZ@(W- 	/668...	/!!#	/ 	/s   D==EN)r   r   r   r   __annotations__rR   r.   classmethodr:   r=   rK   r`   r   r   r   r   r       s\    #%J % x  q"b"a8H.4 4:  50$r   r   c                       e Zd Zd Zd Z	 d Zy)TestResourceManagerc                    t        j                         }|j                  d      }t        t	        |            }d|z   }t        |t              sJ |       y )Nfooz%Unexpected type from get_cache_path: )rB   rP   get_cache_pathstrtype
isinstance)r   mgrr   type_messages        r   test_get_cache_pathz'TestResourceManager.test_get_cache_path{   sL    ++-!!%(DJ9EA$$-g-$r   c                V   t         j                  ffd	g _        t        j                         }|j	                  t        |             t        j                  j                  d      }t        j                  j                  t         d      5  |j                  |       d d d        j                  }t        |      dk(  sJ |d   j                  t        j                        dd  dd	gk(  sJ |d
   j                  t        j                        dd  dgk(  sJ y # 1 sw Y   }xY w)Nc                |    j                   j                  |         ||       }|st        j                  |        |S r   )dirnamesr3   r   makedirs)dirnameunpatched_isdirwas_dirpatched_isdirs      r   rv   zCTestResourceManager.test_get_cache_path_race.<locals>.patched_isdir   s5    ""))'2%g.GG$Nr   )rf   barbazisdir)new   r   rf   rw      )rB   ry   rq   rP   set_extraction_pathrh   r   sepr5   r   patchobjectrg   lensplit)r   tmpdirrk   archive_namecalled_dirnamesrv   s        @r   test_get_cache_path_racez,TestResourceManager.test_get_cache_path_race   s    3@3F3F 	 "$ ++-F,vv{{#89ZZ}g=I 	-|,	- (00?#q((q!''/4FFq!''/4???	- 	-s   DD(c                v    d}t         j                  ddj                  |      g}t        j                  |       y)z
        In a separate Python environment, import pkg_resources and assert
        that action doesn't cause setuptools to be imported.
        )zimport pkg_resourcesz
import syszAassert "setuptools" not in sys.modules, "setuptools was imported"z-cz; N)r   
executabler5   
subprocess
check_call)r   linescmds      r   test_setuptools_not_importedz0TestResourceManager.test_setuptools_not_imported   s2    


 ~~tTYYu%56c"r   N)r   r   r   rn   r   r   r   r   r   rd   rd   z   s    .@8#r   rd   c                   t         j                  j                  |       }t        j                  |       t	        | d      5 }|j                  |       ddd       t        t        j                  |            }|\  }|S # 1 sw Y   -xY w)a  
    Make a test Distribution object, and return it.

    :param metadata_path: the path to the metadata file that should be
        created. This should be inside a distribution directory that should
        also be created. For example, an argument value might end with
        "<project>.dist-info/METADATA".
    :param metadata: the desired contents of the metadata file, as bytes.
    wbN)	r   r   rs   mkdirrV   rW   listrB   distributions_from_metadata)metadata_pathmetadatadist_dirr^   distsdists         r   make_test_distributionr      sp     ww}-HHHX	mT	" a	::8DEEGTK s   A??Bc                   d}t         j                  j                  t        |       d|      }dj	                  d      }t        ||      }t        j                  t              5 }|j                  |       ddd       j                  }t        |      }d}||v s
J d|        |j                  |      s
J d|        y# 1 sw Y   LxY w)	zI
    Test a metadata file with bytes that can't be decoded as utf-8.
    METADATAzfoo.dist-infou   néez
iso-8859-1)r   Nz`codec can't decode byte 0xe9 in position 1: invalid continuation byte in METADATA file at path: zactual: )r   r   r5   rh   encoder   pytestraisesUnicodeDecodeErrorget_metadatavalueendswith)	r   r-   r   r   r   excinfoexcr]   expecteds	            r   test_get_metadata__bad_utf8r      s     HGGLLVoxHM}}\*H!-(CD	)	* $g(#$ --CXF	?  v2&22??=)>XfX+>>)$ $s   $CC
c                    | |z  }|j                          |j                  d      j                          t        t	        j
                  |            }t        |      dk(  sJ |\  }||fS )zN
    Create a distribution directory with no file containing the version.
    ztemp.txtr}   )
ensure_dirr5   ensurer   rB   r   r   )r   basenamer   r   r   s        r   make_distribution_no_versionr      se      H MM*$$&::8DEEu:?GT>r   )r!   expected_filenameexpected_dist_typezegg-infozPKG-INFOz	dist-infor   r{   )   r   finalz/https://github.com/python/cpython/issues/103632reasonc                   d| }t        | |      \  }}d| d}t        j                  j                  ||      }t	        j
                  t              5 }	|j                   ddd       t        	j                        }
||
v sJ t        ||
f             |	j                  j                  \  }}||v sJ ||v sJ t        ||f             t        |      |u sJ y# 1 sw Y   yxY w)zI
    Test Distribution.version when the "Version" header is missing.
    zfoo.z!Missing 'Version:' header and/or z file at path: N)r   r   r   r5   r   r   
ValueErrorversionrh   r   argsri   )r   r!   r   r   r   r   r   expected_textr   r   errmsgs               r   !test_distribution_version_missingr      s    " fXH1&(CND( ,,=+>oN  GGLL+<=M 
z	" g gmm
C C:mS%9!:: ""ICCC:mS%9!:::++++ s   CC"c                     t        d      } t        j                  t              5 }| j                   ddd       j
                  j                  \  }} d}||k(  sJ y# 1 sw Y   ,xY w)zl
    Test Distribution.version when the "Version" header is missing and
    the path can't be detected.
    z/fooNzJMissing 'Version:' header and/or PKG-INFO file at path: [could not detect])r   r   r   r   r   r   r   )r   r   r   r   s       r   1test_distribution_version_missing_undetected_pathr     sc     D	z	" g ""ICT  (?? s   AA&onlyFTc                    | dz  }|j                          t        j                  t        |       t        |      |      rJ y)z5Test path containing a file with dist-info extension.zfoobar.dist-infoN)touchrB   dist_factoryrh   )tmp_pathr   	dist_infos      r   test_dist_info_is_not_dirr   /  s9     --IOO))#h-YNNNr   c                   t         j                  | j                  dt        j                  d             t        dz  d      5 }t        j                  ddi|       ddd       | j                  d	t        j                  d
             fd}t        j                  dt        j                  |            5 }t        j                  j                          t        j                         ddgk(  sJ t        j                  j                          ddd       j                          y# 1 sw Y   xY w# 1 sw Y   &xY w)z-Regression test for pkg_resources._macos_verszplatform.mac_ver)r?   r   r?   )return_value
fake.plistr   ProductVersionz11.4Nzos.path.existsTc                "     dz  g|i |S )Nr   r   )filer   kwargs	orig_openr   s      r   	fake_openz+test_macos_vers_fallback.<locals>.fake_openE  s    L0B4B6BBr   zbuiltins.open)side_effect114)builtinsrV   setattrr   Mockplistlibdumpr   rB   _macos_verscache_clearassert_called)monkeypatchr   	fake_filer   mr   s    `   @r   test_macos_vers_fallbackr   7  s    I *DII<,PQ 
h%t	, =	'0)<= ($))*FGC 
OTYY9%E	F 0!!!--/((*tSk99!!--/0
 OO= =0 0s   D0?AD<0D9<Ec                  *   e Zd Zej                  d        Zd Zd Zej                  j                  dg d      d        Z
ej                  j                  ej                  j                  d      ej                  j                  d      k7  d	
      ej                  j                  ddg      d               Zej                  j                  ej                  j                   dk7  d
      ej                  j                  dg d      d               Zy)TestDeepVersionLookupDistutilsc                     G d dt               } |      }j                  t        j                         d}t	        fd|D              |_        t        t        t        j                  |j
                  j                                      |S )zq
        Create a package environment, similar to a virtualenv,
        in which packages are installed.
        c                      e Zd Zy)7TestDeepVersionLookupDistutils.env.<locals>.EnvironmentN)r   r   r   r   r   r   Environmentr   Y  s    r   r   )homelibscriptsdatazegg-basec              3  >   K   | ]  }|t        |z        f  y wr   )rh   ).0rs   r   s     r   	<genexpr>z5TestDeepVersionLookupDistutils.env.<locals>.<genexpr>_  s      Ng'3v'7#89Ns   )rh   chmodrT   S_IRWXUdictpathsr   mapr   r   values)r   r   r   envsubss    `   r   r   z"TestDeepVersionLookupDistutils.envR  sg    	# 	 &!T\\";NNN	S399++-./
r   c                <   d}t        d||      }t        j                  j                  |      }t        j                  j
                  j                  |      }|j                          |j                  d   |_        |j                          |j                          y)zj
        Create a foo package installed (distutils-style) to env.paths['lib']
        as version.
        u&   This package has unicode metadata! ❄rf   )r4   r   long_descriptionr   N)r   	distutilsr   r   commandinstall_egg_infoinitialize_optionsr   install_dirfinalize_optionsrun)r   r   r   ldattrsr   iei_cmds          r   create_foo_pkgz-TestDeepVersionLookupDistutils.create_foo_pkgc  sy    
 6%2F~~**51##44EEdK""$!ii.  "r   c                    d}| j                  ||       t        j                  j                  d      }t        j                  |j
                  d   g      j                  |      }|j                  |k(  sJ y )Nz1.11.0.dev0+2329eaezfoo>=1.9r   )r   rB   Requirementparse
WorkingSetr   findr   )r   r   r   reqr   s        r   #test_version_resolved_from_egg_infozBTestDeepVersionLookupDistutils.test_version_resolved_from_egg_infoq  sh    'C) ''--j9''5)9(:;@@E||w&&&r   )unnormalized
normalized))rf   rf   )zfoo/rf   )foo/barr  )zfoo/bar/r  c                f    t        j                  |      }t        j                  |      }||k(  sJ y)zeEnsure the trailing slash is cleaned for path comparison.

        See pypa/setuptools#1519.
        NrB   normalize_pathr   r  r  result_from_unnormalizedresult_from_normalizeds        r    test_normalize_path_trailing_sepz?TestDeepVersionLookupDistutils.test_normalize_path_trailing_sep{  s5     $1#?#?#M !.!=!=j!I'+AAAAr   Aaz%Testing case-insensitive filesystems.r   )z
MiXeD/CasEz
mixed/casec                f    t        j                  |      }t        j                  |      }||k(  sJ y)z@Ensure mixed case is normalized on case-insensitive filesystems.Nr	  r  s        r   test_normalize_path_normcasez;TestDeepVersionLookupDistutils.test_normalize_path_normcase  s5     $1#?#?#M !.!=!=j!I'+AAAAr   \z5Testing systems using backslashes as path separators.)r  r   ))zforward/slashforward\slash)zforward/slash/r  )zbackward\slash\zbackward\slashc                T    t        j                  |      }|j                  |      sJ y)z;Ensure path seps are cleaned on backslash path sep systems.N)rB   r
  r   )r   r  r   results       r   !test_normalize_path_backslash_sepz@TestDeepVersionLookupDistutils.test_normalize_path_backslash_sep  s&     --l;x(((r   N)r   r   r   r   fixturer   r   r  markparametrizer  skipifr   r   normcaser  r   r  r   r   r   r   r   Q  s"   ^^  ' [[&	
BB [[
!1!1#!666   [[&(	
B	B [[
tF   [[$	
)	)r   r   c                  h    e Zd Zd ZdddddZej                  j                  dg d      d	        Zy
)TestWorkdirRequirec                Z   |dz  }|j                          | j                  j                         D ]M  \  }}||z  }|j                  j                  dd       |j	                  t        j                  |      d       O |j                  t        d|g       t        j                  |      S )Nzsite-packagesT)exist_okparentsrM   rN   r   )r   FILESitemsparent
write_textinspectcleandocr   r   r   fspath)r   r   r   
dist_filessite_packagesr   contentr   s           r   fake_site_packagesz%TestWorkdirRequire.fake_site_packages  s     ?2!ZZ--/ 	IMD' 4'DKKtT:OOG,,W5OH	I
 	C-9yy''r   ze
            Metadata-Version: 2.4
            Name: pkg1.mod
            Version: 1.2.3
            zd
            Metadata-Version: 2.1
            Name: pkg2.mod
            Version: 0.42
            zE
            Name: pkg3.mod
            Version: 1.2.3.4
            zD
            Name: pkg4.mod
            Version: 0.42.1
            )z!pkg1_mod-1.2.3.dist-info/METADATAz pkg2.mod-0.42.dist-info/METADATAzpkg3_mod.egg-info/PKG-INFOzpkg4.mod.egg-info/PKG-INFO)r   requirement))z1.2.3zpkg1.mod>=1)z0.42zpkg2.mod>=0.4)z1.2.3.4zpkg3.mod<=2)z0.42.1zpkg4.mod>0.2,<1c                z   | j                  ||| j                        }t        j                  |g      }||j	                  dd      fD ]q  }|j                  |      \  }|j                  |k(  sJ t        j                  j                  t        j                  j                  |j                  |g      |      rqJ  y )N.-)r,  r"  rB   r  replacerequirer   r   r   samefile
commonpathlocation)	r   r   r   r   r-  r*  wsr  r   s	            r    test_require_non_normalised_namez3TestWorkdirRequire.test_require_non_normalised_name  s     //+tzzR%%}o6!4!4S#!>? 	CZZ_FT<<7**77##""DMM=#ABM 	r   N)	r   r   r   r,  r"  r   r  r  r7  r   r   r   r  r    sM    	(.
-
''E* [["	
r   r  )(
__future__r   r   rR   r&  r   r   rT   r   r   r(   r*   unittestr   r   rB   r   r   r   "distutils.command.install_egg_infor   distutils.distrh   r	   r   rd   r   r   r   r  r  xfailversion_inforeleaselevelr   r   r   r   r   r  r   r   r   <module>r?     s   "    	    
      Q Q )  W$ W$t3# 3#l(?4" 9	Z!45	j"67 RaG#P(8(8(E(E(P<  ,	,> RaG#P(8(8(E(E(P<  	$ %/O 0O4[) [)|6 6r   