
    .Ph                    b   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j        e          ZddZddZd ZdZ de!d<   d Z"d Z# G d d          Z$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                    |t           j        n|}t          | ||||          }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   results          c/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/virtualenv/discovery/cached_py_info.pyfrom_exer      sf    "**CS(C<PPPF&)$$  	LD&!!!M    c                    t          |          }|s|t          v rt          |         }nt          | ||||          }|x}t          |<   t          |t                    r||_        |S N)r   _CACHE_get_via_file_cacher   r   
executable)r   r   r   r   r   exe_pathr   py_infos           r   r   r   (   sp     CyyH ,H..!%c8XsCHH$++!&*%%  Mr   c                B   t          |          }	 |                                j        }n# t          $ r d}Y nw xY w|t	                      }d |                    |          }}|                                5  |                                r|                                }	|	d         |	d         |	d         }}}
|
|k    rl||k    rf| 	                    |
                                          }|j        }|5t          j                            |          s|                                 d }n|                                 |Gt          | |||          \  }}|.|||                                d}	|                    |	           n|}d d d            n# 1 swxY w 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failures                  r   r#   r#   7   s   D		I		,   "$$!8#3#3D#9#9]G					 " "!! 
	' %%''D/3F|T*=MtT]*[G)##}(D(D..):):;;!3&rw~~g/F/F&!((***"G$$&&&?.sC3GGGW -%&//11 
 ##D))))!-" " " " " " " " " " " " " " ". Ns   + ::8DFFF    intCOOKIE_LENGTHc                 d    d                     d t          t                    D                       S )N c              3  h   K   | ]-}t          j        t           t           t                     V  .d S r!   )randomchoicer   r   r	   ).0_s     r   	<genexpr>zgen_cookie.<locals>.<genexpr>^   sP         	C/C6CCDD     r   )joinrangerD    r   r   
gen_cookierP   ]   s<    77  }%%     r   c           
        t          t          j                            t                              j        dz  }t                      }t                      }|                    |          5 }|t          |          ||g}|	                                }|
                    dd            t                              dt          |                     	 t          |dt          j        t          j        t          j        |d          }|                                \  }	}
|j        }n'# t&          $ r}d|j        |j        }}
}	Y d }~nd }~ww xY wd d d            n# 1 swxY w Y   d\  }}|d	k    r|	                    |d d d
                   }|d
k    r=|	d |         }|rt.          j                            |           |	|t4          z   d          }	|	                    |d d d
                   }|d
k    r=|	|t4          z   d          }|rt.          j                            |           |	d |         }	|                     |	          }||_        n+| d| |	rd|	nd |
rd|
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   encodingrF   )NNr   r(   z with code z out: z err: zfailed to query )r   r   r)   abspath__file__parentrP   ensure_extractedr,   r3   popr   debugLogCmdr
   r   PIPEcommunicate
returncoder.   strerrorerrnofindsysrV   r8   rD   
_from_jsonr$   RuntimeError)r   r   r   r   py_info_scriptstart_cookie
end_cookiecmdprocessouterrcodeos_errorr   rA   
out_starts
pre_cookieout_endspost_cookiemsgs                       r   r6   r6   d   s   "'//(3344;lJN <<LJ		"	">	2	2 CnC''zBhhjj%t,,,7EEE	C#' o!!   G **,,HC%DD 	C 	C 	C!2HNdCCCCCC	C%C C C C C C C C C C C C C C C( !OFGqyyXXl44R4011
??[j[)J -
  ,,,j=0223C88Jttt,--b==h6889K .
  ---ixi.C$$iii3'F'7'7'7'7Bi\_HgHXQTHXHXHXegii7#7788F?s>   +A&EAD%$E%
E	/E?EE		EEEc                       e Zd ZdddZd	dZdS )
r^   NreturnNonec                "    || _         || _        d S r!   )rk   r   )selfrk   r   s      r   __init__zLogCmd.__init__   s    r   r,   c                t    d                     d | j        D                       }| j        | d| j        }|S )N c              3  N   K   | ] }t          t          |                    V  !d S r!   )r   r,   )rJ   cs     r   rL   z"LogCmd.__repr__.<locals>.<genexpr>   s.      <<aE#a&&MM<<<<<<r   z env of )rM   rk   r   )rz   cmd_reprs     r   __repr__zLogCmd.__repr__   sF    88<<48<<<<<8"88DH88Hr   r!   )rw   rx   )rw   r,   )__name__
__module____qualname__r{   r   rO   r   r   r^   r^      sA                 r   r^   c                `    |                                   t                                           d S r!   )py_info_clearr"   clear)r   s    r   r   r      s%    
LLNNNNNr   )r   r   r^   )NTF)T)'__doc__
__future__r   loggingr   rH   re   collectionsr   pathlibr   shlexr   stringr   r   r	   r   r
   virtualenv.app_datar   virtualenv.discovery.py_infor   virtualenv.util.subprocessr"   r$   	getLoggerr   r   r   r   r#   rD   __annotations__rP   r6   r^   r   	___all___rO   r   r   <module>r      s     # " " " " "  				  



 # # # # # #             ; ; ; ; ; ; ; ; ; ;       / / / / / / 3 3 3 3 3 3 1 1 1 1 1 1	)z||ttCN 		8	$	$           F       ; ; ;|	 	 	 	 	 	 	 	  
  			r   