o
    Zhjo                  	   @   s  d dl Z d dlZd dlZd dlZd dlZd dlZ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lmZ d dlmZmZ d dlmZ d dlmZmZmZmZmZ d dlmZmZ eskd d	lmZm Z m!Z! nd d
l"m#Z# e$e%Z&e'edsdge_(ej)*ddkZ+ej)*ddkZ,da-zd dl.Z/W n e0y   d dl/Z/e1fZ2Y nw ej3dkrerz5d dl4Z4d dl5Z5e46d\Z7Z8ze9e8dd Z8e5j:j;<e8 e5j:j;=e8 W n e>e?fy   Y nw W n	 e@y   Y nw ej3dkr	e,r	d dlAZAdZBG dd deAjCZDeDeA_Czd dlEZEW n
 e@y   Y nw er+ejFGdr+dd ZHeHe_Iej)*ddkrQzd dlJZJdD ]	ZKeJLeKd q;W n e@yP   Y nw zej)Md W n
 eNyc   Y nw zd dlOmPZP G dd dePjQZRg eR_SeReP_QW n
 e@y   Y nw zd d lTmUZU G d!d deUjQZRg eR_SeReU_QW n
 e@y   Y nw d dlVZVd d"lVmWZW G d#d$ d$eWZXeXeV_Yz
