o
    Ëý°j8  ã                   @   sö  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 ej d¡rRd dlm  m  m  mZ neje j ZzeZW n eyg   dZY nw eZg d¢Zd-dd„Zejd-dd	„ƒZ ejd
d„ ƒZ!ejdd„ ƒZ"ejdd„ ƒZ#G dd„ de$ƒZ%G dd„ dƒZ&ejdd„ ƒZ'dd„ Z(ejdd„ ƒZ)ejdd„ ƒZ*h d£Z+dd„ Z,dd „ Z-d!d"„ Z.G d#d$„ d$ƒZ/e0e d%ƒrÙe j1gZ2ng Z2G d&d'„ d'e/ƒZ3e 4ej5d(d)„ d* 6¡ D ƒ¡Z7G d+d,„ d,eƒZ8dS ).é    N)ÚDistutilsError)Úworking_setÚjava)ÚAbstractSandboxÚDirectorySandboxÚSandboxViolationÚ	run_setupc                 C   s^   d}t | |ƒ�}| ¡ }W d  ƒ n1 sw   Y  |du r!|}t|| dƒ}t|||ƒ dS )z.
    Python 3 implementation of execfile.
    ÚrbNÚexec)ÚopenÚreadÚcompiler
   )ÚfilenameÚglobalsÚlocalsÚmodeÚstreamÚscriptÚcode© r   ú…/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/setuptools/sandbox.pyÚ	_execfile$   s   
ÿr   c              
   c   sR   � t jd d … }| d ur| t jd d …< z|V  W |t jd d …< d S |t jd d …< w ©N)ÚsysÚargv)ÚreplÚsavedr   r   r   Ú	save_argv1   s   €"r   c               
   c   s<   � t jd d … } z| V  W | t jd d …< d S | t jd d …< w r   )r   Úpath©r   r   r   r   Ú	save_path<   s
   €"r    c                 c   s8   � t j| dd� tj}| t_z	dV  W |t_dS |t_w )zL
    Monkey-patch tempfile.tempdir with replacement, ensuring it exists
    T)Úexist_okN)ÚosÚmakedirsÚtempfileÚtempdir)Úreplacementr   r   r   r   Úoverride_tempE   s   €r'   c              	   c   s8   � t  ¡ }t  | ¡ z|V  W t  |¡ d S t  |¡ w r   )r"   ÚgetcwdÚchdir)Útargetr   r   r   r   ÚpushdV   s   €
r+   c                   @   s   e Zd ZdZedd„ ƒZdS )ÚUnpickleableExceptionzP
    An exception representing another Exception that could not be pickled.
    c              	   C   sJ   zt  | ¡t  |¡fW S  ty$   ddlm} | ||t|ƒƒ¡ Y S w )z‰
        Always return a dumped (pickled) type and exc. If exc can't be pickled,
        wrap it in UnpickleableException first.
        r   )r,   )ÚpickleÚdumpsÚ	ExceptionÚsetuptools.sandboxr,   ÚdumpÚrepr)ÚtypeÚexcÚclsr   r   r   r1   e   s   üzUnpickleableException.dumpN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr1   r   r   r   r   r,   `   s    r,   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚExceptionSaverz^
    A Context Manager that will save an exception, serialized, and restore it
    later.
    c                 C   s   | S r   r   ©Úselfr   r   r   Ú	__enter__z   s   zExceptionSaver.__enter__c                 C   s    |sd S t  ||¡| _|| _dS ©NT)r,   r1   Ú_savedÚ_tb)r=   r3   r4   Útbr   r   r   Ú__exit__}   s
   zExceptionSaver.__exit__c                 C   s.   dt | ƒvrdS ttj| jƒ\}}| | j¡‚)z"restore and re-raise any exceptionr@   N)ÚvarsÚmapr-   Úloadsr@   Úwith_tracebackrA   )r=   r3   r4   r   r   r   Úresumeˆ   s   zExceptionSaver.resumeN)r6   r7   r8   r9   r>   rC   rH   r   r   r   r   r;   t   s
    r;   c                  #   sl   � t j ¡ ‰ tƒ �} ˆ V  W d  ƒ n1 sw   Y  t j ˆ ¡ ‡ fdd„t jD ƒ}t|ƒ |  ¡  dS )z 
    Context in which imported modules are saved.

    Translates exceptions internal to the context into the equivalent exception
    outside the context.
    Nc                 3   s&   � | ]}|ˆ vr|  d ¡s|V  qdS )z
encodings.N©Ú
startswith)Ú.0Úmod_namer   r   r   Ú	<genexpr>    s   € þþýzsave_modules.<locals>.<genexpr>)r   ÚmodulesÚcopyr;   ÚupdateÚ_clear_modulesrH   )Ú	saved_excÚdel_modulesr   r   r   Úsave_modules’   s   €
ÿ
þrT   c                 C   s   t | ƒD ]}tj|= qd S r   )Úlistr   rN   )Úmodule_namesrL   r   r   r   rQ   ¬   s   
ÿrQ   c               	   c   s.   � t  ¡ } z| V  W t  | ¡ d S t  | ¡ w r   )Úpkg_resourcesÚ__getstate__Ú__setstate__r   r   r   r   Úsave_pkg_resources_state±   s
   €rZ   c                 c   s"  � t j | d¡}tƒ �| tƒ �` tƒ �M tƒ  tƒ �7 t|ƒ�# t	| ƒ� t
