
    ;;iN                         d Z ddlZddlmZ ddlZddlZddlZddlZddlZddl	Z	ddl
mZ  ej                  ej                  d ej                  D              Zd	dZ G d dej"                        Zy)
zCompiler tools with improved interactive support.

Provides compilation machinery similar to codeop, but with caching support so
we can provide interactive tracebacks.

Authors
-------
* Robert Kern
* Fernando Perez
* Thomas Kluyver
    N)PyCF_ONLY_AST)contextmanagerc              #   P   K   | ]  }t        t        |      j                     y wN)getattr
__future__compiler_flag).0fnames     T/home/rose/Desktop/poly/venv/lib/python3.12/site-packages/IPython/core/compilerop.py	<genexpr>r   /   s&      I+G% &j%8FF+Gs   $&c                     t        j                  | j                  d            j                         }dj	                  ||dd       S )zf Compute a (probably) unique name for code for caching.

    This now expects code to be unicode.
    zutf-8z<ipython-input-{0}-{1}>N   )hashlibsha1encode	hexdigestformat)codenumberhash_digests      r   	code_namer   6   s@    
 ,,t{{734>>@K %++FK4DEE    c                   X    e Zd ZdZd ZddZd Zed        Zd Z	d Z
dd	Zed
        Zy)CachingCompilerzFA compiler that caches code compiled from interactive statements.
    c                 P    t         j                  j                  |        i | _        y r   )codeopCompile__init___filename_mapselfs    r   r   zCachingCompiler.__init__I   s    %
  r   c                 B    t        |||| j                  t        z  d      S )zParse code to an AST with the current compiler flags active.

        Arguments are exactly the same as ast.parse (in the standard library),
        and are passed to the built-in compile function.   )compileflagsr   )r"   sourcefilenamesymbols       r   	ast_parsezCachingCompiler.ast_parseQ   s     
 vxm1KQOOr   c                 .    t         j                  | _        y)z&Reset compiler flags to default state.N)r   PyCF_DONT_IMPLY_DEDENTr&   r!   s    r   reset_compiler_flagsz$CachingCompiler.reset_compiler_flagsX   s     22
r   c                     | j                   S )z;Flags currently active in the compilation process.
        r&   r!   s    r   compiler_flagszCachingCompiler.compiler_flags^   s     zzr   c                     t        ||      S )a  Compute filename given the code, and the cell number.

        Parameters
        ----------
        raw_code : str
            The raw cell code.
        transformed_code : str
            The executable Python source code to cache and compile.
        number : int
            A number which forms part of the code's name. Used for the execution
            counter.

        Returns
        -------
        The computed filename.
        )r   )r"   raw_codetransformed_coder   s       r   get_code_namezCachingCompiler.get_code_named   s    " )622r   c                 H    || j                   v rdd| j                   |   z  fS y)aN  Return a user-friendly label and name for a code block.

        Parameters
        ----------
        name : str
            The name for the code block returned from get_code_name

        Returns
        -------
        A (label, name) pair that can be used in tracebacks, or None if the default formatting should be used.
        CellzIn[%s]N)r    )r"   names     r   format_code_namez CachingCompiler.format_code_namew   s2     4%%%8d&8&8&>>>> &r   Nc                     ||}| j                  |||      }|| j                  |<   t        |      d|j                         D cg c]  }|dz   	 c}|f}|t        j
                  |<   |S c c}w )ah  Make a name for a block of code, and cache the code.

        Parameters
        ----------
        transformed_code : str
            The executable Python source code to cache and compile.
        number : int
            A number which forms part of the code's name. Used for the execution
            counter.
        raw_code : str
            The raw code before transformation, if None, set to `transformed_code`.

        Returns
        -------
        The name of the cached code (as a string). Pass this as the filename
        argument to compilation, so that tracebacks are correctly hooked up.
        N
)r4   r    len
splitlines	linecachecache)r"   r3   r   r2   r7   lineentrys          r   r>   zCachingCompiler.cache   s    $ 'H!!(,<fE $*4   !%5%@%@%BC%BTTD[%BC	
 !&		 Ds   A*c              #      K   | j                    |z  }| j                   |z  | _         	 d  | xj                   | z  c_         y # | xj                   | z  c_         w xY wwr   r/   )r"   r&   turn_on_bitss      r   extra_flagszCachingCompiler.extra_flags   sT      

{U* ZZ%'
	( JJ<-'JDJJ<-'Js   %AA AAA)z	<unknown>exec)r   N)__name__
__module____qualname____doc__r   r*   r-   propertyr0   r4   r8   r>   r   rC    r   r   r   r   E   sO     P3  
3&?,\ ( (r   r   )r   )rH   r   astr   r   	functoolsr   r=   operatortime
contextlibr   reduceor_all_feature_names	PyCF_MASKr   r   r   rJ   r   r   <module>rT      so   
:         % IX\\I+5+G+GIJ		F{(fnn {(r   