e	jZd%e[d&d' W n
 e@y   Y nw zd dl\Z\d d(l\m]Z]m^Z^ d)d* Z_e_e\_`W n
 e@y   Y nw zd dlaZbd+ebjcjd_ee	jZd%efd,d-d. e	jZd%efd/d-d. W n
 e@y   Y nw ze	jZd%efd0d-d. W n
 e@y/   Y nw esPzd dlgZhehjijjZkd1d2 Zlelehji_jW n
 e@yO   Y nw dTd3d4Zmeme_nee_oeej)*d5dd6Zpd7d8 Zqd9d: Zrd;d< ZsdUd>d?Zt	=	=dVd@dAZudWdBdCZv		=dXdDdEZw		 	dYdFdGZxerewe/_wnewe/_y	=	=dZdHdIZzeze/_zd[dJdKZ{	 	d\dLdMZ|e{e/_{d[dNdOZ}e}e/_}dTdPdQZ~e~e/_~dRdS Ze  dS )]    N)get_ipython)frontend_request)NamespaceManager)	SpyderPdbget_new_debugger)UserModuleReloader)PY2_printencodecompat_execFileNotFoundError)capture_last_Exprcanonic)TransformerManagerleading_indentleading_empty_lines)IPythonInputSplitterargv ZSPY_EXTERNAL_INTERPRETERTrueZSPY_HIDE_CMDTntLANG   i   c                          e Zd Z fddZ  ZS )SubprocessPopenc                    s"   t |d< tt| j|i | d S )Ncreationflags)creation_flagsuperr   __init__selfargskwargs	__class__ _/var/www/html/lang_env/lib/python3.10/site-packages/spyder_kernels/customize/spydercustomize.pyr   k   s   zSubprocessPopen.__init____name__
__module____qualname__r   __classcell__r%   r%   r#   r&   r   j       r   linuxc                   C   s   dS )Nutf-8r%   r%   r%   r%   r&   _getfilesystemencoding_wrapper   s   r/   ZQT_APIZpyqt)ZQStringZQVariantZQDateZ	QDateTimeZQTextStreamZQTimeZQUrl)	QtWidgetsc                       r   )SpyderQApplicationc                    &   t t| j|i | tj|  d S Nr   r1   r   _instance_listappendr   r#   r%   r&   r         SpyderQApplication.__init__r'   r%   r%   r#   r&   r1      r,   r1   )QtGuic                       r   )r1   c                    r2   r3   r4   r   r#   r%   r&   r      r7   r8   r'   r%   r%   r#   r&   r1      r,   )TestProgramc                   @   s   e Zd Zdd ZdS )IPyTesProgramc                 O   sB   t jtjd}|d||d< d|d< tj| g|R i | d S )N)streamZ
testRunnerFexit)unittestZTextTestRunnersysstderrpopr:   r   )r    r!   r"   Ztest_runnerr%   r%   r&   r      s   zIPyTesProgram.__init__N)r(   r)   r*   r   r%   r%   r%   r&   r;      s    r;   ignorezipykernel.ipkernel)actioncategorymodule)Screen
Terminatorc                   C   s.   zt    dtj_W d S  ty   Y d S w )NT)rF   byeturtleZTurtleScreenZ_RUNNINGrG   r%   r%   r%   r&   
spyder_bye   s   
rJ   r.   zpandas.core.formatz .*invalid value encountered in.*)rC   rD   rE   messagezpandas.formats.formatznumpy.core._methodsc                 C   sv   zt | }W n ty   tjd }d|_t | }Y nw tjdkr9d|v r9tj|d s9t	d
|d  |d= |S )z{
            Patched get_preparation_data to work when all variables are
            removed before execution.
            __main__r   r   Zinit_main_from_pathzHWarning: multiprocessing may need the main file to exist. Please save {})_old_preparation_dataAttributeErrorr?   modules__spec__osnamepathexistsr	   format)rR   dZmain_moduler%   r%   r&   _patched_preparation_data"  s    

rW   c                 C   s
   t dS )N)P      )rQ   terminal_size)fdr%   r%   r&   _patched_get_terminal_sizeA  s   
r\   ZSPY_UMR_NAMELIST)namelistc                 C   s   t  }|| ||f t|j}| tks>td td td td d|_	|
  |jj}td ||| dS dS )zb
    For post mortem exception handling, print a banner and enable post
    mortem debugging.
    g?z(****************************************z!Entering post mortem debugging...TN)r   showtracebackpdbPdbcolorsSyntaxErrortimesleepr	   Zsend_initial_notificationresettb_nexttb_frameZinteraction)typevaluetbipython_shellpframer%   r%   r&   post_mortem_excepthookU  s   

rn   c                   C   s<   zt dd W S  ty   td t jdd Y dS w )zGet the current file name.TblockingzThis command failed to be executed because an error occurred while trying to get the current file name from Spyder's editor. The error was:

Zexception_onlyN)r   Zcurrent_filename	Exceptionr	   r   r^   r%   r%   r%   r&   get_current_file_namet  s   rs   c                 C   sR   t r| d}n| jdd}|sdS t|D ]\}}|r$| s$|  S qt|S )z(Count the number of leading empty cells.Tkeependsr   )r   
splitlines	enumerateisspacelen)celllinesiliner%   r%   r&   count_leading_empty_lines  s   r~   Fc                 C   sz   t | }|r%tr
| S | ds| d7 } | jdd}tt|}d|} ntr/t }|| S t	 }|| } d| |  S )z&Transform IPython code to Python code.
Trt   r   )
r~   r   endswithrv   r   r   joinr   transform_cellr   )codeindent_onlyZnumber_empty_linesr{   tmr%   r%   r&   r     s   


r   c                 C   s  d}t rt|}t| } |du rt}t }tj|d dk}	zz}|	sdztt	| dd}
W n< t
yc } z)z	tt	| }
W n t
yP   t rJ|td Y n	w trYtd daW Y d}~nd}~ww tt	| }
|  d	d d
krwd}|rt|
d\}
}|t|
|d|| |r|dd}|dur|W W d}S W nT ty } z|jr|jdd W Y d}~nCd}~w ty } z.t|tjr|jrd|_n|rt|trt \}}}t||| n|jdd W Y d}~nd}~ww W d}dS W d}dS W d}dS d}w )z'Execute code and display any exception.TN   z.ipy)r   zraise e from Nonez
WARNING: This is not valid Python code. If you want to use IPython magics, flexible indentation, and prompt removal, we recommend that you save this file with the .ipy extension.
F;Z_spyder_outexecZ__pdb_exit__rq   )	tb_offset)r   r
   r   r   rQ   rS   splitextastparser   rb   r   SHOW_INVALID_SYNTAX_MSGr	   rstripr   compilerA   
SystemExitr   r^   BaseException
isinstancebdbZBdbQuitpdb_sessionrr   r?   exc_inforn   )r   filename
ns_globals	ns_localspost_mortemexec_funcapture_last_expression__tracebackhide__rk   Z
is_ipythonZast_codeeoutstatuserrorZ
error_typerj   r%   r%   r&   	exec_code  s|     r   c                 C   s   zt ddj| |dW S  ty@   zt| d}| W  d   W  Y S 1 s*w   Y  W n	 ty9   Y nw |r= Y dS w )zRetrieve the content of a file.Tro   save_allrN)r   get_file_coderr   openreadr   )r   r   raise_exceptionfr%   r%   r&   r     s    
*r   c              	   C   s   t | |||||ddS )a  
    Run filename
    args: command line arguments (string)
    wdir: working directory
    namespace: namespace for execution
    post_mortem: boolean, whether to enter post-mortem mode on error
    current_namespace: if true, run the file in the current namespace
    r   stack_depth)
_exec_file)r   r!   wdir	namespacer   current_namespacer%   r%   r&   runfile  s   
r   c	              
   C   s~  d}	t  }
| d u rt } | d u rd S z| d} W n tttfy%   Y nw tr,t| } tj	r3t
  |d ur@t|ts@tdzt| dd}W n ty]   td t  jdd Y d S w |d ure|} nt| } t| ||||d d\}}| gt_|d urt|D ]}tj| qd	tjv rz
tjd
 tjd< W n	 ty   Y nw |d urtrz|d}W n ttfy   Y nw tj|rt| dtjv rzdd l}tj||j_ W n ty   Y n	w ntd!| z7tj"rt#j$| dd}|
%dd|&  W d    n	1 sw   Y  nt'|| ||||dd W dgt_ndgt_w W d    d S 1 s8w   Y  d S )NTr.   z"expected a character buffer object)r   zThis command failed to be executed because an error occurred while trying to get the file code from Spyder's editor. The error was:

rq   r   )	file_coder   multiprocessingrL   __mp_main__zmultiprocessing.processr   z$Working directory {} doesn't exist.
)encodingcythonr   Fr   r   r   )(r   rs   decodeUnicodeError	TypeErrorrN   r   r
   __umr__enabledrunr   
basestringr   rr   r	   r^   r   r   r?   r   shlexsplitr6   rO   rQ   rS   isdirchdirZmultiprocessing.processabspathprocessZORIGINAL_DIRrU   Z
has_cythonior   Zrun_cell_magicr   r   )r   r!   r   r   r   r   r   r   canonic_filenamer   rk   r   r   r   argr   r   r%   r%   r&   r     s   




$r   c           	   	   C   s   d}| du rt  } | du rdS t }| r.dt| d|||f  }|j|| d dS t| d}t| |	| ||||j
dd dS )z
    Debug filename
    args: command line arguments (string)
    wdir: working directory
    post_mortem: boolean, included for compatiblity with runfile
    TNz
runfile({}z), args=%r, wdir=%r, current_namespace=%r)r   )r   r   r!   r   r   r   r   )rs   r   is_debuggingrU   reprr   enter_recursive_debuggerr   r   r   r   )	r   r!   r   r   r   r   shellr   debuggerr%   r%   r&   	debugfilew  s4   	

r   c                 C   s   d}t | ||ddS )a  
    Run a code cell from an editor as a file.

    Parameters
    ----------
    cellname : str or int
        Cell name or index.
    filename : str
        Needed to allow for proper traceback links.
    post_mortem: bool
        Automatically enter post mortem on exception.
    Tr   r   )
_exec_cell)cellnamer   r   r   r%   r%   r&   runcell  s   r   c              
   C   s*  d}|du rt  }|du rdS z|d}W n tttfy"   Y nw t }ztdd| |}W n tyF   t	d t j
dd Y dS w |rO| dkrUt	d dS |jd	 t|d
d}	|durh|}nt|}t|d|	|d d\}
}t|||
|||ddW  d   S 1 sw   Y  dS )z9
    Execute a code cell with a given exec function.
    TNr.   ro   zThis command failed to be executed because an error occurred while trying to get the cell code from Spyder's editor. The error was:

rq   r   z(Nothing to execute, this cell is empty.
Zpost_executeFr   r   )r   r   r   r   )rs   r   r   r   rN   r   r   Zrun_cellrr   r	   r^   stripeventstriggerr   r   r   r   )r   r   r   r   r   r   r   rk   Z	cell_coder   r   r   r%   r%   r&   r     sN   
$r   c                 C   s   d}|du rt  }|du rdS t }| r.dt| dt| }|j||d dS t|d}t| ||	||j
dd dS )zDebug a cell.TNzruncell({}, z{})Fr   )r   r   r   r   r   )rs   r   r   rU   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r%   r%   r&   	debugcell  s,   

r   c                 C   sZ   | du rt  } | du rtdztdd| }|W S  ty,   t \}}}||w )z
    Get the number of cells in a file.

    Parameters
    ----------
    filename : str
        The file to get the cells from. If None, the currently opened file.
    Nz'Could not get cell count from frontend.Tro   )rs   RuntimeErrorr   
cell_countrr   r?   r   )r   r   etyper   rj   r%   r%   r&   r     s   	r   c                  C   s<   t jd} | rtj| t j t jd| i d S d S )NZSPY_PYTHONPATH
PYTHONPATH)	rQ   environgetr?   rS   extendr   pathsepupdate)Zpypathr%   r%   r&   set_spyder_pythonpath,  s
   r   r3   )F)NFNF)TF)NNNNFF)	NNNNFFr   NN)NNNFF)NF)NFr   NN)r   r   r   loggingrQ   r_   r   r?   rc   warningsZIPython.core.getipythonr   Z!spyder_kernels.comms.frontendcommr   Z*spyder_kernels.customize.namespace_managerr   Z"spyder_kernels.customize.spyderpdbr   r   Zspyder_kernels.customize.umrr   Zspyder_kernels.py3compatr   r	   r
   r   r   Zspyder_kernels.customize.utilsr   r   ZIPython.core.inputtransformer2r   r   r   ZIPython.core.inputsplitterr   	getLoggerr(   loggerhasattrr   r   r   ZIS_EXT_INTERPRETERZHIDE_CMD_WINDOWSr   __builtin__builtinsImportErrorstrr   rR   localectypesgetdefaultlocaleZ_tZ_cpintZwindllZkernel32ZSetConsoleCPZSetConsoleOutputCP
ValueErrorr   rr   
subprocessr   Popenr   sitecustomizeplatform
startswithr/   getfilesystemencodingsipZqtypeZsetapirA   KeyErrorZPyQt5r0   ZQApplicationr1   r5   ZPyQt4r9   r>   r:   r;   mainfilterwarningsDeprecationWarningrI   rF   rG   rJ   rH   Zpandaspdoptionsdisplayr   RuntimeWarningZmultiprocessing.spawnr   ZspawnZget_preparation_datarM   rW   r\   get_terminal_sizer`   r   rn   rs   r~   r   r   r   r   r   Zspyder_runfiler   r   r   r   r   r   r%   r%   r%   r&   <module>   sb  

















O

\
(

5

	
