o
    DDi[                  	   @   s  d Z ddl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 ddlmZ edd	G d
d dZedd	G dd dZedd	G dd dZG dd deZedd	G dd dZG dd deZe	eeeef Zdddededee defddZdS )z5
Provides everything needed to run a CodemodCommand.
    N)	dataclass)Enum)OptionalSequenceUnion)parse_modulePartialParserConfig)CodemodT)frozenc                   @   s&   e Zd ZU dZee ed< eed< dS )TransformSuccessz
    A :class:`~libcst.codemod.TransformResult` used when the codemod was successful.
    Stores all the information we might need to display to the user upon success, as
    well as the transformed file contents.
    warning_messagescodeN)__name__
__module____qualname____doc__r   str__annotations__ r   r   O/var/www/Datamplify/venv/lib/python3.10/site-packages/libcst/codemod/_runner.pyr      s   
 r   c                   @   s.   e Zd ZU dZee ed< eed< eed< dS )TransformFailurez
    A :class:`~libcst.codemod.TransformResult` used when the codemod failed.
    Stores all the information we might need to display to the user upon a failure.
    r   errortraceback_strN)r   r   r   r   r   r   r   	Exceptionr   r   r   r   r   &   s
   
 r   c                   @   s"   e Zd ZU dZdZee ed< dS )TransformExitz
    A :class:`~libcst.codemod.TransformResult` used when the codemod was interrupted
    by the user (e.g. KeyboardInterrupt).
    r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   7   s   
 r   c                   @   s   e Zd ZdZdZdZdZdS )
SkipReasonzD
    An enumeration of all valid reasons for a codemod to skip.
    	generatedblacklistedotherN)r   r   r   r   	GENERATEDBLACKLISTEDOTHERr   r   r   r   r   C   s
    r   c                   @   s2   e Zd ZU dZeed< eed< dZee ed< dS )TransformSkipz
    A :class:`~libcst.codemod.TransformResult` used when the codemod requested to
    be skipped. This could be because it's a generated file, or due to filename
    blacklist, or because the transform raised :class:`~libcst.codemod.SkipFile`.
    skip_reasonskip_descriptionr   r   N)	r   r   r   r   r   r   r   r   r   r   r   r   r   r"   U   s
   
 r"   c                   @   s   e Zd ZdZdS )SkipFilez
    Raise this exception to skip codemodding the current file.

    The exception message should be the reason for skipping.
    N)r   r   r   r   r   r   r   r   r%   g   s    r%   python_versiontransformerr   r'   returnc             
   C   s   zt ||durt|dnt d}| |}t|j| jjdW S  ty+   t  Y S  t	yH } zt
t|tj| jjdW  Y d}~S d}~w tyd } zt|t | jjdW  Y d}~S d}~ww )a  
    Given a module as represented by a string and a :class:`~libcst.codemod.Codemod`
    that we wish to run, execute the codemod on the code and return a
    :class:`~libcst.codemod.TransformResult`. This should never raise an exception.
    On success, this returns a :class:`~libcst.codemod.TransformSuccess` containing
    any generated warnings as well as the transformed code. If the codemod is
    interrupted with a Ctrl+C, this returns a :class:`~libcst.codemod.TransformExit`.
    If the codemod elected to skip by throwing a :class:`~libcst.codemod.SkipFile`
    exception, this will return a :class:`~libcst.codemod.TransformSkip` containing
    the reason for skipping as well as any warnings that were generated before
    the codemod decided to skip. If the codemod throws an unexpected exception,
    this will return a :class:`~libcst.codemod.TransformFailure` containing the
    exception that occured as well as any warnings that were generated before the
    codemod crashed.
    Nr&   )config)r   r   )r$   r#   r   )r   r   r   )r   r   transform_moduler   r   contextwarningsKeyboardInterruptr   r%   r"   r   r   r!   r   r   	traceback
format_exc)r(   r   r'   
input_treeoutput_treeexr   r   r   r+   t   s8   



r+   )r   r/   dataclassesr   enumr   typingr   r   r   libcstr   r   libcst.codemod._codemodr	   r   r   r   r   r"   r   r%   TransformResultr   r+   r   r   r   r   <module>   s<   
