Format: application/x-python-code
1 o
2
3 ��h2 � @ s� d Z ddlZddlmZ ddlZddlZddlZddlZddlZddl Z ddl
4 mZ e�ej
5 dd� ejD ��Zd
6 dd�ZG d 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)�contextmanagerc c s � | ] }t t|�jV qd S �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 c C s( 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_name6 s r c @ s\ e Zd ZdZdd� Zddd�Zdd � Zed
28 d� �Zdd
29 � Z dd� Z
30 ddd�Zedd� �Z
31 dS )�CachingCompilerzFA compiler that caches code compiled from interactive statements.
32 c C s t j�| � i | _d S r )�codeop�Compile�__init__�
33 _filename_map��selfr
34 r
35 r r I s
36 zCachingCompiler.__init__� <unknown>�execc C s t |||| jtB d�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_parseQ s zCachingCompiler.ast_parsec C s t j| _dS )z&Reset compiler flags to default state.N)r ZPyCF_DONT_IMPLY_DEDENTr! r r
42 r
43 r �reset_compiler_flagsX s z$CachingCompiler.reset_compiler_flagsc C s | j S )z;Flags currently active in the compilation process.
44 �r! r r
45 r
46 r �compiler_flags^ s zCachingCompiler.compiler_flagsc C s
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_coder r
63 r
64 r �
65 get_code_named s
66 zCachingCompiler.get_code_namec C s || j v rdd| j | fS dS )aN Return 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_namew s
79 �z CachingCompiler.format_code_namer Nc C sP |du r|}| � |||�}|| j|<