/ lib / IPython / core / compilerop.pyc
compilerop.pyc
  1  o

  2  .��c2�@s�dZddlZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
  3  mZe�ej
dd�ejD��Zd
dd�ZGd	d
  4  �d
  5  ej�Zdd�ZdS)z�Compiler tools with improved interactive support.
  6  
  7  Provides compilation machinery similar to codeop, but with caching support so
  8  we can provide interactive tracebacks.
  9  
 10  Authors
 11  -------
 12  * Robert Kern
 13  * Fernando Perez
 14  * Thomas Kluyver
 15  �N)�
PyCF_ONLY_AST)�contextmanagerccs�|]	}tt|�jVqdS�N)�getattr�
 16  __future__�
compiler_flag)�.0�fname�r
 17  ��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\IPython\core\compilerop.py�	<genexpr>/s��rcCs(t�|�d����}d�||dd��S)zf Compute a (probably) unique name for code for caching.
 18  
 19      This now expects code to be unicode.
 20      zutf-8z<ipython-input-{0}-{1}>N�)�hashlib�sha1�encode�	hexdigest�format)�code�numberZhash_digestr
 21  r
 22  r�	code_name6src@s\eZdZdZdd�Zddd�Zdd	�Zed
 23  d��Zdd
�Z	dd�Z
 24  ddd�Zedd��Z
dS)�CachingCompilerzFA compiler that caches code compiled from interactive statements.
 25      cCstj�|�i|_dSr)�codeop�Compile�__init__�
_filename_map��selfr
 26  r
 27  rrIs
 28  zCachingCompiler.__init__�	<unknown>�execcCst||||jtBd�S)z�Parse code to an AST with the current compiler flags active.
 29  
 30          Arguments are exactly the same as ast.parse (in the standard library),
 31          and are passed to the built-in compile function.�)�compile�flagsr)r�source�filename�symbolr
 32  r
 33  r�	ast_parseQszCachingCompiler.ast_parsecCstj|_dS)z&Reset compiler flags to default state.N)r�PyCF_DONT_IMPLY_DEDENTr!rr
 34  r
 35  r�reset_compiler_flagsXsz$CachingCompiler.reset_compiler_flagscCs|jS)z;Flags currently active in the compilation process.
 36          �r!rr
 37  r
 38  r�compiler_flags^szCachingCompiler.compiler_flagscCs
 39  t||�S)a�Compute filename given the code, and the cell number.
 40  
 41          Parameters
 42          ----------
 43          raw_code : str
 44              The raw cell code.
 45          transformed_code : str
 46              The executable Python source code to cache and compile.
 47          number : int
 48              A number which forms part of the code's name. Used for the execution
 49              counter.
 50  
 51          Returns
 52          -------
 53          The computed filename.
 54          )r)r�raw_code�transformed_coderr
 55  r
 56  r�
get_code_nameds
 57  zCachingCompiler.get_code_namecCs ||jvrdd|j|fSdS)aNReturn a user-friendly label and name for a code block.
 58  
 59          Parameters
 60          ----------
 61          name : str
 62              The name for the code block returned from get_code_name
 63  
 64          Returns
 65          -------
 66          A (label, name) pair that can be used in tracebacks, or None if the default formatting should be used.
 67          �CellzIn[%s]N)r)r�namer
 68  r
 69  r�format_code_namews
 70  �z CachingCompiler.format_code_namerNcCsP|dur|}|�|||�}||j|<t|�ddd�|��D�|f}|tj|<|S)ahMake a name for a block of code, and cache the code.
 71  
 72          Parameters
 73          ----------
 74          transformed_code : str
 75              The executable Python source code to cache and compile.
 76          number : int
 77              A number which forms part of the code's name. Used for the execution
 78              counter.
 79          raw_code : str
 80              The raw code before transformation, if None, set to `transformed_code`.
 81  
 82          Returns
 83          -------
 84          The name of the cached code (as a string). Pass this as the filename
 85          argument to compilation, so that tracebacks are correctly hooked up.
 86          NcSsg|]}|d�qS)�
 87  r
 88  )r�liner
 89  r
 90  r�
 91  <listcomp>�sz)CachingCompiler.cache.<locals>.<listcomp>)r,r�len�
 92  splitlines�	linecache�cache)rr+rr*r.�entryr
 93  r
 94  rr6�s
 95  �
 96  zCachingCompiler.cachec	csJ�|j|@}|j|B|_zdVW|j|M_dS|j|M_wrr()rr!Zturn_on_bitsr
 97  r
 98  r�extra_flags�s�&zCachingCompiler.extra_flags)rr)rN)�__name__�
 99  __module__�__qualname__�__doc__rr%r'�propertyr)r,r/r6rr8r
100  r
101  r
102  rrEs
103  
104  
105  .rcGs$ddl}|jdtdd�t��dS)a�Deprecated since IPython 8.6.  Call linecache.checkcache() directly.
106  
107      It was already not necessary to call this function directly.  If no
108      CachingCompiler had been created, this function would fail badly.  If
109      an instance had been created, this function would've been monkeypatched
110      into place.
111  
112      As of IPython 8.6, the monkeypatching has gone away entirely.  But there
113      were still internal callers of this function, so maybe external callers
114      also existed?
115      rNzHDeprecated Since IPython 8.6, Just call linecache.checkcache() directly.�)�
116  stacklevel)�warnings�warn�DeprecationWarningr5�
117  checkcache)�argsr@r
118  r
119  r�check_linecache_ipython�s�rE)r)r<r�astrr�	functoolsrr5�operator�time�
120  contextlibr�reduce�or_�all_feature_names�	PyCF_MASKrrrrEr
121  r
122  r
123  r�<module>s$��
124  ~