dƒ d V  W d   ƒ n1 s6w   Y  W d   ƒ n1 sEw   Y  W d   ƒ n1 sTw   Y  W d   ƒ n1 scw   Y  W d   ƒ n1 srw   Y  W d   ƒ d S W d   ƒ d S 1 sŠw   Y  d S )NÚtempÚ
setuptools)r"   r   ÚjoinrZ   rT   r    Úhide_setuptoolsr   r'   r+   Ú
__import__)Ú	setup_dirÚtemp_dirr   r   r   Úsetup_contextº   s.   €

ý€ÿ€ÿ€þ€ÿÿ"ÿrb   >   ÚCythonÚ	distutilsr\   rW   Ú_distutils_hackc                 C   s   |   dd¡d }|tv S )aH  
    >>> _needs_hiding('setuptools')
    True
    >>> _needs_hiding('pkg_resources')
    True
    >>> _needs_hiding('setuptools_plugin')
    False
    >>> _needs_hiding('setuptools.__init__')
    True
    >>> _needs_hiding('distutils')
    True
    >>> _needs_hiding('os')
    False
    >>> _needs_hiding('Cython')
    True
    Ú.é   r   )ÚsplitÚ_MODULES_TO_HIDE)rL   Úbase_moduler   r   r   Ú_needs_hidingÒ   s   rk   c                  C   s6   t j dd¡} | dur|  ¡  ttt jƒ}t|ƒ dS )a%  
    Remove references to setuptools' modules from sys.modules to allow the
    invocation to import the most appropriate setuptools. This technique is
    necessary to avoid issues such as #315 where setuptools upgrading itself
    would fail to find a function declared in the metadata.
    re   N)r   rN   ÚgetÚremove_shimÚfilterrk   rQ   )re   rN   r   r   r   r^   ç   s
   r^   c                 C   s
  t j t j | ¡¡}t|ƒ�m z@| gt|ƒ tjdd…< tj d|¡ t	 
