U
    ݫ^(                     @   s   d Z ddlZddlZejeZdd ZdZej	dkrddl
mZ ddlmZ dd	lmZ dd
lmZ G dd deZejde  nNddlmZ ddlmZmZ G dd deeZG dd deeZeje  dS )z>Patches that are applied at runtime to the virtual environment    Nc                    s    | j j  fdd}|| j _dS )a  
    Distutils allows user to configure some arguments via a configuration file:
    https://docs.python.org/3/install/index.html#distutils-configuration-files

    Some of this arguments though don't make sense in context of the virtual environment files, let's fix them up.
    c                    sd    | f||}|  d}d|kr8ttjtjf|d< dD ]"}d|}||kr<||d  q<|S )Ninstallprefix)ZpurelibZplatlibZheadersZscriptsdataz
install_{})	Zget_option_dictVIRTUALENV_PATCH_FILEospathabspathsysr   formatpop)selfargskwargsresultr   basekeyZold_parse_config_files N/var/www/data.klee.studio/wsgi_test/lib/python3.8/site-packages/_virtualenv.pyparse_config_files   s    

z&patch_dist.<locals>.parse_config_filesN)ZDistributionr   )Zdistr   r   r   r   
patch_dist
   s    r   )zdistutils.distzsetuptools.dist)      )MetaPathFinder)	find_spec)Lock)partialc                   @   s<   e Zd ZdZdZe Zd	ddZedd Z	edd Z
dS )
_FinderzFA meta path finder that allows patching the imported distutils modulesNc           	   
   C   s   |t kr| jd kr| j || _zt||}|d k	rt|jd}|rHdnd}t|j|}|rb| jn| j}||k	rzt	|j|t
|| W n tk
r   Y nX |W W  5 Q R  S W 5 d | _X W 5 Q R X d S )Nexec_moduleload_module)_DISTUTILS_PATCHfullnamelockr   hasattrloadergetattrr   r   setattrr   AttributeError)	r   r!   r   targetspecZ
is_new_apiZ	func_nameoldfuncr   r   r   r   3   s"    
z_Finder.find_specc                 C   s   | | |j tkrt| d S N__name__r    r   )r*   moduler   r   r   r   H   s    
z_Finder.exec_modulec                 C   s   | |}|j tkrt| |S r,   r-   )r*   namer/   r   r   r   r   N   s    
z_Finder.load_module)N)r.   
__module____qualname____doc__r!   r   r"   r   staticmethodr   r   r   r   r   r   r   -   s   

r   )find_module)ImpImporter	ImpLoaderc                   @   s    e Zd ZdddZdddZdS )_VirtualenvImporterNc                 C   s   t |  t| | d S r,   )object__init__r6   )r   r   r   r   r   r:   \   s    
z_VirtualenvImporter.__init__c                 C   sB   |t kr>z t|ft|dd | W S  tk
r<   Y nX d S )N.)r    _VirtualenvLoaderr5   splitImportError)r   r!   r   r   r   r   r5   `   s     z_VirtualenvImporter.find_module)N)N)r.   r1   r2   r:   r5   r   r   r   r   r8   [   s   
r8   c                       s$   e Zd Zdd Z fddZ  ZS )r=   c                 C   s    t |  t| |||| d S r,   )r9   r:   r7   )r   r!   filefilenameZetcr   r   r   r:   i   s    
z_VirtualenvLoader.__init__c                    s"   t t| |}t| d |_|S r,   )superr=   r   r   
__loader__)r   r!   r/   	__class__r   r   r   m   s    z_VirtualenvLoader.load_module)r.   r1   r2   r:   r   __classcell__r   r   rD   r   r=   h   s   r=   )r3   r   r	   r   join__file__r   r   r    version_infoimportlib.abcr   Zimportlib.utilr   Z	threadingr   Z	functoolsr   r   	meta_pathinsertZimpr5   Zpkgutilr6   r7   r9   r8   r=   appendr   r   r   r   <module>   s"   
(