o
    Zh1                     @   sT   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d Z	G dd de
ZdS )    N)get_ipython)PY2c                 C   s.   t j| } tj|dd}| |_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                   S   s   dS )NT r   r   r   a/var/www/html/lang_env/lib/python3.10/site-packages/spyder_kernels/customize/namespace_manager.py<lambda>   s    znew_main_mod.<locals>.<lambda>)ospathabspathtypes
ModuleType__file____nonzero__)filenamemodnamemain_modr   r   r   new_main_mod   s   
r   c                   @   s.   e Zd ZdZ		dddZdd Zd	d
 ZdS )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.
    NF   c                 C   s`   || _ || _d | _|| _d | _d | _d | _d| _|| _t	 }|
|d | _||d | _d S )NFr   )r   
ns_globals	ns_localscurrent_namespace_previous_filename_previous_main_previous_running_namespace_reset_main
_file_coder   Zget_global_scopecontext_globalsZget_local_scopecontext_locals)selfr   	namespacer   Z	file_codeZstack_depthipython_shellr   r   r   __init__,   s   zNamespaceManager.__init__c                 C   s*  t  }| jdu rE| jr%| j| _| j| _d| jv r| jd | _| j| jd< n t| jd}|j	| _d| _dt
jv r=t
jd | _|t
jd< d| _|jj| _| j| jf|j_| jdurttstt| jtrtz| j | _W n tys   d| _Y nw | jdurt| jddd | j D | jftj| j< | j| jfS )z(
        Prepare the namespace.
        Nr   __main__Tc                 S   s   g | ]}|d  qS )
r   ).0liner   r   r   
<listcomp>e   s    z.NamespaceManager.__enter__.<locals>.<listcomp>)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   r   r   r   	__enter__;   sF   








zNamespaceManager.__enter__c                 C   s   t  }| j|j_| jr| j| jd< nd| jv r| jd | js4| j	| j | j
r4| jr4| j
	| j | jr>| jtjd< ndtjv rJ| jrJtjd= | jtjv r`tj| jrbtj| j dS dS dS )z&
        Reset the namespace.
        r   r#   N)r   r   r+   r,   r   r   popr   r   updater   r   r   r)   r*   r   r   r3   r4   r   r	   exists)r   exc_typeexc_valexc_tbr!   r   r   r   __exit__i   s$   
zNamespaceManager.__exit__)NFNr   )__name__
__module____qualname____doc__r"   r5   r<   r   r   r   r   r   $   s    
.r   )r3   Zos.pathr   r   r)   ZIPython.core.getipythonr   Zspyder_kernels.py3compatr   r   objectr   r   r   r   r   <module>   s   