¡  t	j dd„ ¡ t|ƒ� t| dd�}t| |ƒ W d  ƒ n1 sIw   Y  W n tyj } z|jr`|jd r`‚ W Y d}~nd}~ww W d  ƒ dS W d  ƒ dS 1 s~w   Y  dS )z8Run a distutils setup script, sandboxed in its directoryNr   c                 S   s   |   ¡ S r   )Úactivate)Údistr   r   r   Ú<lambda>ÿ   s    zrun_setup.<locals>.<lambda>Ú__main__)Ú__file__r6   )r"   r   ÚabspathÚdirnamerb   rU   r   r   Úinsertr   Ú__init__Ú	callbacksÚappendr   Údictr   Ú
SystemExitÚargs)Úsetup_scriptr|   r`   ÚnsÚvr   r   r   r   ö   s*   

þ€€þ€õ€" r   c                   @   s  e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dD ]Zeeeƒr0e
eƒeƒ e< q"d$dd„Zer=edeƒZedeƒZdD ]ZeeeƒrReeƒeƒ e< qDdd„ ZdD ]Zeeeƒrgeeƒeƒ e< qYdd„ ZdD ]Zeeeƒr|eeƒeƒ e< qndd„ Zdd„ Zd d!„ Zd"d#„ ZdS )%r   zDWrap 'os' module and 'open()' builtin for virtualizing setup scriptsFc                    s   ‡ fdd„t tƒD ƒˆ _d S )Nc                    s$   g | ]}|  d ¡stˆ |ƒr|‘qS )Ú_)rJ   Úhasattr)rK   Únamer<   r   r   Ú
<listcomp>  s    ýýÿz,AbstractSandbox.__init__.<locals>.<listcomp>)ÚdirÚ_osÚ_attrsr<   r   r<   r   rw     s   
þzAbstractSandbox.__init__c                 C   s"   | j D ]}tt|t||ƒƒ qd S r   )r†   Úsetattrr"   Úgetattr)r=   Úsourcer‚   r   r   r   Ú_copy  s   
ÿzAbstractSandbox._copyc                 C   s(   |   | ¡ tr| jt_| jt_d| _d S r?   )rŠ   Ú_fileÚbuiltinsÚfileÚ_openr   Ú_activer<   r   r   r   r>     s
   

zAbstractSandbox.__enter__c                 C   s$   d| _ trtt_tt_|  t¡ d S ©NF)r�   r‹   rŒ   r�   rŽ   r   rŠ   r…   )r=   Úexc_typeÚ	exc_valueÚ	tracebackr   r   r   rC   !  s
   zAbstractSandbox.__exit__c                 C   s.   | � |ƒ W  d  ƒ S 1 sw   Y  dS )zRun 'func' under os sandboxingNr   )r=   Úfuncr   r   r   Úrun(  s   $ÿzAbstractSandbox.runc                    ó   t tˆ ƒ‰‡ ‡fdd„}|S )Nc                    s>   | j r| jˆ ||g|¢R i |¤Ž\}}ˆ||g|¢R i |¤ŽS r   )r�   Ú_remap_pair)r=   ÚsrcÚdstr|   Úkw©r‚   Úoriginalr   r   Úwrap0  s    z3AbstractSandbox._mk_dual_path_wrapper.<locals>.wrap©rˆ   r…   ©r‚   r�   r   r›   r   Ú_mk_dual_path_wrapper-  s   
z%AbstractSandbox._mk_dual_path_wrapper)ÚrenameÚlinkÚsymlinkNc                    s    ˆpt tˆ ƒ‰‡ ‡fdd„}|S )Nc                    s6   | j r| jˆ |g|¢R i |¤Ž}ˆ|g|¢R i |¤ŽS r   )r�   Ú_remap_input©r=   r   r|   rš   r›   r   r   r�   >  s   z5AbstractSandbox._mk_single_path_wrapper.<locals>.wraprž   )r‚   rœ   r�   r   r›   r   Ú_mk_single_path_wrapper;  s   z'AbstractSandbox._mk_single_path_wrapperr�   r   )ÚstatÚlistdirr)   r   ÚchmodÚchownÚmkdirÚremoveÚunlinkÚrmdirÚutimeÚlchownÚchrootÚlstatÚ	startfileÚmkfifoÚmknodÚpathconfÚaccessc                    r–   )Nc                    sT   | j r| jˆ |g|¢R i |¤Ž}|  ˆ ˆ|g|¢R i |¤Ž¡S ˆ|g|¢R i |¤ŽS r   )r�   r¤   Ú_remap_outputr¥   r›   r   r   r�   c  s   z4AbstractSandbox._mk_single_with_return.<locals>.wraprž   rŸ   r   r›   r   Ú_mk_single_with_return`  ó   
z&AbstractSandbox._mk_single_with_return)ÚreadlinkÚtempnamc                    r–   )Nc                    s$   ˆ|i |¤Ž}| j r|  ˆ |¡S |S r   )r�   r¸   )r=   r|   rš   Úretvalr›   r   r   r�   r  s   z'AbstractSandbox._mk_query.<locals>.wraprž   rŸ   r   r›   r   Ú	_mk_queryo  rº   zAbstractSandbox._mk_query)r(   Útmpnamc                 C   s   |S )z=Called to remap or validate any path, whether input or outputr   )r=   r   r   r   r   Ú_validate_path~  s   zAbstractSandbox._validate_pathc                 O   ó
   |   |¡S ©zCalled for path inputs©rÀ   ©r=   Ú	operationr   r|   rš   r   r   r   r¤   ‚  ó   
