
    wi(                    j   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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          s/root/.openclaw/workspace/chatterbox_venv_py311/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                   t          |          }	 |                                j        }n# t          $ r d}Y nw xY wt	          t
          j                            t                              j	        dz  }	 t          j        |                                                                          }n# t          $ r d }Y nw xY w|t                      }d |                    |          }
}	|
                                5  |
                                r|
                                }|                    d          }|                    d          }|                    d          }|                    d          }||k    rr||k    rl||k    rf|                     |                                          }	|	j        }|5t
          j                            |          s|
                                 d }	n|
                                 |	Ht1          | |||          \  }}	|/|||	                                |d}|
                    |           n|}	d d d            n# 1 swxY w Y   |	S )N
py_info.pypathst_mtimecontenthash)r+   r*   r,   r-   )strstatr+   OSErrorr   r   r*   abspath__file__parenthashlibsha256
read_bytes	hexdigestr   r&   lockedexistsreadget
_from_dictcopysystem_executableremove_run_subprocess_to_dictwrite)r   r   r*   r   r   	path_textpath_modifiedpy_info_scriptpy_info_hashr&   py_info_storedataof_pathof_st_mtime
of_contentof_hashsys_exefailures                     r   r#   r#   8   s   D		I		,   "'//(3344;lJN~n&?&?&A&ABBLLNN    "$$!8#3#3D#9#9]G					 " "!! 	' %%''Dhhv&&G((:..K),,Jhhv&&G)##}(D(DT`I`I`..):):;;!3&rw~~g/F/F&!((***"G$$&&&?.sC3GGGW -%&//11(	  ##D))))!5" " " " " " " " " " " " " " "6 Ns1   + ::78B0 0B?>B?=EII #I     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>i   sP         	C/C6CCDD     r   )joinrangerQ    r   r   
gen_cookier]   h   s<    77  }%%     r   c                   t          t          j                            t                              j        dz  }t                      }t                      }|                    |          5 }|t          |          ||g}|	                                }|
                    dd            d|d<   t                              dt          |                     	 t          |dt          j        t          j        t          j        |d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 )Nr)   __PYVENV_LAUNCHER__1
PYTHONUTF8z get interpreter info via cmd: %sTzutf-8backslashreplace)universal_newlinesstdinstderrstdoutr   encodingerrorsrS   )NNr   r(   z with code z out: z err: zfailed to query )r   r   r*   r1   r2   r3   r]   ensure_extractedr.   r=   popr   debugLogCmdr
   r   PIPEcommunicate
returncoder0   strerrorerrnofindsysrf   rB   rQ   
_from_jsonr$   RuntimeError)r   r   r   r   rE   start_cookie
end_cookiecmdprocessouterrcodeos_errorr   rN   
out_starts
pre_cookieout_endspost_cookiemsgs                       r   r@   r@   o   s   "'//(3344;lJN <<LJ		"	">	2	2 CnC''zBhhjj%t,,,  L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0 !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5E
E
EEE"%E"c                       e Zd ZdddZd	dZdS )
rl   NreturnNonec                "    || _         || _        d S r!   )rx   r   )selfrx   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.   )rW   cs     r   rY   z"LogCmd.__repr__.<locals>.<genexpr>   s.      <<aE#a&&MM<<<<<<r   z env of )rZ   rx   r   )r   cmd_reprs     r   __repr__zLogCmd.__repr__   sF    88<<48<<<<<8"88DH88Hr   r!   )r   r   )r   r.   )__name__
__module____qualname__r   r   r\   r   r   rl   rl      sA                 r   rl   c                `    |                                   t                                           d S r!   )py_info_clearr"   clear)r   s    r   r   r      s%    
LLNNNNNr   )r   r   rl   )NTF)T)(__doc__
__future__r   r4   loggingr   rU   rs   collectionsr   pathlibr   shlexr   stringr   r   r	   r   r
   virtualenv.app_datar   virtualenv.discovery.py_infor   virtualenv.util.subprocessr"   r$   	getLoggerr   r   r   r   r#   rQ   __annotations__r]   r@   rl   r   	___all___r\   r   r   <module>r      s     # " " " " "   				  



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