Your IP : 216.73.216.196


Current Path : /opt/alt/python37/lib/python3.7/site-packages/astroid/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/astroid/__pycache__/manager.cpython-37.pyc

B

��\1�@s^dZddlZddlZddlmZddlmZddlmZddlmZdd�Z	Gd	d
�d
�Z
dS)z�astroid manager: avoid multiple astroid build of a same module when
possible by providing a class responsible to get astroid representation
from various source and using a cache of built modules)
�N)�
exceptions)�spec)�modutils)�
transformscCs"yt|�Stk
rdSXdS)Nz???)�repr�	Exception)�obj�r	�@/opt/alt/python37/lib/python3.7/site-packages/astroid/manager.py�	safe_reprsrc@s�eZdZdZdZiZdd�Zedd��Zdd�Z	d(dd
�Z
dd�Zdd�Zdd�Z
d)dd�Zdd�Zdd�Zd*dd�Zd+dd�Zd,dd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd	S)-�AstroidManagerzmthe astroid manager, responsible to build astroid from files
     or modules.

    Use the Borg pattern.
    zastroid loadercCs\tj|_|jsXi|_i|_g|_d|_d|_t�|_	t
��|_|jj
|_
|jj|_d|_dS)NF�d)r�brain�__dict__�
astroid_cache�_mod_file_cache�_failed_import_hooks�always_load_extensionsZoptimize_ast�set�extension_package_whitelistrZTransformVisitor�
_transformZregister_transformZunregister_transformZmax_inferable_values)�selfr	r	r
�__init__.s


zAstroidManager.__init__cCs
|jdS)N�builtins)r)rr	r	r
�builtins_module?szAstroidManager.builtins_modulecCs|j�|�S)z8Visit the transforms and apply them to the given *node*.)r�visit)r�noder	r	r
�visit_transformsCszAstroidManager.visit_transformsNTFcCs�ytj|dd�}d}Wntjk
r,YnX|dkrdyd�t�|��}Wntk
rb|}YnX||jkr�|j|j|kr�|j|S|r�ddlm	}||��
||�S|r�|r�|�|�Stj
d|d��dS)	z.given a module name, return the astroid objectT)Zinclude_no_extN�.r)�AstroidBuilderz"Unable to build an AST for {path}.)�path)rZget_source_fileZNoSourceFile�joinZmodpath_from_file�ImportErrorr�file�astroid.builderrZ
file_build�ast_from_module_namer�AstroidBuildingError)r�filepath�modname�fallback�sourcerr	r	r
�
ast_from_fileGs(



zAstroidManager.ast_from_filecCsddlm}||��d|�S)Nr)r�)r$r�string_build)rr(rr	r	r
�_build_stub_modulebsz!AstroidManager._build_stub_modulecCsddlm}|||�S)Nr)�build_namespace_package_module)r$r/)rr(r r/r	r	r
�_build_namespace_modulegsz&AstroidManager._build_namespace_modulecsH�jr
dSt�|�rdS|�d��t��fdd�tdt��d�D��S)NTrc3s&|]}d��d|���jkVqdS)rN)r!r)�.0�x)�partsrr	r
�	<genexpr>ssz5AstroidManager._can_load_extension.<locals>.<genexpr>�)rrZis_standard_module�split�any�range�len)rr(r	)r3rr
�_can_load_extensionls

