o
    Uh                     @  s  U d Z ddlm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
 ddlmZ ddlmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ e Ze ee
ej< eeZd ddZd!ddZdd ZdZ de!d< dd Z"dd Z#G dd dZ$dd Z%g dZ&dS )"z

We acquire the python information by running an interrogation script via subprocess trigger. This operation is not
cheap, especially not on Windows. To not have to pay this hefty cost every time we apply multiple levels of
caching.
    )annotationsN)OrderedDict)Path)quote)ascii_lowercaseascii_uppercasedigits)Popen)AppDataDisabled)
PythonInfo)
subprocessTFc                 C  sJ   |d u rt jn|}t| ||||d}t|tr#|r|td| d }|S )N)ignore_cachez%s)osenviron_get_from_cache
isinstance	ExceptionLOGGERinfo)clsapp_dataexeenvraise_on_errorr   result r   w/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/virtualenv/discovery/cached_py_info.pyfrom_exe   s   
r   c                 C  sN   t |}|s|tv rt| }nt| ||||}| }t|< t|tr%||_|S N)r   _CACHE_get_via_file_cacher   r   
executable)r   r   r   r   r   exe_pathr   py_infor   r   r   r   (   s   

r   c                 C  sV  t |}z| j}W n ty   d}Y nw |d u rt }d ||}}| w | rh| }	|	d |	d |	d }
}}|
|krd||krd| 	|
 }|j}|d urctj|sc|  d }n|  |d u rt| |||\}}|d u r||| d}	||	 n|}W d    |S W d    |S W d    |S 1 sw   Y  |S )Npathst_mtimecontent)r&   r%   r'   )strstatr&   OSErrorr
   r#   lockedexistsread
_from_dictcopysystem_executabler   r%   remove_run_subprocess_to_dictwrite)r   r   r%   r   r   	path_textpath_modifiedr#   py_info_storedataof_pathof_st_mtime
of_contentsys_exefailurer   r   r   r    7   sP   



r        intCOOKIE_LENGTHc                   C  s   d dd ttD S )N c                 s  s&    | ]}t t t t V  qd S r   )randomchoicer   r   r   ).0_r   r   r   	<genexpr>^   s
    
zgen_cookie.<locals>.<genexpr>)joinranger@   r   r   r   r   
gen_cookie]   s   
rI   c                 C  s  t tjtjd }t }t }||X}|t|||g}|	 }|
dd  tdt| zt|dtjtjtj|dd}| \}	}
|j}W n tyf } zd|j|j}	}
}W Y d }~nd }~ww W d    n1 sqw   Y  d\}}|d	kr|	|d d d
 }|d
kr|	d | }|rtj| |	|t d  }	|	|d d d
 }|d
kr|	|t d  }|rtj| |	d | }	| |	}||_||fS | d| |	rd|	nd |
rd|
nd }td| }||fS )Nz
py_info.py__PYVENV_LAUNCHER__z get interpreter info via cmd: %sTzutf-8)universal_newlinesstdinstderrstdoutr   encodingrA   )NNr   r$   z with code z out: z err: zfailed to query )r   r   r%   abspath__file__parentrI   ensure_extractedr(   r/   popr   debugLogCmdr	   r   PIPEcommunicate
returncoder*   strerrorerrnofindsysrN   r4   r@   
_from_jsonr!   RuntimeError)r   r   r   r   py_info_scriptstart_cookie
end_cookiecmdprocessouterrcodeos_errorr   r=   
out_starts
pre_cookieout_endspost_cookiemsgr   r   r   r2   d   s\   		
 
2r2   c                   @  s"   e Zd Zd	d
ddZdddZdS )rV   NreturnNonec                 C  s   || _ || _d S r   )rc   r   )selfrc   r   r   r   r   __init__   s   
zLogCmd.__init__r(   c                 C  s4   d dd | jD }| jd ur| d| j}|S )N c                 s  s    | ]	}t t|V  qd S r   )r   r(   )rD   cr   r   r   rF      s    z"LogCmd.__repr__.<locals>.<genexpr>z env of )rG   rc   r   )rp   cmd_reprr   r   r   __repr__   s   
zLogCmd.__repr__r   )rn   ro   )rn   r(   )__name__
__module____qualname__rq   ru   r   r   r   r   rV      s    rV   c                 C  s   |    t  d S r   )py_info_clearr   clear)r   r   r   r   rz      s   rz   )r   rz   rV   )NTF)T)'__doc__
__future__r   loggingr   rB   r]   collectionsr   pathlibr   shlexr   stringr   r   r   r   r	   virtualenv.app_datar
   virtualenv.discovery.py_infor   virtualenv.util.subprocessr   r!   	getLoggerrv   r   r   r   r    r@   __annotations__rI   r2   rV   rz   	___all___r   r   r   r   <module>   s4    


#>