B
    u9a;S                 @   s  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! se  d.d/ Z"e#d0kre"  dS )4    Nc              G   sB   t jj|  }yt j|}W n tk
r0   Y nX |t j|fS )N)ospathjoinabspathOSErrornormcase)pathsdir r
   /usr/lib/python3.7/site.pymakepathZ   s    r   c              C   s   xt tj D ]~} tt| dd dd dkr.qytj| j| _W n t	t
tfk
r\   Y nX ytj| j| _W q t	t
tfk
r   Y qX qW 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_pathsc   s    r   c              C   sT   g } t  }x6tjD ],}t|\}}||kr| | || qW | tjd d < |S )N)r   r   r   r   appendadd)Lknown_pathsr	   dircaser
   r
   r   removeduppathss   s    
r!   c           	   C   sX   t  } xLtjD ]B}y&tj|r6t|\}}| | W q tk
rN   wY qX qW | S )N)r   r   r   r   existsr   r   r   )ditem_itemcaser
   r
   r   _init_pathinfo   s    r'   c             C   sp  |d krt  }d}nd}tj| |}yt|d}W n tk
rH   d S X | xt|D ]\}}|drrq^yX|drt| w^|	 }t
| |\}}	|	|krtj|rtj| ||	 W q^ tk
rR   td|d |tjd d	d l}
x>|
jt  D ],}x$| D ]}td
| tjd qW qW tdtjd P Y q^X q^W W d Q R X |rld }|S )NTFr#)zimport zimport	z"Error processing line {:d} of {}:
   )filer   z  z
Remainder of file ignored)r'   r   r   r   openr   	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    r5   recordr
   r
   r   
addpackage   sD    


rA   c             C   s   |d krt  }d}nd}t| \} }||krBtj|  || yt| }W n tk
rd   d S X dd |D }xt	|D ]}t
| || q~W |rd }|S )NTFc             S   s   g | ]}| d r|qS )z.pth)endswith).0r:   r
   r
   r   
<listcomp>   s    zaddsitedir.<locals>.<listcomp>)r'   r   r   r   r   r   r   listdirr   sortedrA   )r9   r   r;   sitedircasenamesr:   r
   r
   r   
addsitedir   s$    
rI   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   rK   rJ   rM   rL   r
   r
   r
   r   check_enableusersite   s    
rQ   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 )N)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_baserU   baser
   r
   r   _getuserbase   s    


rd   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 )NrV   z\Pythonr   r*   z\site-packagesrZ   z/lib/python/site-packagesz/lib/python.z/site-packages)r   ra   r   r:   r_   r`   )userbaseversionr
   r
   r   	_get_path	  s    

rh   c               C   s   t d krt a t S )N)	USER_BASErd   r
   r
   r
   r   getuserbase  s    rj   c              C   s   t  } td krt| atS )N)rj   	USER_SITErh   )rf   r
   r
   r   getusersitepackages"  s    rl   c             C   s$   t  }tr tj|r t||  | S )N)rl   ENABLE_USER_SITEr   r   isdirrI   )r   	user_siter
   r
   r   addusersitepackages0  s    
rp   c             C   s   g }t  }| d krt} xv| D ]n}|r||kr.q|| tjdkrj|tj|ddtj	d d  d q|| |tj|dd qW |S )N/libzpython%d.%dr\   zsite-packages)
r   PREFIXESr   r   sepr   r   r   r   ra   )prefixessitepackagesseenprefixr
   r
   r   getsitepackages>  s    




ry   c             C   s,   x&t |D ]}tj|r
t||  q
W | S )N)ry   r   r   rn   rI   )r   ru   r9   r
   r
   r   addsitepackagesY  s    rz   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   rt   _sitebuiltinsQuitterbuiltinsr|   r}   )eofr
   r
   r   setquita  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   r_   r   rP   r   r   dirnamer   extendr   pardircurdirr   )filesdirsherer
   r
   r   setcopyrightq  s     


r   c               C   s   t  t_d S )N)r~   _Helperr   helpr
   r
   r
   r   	sethelper  s    r   c              C   s   dd } | t _d S )Nc                 s   dd l } ydd ldd l}W n tk
r0   d S X tdd}|d k	rZd|krZd n
d y  W n tk
r   Y nX  dkrt	j
t	j
dd y  W n tk
r   Y nX  fd	d
}| | d S )Nr   __doc__ libeditzbind ^I rl_completeztab: completerX   z.python_historyc            	      s,   y   W n ttfk
r&   Y nX d S )N)write_history_fileFileNotFoundErrorPermissionErrorr
   )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   rS   read_history_fileregister)r   r   readline_docr   r
   )r   r   r   register_readline  s.    
z,enablerlcompleter.<locals>.register_readline)r   __interactivehook__)r   r
   r
   r   enablerlcompleter  s    	0r   c          	   C   sL  t j}tjdkr*d|k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 }|rH|d }d}	t|dd	`}
