
    ^h2                         S r SSKrSSKJr  SSKrSSKrSSKrSSKrSSKrSSK	r	SSK
Jr  \R                  " \R                  S \R                   5       5      rS
S jr " S S\R"                  5      rS	 rg)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              #   V   #    U  H  n[        [        U5      R                  v   M!     g 7fN)getattr
__future__compiler_flag).0fnames     Q/home/james-whalen/.local/lib/python3.13/site-packages/IPython/core/compilerop.py	<genexpr>r   /   s%      I+G% &j%8FF+Gs   ')c                     [         R                  " U R                  S5      5      R                  5       nSR	                  XSS 5      $ )z]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 %++F4DEE    c                   d    \ rS rSrSrS rSS jrS r\S 5       r	S r
S rSS
 jr\S 5       rSrg	)CachingCompilerE   zFA compiler that caches code compiled from interactive statements.
    c                 P    [         R                  R                  U 5        0 U l        g r   )codeopCompile__init___filename_mapselfs    r   r    CachingCompiler.__init__I   s    %
  r   c                 >    [        XX0R                  [        -  S5      $ )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_parseCachingCompiler.ast_parseQ   s    
 vm1KQOOr   c                 .    [         R                  U l        g)z&Reset compiler flags to default state.N)r   PyCF_DONT_IMPLY_DEDENTr(   r"   s    r   reset_compiler_flags$CachingCompiler.reset_compiler_flagsX   s     22
r   c                     U R                   $ )z;Flags currently active in the compilation process.
        r(   r"   s    r   compiler_flagsCachingCompiler.compiler_flags^   s     zzr   c                     [        X#5      $ )aQ  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_nameCachingCompiler.get_code_named   s    " )22r   c                 J    XR                   ;   a  SSU R                   U   -  4$ g)a  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_name CachingCompiler.format_code_namew   s0     %%%8d&8&8&>>>> &r   Nc                     Uc  UnU R                  X1U5      nX R                  U'   [        U5      SUR                  5        Vs/ s H  oUS-   PM	     snU4nU[        R
                  U'   U$ s  snf )a  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
)r9   r!   len
splitlines	linecachecache)r#   r8   r   r7   r=   lineentrys          r   rE   CachingCompiler.cache   s    $ 'H!!(fE $*4   !%5%@%@%BC%BTD[%BC	
 !&		 Ds   A+c              #      #    U R                   ) U-  nU R                   U-  U l          S v   U =R                   U) -  sl         g ! U =R                   U) -  sl         f = f7fr   r3   )r#   r(   turn_on_bitss      r   extra_flagsCachingCompiler.extra_flags   sS      

{U* ZZ%'
	( JJ<-'JDJJ<-'Js   %AA AAA)r!   r(   )z	<unknown>exec)r   N)__name__
__module____qualname____firstlineno____doc__r    r,   r0   propertyr4   r9   r>   rE   r   rK   __static_attributes__ r   r   r   r   E   sO     P3  
3&?,\ ( (r   r   c                  `    SSK nUR                  S[        SS9  [        R                  " 5         g)a  Deprecated since IPython 8.6.  Call linecache.checkcache() directly.

It was already not necessary to call this function directly.  If no
CachingCompiler had been created, this function would fail badly.  If
an instance had been created, this function would've been monkeypatched
into place.

As of IPython 8.6, the monkeypatching has gone away entirely.  But there
were still internal callers of this function, so maybe external callers
also existed?
r   NzHDeprecated Since IPython 8.6, Just call linecache.checkcache() directly.   )
stacklevel)warningswarnDeprecationWarningrD   
checkcache)argsrY   s     r   check_linecache_ipythonr^      s/     MMR  
 r   )r   )rR   r   astr   r   	functoolsr   rD   operatortime
contextlibr   reduceor_all_feature_names	PyCF_MASKr   r   r   r^   rU   r   r   <module>rh      ss   
:         % X\\I+5+G+GIJ		F{(fnn {(|r   