Your IP : 18.218.1.38


Current Path : /opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/__pycache__/modulefinder.cpython-35.pyc



��Yf-Z�@s}dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
e
j��!e
jde
�ddlZWdQRXejdZejdZejdZejdZeefZejZiZdd	�ZiZd
d�ZGdd
�d
�ZGdd�d�Zdd�Zedkryy
e�ZWnek
rxe d�YnXdS)z3Find modules used by a script, using introspection.�N�ignore�
LOAD_CONST�IMPORT_NAME�
STORE_NAME�STORE_GLOBALcCstj|g�j|�dS)N)�packagePathMap�
setdefault�append)Zpackagename�path�r�1/opt/alt/python35/lib64/python3.5/modulefinder.py�AddPackagePath sr
cCs|t|<dS)N)�replacePackageMap)Zoldname�newnamerrr�ReplacePackage+src@s.eZdZdddd�Zdd�ZdS)�ModuleNcCs:||_||_||_d|_i|_i|_dS)N)�__name__�__file__�__path__�__code__�globalnames�starimports)�self�name�filer
rrr�__init__1s					zModule.__init__cCsdd|jf}|jdk	r3|d|jf}|jdk	rV|d|jf}|d}|S)Nz	Module(%rz, %r�))rrr)r�srrr�__repr__>s
zModule.__repr__)r�
__module__�__qualname__rrrrrrr/s
rc@sceZdZddggdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zddd6dd�Z	d7dd�Z
dd�Zdd�Zddd�Z
dd�Zdd�Zdd�Zd d!�Zd8d"d#�Zejd$d%�Zd&d'�Zd(d)�Zd*d+�Zdd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�ZdS)9�ModuleFinderNrcCsa|dkrtj}||_i|_i|_||_d|_||_||_g|_dS)Nr)	�sysr
�modules�
badmodules�debug�indent�excludes�
replace_paths�processed_paths)rr
r%r'r(rrrrIs								zModuleFinder.__init__cGs{||jkrwx't|j�D]}tddd�qWt|dd�x$|D]}tt|�dd�qPWt�dS)Nz   �end� )r%�ranger&�print�repr)r�level�str�args�i�argrrr�msgUs
zModuleFinder.msgcGs:|d}||jkr6|jd|_|j|�dS)Nr�)r%r&r4)rr1r/rrr�msgin^s
zModuleFinder.msgincGs:|d}||jkr6|jd|_|j|�dS)Nrr5)r%r&r4)rr1r/rrr�msgoutds
zModuleFinder.msgoutcCsU|jdd|�t|��/}ddtjf}|jd|||�WdQRXdS)N��
run_script��r�__main__)r4�open�imp�	PY_SOURCE�load_module)r�pathname�fp�stuffrrrr9jszModuleFinder.run_scriptcCsrtjj|�\}}tjj|�\}}t|��/}|dtjf}|j||||�WdQRXdS)Nr;)�osr
�split�splitextr=r>r?r@)rrA�dirrZextrBrCrrr�	load_fileps
zModuleFinder.load_filer5c	Cs�|jdd||||�|j|d|�}|j||�\}}|j||�}|se|S|jr~|j||�dS)N��import_hookr/)r4�determine_parent�find_head_package�	load_tailr�ensure_fromlist)	rr�caller�fromlistr/�parent�q�tail�mrrrrJws	zModuleFinder.import_hookcCs�|jdd||�|s)|dkr=|jdd�dS|j}|dkr|jre|d8}|dkr�|j|}||ks�t�|jdd|�|S|jd�|kr�td��dj|j	d�d|��}|j|}|jdd|�|S|jrN|j|}||ks7t�|jdd|�|Sd|kr�|j
d�}|d|�}|j|}|j|ks�t�|jdd|�|S|jdd�dS)	N�rKrzdetermine_parent -> Noner5zdetermine_parent ->�.zrelative importpath too deep)r6r7rrr#�AssertionError�count�ImportError�joinrE�rfind)rrOr/ZpnamerQr2rrrrK�sB		

#
	

zModuleFinder.determine_parentcCs;|jdd||�d|krX|jd�}|d|�}||dd�}n|}d}|r�d|j|f}n|}|j|||�}|r�|jdd||f�||fS|r|}d}|j|||�}|r|jdd||f�||fS|jdd|�td	|��dS)
NrUrLrVr5r:z%s.%szfind_head_package ->z"raise ImportError: No module namedzNo module named )r6�findr�
import_moduler7rY)rrQrr2�headrSZqnamerRrrrrL�s.

