Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/astroid/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/astroid/__pycache__/builder.cpython-311.pyc

�

�܋fdI��v�dZddlmZddlZddlZddlZddlZddlmZm	Z	ddl
mZddlm
Z
ddlmZddlmZmZmZmZmZmZdd	lmZmZdd
lmZmZmZddlmZerddlm Z nej!d
��Z dZ"dZ#dZ$d7d�Z%d8d�Z&Gd�dej'��Z(d9d"�Z)			d:d;d(�Z*d<d+�Z+d=d/�Z,d>d?d1�Z-d>d@d2�Z.	dAdBd6�Z/dS)Cz�The AstroidBuilder makes astroid from living object and / or from _ast.

The builder is not thread safe and can't be used to parse different sources
at the same time.
�)�annotationsN)�Iterator�Sequence)�
TextIOWrapper)�detect_encoding)�
TYPE_CHECKING)�bases�modutils�nodes�raw_building�	rebuilder�util)�ParserModule�get_parser_module)�AstroidBuildingError�AstroidSyntaxError�InferenceError)�AstroidManager)�objectsr�__z#@zmisplaced type annotation�filename�str�return�tuple[TextIOWrapper, str, str]c���t|d��5}t|j��d}ddd��n#1swxYwYt|d|���}|���}|||fS)N�rbr)�newline�encoding)�openr�readline�read)r�byte_streamr�stream�datas     �`/builddir/build/BUILD/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/astroid/builder.py�open_source_filer&,s���	
�h��	�	�<��"�;�#7�8�8��;��<�<�<�<�<�<�<�<�<�<�<����<�<�<�<�
�(�D�8�
<�
<�
<�F��;�;�=�=�D��8�T�!�!s�8�<�<�node�nodes.ClassDef�attrname�
str | None�boolc��	|���}|r|d�|D��vrdSn#t$rYnwxYw|���dkS)Nc��h|]	}|j��
S�)�value)�.0�slots  r%�	<setcomp>z#_can_assign_attr.<locals>.<setcomp>;s��%C�%C�%C�T�d�j�%C�%C�%C�Fzbuiltins.object)�slots�NotImplementedError�qname)r'r)r4s   r%�_can_assign_attrr75su����
�
�����	�X�%C�%C�U�%C�%C�%C�C�C��5���	�
�
�
���
����
�:�:�<�<�,�,�,s�)�
6�6c�j��eZdZdZ	d"d#�fd
�
Z	d$d%d�Zd$d&d�Z	d'd(d�Zd)d�Zd*d�Z	d+d�Z
d,d!�Z�xZS)-�AstroidBuildera�Class for building an astroid tree from source code or from a live module.

    The param *manager* specifies the manager class which should be used.
    If no manager is given, then the default one will be used. The
    param *apply_transforms* determines if the transforms should be
    applied after the tree was built from source or from a live object,
    by default being True.
    NT�manager�AstroidManager | None�apply_transformsr+r�Nonec�X��t���|��||_dS�N)�super�__init__�_apply_transforms)�selfr:r<�	__class__s   �r%rAzAstroidBuilder.__init__Js+���	������!�!�!�!1����r3�module�types.ModuleType�modnamer*�nodes.Modulec�^�d}t|dd��}t|dd��}|r8|p|j}|�|��}|r|�|||���}|�u|�stj�tj|����\}}|dvr;tj�	|dz��r|�
