Your IP : 216.73.216.74


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__/raw_building.cpython-37.pyc

B

��\�>�@s`dZddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddlm
Z
ddlmZe	��Z
ee
j�Zee�Ze�e�Zdd�Zd	d
�Zdd�Ze�Zefd
d�Zdd�Zeej_dd�Zdd�Z d2dd�Z!d3dd�Z"d4dd�Z#dd�Z$d5dd�Z%d d!�Z&d"d#�Z'd$d%�Z(d&d'�Z)d6d(d)�Z*d*d+�Z+Gd,d-�d-�Z,iZ-d.d/�Z.d0d1�Z/e/�dS)7z�this module contains a set of functions to create astroid trees from scratch
(build_* functions) or from living object (object_build_* functions)
�N)�bases)�manager)�node_classes)�nodescCs.t|dd�}|o,t�|�o,|jdko,|jdkS)N�__self__�_io�io)�getattr�inspect�ismodule�__name__�
__module__)�memberZmember_self�r�E/opt/alt/python37/lib/python3.7/site-packages/astroid/raw_building.py�_io_discrepancy)s


rcCs||_|�|�dS)N)�name�add_local_node)�parent�noderrrr�_attach_local_node4srcCsH|j}t|dd�}|sdSdd�|jD�}t|||j�}|g|jd<dS)zFAdd a __class__ member to the given func node, if we can determine it.rNcSsg|]
}|j�qSr)r)�.0Zancestorrrr�
<listcomp>?sz%_add_dunder_class.<locals>.<listcomp>�	__class__)rr	�	__bases__�build_class�__doc__�instance_attrs)�funcrZ
python_clsZcls_nameZ	cls_basesZ	ast_klassrrr�_add_dunder_class9srcCst��}||_t|||�dS)zdcreate a dummy node and register it in the locals of the given
    node with the specified name
    N)r�	EmptyNode�objectr)rrZruntime_objectZenoderrr�attach_dummy_nodeGsr"cCs|jdk	o|jtk	S)N)r!�_marker)�selfrrr�_has_underlying_objectPsr%cCs ||jkrt|t�|�|�dS)zdcreate a Const node and register it in the locals of the given
    node with the specified name
    N)Zspecial_attributesrr�
const_factory)rr�valuerrr�attach_const_nodeWs
r(cCs"t�||dfg�}t|||�dS)zicreate a ImportFrom node and register it in the locals of the given
    node with the specified name
    N)r�
ImportFromr)r�modnameZ
membernameZ	from_noderrr�attach_import_node_sr+cCs tj||dd�}d|_d|_|S)z,create and initialize an astroid Module nodeF)Zpure_pythonN)r�Module�packager)r�docrrrr�build_modulegsr/rcCs>t�||�}x,|D]$}t��}||_|j�|�||_qW|S)z.create and initialize an astroid ClassDef node)r�ClassDef�Namerr�appendr)r�	basenamesr.r�baseZbasenoderrrros

rcCs�|pg|pg}}t�||�}t��|_}g|_x4|D],}|j�t���||jd_||jd_q8Wg|_x*|D]"}|j�t�	|��||jd_qtWd|_
d|_||_|r�t|�|S)z1create and initialize an astroid FunctionDef node���N)
rZFunctionDef�	Arguments�argsr2r1rr�defaultsr&�kwarg�vararg�register_arguments)rr7r8r.rZargsnode�arg�defaultrrr�build_functionzs$

r>cCst�|dd�|D��S)z<create and initialize an astroid ImportFrom import statementcSsg|]}|df�qS)Nr)rrrrrr�sz%build_from_import.<locals>.<listcomp>)rr))�fromname�namesrrr�build_from_import�srAcCs~|dkrD|jj}|jjr*|�|jj|j�|jjrD|�|jj|j�x4|D],}t|tj�rj|�|j|�qJt||j	�qJWdS)z{add given arguments to local

    args is a list that may contains nested lists
    (i.e. def func(a, (b, c, d)): ...)
    N)
r7r:Z	set_localr9�
isinstancerr1rr;Zelts)rr7r<rrrr;�s
r;cCs dd�|jD�}t||||d�S)z(create astroid for a living class objectcSsg|]
}|j�qSr)r)rr4rrrr�sz&object_build_class.<locals>.<listcomp>)�	localname)r�_base_class_object_build)rrrCr3rrr�object_build_class�srEcCsbt�|�\}}}}|dk	r$|�|�|dk	r6|�|�tt|dd�pF||||j�}|�||�dS)z+create astroid for a living function objectNr)r
�
getargspecr2r>r	rr)rrrCr7�varargs�varkwr8rrrr�object_build_function�s

rIcCst||g|�S)z2create astroid for a living data descriptor object)rD)rrrrrr�object_build_datadescriptor�srJcCs<tt|dd�p||jd�}d|j_|�||�t||�dS)z4create astroid for a living method descriptor objectrN)r.)r>r	rr7rr)rrrCrrrr�object_build_methoddescriptor�s
rKc
Cs�t|pt|dd�p|||j�}t|t�|_|�||�yt|t�rL|�j	}nt
�WnYn>Xx:|��D].\}}t�
�}	||	_||	_d|	_|	g|j|<qjW|S)zbcreate astroid for a living class object, with a given set of base names
    (e.g. ancestors)
    rN�)rr	rrB�typeZ	_newstyler�
issubclass�	Exception�__dict__�	TypeError�itemsrr r!r�linenor)
rrr3rrC�klassZinstdictZ	item_name�objZvalnoderrrrD�s&

rDcCs�y
|j}Wntk
r"d}YnXt|dd�}|dkrTt|t�sFt�t|||�n*|t|dd�krrt|||�nt|||�dS)N�co_filename�__file__)	�__code__�AttributeErrorr	rBr!�AssertionErrorrKr"rI)rrr�module�code�filenamerrr�_build_from_function�s

r^c@s2eZdZdZdd�Zddd�Zdd�Zd	d
�ZdS)�InspectBuilderz�class for building nodes from living object

    this is actually a really minimal representation, including only Module,
    FunctionDef and ClassDef nodes and some others as guessed.
    cCsi|_d|_dS)N)�_done�_module)r$rrr�__init__szInspectBuilder.__init__NcCs�||_|dkr|j}yt||j�}Wntk
r@t|�}YnX|rRtj�|�n||_|_||_	t
�|�t|d�|_
i|_|�||�|S)z�build astroid from a living module (i.e. using inspect)
        this is used when there is no python source code available (either
        because it's a built-in module or because the .py is not available)
        N�__path__)rarr/rrY�os�path�abspath�filer�MANAGER�cache_module�hasattrr-r`�object_build)r$r[r*rerrrr�
inspect_builds
zInspectBuilder.inspect_buildc	Cs�||jkr|j|S||j|<�x�t|�D�]�}yt||�}Wn tk
r^t||�w*YnXt�|�rp|j}t�|�r�t	||||j
�q*t�|�r�t|�s�|�
|||�r�q*t|||�q*t�|��rN|�
|||�r�q*||jk�r|j|}||j�|d�k�r(|�||�nt|||�}|�||�|dk�r�|jdk�r�|j|j
|_q*t�|��rxt|t��sjt�t|||�q*t�|��r�t|t��s�t�t|||�q*t|t��r�t|||�q*t�|��r�t	||||j
�q*t|||�q*WdS)z~recursive method which create a partial ast from real objects
         (only function, class, and method are handled)
        rrN)r`�dirr	rYr"r
�ismethod�__func__�
isfunctionr^ra�	isbuiltinr�imported_memberrK�isclass�locals�getrrErkr�ismethoddescriptorrBr!rZ�isdatadescriptorrJ�
_CONSTANTSr(�	isroutine)r$rrUrrZ
class_noderrrrk!sR








zInspectBuilder.object_buildc	Cs�yt|dd�}Wnt�d�d}YnX|dkrT|dkrDtj}nt|||�dSddd��||�}||jjkr�yttj	||�Wn$t
tfk
r�t|||�YnXt|||�dSd	S)
z1verify this is not an imported class or handle itr
Nz:unexpected error while building astroid from living object)�__new__�__subclasshook__TZgtk_gtkr)ZgtkrF)
r	�_LOG�	exception�builtinsrr"rura�sys�modules�KeyErrorrYr+)r$rrrr*Z	real_namerrrrrWs(
zInspectBuilder.imported_member)NN)rr
�__qualname__rrbrlrkrrrrrrr_s

6r_cCst|jjS)N)�_CONST_PROXYr'r)�constrrr�_set_proxied�sr�c	
Cs�t�}|�t�}x~tj��D]p\}}|td�kr@td�}||_n,|tt	�kr\td�}||_n|�
|j�d}|tt
ttfkr�||_q|t|<qWtt�tj_t�tjjtjj�}||_|tj_|�tjjtj�ttd��rt�tjjtjj�}||_|tj_|�tjjtj�tj tjtj!td�tt	�tj"tj#tj$tj%tj&f
}xF|D]>}|j|k�rFt�|j|j�}||_|�||�|||j<�qFWdS)z)astroid bootstrapping the builtins moduleNZNoneTypeZNotImplementedTyper�AsyncGeneratorType)'r_rlr~r�	CONST_CLSrRrMrr�NotImplementedr	r�dict�list�set�tupleZ_proxiedr��propertyr�rZConstr0�types�
GeneratorTyperr�	Generatorrkrjr��AsyncGenerator�GetSetDescriptorType�MemberDescriptorType�FunctionType�
MethodType�BuiltinFunctionType�
ModuleType�
TracebackType)	ZbuilderZastroid_builtin�clsZnode_cls�proxyZ_GeneratorTypeZ_AsyncGeneratorTypeZ
builtin_typesZ_typerrr�_astroid_bootstrapping�sR

r�)N)rN)NNN)N)NN)0rr~r
Zloggingrdrr��astroidrrrrZAstroidManagerrhr�r�rx�varsZ	_BUILTINSZ	getLoggerrr|rrrr!r#r"r%r Zhas_underlying_objectr(r+r/rr>rAr;rErIrJrKrDr^r_r�r�r�rrrr�<module>sN

	




 }<