o
    1c                     @   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)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 D/var/www/html/django/env/lib/python3.10/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)      )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	threadingZLockappendr   hasattrloadergetattrr   r   setattrr   AttributeError)r   r    r   targetr#   r"   specZ
is_new_apiZ	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   )r,   moduler   r   r   r   W   s   
z_Finder.exec_modulec                 C   s   | |}|j tv rt| |S r.   r/   )r,   namer1   r   r   r   r   ]   s   
z_Finder.load_moduler.   )
r0   
__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 r.   )object__init__r8   )r   r   r   r   r   r<   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   _VirtualenvLoaderr7   splitImportError)r   r    r   r   r   r   r7   o   s   "z_VirtualenvImporter.find_moduler.   )r0   r3   r4   r<   r7   r   r   r   r   r:   j   s    
r:   c                       s$   e Zd Zdd Z fddZ  ZS )r?   c                 C   s    t |  t| |||| d S r.   )r;   r<   r9   )r   r    filefilenameZetcr   r   r   r<   x   s   
z_VirtualenvLoader.__init__c                    s"   t t| |}t| d |_|S r.   )superr?   r   r   
__loader__)r   r    r1   	__class__r   r   r   |   s   z_VirtualenvLoader.load_module)r0   r3   r4   r<   r   __classcell__r   r   rF   r   r?   w   s    r?   )r5   r   r	   r   join__file__r   r   r   version_infoZ	functoolsr   Zimportlib.abcr   Zimportlib.utilr   r   	meta_pathinsertZimpr7   Zpkgutilr8   r9   r;   r:   r?   r$   r   r   r   r   <module>   s"    
8