a
    ze<T                     @   s"  d dl Z d dlZd dlZd dlZd dlZe je jgadada	da
dd Zdd Zdd Zdd	 Zd
d Zd1ddZdd Zdd Zdd Zdd Zdd Zdd Zd2ddZd3ddZdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Z e j!j"se   d.d/ Z#e$d0kre#  dS )4    Nc                  G   s@   t jj|  }zt j|}W n ty.   Y n0 |t j|fS N)ospathjoinabspathOSErrornormcase)pathsdir r   /usr/lib/python3.9/site.pymakepath[   s    r   c                  C   s   t tj D ]z} tt| dd dd dvr,qztj| j| _W n t	t
tfyX   Y n0 ztj| j| _W q t	t
tfy   Y q0 qd S )N
__loader__
__module__)_frozen_importlib_frozen_importlib_external)setsysmodulesvaluesgetattrr   r   r   __file__AttributeErrorr   	TypeError
__cached__)mr   r   r   	abs_pathsd   s    r   c                  C   sP   g } t  }tjD ],}t|\}}||vr| | || q| tjd d < |S r   )r   r   r   r   appendadd)Lknown_pathsr
   dircaser   r   r   removeduppathst   s    

r"   c               	   C   sT   t  } tjD ]B}z&tj|r4t|\}}| | W q tyL   Y qY q0 q| S r   )r   r   r   r   existsr   r   r   )ditem_itemcaser   r   r   _init_pathinfo   s    
r(   c                 C   s  |d u rt  }d}nd}tj| |}ztt|}W n tyN   Y d S 0 | t|D ]\}}|	drtq`zZ|	drt
| W q`| }t| |\}}	|	|vrtj|rtj| ||	 W q` tyR   td|d |tjd dd l}
|
jt  D ](}| D ]}td	| tjd qqtd
tjd Y  qVY q`0 q`W d    n1 sl0    Y  |rd }|S )NTF#)zimport zimport	z"Error processing line {:d} of {}:
   )filer   z  z
Remainder of file ignored)r(   r   r   r   ioTextIOWrapper	open_coder   	enumerate
startswithexecrstripr   r#   r   r   r   	Exceptionprintformatstderr	tracebackformat_exceptionexc_info
splitlines)sitedirnamer    resetfullnamefnliner
   r!   r7   recordr   r   r   
addpackage   sF    

0rC   c                 C   s   |d u rt  }d}nd}t| \} }||vrBtj|  || zt| }W n tyd   Y d S 0 dd |D }t	|D ]}t
| || q||rd }|S )NTFc                 S   s   g | ]}| d r|qS )z.pth)endswith).0r<   r   r   r   
<listcomp>       zaddsitedir.<locals>.<listcomp>)r(   r   r   r   r   r   r   listdirr   sortedrC   )r;   r    r=   sitedircasenamesr<   r   r   r   
addsitedir   s$    
rL   c                   C   s`   t jjrdS ttdr4ttdr4t t kr4d S ttdr\ttdr\t t kr\d S dS )NFgetuidgeteuidgetgidgetegidT)	r   flagsno_user_sitehasattrr   rN   rM   rP   rO   r   r   r   r   check_enableusersite   s    
rT   c                  C   sz   t jdd } | r| S dd }t jdkrBt jdp6d}||dS tjdkrptjrp|dd	tjd
tjd d  S |ddS )NPYTHONUSERBASEc                  W   s   t jt jj|  S r   )r   r   
expanduserr   )argsr   r   r   joinuser   s    z_getuserbase.<locals>.joinuserntAPPDATA~PythondarwinLibraryz%d.%d   z.local)r   environgetr<   r   platform
_frameworkversion_info)env_baserX   baser   r   r   _getuserbase   s    


rg   c                 C   sd   t j}tjdkr,|  d|d  |d  dS t jdkrFt jrF|  dS |  d|d  d	|d  d
S )NrY   z\Pythonr   r*   z\site-packagesr]   z/lib/python/site-packagesz/lib/python.z/site-packages)r   rd   r   r<   rb   rc   )userbaseversionr   r   r   	_get_path
  s    

rk   c                   C   s   t d u rt a t S r   )	USER_BASErg   r   r   r   r   getuserbase  s    rm   c                  C   s   t  } td u rt| atS r   )rm   	USER_SITErk   )ri   r   r   r   getusersitepackages#  s    ro   c                 C   s$   t  }tr tj|r t||  | S r   )ro   ENABLE_USER_SITEr   r   isdirrL   )r    	user_siter   r   r   addusersitepackages1  s    
rs   c              
   C   s   g }t  }| d u rt} | D ]}|r||v r,q|| tjg}tjdkrR|d tjdkr|D ].}tj	||dtj
