
    MhN                         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dS )
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              #   J   K   | ]}t          t          |          j        V  d S N)getattr
__future__compiler_flag).0fnames     W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/IPython/core/compilerop.py	<genexpr>r   /   sK       I I"' &j%88F I I I I I I    c                     t          j        |                     d                                                    }d                    ||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   sL    
 ,t{{73344>>@@K %++FK4DEEEr   c                   f    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dS )CachingCompilerzFA compiler that caches code compiled from interactive statements.
    c                 R    t           j                            |            i | _        d S r   )codeopCompile__init___filename_mapselfs    r   r   zCachingCompiler.__init__I   s(    %%%
  r   	<unknown>execc                 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OOr   c                 (    t           j        | _        dS )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


r   c                     | j         S )z;Flags currently active in the compilation process.
        r(   r!   s    r   compiler_flagszCachingCompiler.compiler_flags^   s     z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22r   c                 <    || j         v rdd| j         |         z  fS dS )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&>>>> &%r   r   Nc                     ||}|                      |||          }|| j        |<   t          |          dd |                                D             |f}|t          j        |<   |S )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.
        Nc                     g | ]}|d z   S )
 )r
   lines     r   
<listcomp>z)CachingCompiler.cache.<locals>.<listcomp>   s    CCCTTD[CCCr   )r6   r    len
splitlines	linecachecache)r"   r5   r   r4   r9   entrys         r   rD   zCachingCompiler.cache   s    $ 'H!!(,<fEE $*4   !!CC%5%@%@%B%BCCC	
 !&	r   c              #      K   | j          |z  }| j         |z  | _         	 d V  | xj         | z  c_         d S # | xj         | z  c_         w xY wr   r1   )r"   r(   turn_on_bitss      r   extra_flagszCachingCompiler.extra_flags   sf       
{U* Z%'
	(EEE JJ<-'JJJJDJJ<-'JJJJJJs	   5 A)r#   r$   )r   N)__name__
__module____qualname____doc__r   r,   r/   propertyr2   r6   r:   rD   r   rH   r>   r   r   r   r   E   s              P P P P3 3 3   X
3 3 3&? ? ?, , , ,\ ( ( ^( ( (r   r   )r   )rL   r   astr   r   	functoolsr   rC   operatortime
contextlibr   reduceor_all_feature_names	PyCF_MASKr   r   r   r>   r   r   <module>rW      s  
 
:                       % % % % % % IX\I I+5+GI I IJ J		F 	F 	F 	F{( {( {( {( {(fn {( {( {( {( {(r   