zModuleFinder.find_head_packagecCs�|jdd||�|}x�|r�|jd�}|dkrLt|�}|d|�||dd�}}d|j|f}|j|||�}|s|jdd|�td|��qW|jdd	|�|S)
NrUrMrVrr5z%s.%sz"raise ImportError: No module namedzNo module named zload_tail ->)r6r\�lenrr]r7rY)rrRrSrTr2r^ZmnamerrrrM�s	%zModuleFinder.load_tailcCs�|jdd|||�x�|D]�}|dkrc|s�|j|�}|r�|j||d�q t||�s d|j|f}|j|||�}|s td|��q WdS)NrUrN�*r5z%s.%szNo module named )r4�find_all_submodulesrN�hasattrrr]rY)rrTrPZ	recursive�sub�all�subnameZsubmodrrrrN�s
zModuleFinder.ensure_fromlistc
Cs<|js
dSi}g}|tjjdd�7}|tjjdd�7}|tjjdd�7}x�|jD]�}ytj|�}Wn(tk
r�|j	dd|�wqYnXxv|D]n}d}xC|D];}t
|�}	||	d�|kr�|d|	�}Pq�W|r�|dkr�|||<q�WqqW|j�S)Nr8zcan't list directoryr)r�	importlib�	machinery�EXTENSION_SUFFIXES�SOURCE_SUFFIXES�BYTECODE_SUFFIXESrD�listdir�OSErrorr4r_�keys)
rrTr#�suffixesrG�namesr�modZsuff�nrrrra�s.	


z ModuleFinder.find_all_submodulescCsV|jdd|||�y|j|}Wntk
r>YnX|jdd|�|S||jkry|jdd�dS|r�|jdkr�|jdd�dSy+|j||o�|j|�\}}}Wn)tk
r�|jddd�dSYnXz|j||||�}Wd|r(|j	�X|r?t
|||�|jdd|�|S)NrIr]zimport_module ->zimport_module -> None)r6r#�KeyErrorr7r$r�find_modulerYr@�close�setattr)rZpartname�fqnamerQrTrBrArCrrrr]�s6
	"
	zModuleFinder.import_modulecCs�|\}}}|jdd||o'd|�|tjkrf|j||�}|jdd|�|S|tjkr�t|j�d|d�}	n�|tjkryt	j
j|j��}
WnEtk
r}z%|jddt
|�|��WYdd}~XnXtj|
�}	nd}	|j|�}||_|	rn|jrU|j|	�}	|	|_|j|	|�|jdd|�|S)Nr8r@rBzload_module ->�
�execzraise ImportError: )r6r>Z
PKG_DIRECTORY�load_packager7r?�compile�readZPY_COMPILEDrf�_bootstrap_external�_validate_bytecode_headerrYr0�marshal�loads�
add_modulerr(�replace_paths_in_coder�	scan_code)rrvrBrA�	file_info�suffix�mode�typerT�coZmarshal_data�excrrrr@s2			zModuleFinder.load_modulecCsN||jkri|j|<|r9d|j||j<nd|j|d<dS)Nr5�-)r$r)rrrOrrr�_add_badmodule4s

zModuleFinder._add_badmodulecCsJ||jkr#|j||�dSy|j||d|�WnNtk
r�}z.|jddt|��|j||�WYdd}~Xn�X|rFx�|D]�}||jkr�|j||�q�y |j|||gd|�Wq�tk
rA}z<|jddt|��|d|}|j||�WYdd}~Xq�Xq�WdS)Nr/r8zImportError:rV)r$r�rJrYr4r0)rrrOrPr/r4rc�fullnamerrr�_safe_import_hook<s&#
 zModuleFinder._safe_import_hookccs6|j}|j}|j}dd�tj|�D�}x�t|�D]�\}\}}	|tkrwd||	ffVqD|tkrD|dkrD||dd||ddko�tknrD|||dd}
|||dd}|
dkrd|||	ffVqDd|
|||	ffVqDqDWdS)	NcSs1g|]'\}}}|tkr||f�qSr)�EXTENDED_ARG)�.0�_�opr3rrr�
<listcomp>Ys	z0ModuleFinder.scan_opcodes_25.<locals>.<listcomp>�storer8r5r�absolute_import�relative_import)	�co_code�co_names�	co_consts�disZ_unpack_opargs�	enumerate�	STORE_OPSrr)rr��unpack�codero�constsZopargsr2r�Zopargr/rPrrr�scan_opcodes_25Ss 			4zModuleFinder.scan_opcodes_25cCs'|j}|j}x�||�D]�\}}|dkrP|\}d|j|<q|dkri|\}}d}	|dk	r�d|kr�d}	dd�|D�}|j|||dd�|	r�d}
|jr�|jj|jd	|�}
|
dkr|jj|�}
|
dk	rY|jj|
j�|j	j|
j	�|
j
dkrfd|j	|<q�d|j	|<q|d
kr�|\}}}|r�|j|||d|�q�|j|d|�}|j|jd|dd�qt|��qWx6|j
D]+}
t|
t|��r�|j|
|�q�WdS)Nr�r5r�rr`cSs"g|]}|dkr|�qS)r`r)r��frrrr�vs	z*ModuleFinder.scan_code.<locals>.<listcomp>r/rVr�)r�r�rr�rr#�getr�updaterrrK�RuntimeErrorr��
isinstancer�r�)rr�rTr��scannerZwhatr1rrPZ	have_starZmmr/rQ�crrrr�isH				zModuleFinder.scan_codecCs�|jdd||�tj|�}|r1|}|j|�}||_|g|_|jtj|g�|_|jd|j�\}}}z1|j||||�|j	dd|�|SWd|r�|j
�XdS)Nr8ryrzload_package ->)r6rr�r�rrrrsr@r7rt)rrvrArrTrBZbufrCrrrry�s	zModuleFinder.load_packagecCs5||jkr|j|St|�|j|<}|S)N)r#r)rrvrTrrrr��szModuleFinder.add_modulecCs�|dk	r |jd|}n|}||jkrT|jdd|�t|��|dkr�|tjkr�ddddtjffS|j}tj	||�S)NrVrIzfind_module -> Excludedr:)
rr'r7rYr"�builtin_module_namesr>Z	C_BUILTINr
rs)rrr
rQr�rrrrs�s	zModuleFinder.find_modulecCs|t�tdd�tdd�t|jj��}xa|D]Y}|j|}|jrntddd�ntddd�td	||jp�d
�q?W|j�\}}|rt�td�xC|D];}t|j|j��}td|d
dj|��q�W|rxt�tddd�td�xC|D];}t|j|j��}td|d
dj|��q9WdS)z�Print a report to stdout, listing the found modules with their
        paths, as well as modules that are missing, or seem to be missing.
        z
  %-25s %s�Name�File�----�Pr*r+rTz%-25sr:zMissing modules:�?z