xX|
D ]P}d
|kr|d
\}}}|  }| }|dkr| }	q|dkr|t_
qW W d Q R X | t_t_t| tjg |	dkr<tdtj ntjgada| S )NrZ   __PYVENV_LAUNCHER__z
pyvenv.cfgc             S   s   g | ]}t j|r|qS r
   )r   r   isfile)rC   conffiler
   r
   r   rD     s    zvenv.<locals>.<listcomp>r   truezutf-8)encoding=zinclude-system-site-packageshomeF)r   r]   r   r_   _base_executable
executabler   splitr   r   _homer   r,   	partitionstriplowerrx   exec_prefixrz   rs   insertrm   )r   envr   exe_dirr%   site_prefixconf_basenamecandidate_confsvirtual_confsystem_siter=   r?   keyvaluer
   r
   r   venv  s>    


r   c           
   C   s   yBydd l } W n0 tk
r> } z|jdkr,n W d d }~X Y nX W nR tk
r } z4tjjrltjt   ntj	
d|jj|f  W d d }~X Y nX d S )Nr   sitecustomizez@Error in sitecustomize; set PYTHONVERBOSE for traceback:
%s: %s
)r   r   r:   r1   r   rN   verbose
excepthookr7   r4   write	__class____name__)r   excerrr
   r
   r   execsitecustomize  s    
r   c           
   C   s   yBydd l } W n0 tk
r> } z|jdkr,n W d d }~X Y nX W nR tk
r } z4tjjrltjt   ntj	
d|jj|f  W d d }~X Y nX d S )Nr   usercustomizez@Error in usercustomize; set PYTHONVERBOSE for traceback:
%s: %s
)r   r   r:   r1   r   rN   r   r   r7   r4   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 kr:t at|}t|}t	  t
  t  t jjsjt  t  trzt  d S )N)r   r   r!   r   r   rm   rQ   rp   rz   r   r   r   rN   isolatedr   r   r   )	orig_pathr   r
   r
   r   main#  s"    
r   c              C   s`  d} t jdd  }|st }t }td xt jD ]}td|f  q2W td td|tj|rfdndf  td	|tj|rdndf  td
t  t 	d g }d|kr|
t d|kr|
t |r,ttj| trt 	d n6tdkr
t 	d n td k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 - uses 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   argvrj   rl   r2   r   r   rn   rm   r}   r   ri   rk   pathsepr   textwrapdedent)r   rT   	user_basero   r	   bufferr   r
   r
   r   _scriptE  s@    




r   __main__)N)N)N)$r   r   r   r~   rx   r   rs   rm   rk   ri   r   r   r!   r'   rA   rI   rQ   rd   rh   rj   rl   rp   ry   rz   r   r   r   r   r   r   r   r   rN   no_siter   r   r
   r
   r
   r   <module>H   sD   	*
 

;4
3
