compilerop.pyc
1 o 2 .��c2 � @ s� d Z ddlZddlmZ ddlZddlZddlZddlZddlZddl Z ddl 3 mZ e�ej dd� ejD ��Zd dd�ZG d 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)�contextmanagerc c s � | ] }t t|�jV qd S �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 c C s( 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_name6 s r c @ s\ e Zd ZdZdd� Zddd�Zdd � Zed 23 d� �Zdd � Z dd� Z 24 ddd�Zedd� �Z dS )�CachingCompilerzFA compiler that caches code compiled from interactive statements. 25 c C s t j�| � i | _d S r )�codeop�Compile�__init__� _filename_map��selfr 26 r 27 r r I s 28 zCachingCompiler.__init__� <unknown>�execc C s t |||| jtB d�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_parseQ s zCachingCompiler.ast_parsec C s t j| _dS )z&Reset compiler flags to default state.N)r �PyCF_DONT_IMPLY_DEDENTr! r r 34 r 35 r �reset_compiler_flagsX s z$CachingCompiler.reset_compiler_flagsc C s | j S )z;Flags currently active in the compilation process. 36 �r! r r 37 r 38 r �compiler_flags^ s zCachingCompiler.compiler_flagsc C s 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_coder r 55 r 56 r � get_code_named s 57 zCachingCompiler.get_code_namec C s || j v rdd| j | fS dS )aN Return 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_namew s 70 �z CachingCompiler.format_code_namer Nc C sP |du r|}| � |||�}|| j|<