imported fromz, z7Submodules that appear to be missing, but could also bez#global names in the parent package:N)r�r�)r�r�)	r-�sortedr#rmrr�any_missing_mayber$rZ)rrm�keyrT�missing�mayberZmodsrrr�report�s0

	

 

zModuleFinder.reportcCs|j�\}}||S)z�Return a list of modules that appear to be missing. Use
        any_missing_maybe() if you want to know which modules are
        certain to be missing, and which *may* be missing.
        )r�)rr�r�rrr�any_missing�szModuleFinder.any_missingcCs(g}g}x�|jD]�}||jkr.q|jd�}|dkrY|j|�q||dd�}|d|�}|jj|�}|dk	r�||j|kr�|j|�q||jkr�q|jr�|j|�q|j|�q|j|�qW|j�|j�||fS)a�Return two lists, one with modules that are certainly missing
        and one with modules that *may* be missing. The latter names could
        either be submodules *or* just global names in the package.

        The reason it can't always be determined is that it's impossible to
        tell which names are imported when "from module import *" is done
        with an extension module, short of actually importing it.
        rVrr5N)	r$r'r[r	r#r�rr�sort)rr�r�rr2reZpkgnameZpkgrrrr��s0	
	

zModuleFinder.any_missing_maybecCs�tjj|j�}}xA|jD]6\}}|j|�r#||t|�d�}Pq#W|jr�||jkr�||kr�|j	dd||f�n|j	dd|f�|jj
|�t|j�}xJt
t|��D]6}t||t|��r�|j||�||<q�Wtj|j|j|j|j|j|jt|�|j|j||j|j|j|j|j �S)Nr8zco_filename %r changed to %rz co_filename %r remains unchanged)!rDr
�normpath�co_filenamer(�
startswithr_r%r)r7r	�listr�r,r�r�r��types�CodeType�co_argcount�co_kwonlyargcount�
co_nlocals�co_stacksize�co_flagsr��tupler��co_varnames�co_name�co_firstlineno�	co_lnotab�co_freevars�co_cellvars)rr�Znew_filenameZoriginal_filenamer�r;r�r2rrrr�s,z"ModuleFinder.replace_paths_in_code���r�r�)rrr rr4r6r7r9rHrJrKrLrMrNrar]r@r�r��structr�r�r�ryr�rsr�r�r�r�rrrrr!Gs2	#1".r!cCsQddl}y)|jtjdd�d�\}}Wn6|jk
rm}zt|�dSWYdd}~XnXd}d}g}g}x�|D]�\}}	|dkr�|d}|dkr�d}|dkr�||	jtj�}|dkr�d}|dkr�|j|	�q�W|s!d	}
n
|d}
tj	dd�}tj	j
|
�|d<||}|dkr�td
�x!|D]}tdt|��q{Wt|||�}
x�|dd�D]w}|dkr�d}q�|r%|dd�d
kr|
j
|dd�ddg�q2|
j
|�q�|
j|�q�W|
j|
�|
j�|
S)Nrr5zdmp:qx:z-dz-mz-pz-qz-xzhello.pyzpath:z   r8z.*r`���r�)�getoptr"�argv�errorr-rErD�pathsepr	r
�dirnamer.r!rJrHr9r�)r�Zoptsr1r4r%ZdomodsZaddpathZexclude�o�aZscriptr
�item�mfr3rrr�test;sX)

	



#

r�r<z
[interrupted])!�__doc__r�Zimportlib._bootstrap_externalrf�importlib.machineryr~rDr"r�r��warnings�catch_warnings�simplefilter�PendingDeprecationWarningr>Zopmaprrrrr�r�rr
rrrr!r�rr��KeyboardInterruptr-rrrr�<module>s>




	��;



?>