
    ` Ie1                     X    d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d Z	 G d de
      Zy)    N)get_ipython)PY2c                     t         j                  j                  |       } t        j                  |d      }| |_        d |_        |S )zt
    Reimplemented from IPython/core/interactiveshell.py to avoid caching
    and clearing recursive namespace.
    z(Module created for script run in IPython)docc                       y)NT r       L/usr/lib/python3/dist-packages/spyder_kernels/customize/namespace_manager.py<lambda>znew_main_mod.<locals>.<lambda>   s    r	   )ospathabspathtypes
ModuleType__file____nonzero__)filenamemodnamemain_mods      r
   new_main_modr      sE    
 wwx(H68H !H )HOr	   c                   (    e Zd ZdZ	 	 ddZd Zd Zy)NamespaceManagerz
    Get a namespace and set __file__ to filename for this namespace.

    The namespace is either namespace, the current namespace if
    current_namespace is True, or a new namespace.
    Nc                     || _         || _        d | _        || _        d | _        d | _        d | _        d| _        || _        t               }|j                  |dz         | _        |j                  |dz         | _        y )NF   )r   
ns_globals	ns_localscurrent_namespace_previous_filename_previous_main_previous_running_namespace_reset_main
_file_coder   get_global_scopecontext_globalsget_local_scopecontext_locals)selfr   	namespacer   	file_codestack_depthipython_shells          r
   __init__zNamespaceManager.__init__,   s{     #!2"&"+/( ##,==kAoN+;;K!OLr	   c                 N   t               }| j                  | j                  r^| j                  | _        | j                  | _        d| j                  v r| j                  d   | _        | j                  | j                  d<   nrt        | j                  d      }|j                  | _        d| _        dt        j                  v rt        j                  d   | _        |t        j                  d<   d| _        |j                  j                  | _        | j                  | j
                  f|j                  _        | j"                  @t$        s:t'        | j"                  t(              r 	 | j"                  j+                         | _        | j"                  gt/        | j"                        d| j"                  j1                         D cg c]  }|dz   	 c}| j                  ft2        j4                  | j                  <   | j                  | j
                  fS # t,        $ r
 d| _        Y w xY wc c}w )z(
        Prepare the namespace.
        Nr   __main__T
)r   r   r   r$   r&   r   r   r   r   __dict__sysmodulesr   r!   kernel_running_namespacer    r"   r   
isinstancebytesdecodeUnicodeDecodeErrorlen
splitlines	linecachecache)r'   r+   r   lines       r
   	__enter__zNamespaceManager.__enter__;   s   
 $??"%%"&"6"6!%!4!40.2ooj.ID+.2mm
+'zB"*"3"3!%,*-++j*AD'*2J'#'    33 	( OOT^^3-/ OO't6'"&//"8"8": ??& DOO$d)-)C)C)EFF.IOODMM* .. & '"&' Gs   "H >H"HHc                 Z   t               }| j                  |j                  _        | j                  r| j                  | j
                  d<   n)d| j
                  v r| j
                  j                  d       | j                  sb| j                  j                  | j
                         | j                  r1| j                  r%| j                  j                  | j                         | j                  r| j                  t        j                  d<   n/dt        j                  v r| j                  rt        j                  d= | j                   t"        j$                  v rTt&        j(                  j+                  | j                         r*t"        j$                  j                  | j                          yyy)z&
        Reset the namespace.
        r   r.   N)r   r    r3   r4   r   r   popr   r$   updater&   r   r   r1   r2   r!   r   r;   r<   r   r   exists)r'   exc_typeexc_valexc_tbr+   s        r
   __exit__zNamespaceManager.__exit__i   s$    $,, 	/""*.*A*ADOOJ'4??*OO
+%%  ''8""t~~##**4>>:&*&9&9CKK
#3;;&4+;+;J'==IOO+t}}0MOO. 1N+r	   )NFNr   )__name__
__module____qualname____doc__r,   r>   rF   r   r	   r
   r   r   $   s"     DI-.M,/\/r	   r   )r;   os.pathr   r   r1   IPython.core.getipythonr   spyder_kernels.py3compatr   r   objectr   r   r	   r
   <module>rO      s,       
 / (&[/v [/r	   