o
    5‘ði^  ã                   @   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mZ e j	dd„ fdd„ƒZ
e j	dd„ ƒZe j	d	d
„ ƒZe j	dd„ ƒZe j	dd„ ƒZdd„ Ze j	dd„ ƒZe j	dd„ ƒZe j	dd„ ƒZdS )é    N)ÚFileLockc                 C   s   d S ©N© )Údirr   r   úX/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/tests/contexts.pyÚ<lambda>   s    r   c              	   k   sV   � t jdi |¤Ž}t ¡ }z| |ƒ |V  W | |ƒ t |¡ d S | |ƒ t |¡ w )Nr   )ÚtempfileÚmkdtempÚosÚgetcwdÚshutilÚrmtree)ÚcdÚkwargsÚtemp_dirÚorig_dirr   r   r   Útempdir   s   €ÿr   c                  k   s°   � t dd„ | D ƒƒ}dd„ |  ¡ D ƒ}t|ƒD ]}tj |d¡ |  |¡ qtj | ¡ z|V  W | D ]	}tj |d¡ q3tj |¡ dS | D ]	}tj |d¡ qGtj |¡ w )zj
    In a context, patch the environment with replacements. Pass None values
    to clear the values.
    c                 s   s(   � | ]}|t jv r|t j| fV  qd S r   )r
   Úenviron)Ú.0Úkeyr   r   r   Ú	<genexpr>   s   €& zenvironment.<locals>.<genexpr>c                 s   s    � | ]\}}|d u r|V  qd S r   r   )r   r   Úvaluer   r   r   r   !   s   € N)ÚdictÚitemsÚlistr
   r   ÚpopÚupdate)ÚreplacementsÚsavedÚremover   r   r   r   Úenvironment   s   €þr    c               	   c   s~   � t j} t j}t ¡  }t _t ¡  }t _z||fV  W | d¡ | d¡ | t _|t _dS | d¡ | d¡ | t _|t _w )zk
    Redirect stdout/stderr to StringIO objects to prevent console output from
    distutils commands.
    r   N)ÚsysÚstdoutÚstderrÚioÚStringIOÚseek)Ú
old_stdoutÚ
old_stderrÚ
new_stdoutÚ
new_stderrr   r   r   Úquiet0   s   €



ý
r+   c                  c   s$   � t j} z	| V  W | t _d S | t _w r   )ÚsiteÚENABLE_USER_SITE)r   r   r   r   Úsave_user_site_settingD   s
   €r.   c                  g   s$   � zd V  W d S  | y   Y d S w r   r   )Úexcsr   r   r   Úsuppress_exceptionsM   s   €ÿr0   c                 C   s*   z
|   d¡}W |dkS  ty   Y dS w )zO
    Return True if running under xdist and multiple
    workers are used.
    Ú	worker_idFÚmaster)ÚgetfixturevalueÚ	Exception)Úrequestr1   r   r   r   Ú	multiprocU   s   þÿr6   c                 c   sl   � |  ¡ }t| ƒr|jn|}|| }t| d¡ƒ� |jddd� |V  W d  ƒ dS 1 s/w   Y  dS )zCUses a file lock to guarantee only one worker can access a temp dirz.lockT)Úexist_okÚparentsN)Úgetbasetempr6   Úparentr   Úwith_suffixÚmkdir)r5   Útmp_path_factoryÚnameÚbaseÚ
shared_dirÚ
locked_dirr   r   r   Úsession_locked_tmp_dira   s   €"ýrB   c               
   c   sZ   � t jdd… t jdd… t jdd… f} zdV  W | \t _t _t _dS | \t _t _t _w )zNMake sure ``sys.path``, ``sys.meta_path`` and ``sys.path_hooks`` are preservedN)r!   ÚpathÚ	meta_pathÚ
path_hooks)Úprevr   r   r   Ú
save_pathso   s
   €(&rG   c                  c   s0   � t j} zt j ¡ t _dV  W | t _dS | t _w )z.Make sure initial ``sys.modules`` is preservedN)r!   ÚmodulesÚcopy)Úprev_modulesr   r   r   Úsave_sys_modulesz   s   €rK   )Ú
contextlibr$   r
   r   r,   r!   r   Úfilelockr   Úcontextmanagerr   r    r+   r.   r0   r6   rB   rG   rK   r   r   r   r   Ú<module>   s2    