z"AstroidManager._can_load_extensionc	Cs�||jkr|j|S|dkr&|�|�St��}|rDt�tj�|���z��y.|�||�}|jt	j
jkr�|�|j
�}|dk	r~|Sn�|jt	j
jt	j
jfk�r|jt	j
jkr�|�|�s�|�|�Syt�|�}Wn6tk
r�}ztjd||j
d�|�Wdd}~XYnX|�||�S|jt	j
jk�r0tjd||j
d��n|jt	j
jk�rN|�||j�S|j
dk�rhtjd|d��|j|j
|dd	�Stjk
�r�}z<x2|jD](}y||�Stjk
�r�YnX�q�W|�Wdd}~XYnXWdt�|�XdS)
z.given a module name, return the astroid object�__main__Nz&Loading {modname} failed with:
{error})r(r z)Unable to load compiled module {modname}.z'Can't find a file for module {modname}.)r(F)r))rr.�os�getcwd�chdirr �dirname�file_from_module_name�typer�
ModuleTypeZPY_ZIPMODULE�zip_import_data�location�	C_BUILTIN�C_EXTENSIONr:rZload_module_from_namerr�AstroidImportError�ast_from_module�PY_COMPILEDZPY_NAMESPACEr0�submodule_search_locationsr+r&r)	rr(�context_fileZold_cwdZ
found_spec�module�ex�e�hookr	r	r
r%ws`






z#AstroidManager.ast_from_module_namec
	Cs�tdkrdSddlm}||�}x�dD]�}y|�|tjjd�\}}Wntk
r\w&YnXyHt�||�}|�	tjjd�}|�
|�r�|d}|�|�|�||�}	|	St
k
r�w&Yq&Xq&WdS)Nr)r)z.zipz.eggr5rz	.__init__)�	zipimportr$r�rsplitr<r �sep�
ValueError�zipimporter�replace�
is_packager-�
get_sourcer)
rr'rZbuilder�extZeggpath�resource�importerZzmodnamerLr	r	r
rC�s(

zAstroidManager.zip_import_datac
Cs�y|j||f}Wnntk
r�ytj|�d�|d�}Wn2tk
rl}ztjd||d�}Wdd}~XYnX||j||f<YnXt|tj	�r�|�|S)Nr)rKz6Failed to import module {modname} with error:
{error}.)r(�error)
r�KeyErrorrZfile_info_from_modpathr6r"rrG�
isinstancer&)rr(Zcontextfile�valuerMr	r	r
r@�sz$AstroidManager.file_from_module_namecCsp|p|j}||jkr|j|Sy |j}t�|�r<|�||�SWntk
rRYnXddlm}||��	||�S)z3given an imported module, return the astroid objectr)r)
�__name__r�__file__rZis_python_sourcer+�AttributeErrorr$rZmodule_build)rrLr(r'rr	r	r
rH�s



zAstroidManager.ast_from_modulec
Csh|dkrNy
|j}Wn:tk
rL}ztjd|t|�|d�|�Wdd}~XYnX|�|�}|�|j�dS)zget astroid for the given classNz,Unable to get module for class {class_name}.)�cls�
class_reprr(r)�
__module__rarr&rr%�getattrr_)r�klassr(�exc�
modastroidr	r	r
�ast_from_class�s

zAstroidManager.ast_from_classc	
cspt|d�rt|t�s|j}n|}y
|j}Wnntk
rb}ztjd|t|�d�|�Wdd}~XYn8t	k
r�}ztj
d|t|�d�|�Wdd}~XYnXy
|j}Wnptk
r�}ztjd|t|�d�|�Wdd}~XYn:t	k
�r}ztj
d|t|�d�|�Wdd}~XYnX|�|�}||k�rJx@|�
||�D]}|V�q8Wn"x |�
||�D]}|��V�qXWdS)z!infer astroid for the given class�	__class__z&Unable to get module for {class_repr}.)rbrcNzBUnexpected error while retrieving module for {class_repr}:
{error}z%Unable to get name for {class_repr}:
z@Unexpected error while retrieving name for {class_repr}:
{error})�hasattrr]rArjrdrarr&rrrGr_r%ZigetattrZinstantiate_class)	rr�contextrfr(rg�namerh�inferredr	r	r
�infer_ast_from_somethingsJ







z'AstroidManager.infer_ast_from_somethingcCs|j�|�dS)a}Registers a hook to resolve imports that cannot be found otherwise.

        `hook` must be a function that accepts a single argument `modname` which
        contains the name of the module or package that could not be imported.
        If `hook` can resolve the import, must return a node of type `astroid.Module`,
        otherwise, it must raise `AstroidBuildingError`.
        N)r�append)rrOr	r	r
�register_failed_import_hook,sz*AstroidManager.register_failed_import_hookcCs|j�|j|�dS)z<Cache a module if no module with the same name is known yet.N)r�
setdefaultrm)rrLr	r	r
�cache_module6szAstroidManager.cache_modulecCsddl}|j��dS)z�Bootstrap the required AST modules needed for the manager to work

        The bootstrap usually involves building the AST for the builtins
        module, which is required by the rest of astroid to work correctly.
        rN)Zastroid.raw_buildingZraw_buildingZ_astroid_bootstrapping)r�astroidr	r	r
�	bootstrap:szAstroidManager.bootstrapcCs|j��|��dS)z@Clear the underlying cache. Also bootstraps the builtins module.N)r�clearru)rr	r	r
�clear_cacheDs
zAstroidManager.clear_cache)NTF)N)N)N)N)r_rd�__qualname__�__doc__rmrr�propertyrrr+r.r0r:r%rCr@rHrirorqrsrurwr	r	r	r
r$s(

?


,

r)ryr<rPrtrZastroid.interpreter._importrrrrrr	r	r	r
�<module>s