o
    ÷e                     @   s   d Z ddlZddlZejeZdd ZdZej	dkr?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  dS d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                    sj    | g|R i |}|  d}d|v rttjtjf|d< dD ]}d|}||v r2||d  q!|S )Ninstallprefix)purelibplatlibheadersscriptsdataz
install_{})	get_option_dictVIRTUALENV_PATCH_FILEospathabspathsysr   formatpop)selfargskwargsresultr   basekeyold_parse_config_files B/var/www/ideatree/venv/lib/python3.10/site-packages/_virtualenv.pyparse_config_files   s   

z&patch_dist.<locals>.parse_config_filesN)Distributionr   )distr   r   r   r   
patch_dist
   s   r   )zdistutils.distzsetuptools.dist)      )partial)MetaPathFinder)	find_specc                   @   s:   e Zd ZdZdZg 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 v r| jd u rt| jdkrdd l}| }| j| | jd ` || _zOt||}|d urrt|j	d}|r;dnd}t
|j	|}	|rH| jn| j}
|	|
urezt|j	|t|
|	 W n	 tyd   Y nw |W d | _W  d    S W d | _nd | _w W d    d S 1 sw   Y  d S d S d S )Nr   exec_moduleload_module)_DISTUTILS_PATCHfullnamelenlock	threadingLockappendr#   hasattrloadergetattrr%   r&   setattrr!   AttributeError)r   r(   r   targetr+   r*   spec
is_new_api	func_nameoldfuncr   r   r   r#   6   s6   
"z_Finder.find_specc                 C   s"   | | |j tv rt| d S d S N__name__r'   r   )r7   moduler   r   r   r%   W   s   
z_Finder.exec_modulec                 C   s   | |}|j tv rt| |S r9   r:   )r7   namer<   r   r   r   r&   ]   s   
z_Finder.load_moduler9   )
r;   
__module____qualname____doc__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 r9   )object__init__rC   )r   r   r   r   r   rG   k   s   
z_VirtualenvImporter.__init__c                 C   sD   |t v r zt|gt|dd |R  W S  ty   Y d S w d S )N.)r'   _VirtualenvLoaderrB   splitImportError)r   r(   r   r   r   r   rB   o   s   "z_VirtualenvImporter.find_moduler9   )r;   r>   r?   rG   rB   r   r   r   r   rE   j   s    
rE   c                       s$   e Zd Zdd Z fddZ  ZS )rJ   c                 C   s    t |  t| |||| d S r9   )rF   rG   rD   )r   r(   filefilenameetcr   r   r   rG   x   s   
z_VirtualenvLoader.__init__c                    s"   t t| |}t| d |_|S r9   )superrJ   r&   r   
__loader__)r   r(   r<   	__class__r   r   r&   |   s   z_VirtualenvLoader.load_module)r;   r>   r?   rG   r&   __classcell__r   r   rR   r   rJ   w   s    rJ   )r@   r   r   r   join__file__r
   r   r'   version_info	functoolsr!   importlib.abcr"   importlib.utilr#   r$   	meta_pathinsertimprB   pkgutilrC   rD   rF   rE   rJ   r-   r   r   r   r   <module>   s"    
8