o
    DDi                     @   s   d dl mZ d dlmZmZmZmZmZmZ d dl	m
Z
 d dlmZ d dlmZmZmZ d dlmZmZmZ d dlmZ d dlmZ d d	lmZ erPd d
lmZ edddZeZe
eddG dd deZ dS )    )	dataclass)castOptionalSequenceTYPE_CHECKINGTypeVarUnion)	add_slots)CSTNode)CodegenStatevisit_body_sequencevisit_sequence)BaseCompoundStatementget_docstring_implSimpleStatementLine)	EmptyLine)RemovalSentinel)CSTVisitorTPartialParserConfig_ModuleSelfTModule)boundT)frozenc                       s  e Zd ZU dZeeeef  ed< dZ	ee
 ed< dZee
 ed< dZeed< dZeed	< d
Zeed< dZeed< dedd fddZdededef fddZdeddfddZedefddZedefddZdedefddZed&d!d"Zd'd#edee fd$d%Z   Z!S )(r   z
    Contains some top-level information inferred from the file letting us set correct
    defaults when printing the tree about global formatting rules. All code parsed
    with :func:`parse_module` will be encapsulated in a module.
    body headerfooterzutf-8encodingz    default_indent
default_newlineThas_trailing_newlinevisitorreturnc              	   C   sB   t t| d| j|t| d| j|t| d| j|| j| j| j| j	dS )Nr   r   r   )r   r   r   r   r   r!   r"   )
r   r   r   r   r   r   r   r   r!   r"   )selfr#   r   r   M/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/_nodes/module.py_visit_and_replace_childrenG   s   z"Module._visit_and_replace_childrenr%   c                    s4   t t| |}t|tr| jddddS tt|S )z
        Returns the result of running a visitor over this module.

        :class:`Module` overrides the default visitor entry point to resolve metadata
        dependencies declared by 'visitor'.
        r   )r   r   r   )superr   visit
isinstancer   with_changesr   r   )r%   r#   result	__class__r   r&   r)   R   s   

zModule.visitstateNc                 C   sv   | j D ]}|| q| jD ]}|| q| jD ]}|| q| jr5t|jdkr3||j d S d S |	  d S )Nr   )
r   _codegenr   r   r"   lentokens	add_tokenr!   pop_trailing_newline)r%   r/   hstmtfr   r   r&   _codegen_impl_   s   


zModule._codegen_implc                 C   s
   |  | S )zy
        The string representation of this module, respecting the inferred indentation
        and newline type.
        )code_for_noder%   r   r   r&   coden   s   
zModule.codec                 C   s   | j | jS )z
        The bytes representation of this module, respecting the inferred indentation
        and newline type, using the current encoding.
        )r;   encoder   r:   r   r   r&   bytesv   s   zModule.bytesnodec                 C   s&   t | j| jd}|| d|jS )z
        Generates the code for the given node in the context of this module. This is a
        method of Module, not CSTNode, because we need to know the module's default
        indentation and newline formats.
        )r   r!    )r   r   r!   r0   joinr2   )r%   r>   r/   r   r   r&   r9   ~   s
   
zModule.code_for_noder   c                 C   s    ddl m} || j| j| jdS )ak  
        Generates a parser config appropriate for passing to a :func:`parse_expression`
        or :func:`parse_statement` call. This is useful when using either parser
        function to generate code from a string template. By using a generated parser
        config instead of the default, you can guarantee that trees generated from
        both statement and expression strings have the same inferred defaults for things
        like newlines, indents and similar::

            module = cst.parse_module("pass\n")
            expression = cst.parse_expression("1 + 2", config=module.config_for_parsing)
        r   r   )r   r   r!   )libcst._parser.types.configr   r   r   r!   )r%   r   r   r   r&   config_for_parsing   s   zModule.config_for_parsingcleanc                 C   s   t | j|S )zy
        Returns a :func:`inspect.cleandoc` cleaned docstring if the docstring is available, ``None`` otherwise.
        )r   r   )r%   rC   r   r   r&   get_docstring   s   zModule.get_docstring)r$   r   )T)"__name__
__module____qualname____doc__r   r   r   r   __annotations__r   r   r   r   strr   r!   r"   boolr   r'   r   r)   r   r8   propertyr;   builtin_bytesr=   r
   r9   rB   r   rD   __classcell__r   r   r-   r&   r       s(   
  N)!dataclassesr   typingr   r   r   r   r   r   libcst._add_slotsr	   libcst._nodes.baser
   libcst._nodes.internalr   r   r   libcst._nodes.statementr   r   r   libcst._nodes.whitespacer   libcst._removal_sentinelr   libcst._visitorsr   rA   r   r   r=   rM   r   r   r   r   r&   <module>   s     