zAbstractSandbox._remap_inputc                 C   rÁ   )zCalled for path outputsrÃ   )r=   rÅ   r   r   r   r   r¸   †  rÆ   zAbstractSandbox._remap_outputc                 O   s<   | j |d |g|¢R i |¤Ž| j |d |g|¢R i |¤ŽfS )ú?Called for path pairs like rename, link, and symlink operationsz-fromz-to)r¤   ©r=   rÅ   r˜   r™   r|   rš   r   r   r   r—   Š  s   þzAbstractSandbox._remap_pairr   )r6   r7   r8   r9   r�   rw   rŠ   r>   rC   r•   r    r‚   r�   r…   r   r¦   r‹   rŽ   r¹   r¾   rÀ   r¤   r¸   r—   r   r   r   r   r   
  sF    

€




€
€
€r   Údevnullc                   @   s‚   e Zd ZdZe g d¢¡Zg Z	 efdd„Z	dd„ Z
er!ddd	„Zdd
d„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zddd„ZdS )r   z<Restrict operations to a single subdirectory - pseudo-chroot)r   r©   rª   r«   r¬   r­   r®   r¯   r°   r±   r´   rµ   r¼   c                 C   sF   t j t j |¡¡| _t j | jd¡| _dd„ |D ƒ| _t 	| ¡ d S )NÚ c                 S   s    g | ]}t j t j |¡¡‘qS r   )r"   r   ÚnormcaseÚrealpath)rK   r   r   r   r   rƒ   ³  s    ÿz-DirectorySandbox.__init__.<locals>.<listcomp>)
r"   r   rË   rÌ   Ú_sandboxr]   Ú_prefixÚ_exceptionsr   rw   )r=   ÚsandboxÚ
exceptionsr   r   r   rw   °  s   ÿzDirectorySandbox.__init__c                 O   s   ddl m} ||||ƒ‚)Nr   )r   )r0   r   )r=   rÅ   r|   rš   r   r   r   r   Ú
_violation¸  s   zDirectorySandbox._violationÚrc                 O   óF   |dvr|   |¡s| jd||g|¢R i |¤Ž t||g|¢R i |¤ŽS )N©rÓ   Úrtr	   ÚrUÚUr�   )Ú_okrÒ   r‹   ©r=   r   r   r|   rš   r   r   r   r‹   ¿  ó   zDirectorySandbox._filec                 O   rÔ   )NrÕ   r   )rÙ   rÒ   rŽ   rÚ   r   r   r   rŽ   Ä  rÛ   zDirectorySandbox._openc                 C   s   |   d¡ d S )Nr¿   )rÒ   r<   r   r   r   r¿   É  s   zDirectorySandbox.tmpnamc                 C   sR   | j }z!d| _ tj tj |¡¡}|  |¡p || jkp | | j¡W || _ S || _ w r�   )	r�   r"   r   rË   rÌ   Ú	_exemptedrÍ   rJ   rÎ   )r=   r   ÚactiverÌ   r   r   r   rÙ   Ì  s   
ÿ
ýzDirectorySandbox._okc                    s<   ‡ fdd„| j D ƒ}‡ fdd„| jD ƒ}t ||¡}t|ƒS )Nc                 3   s   � | ]}ˆ   |¡V  qd S r   rI   )rK   Ú	exception©Úfilepathr   r   rM   Ú  s   € 

