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