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

B

��\1
�@s&ddlZddlmZGdd�d�ZdS)�N)�	lru_cachec@sZeZdZdZdZdd�Zeed�dd��Zdd	�Zd
d�Z	dd
d�Z
ddd�Zdd�ZdS)�TransformVisitorz�A visitor for handling transforms.

    The standard approach of using it is to call
    :meth:`~visit` with an *astroid* module and the class
    will take care of the rest, walking the tree and running the
    transforms for each encountered node.
    i'cCst�t�|_dS)N)�collections�defaultdict�list�
transforms)�self�r	�C/opt/alt/python37/lib/python3.7/site-packages/astroid/transforms.py�__init__szTransformVisitor.__init__)�maxsizecCsd|j}||jkr|S|j|}x@|D]8\}}|dks<||�r$||�}|dk	rP|}|j|kr$Pq$W|S)zdCall matching transforms for the given node if any and return the
        transformed node.
        N)�	__class__r)r�node�clsrZtransform_func�	predicate�retr	r	r
�
_transforms


zTransformVisitor._transformcCsLt|d�rBx6|jD],}t||�}|�|�}||krt|||�qW|�|�S)N�_astroid_fields)�hasattrr�getattr�_visit_generic�setattrr)rr�name�value�visitedr	r	r
�_visit2s


zTransformVisitor._visitcsXt|t�r�fdd�|D�St|t�r<t�fdd�|D��S|rJt|t�rN|S��|�S)Ncsg|]}��|��qSr	)r)�.0�child)rr	r
�
<listcomp>=sz3TransformVisitor._visit_generic.<locals>.<listcomp>c3s|]}��|�VqdS)N)r)rr)rr	r
�	<genexpr>?sz2TransformVisitor._visit_generic.<locals>.<genexpr>)�
isinstancer�tuple�strr)rrr	)rr
r;s

zTransformVisitor._visit_genericNcCs|j|�||f�dS)a7Register `transform(node)` function to be applied on the given
        astroid's `node_class` if `predicate` is None or returns true
        when called with the node as argument.

        The transform function may return a value which is then used to
        substitute the original node in the tree.
        N)r�append)r�
node_class�	transformrr	r	r
�register_transformEsz#TransformVisitor.register_transformcCs|j|�||f�dS)zUnregister the given transform.N)r�remove)rr$r%rr	r	r
�unregister_transformOsz%TransformVisitor.unregister_transformcs �fdd�|jD�|_��|�S)z�Walk the given astroid *tree* and transform each encountered node

        Only the nodes which have transforms registered will actually
        be replaced or changed.
        csg|]}��|��qSr	)r)rr)rr	r
rYsz*TransformVisitor.visit.<locals>.<listcomp>)�bodyr)r�moduler	)rr
�visitSszTransformVisitor.visit)N)N)
�__name__�
__module__�__qualname__�__doc__ZTRANSFORM_MAX_CACHE_SIZErrrrrr&r(r+r	r	r	r
r
s	



r)r�	functoolsrrr	r	r	r
�<module>	s