|dz|��}|�9|�|||���}|jr|j
�|��}t|t j��sJ�|S)z/Build an astroid from a living module instance.N�__file__�
__loader__)�path>�.pyc�.pyo�.pyrO�rGrL)�getattr�__name__�
get_source�string_build�osrL�splitextr
�_path_from_filename�exists�
file_build�
inspect_buildrB�_manager�visit_transforms�
isinstancer�Module)	rCrErGr'rL�loader�source�path_�exts	         r%�module_buildzAstroidBuilder.module_buildPs@�����v�z�4�0�0�����t�4�4���	E��0���G��&�&�w�/�/�F��
E��(�(���t�(�D�D���<�D�,���)�)�(�*F�t�*L�*L�M�M�J�E�3��-�-�-�"�'�.�.����2O�2O�-����u�u�}�g�>�>���<��%�%�f�g�D�%�I�I�D��%�
<��}�5�5�d�;�;���$���-�-�-�-�-��r3rLrc��	t|��\}}}nm#t$r}td|||���|�d}~wttf$r}td|||���|�d}~wt$r}td|���|�d}~wwxYw|5|�{	d�tj	|����}nR#t$rEtj�
tj�|����d}YnwxYw|�|||��\}}|�|||��cddd��S#1swxYwYdS)	zyBuild astroid from a source code file (i.e. from an ast).

        *path* is expected to be a python source file
        z#Unable to load file {path}:
{error})rGrL�errorNzBPython 3 encoding specification error or unknown encoding:
{error}z.Wrong or no encoding specified for {filename}.)r�.r)r&�OSErrorr�SyntaxError�LookupErrorr�UnicodeError�joinr
�modpath_from_file�ImportErrorrUrLrV�basename�_data_build�_post_build)	rCrLrGr#rr$�excrE�builders	         r%rYzAstroidBuilder.file_buildms���
	�%5�d�%;�%;�"�F�H�d�d���	�	�	�&�6����	���
�
������[�)�	�	�	�$���������

������	�	�	�&�@�4�����
�����	����
�		?�		?���J�!�h�h�x�'A�$�'G�'G�H�H�G�G��"�J�J�J� �g�.�.�r�w�/?�/?��/E�/E�F�F�q�I�G�G�G�J����#�.�.�t�W�d�C�C�O�F�G��#�#�F�G�X�>�>�		?�		?�		?�		?�		?�		?�		?�		?�		?�		?�		?�		?����		?�		?�		?�		?�		?�		?sa��
B�4�B�A�
B�)A;�;B�E�	'B1�0E�1AD�=E�?D�3E�E�E�r$c��|�|||��\}}|�d��|_|�||d��S)z&Build astroid from source code string.zutf-8)ro�encode�
file_bytesrp)rCr$rGrLrErrs      r%rTzAstroidBuilder.string_build�sK���*�*�4��$�?�?���� �K�K��0�0���������9�9�9r3rr�rebuilder.TreeRebuilderrc�j�||_|j�|��|jD]I}|jdkr'|jD]\}}|j�|��� |�|���J|j	D]}|�
|���|jr|j�|��}|S)zAHandles encoding and delayed nodes after a module has been built.�
__future__)
�
file_encodingr[�cache_module�_import_from_nodesrG�names�future_imports�add�add_from_names_to_locals�_delayed_assattr�delayed_assattrrBr\)rCrErrr�	from_node�symbol�_�delayeds        r%rpzAstroidBuilder._post_build�s��� (����
�"�"�6�*�*�*� �3�	5�	5�I�� �L�0�0�!*��6�6�I�F�A��)�-�-�f�5�5�5�5��)�)�)�4�4�4�4��/�	*�	*�G�� � ��)�)�)�)��!�	<��]�3�3�F�;�;�F��
r3�,tuple[nodes.Module, rebuilder.TreeRebuilder]c�$�	t|d���\}}n4#tttf$r}t	d||||���|�d}~wwxYw|� t
j�|��}nd}|�d��r
|dd�}d}nJ|duoEt
j�	t
j�
|����d	d
k}tj|j
||��}	|	�||||��}
|
|	fS)z4Build tree node from data and add some informations.T��
type_commentsz#Parsing Python code failed:
{error})r`rGrLreNz<?>z	.__init__i����rrA)�
_parse_string�	TypeError�
ValueErrorrhrrUrL�abspath�endswithrVrnr
�
TreeRebuilderr[�visit_module)rCr$rGrLr'�
parser_modulerq�	node_file�packagerrrEs           r%rozAstroidBuilder._data_build�s:��		�"/��D�"I�"I�"I��D�-�-���:�{�3�	�	�	�$�6���������

�����	�����������-�-�I�I��I����K�(�(�	��c�r�c�l�G��G�G��D� �N��G�$�$�R�W�%5�%5�d�%;�%;�<�<�Q�?�:�M�
��)�$�-���M�M���%�%�d�G�Y��H�H���w��s��A�A�Ar'�nodes.ImportFromc���dd��d
�fd	�}|jsJ�|jD]�\}}|d
kr�	|���}n#t$rY�-wxYw|���D]J}|j�||��||j���j|���K��|j�|p||��||j���j|p|����dS)zeStore imported names to the locals.

        Resort the locals if coming from a delayed node
        r'�nodes.NodeNGr�intc��|jpdS)Nr)�
fromlineno�r's r%�	_key_funcz:AstroidBuilder.add_from_names_to_locals.<locals>._key_func�s���?�'�a�'r3�my_list�list[nodes.NodeNG]r=c�4��|�����dS)N)�key)�sort)r�r�s �r%�sort_localsz<AstroidBuilder.add_from_names_to_locals.<locals>.sort_locals�s����L�L�Y�L�'�'�'�'�'r3�*N)r'r�rr�)r�r�rr=)�parentr}�do_import_moduler�public_names�	set_local�scope�locals)rCr'r��name�asname�importedr�s      @r%r�z'AstroidBuilder.add_from_names_to_locals�sW���	(�	(�	(�	(�	(�	(�	(�	(�	(�	(��{���{� �J�	H�	H�L�D�&��s�{�{��#�4�4�6�6�H�H��+�����H�����$�1�1�3�3�B�B�D��K�)�)�$��5�5�5��K��� 1� 1� 3� 3� :�4� @�A�A�A�A�B���%�%�f�n��d�;�;�;���D�K�-�-�/�/�6�v�~��F�G�G�G�G�	H�	Hs�=�
A
�	A
�nodes.AssignAttrc�Z�	|�d���}|j���D�]g}t|tj��r�	t
|��tjkst
|��tj
kr%|j}|j}t||j��s�}nXt|tj��r��t|tjtjf��r��|jr|j}n|j}n#t$$rY��wxYw|�|jg��}||vr��|jdkr?|r=|d�d���jdkr|�d|����R|�|����idS#t.$rYdSwxYw)z_Visit a AssAttr node.

        This adds name to locals and handle members definition.
        T)�futurerArN)�frame�expr�inferr]r�UninferableBase�typer	�Instancer�ExceptionInstance�_proxied�instance_attrsr7r)�Proxy�is_functionr��AttributeError�
setdefaultr��insert�appendr)rCr'r��inferred�iattrs�valuess      r%r�zAstroidBuilder.delayed_assattr�s���
*	��J�J�d�J�+�+�E� �I�O�O�-�-�&
(�&
(���h��(<�=�=�����X���%�.�8�8���>�>�W�-F�F�F�#+�#4��!)�!8��/��$�-�H�H�%�$�%�#�H�e�n�=�=�	1�!�#�H�u�{�D�<P�.Q�R�R�1� �!�-�1�!)�!8���!)�����%�����H����� �*�*�4�=�"�=�=���6�>�>���J�*�,�,��-��q�	���t��4�4�9�Z�G�G��M�M�!�T�*�*�*�*��M�M�$�'�'�'�'�M&
(�&
(��N�	�	�	��D�D�	���s\�A
F�AD�-F�.D�	F�
&D�0F�1D�F�
D�F�D�BF�
F*�)F*)NT)r:r;r<r+rr=r?)rErFrGr*rrH)rLrrGr*rrH)rsN)r$rrGrrLr*rrH)rErHrrrwrrrrH)r$rrGrrLr*rr�)r'r�rr=)r'r�rr=)
rR�
__module__�__qualname__�__doc__rArcrYrTrpror�r��
__classcell__)rDs@r%r9r9@s���������OS�2�2�2�2�2�2�2�?C������:$?�$?�$?�$?�$?�N@D�:�:�:�:�:�����*����>H�H�H�H�4/�/�/�/�/�/�/�/r3r9r�rL�
Sequence[str]rHc�J�tj|t|��d���S)NT)rLr�)rr^�list)r�rLs  r%�build_namespace_package_moduler�s���<��4��:�:�t�<�<�<�<r3rsT�code�module_namer<c��tj|��}tt��|���}|�|||���S)awParses a source string in order to obtain an astroid AST from it.

    :param str code: The code for the module.
    :param str module_name: The name for the module, if any
    :param str path: The path for the module
    :param bool apply_transforms:
        Apply the transforms for the give code. Use it if you
        don't want the default transforms to be applied.
    )r:r<rP)�textwrap�dedentr9rrT)r�r�rLr<rrs     r%�parser� sP���?�4� � �D��� � �3C����G�����k���E�E�Er3r��Iterator[nodes.NodeNG]c#�2K�t|tj��r�t|jtj��r�|jjtkr�|jd}|jsJ�|j|_|jj	D]e}t|j|��}t|t��rt|��D]\}}||ur|||<��K||urt|j||���f|V�dS|���D]}t|��Ed{V���dS)aFind expressions in a call to _TRANSIENT_FUNCTION and extract them.

    The function walks the AST recursively to search for expressions that
    are wrapped into a call to _TRANSIENT_FUNCTION. If it finds such an
    expression, it completely removes the function call node from the tree,
    replacing it by the wrapped expression inside the parent.

    :param node: An astroid node.
    :type node:  astroid.bases.NodeNG
    :yields: The sequence of wrapped expressions on the modified tree
    expression can be found.
    rN)r]r�Call�func�Namer��_TRANSIENT_FUNCTION�argsr��_astroid_fieldsrQr��	enumerate�setattr�get_children�_extract_expressions)r'�	real_exprr��child�idx�compound_childs      r%r�r�6sJ����	�4���$�$�3��t�y�%�*�-�-�3�
�I�N�1�1�1��I�a�L�	��{���{��;�	���K�/�	6�	6�D��D�K��.�.�E��%��&�&�
6�+4�U�+;�+;�/�/�'�C��%��-�-�%.��c�
��/��$������T�9�5�5�5���������&�&�(�(�	3�	3�E�+�E�2�2�2�2�2�2�2�2�2�2�	3�	3r3�liner��nodes.NodeNG | Nonec���t|tjtjtjf��r|j}n|j}||kr|S|���D]}t||��}|r|cS�dS)a�Extracts the statement on a specific line from an AST.

    If the line number of node matches line, it will be returned;
    otherwise its children are iterated and the function is called
    recursively.

    :param node: An astroid node.
    :type node: astroid.bases.NodeNG
    :param line: The line number of the statement to extract.
    :type line: int
    :returns: The statement on the line, or None if no statement for the line
      can be found.
    :rtype:  astroid.bases.NodeNG or None
    N)	r]r�ClassDef�FunctionDef�	MatchCaser��linenor��_find_statement_by_line)r'r��	node_liner��results     r%r�r�^s����$����):�E�O�L�M�M� �
�O�	�	��K�	��D������"�"�$�$����(���5�5���	��M�M�M�	��4r3�!nodes.NodeNG | list[nodes.NodeNG]c�P���d
d��g}t|�����D]I\}}|����t��r|�|dz���Jt
||�����jstd���g}|r�fd�|D��}|�	t�����|s |��jd	���fd
�|D��}d�|D��}t|��dkr|dS|S)ahParses some Python code as a module and extracts a designated AST node.

    Statements:
     To extract one or more statement nodes, append #@ to the end of the line

     Examples:
       >>> def x():
       >>>   def y():
       >>>     return 1 #@

       The return statement will be extracted.

       >>> class X(object):
       >>>   def meth(self): #@
       >>>     pass

      The function object 'meth' will be extracted.

    Expressions:
     To extract arbitrary expressions, surround them with the fake
     function call __(...). After parsing, the surrounded expression
     will be returned and the whole AST (accessible via the returned
     node's parent attribute) will look like the function call was
     never there in the first place.

     Examples:
       >>> a = __(1)

       The const node will be extracted.

       >>> def x(d=__(foo.bar)): pass

       The node containing the default argument will be extracted.

       >>> def foo(a, b):
       >>>   return 0 < __(len(a)) < b

       The node containing the function call 'len' will be extracted.

    If no statements or expressions are selected, the last toplevel
    statement will be returned.

    If the selected statement is a discard statement, (i.e. an expression
    turned into a statement), the wrapped expression is returned instead.

    For convenience, singleton lists are unpacked.

    :param str code: A piece of Python code that is parsed as
    a module. Will be passed through textwrap.dedent first.
    :param str module_name: The name of the module.
    :returns: The designated node from the parse tree, or a list of nodes.
    r'r�rc�H�t|tj��r|jS|Sr?)r]r�Exprr/r�s r%�_extractzextract_node.<locals>._extract�s#���d�E�J�'�'�	��:���r3�)r�z"Empty tree, cannot extract from itc�0��g|]}t�|����Sr.)r�)r0r��trees  �r%�
<listcomp>z extract_node.<locals>.<listcomp>�s$���U�U�U�T�,�T�4�8�8�U�U�Ur3���c�&��g|]
}�|����Sr.r.)r0r'r�s  �r%r�z extract_node.<locals>.<listcomp>�s!���6�6�6�D���$���6�6�6r3c��g|]}|�|��Sr?r.)r0r's  r%r�z extract_node.<locals>.<listcomp>�s��M�M�M�t�D�<L�d�<L�<L�<Lr3r)r'r�rr�)r��
splitlines�stripr��_STATEMENT_SELECTORr�r��bodyr��extendr��len)	r�r��requested_linesr�r��	extracted�extracted_without_noner�r�s	       @@r%�extract_noder��sb����l����"$�O��t���0�0�1�1�,�,�	��T��:�:�<�<� � �!4�5�5�	,��"�"�3��7�+�+�+����;�/�/�/�D��9�?��=�>�>�>�+-�I��V�U�U�U�U�_�U�U�U�	����)�$�/�/�0�0�0��(������2��'�'�'�6�6�6�6�I�6�6�6�I�M�M�y�M�M�M��
�!�"�"�a�'�'�%�a�(�(�!�!r3c�`�t||��}t|t��r|dS|S)zDCall extract_node while making sure that only one value is returned.r)r�r]r�)r�r��rets   r%�_extract_single_noder�s1��
�t�[�
)�
)�C��#�t�����1�v�
��Jr3r$r��tuple[ast.Module, ParserModule]c��t|���}	|�|dz|���}nZ#t$rM}|jdtks|s�td���}|�|dzd���}Yd}~nd}~wwxYw||fS)Nr��
rF)rr�rhr��MISPLACED_TYPE_ANNOTATION_ERROR)r$r�r��parsedrqs     r%r�r��s���&�M�B�B�B�M�
G��$�$�T�D�[�
�$�N�N�����G�G�G��8�A�;�9�9�9��9��)��>�>�>�
��$�$�T�D�[��$�F�F�����������G�����=� � s�-�
B�AA?�?B)rrrr)r'r(r)r*rr+)r�rrLr�rrH)rsNT)
r�rr�rrLr*r<r+rrH)r'r�rr�)r'r�r�r�rr�)rs)r�rr�rrr�)r�rr�rrr�)T)r$rr�r+rr)0r�ryr�astrUr��types�collections.abcrr�ior�tokenizer�typingr�astroidr	r
rrr
r�astroid._astrr�astroid.exceptionsrrr�astroid.managerrr�lazy_importr�r�rr&r7�InspectBuilderr9r�r�r�r�r�rr�r.r3r%�<module>rsw��
��#�"�"�"�"�"�
�
�
�
�	�	�	�	���������.�.�.�.�.�.�.�.�������$�$�$�$�$�$� � � � � � �I�I�I�I�I�I�I�I�I�I�I�I�I�I�I�I�8�8�8�8�8�8�8�8�W�W�W�W�W�W�W�W�W�W�*�*�*�*�*�*��*���������d��y�)�)�G�����"=��"�"�"�"�-�-�-�-�X�X�X�X�X�\�0�X�X�X�v=�=�=�=���!�	F�F�F�F�F�,%3�%3�%3�%3�P � � � �FS"�S"�S"�S"�S"�l�����&*�!�!�!�!�!�!�!r3

Hacked By AnonymousFox1.0, Coded By AnonymousFox