ÿz-DirectorySandbox._exempted.<locals>.<genexpr>c                 3   s   � | ]	}t  |ˆ ¡V  qd S r   )ÚreÚmatch)rK   Úpatternrß   r   r   rM   Ý  s   € 
ÿ)rÏ   Ú_exception_patternsÚ	itertoolsÚchainÚany)r=   rà   Ústart_matchesÚpattern_matchesÚ
candidatesr   rß   r   rÜ   Ù  s   
ÿ
ÿzDirectorySandbox._exemptedc                 O   s:   || j v r|  |¡s| j|tj |¡g|¢R i |¤Ž |S rÂ   )Ú	write_opsrÙ   rÒ   r"   r   rÌ   rÄ   r   r   r   r¤   ã  s   "zDirectorySandbox._remap_inputc                 O   s8   |   |¡r
|   |¡s| j|||g|¢R i |¤Ž ||fS )rÇ   )rÙ   rÒ   rÈ   r   r   r   r—   é  s   zDirectorySandbox._remap_pairéÿ  c                 O   sL   |t @ r|  |¡s| jd|||g|¢R i |¤Ž tj|||g|¢R i |¤ŽS )zCalled for low-level os.open()zos.open)ÚWRITE_FLAGSrÙ   rÒ   r…   r   )r=   r�   Úflagsr   r|   rš   r   r   r   r   ï  s   zDirectorySandbox.openN)rÓ   )rì   )r6   r7   r8   r9   rz   Úfromkeysrë   rä   Ú_EXCEPTIONSrw   rÒ   r‹   rŽ   r¿   rÙ   rÜ   r¤   r—   r   r   r   r   r   r   ˜  s$    ÿ


r   c                 C   s   g | ]}t t|d ƒ‘qS )r   rž   )rK   Úar   r   r   rƒ   ø  s    
ÿÿrƒ   z4O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARYc                   @   s&   e Zd ZdZe d¡ ¡ Zdd„ ZdS )r   zEA setup script attempted to modify the filesystem outside the sandboxa  
        SandboxViolation: {cmd}{args!r} {kwargs}

        The package setup script has attempted to modify files on your system
        that are not within the EasyInstall build area, and has been aborted.

        This package cannot be safely installed by EasyInstall, and may not
        support alternate installation locations even if you run its setup
        script by hand.  Please inform the package's author and the EasyInstall
        maintainers to find out if a fix or workaround is available.
        c                 C   s    | j \}}}| jjdi tƒ ¤ŽS )Nr   )r|   ÚtmplÚformatr   )r=   Úcmdr|   Úkwargsr   r   r   Ú__str__  s   zSandboxViolation.__str__N)	r6   r7   r8   r9   ÚtextwrapÚdedentÚlstriprò   rö   r   r   r   r   r   ÿ  s    ÿôr   r   )9r"   r   r$   ÚoperatorÚ	functoolsrå   rá   Ú
contextlibr-   r÷   rŒ   rW   Údistutils.errorsr   r   ÚplatformrJ   Ú$org.python.modules.posix.PosixModuleÚpythonrN   ÚposixÚPosixModuler…   r‚   r�   r‹   Ú	NameErrorr   rŽ   Ú__all__r   Úcontextmanagerr   r    r'   r+   r/   r,   r;   rT   rQ   rZ   rb   ri   rk   r^   r   r   r�   rÉ   rð   r   ÚreduceÚor_rh   rí   r   r   r   r   r   Ú<module>   sv     ÿ




	


	 
	
^þþ	