d d  d}|| q`q|| |D ]}tj	||d}|| qq|S )Nlib/zpython%d.%dr_   zsite-packages)r   PREFIXESr   r   
platlibdirr   r   sepr   r   rd   )prefixessitepackagesseenprefixlibdirslibdirr   r   r   r   getsitepackages?  s.    





r   c                 C   s(   t |D ]}tj|rt||  q| S r   )r   r   r   rq   rL   )r    ry   r;   r   r   r   addsitepackagesc  s    r   c                  C   s4   t jdkrd} nd} td| t_td| t_d S )N\zCtrl-Z plus ReturnzCtrl-D (i.e. EOF)quitexit)r   rx   _sitebuiltinsQuitterbuiltinsr   r   )eofr   r   r   setquitk  s
    
r   c                  C   s   t dtjt_tjd d dkr2t ddt_nt ddt_g g  } }ttdrtj	
tj}| dd	g |tj	|tj|tjg t d
d| |t_d S )N	copyright   javacreditsz?Jython is maintained by the Jython developers (www.jython.org).z    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
    for supporting Python development.  See www.python.org for more information.r   zLICENSE.txtLICENSElicensez'See https://www.python.org/psf/license/)r   _Printerr   r   r   rb   r   rS   r   r   dirnamer   extendr   pardircurdirr   )filesdirsherer   r   r   setcopyright{  s"    

r   c                   C   s   t  t_d S r   )r   _Helperr   helpr   r   r   r   	sethelper  s    r   c                  C   s   dd } | t _d S )Nc                     s   dd l } zdd ldd l}W n ty0   Y d S 0 tdd}|d urZd|v rZd n
d z  W n ty   Y n0  dkrt	j
t	j
dd z  W n ty   Y n0  fd	d
}| | d S )Nr   __doc__ libeditzbind ^I rl_completeztab: completer[   z.python_historyc                      s&   z   W n ty    Y n0 d S r   )write_history_filer   r   historyreadliner   r   write_history  s    zCenablerlcompleter.<locals>.register_readline.<locals>.write_history)atexitr   rlcompleterImportErrorr   parse_and_bindread_init_filer   get_current_history_lengthr   r   r   rV   read_history_fileregister)r   r   readline_docr   r   r   r   register_readline  s0    
z,enablerlcompleter.<locals>.register_readline)r   __interactivehook__)r   r   r   r   enablerlcompleter  s    	0r   c                 C   s^  t j}tjdkr*d|v r*t jd  }t_ntj}t jt j|\}}t j	|}d t_
d}dd t j||t j||fD }|rZ|d }d}	t|dd	f}
|
D ]P}d
|v r|d
\}}}|  }| }|dkr| }	q|dkr|t_
qW d    n1 s0    Y  | t_t_t| tjg |	dkrNtdtj ntjgada| S )Nr]   __PYVENV_LAUNCHER__z
pyvenv.cfgc                 S   s   g | ]}t j|r|qS r   )r   r   isfile)rE   conffiler   r   r   rF     s   zvenv.<locals>.<listcomp>r   truezutf-8)encoding=zinclude-system-site-packageshomeF)r   r`   r   rb   _base_executable
executabler   splitr   r   _homer   open	partitionstriplowerr|   exec_prefixr   rv   insertrp   )r    envr   exe_dirr&   site_prefixconf_basenamecandidate_confsvirtual_confsystem_siter?   rA   keyvaluer   r   r   venv  sB    
(
r   c               
   C   s   zDzdd l } W n2 ty@ } z|jdkr*n W Y d }~n
d }~0 0 W nT ty } z<tjjrltjt   ntj	
d|jj|f  W Y d }~n
d }~0 0 d S )Nr   sitecustomizez@Error in sitecustomize; set PYTHONVERBOSE for traceback:
%s: %s
)r   r   r<   r3   r   rQ   verbose
excepthookr9   r6   write	__class____name__)r   excerrr   r   r   execsitecustomize  s    

r   c               
   C   s   zDzdd l } W n2 ty@ } z|jdkr*n W Y d }~n
d }~0 0 W nT ty } z<tjjrltjt   ntj	
d|jj|f  W Y d }~n
d }~0 0 d S )Nr   usercustomizez@Error in usercustomize; set PYTHONVERBOSE for traceback:
%s: %s
)r   r   r<   r3   r   rQ   r   r   r9   r6   r   r   r   )r   r   r   r   r   r   execusercustomize  s    

r   c                  C   s~   t jd d  } t }| t jkr$t  t|}td u r:t at|}t|}t	  t
  t  t jjsjt  t  trzt  d S r   )r   r   r"   r   r   rp   rT   rs   r   r   r   r   rQ   isolatedr   r   r   )	orig_pathr    r   r   r   main-  s"    
r   c                  C   s\  d} t jdd  }|st }t }td t jD ]}td|f  q0td td|tj|rbdndf  td	|tj|rdndf  td
t  t 	d g }d|v r|
t d|v r|
t |r(ttj| trt 	d n6tdu rt 	d n td u rt 	d n
t 	d n0dd l}t|| t jd tjf  t 	d d S )Na      %s [--user-base] [--user-site]

    Without arguments print some useful information
    With arguments print the value of USER_BASE and/or USER_SITE separated
    by '%s'.

    Exit codes with --user-base or --user-site:
      0 - user site directory is enabled
      1 - user site directory is disabled by user
      2 - user site directory is disabled by super user
          or for security reasons
     >2 - unknown error
    r*   zsys.path = [z    %r,]zUSER_BASE: %r (%s)r#   zdoesn't existzUSER_SITE: %r (%s)zENABLE_USER_SITE: %rr   z--user-basez--user-siteFr_      
   )r   argvrm   ro   r4   r   r   rq   rp   r   r   rl   rn   pathsepr   textwrapdedent)r   rW   	user_baserr   r
   bufferr   r   r   r   _scriptO  sD    





r   __main__)N)N)N)%r   r   r   r   r,   r|   r   rv   rp   rn   rl   r   r   r"   r(   rC   rL   rT   rg   rk   rm   ro   rs   r   r   r   r   r   r   r   r   r   r   rQ   no_siter   r   r   r   r   r   <module>H   sF   	*
 
$
;4
3
