
    ` Iejo                     *	   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sd d	lmZm Z m!Z! nd d
l"m#Z#  ejH                  e%      Z& e'ed      sdge_(        ejR                  jU                  d      dk(  Z+ejR                  jU                  d      dk(  Z,da-	 d dl.Z/ejf                  dk(  rvert	 d dl4Z4d dl5Z5 e4jl                  d      \  Z7Z8	  e9e8dd       Z8e5jt                  jv                  jy                  e8       e5jt                  jv                  j{                  e8       ejf                  dk(  r$e,r"d dlAZAdZB G d deAj                        ZDeDeA_C        	 d dlEZEer%ej                  j                  d      r
d ZHeHe_I        ejR                  jU                  d      dk(  r 	 d dlJZJdD ]  ZK eJj                  eKd        n	 ejR                  j                  d       	 d dlOmPZP  G d dePj                        ZRg eR_S        eReP_Q        	 d dlTmUZU  G d  deUj                        ZRg eR_S        eReU_Q        d dlVZVd d!lVmWZW  G d" d#eW      ZXeXeV_Y        	  e	j                  d$e[d%&       	 d dl\Z\d d'l\m]Z]m^Z^ d( Z_e_e\_`        	 d dlaZbd)ebj                  j                  _e         e	j                  d$efd*d+,        e	j                  d$efd-d+,       	  e	j                  d$efd.d+,       es/	 d dlgZhehj                  j                  Zkd/ Zlelehj                  _j        dAd0Zmeme_n        ee_o         eejR                  jU                  d1d      2      Zpd3 Zqd4 Zrd5 ZsdBd6Zt	 	 dCd7ZudDd8Zv	 	 dEd9Zw	 	 	 dFd:Zxerewe/_w        newe/_y        	 	 dGd;Zzeze/_z        dHd<Z{	 	 dId=Z|e{e/_{        dHd>Z}e}e/_}        dAd?Z~e~e/_~        d@ Z e        y# e0$ r d dl/Z/e1fZ2Y 'w xY w# e>e?f$ r Y w xY w# e@$ r Y w xY w# e@$ r Y w xY w# e@$ r Y w xY w# eN$ r Y 'w xY w# e@$ r Y 	w xY w# e@$ r Y w xY w# e@$ r Y w xY w# e@$ r Y w xY w# e@$ r Y zw xY w# e@$ r Y ow xY w# e@$ r Y Jw xY w)J    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 SPY_EXTERNAL_INTERPRETERTrueSPY_HIDE_CMDTntLANG   i   c                        e Zd Z fdZ xZS )SubprocessPopenc                 >    t         |d<   t        t        |   |i | y )Ncreationflags)creation_flagsuperr   __init__selfargskwargs	__class__s      J/usr/lib/python3/dist-packages/spyder_kernels/customize/spydercustomize.pyr"   zSubprocessPopen.__init__k   s!    &3F?#/414B6B    __name__
__module____qualname__r"   __classcell__r'   s   @r(   r   r   j   s    	C 	Cr)   r   linuxc                       y)Nutf-8 r3   r)   r(   _getfilesystemencoding_wrapperr4      s    r)   QT_APIpyqt)QStringQVariantQDate	QDateTimeQTextStreamQTimeQUrl)	QtWidgetsc                        e Zd Z fdZ xZS )SpyderQApplicationc                 j    t        t        | 
  |i | t        j                  j	                  |        y Nr!   r@   r"   _instance_listappendr#   s      r(   r"   zSpyderQApplication.__init__   .    $d4dEfE --44T:r)   r*   r/   s   @r(   r@   r@          	; 	;r)   r@   )QtGuic                        e Zd Z fdZ xZS )r@   c                 j    t        t        | 
  |i | t        j                  j	                  |        y rB   rC   r#   s      r(   r"   zSpyderQApplication.__init__   rF   r)   r*   r/   s   @r(   r@   r@      rG   r)   )TestProgramc                       e Zd Zd Zy)IPyTesProgramc                     t        j                  t        j                        }|j	                  d|      |d<   d|d<   t        j                  | g|i | y )N)stream
testRunnerFexit)unittestTextTestRunnersysstderrpoprK   r"   )r$   r%   r&   test_runners       r(   r"   zIPyTesProgram.__init__   sL    --SZZ@%zz,D|vT3D3F3r)   N)r+   r,   r-   r"   r3   r)   r(   rM   rM      s    4r)   rM   ignorezipykernel.ipkernel)actioncategorymodule)Screen
Terminatorc                  ~    	 t               j                          dt        j                  _        y # t
        $ r Y y w xY w)NT)r\   byeturtleTurtleScreen_RUNNINGr]   r3   r)   r(   
spyder_byerc      s2    	HLLN+/F( 		s   -0 	<<r2   zpandas.core.formatz .*invalid value encountered in.*)rY   rZ   r[   messagezpandas.formats.formatznumpy.core._methodsc                 8   	 t        |       }t
        j                  dk(  rFd|v rBt
        j                  j                  |d         s t        dj                  |d                |d= |S # t        $ r( t        j                  d   }d|_        t        |       }Y w xY w)z{
            Patched get_preparation_data to work when all variables are
            removed before execution.
            __main__r   r   init_main_from_pathzHWarning: multiprocessing may need the main file to exist. Please save {})_old_preparation_dataAttributeErrorrT   modules__spec__osnamepathexistsr
   format)rm   dmain_modules      r(   _patched_preparation_datars   "  s    
0)$/ 4$9Q$>GGNN1-B+CD%%+VA.C,D%EG +,H " 0!kk*5')$)$/	0s   A( (.BBc                 ,    t        j                  d      S )N)P      )rl   terminal_size)fds    r(   _patched_get_terminal_sizery   A  s    H%%r)   SPY_UMR_NAMELIST)namelistc                    t               }|j                  | ||f       t        j                  |j                        }| t
        k(  st        j                  d       t        d       t        d       t        d       d|_	        |j                          |j                  j                  }t        j                  d       |j                  ||       yy)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
   send_initial_notificationresettb_nexttb_frameinteraction)typevaluetbipython_shellpframes         r(   post_mortem_excepthookr   U  s    
  MMub 12$$%A;

3x23x
 '+#		

##

3	eR ! r)   c                      	 t        d      j                         S # t        $ r( t        d       t	               j                  d       Y yw xY 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:

exception_onlyN)r   current_filename	Exceptionr
   r   r}   r3   r)   r(   get_current_file_namer   t  sO    .??AA  - 	. 	##4#8s    .AAc                     t         r| j                  d      }n| j                  d      }|syt        |      D ]  \  }}|s	|j                         r|c S  t	        |      S )z(Count the number of leading empty cells.Tkeependsr   )r	   
splitlines	enumerateisspacelen)celllinesilines       r(   count_leading_empty_linesr     s]    
%.U# 4H u:r)   c                 P   t        |       }|rVt        r| S | j                  d      s| dz  } | j                  d      }t	        t        |            }dj                  |      } n<t        rt               }|j                  |       S t               }|j                  |       } d|z  | z   S )z&Transform IPython code to Python code.
Tr   r   )
r   r	   endswithr   r   r   joinr   transform_cellr   )codeindent_onlynumber_empty_linesr   tms        r(   r   r     s    248K}}T"DLD.259:wwu~%'B$$T**#%B$$T*D$$t++r)   c                 N   d}t         rt        |      }t        |       } |t        }t               }t        j
                  j                  |      d   dk(  }		 |	s"	 t        j                  t        | d            }
nt        j                  t        |             }
| j                         d	d d
k(  rd}|rt        
d      \  }
} |t!        
|d      ||       |r|j#                  dd      }||d}S d}y# t        $ r_}	 t        j                  t        |             }
t        r0t        d       dan"# t        $ r t         r|t        d       Y nw xY wY d}~d}~ww xY w# t$        $ r*}|j&                  r|j)                  d       Y d}~d}yd}~wt*        $ r}t-        |t.        j0                        r|j2                  rd|_        nJ|r6t-        |t4              r&t7        j8                         \  }}}t;        |||       n|j)                  d       Y d}~d}yd}~ww xY w# d}w xY w)z'Execute code and display any exception.TN   z.ipy)r   z
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.
Fzraise e from None;_spyder_outexec__pdb_exit__r   )	tb_offset)r	   r   r   r   rl   rn   splitextastparser   r   SHOW_INVALID_SYNTAX_MSGr
   r   rstripr   compilerV   
SystemExitr   r}   BaseException
isinstancebdbBdbQuitpdb_sessionr   rT   exc_infor   )r   filename
ns_globals	ns_localspost_mortemexec_funcapture_last_expression__tracebackhide__r   
is_ipythonast_codeeoutstatuserror
error_typer   s                    r(   	exec_coder     s     (#d|MM!!(+A.&8J;+899^Dd%KL* yy!56H;;=$&+#"0A-1)-H- 	8V4j)L"..5C$ +Nk  88"yy)=>H /01 38/ # 2 0128J  =;;''t'< +  
5uckk*!--(,M%Zy9$'LLN!Jr":ub9 ''!'4*
5 +s   E  C4 :A4E 4	E>D0E0EEEEE EE 	H(FH  HA8HH  HH   H$c                     	 t        d      j                  | |      S # t        $ rK 	 t        | d      5 }|j	                         cddd       cY S # 1 sw Y   nxY wn# t
        $ r Y nw xY w|r Y yw xY w)zRetrieve the content of a file.Tr   save_allrN)r   get_file_coder   openreadr   )r   r   raise_exceptionfs       r(   r   r     s    .<<x = ) 	) 
	h$  vvx         		
sO    	A3AA	AA3A	AA3	A*'A3)A**A32A3c           	      &    t        | |||||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_namespaces         r(   runfiler     s"     $i&A7 7r)   c	           
         d}	t               }
| t               } | y 	 | j                  d      } t        rt        |       } t        j                  rt        j                          |t        |t              st	        d      	 t        | d      }||} nt#        |       } t%        | ||||dz         5 \  }}| gt&        _        |9t+        j,                  |      D ]!  }t&        j(                  j/                  |       # d	t&        j0                  v r%	 t&        j0                  d
   t&        j0                  d<   |t        r	 |j                  d      }t2        j4                  j7                  |      r[t3        j8                  |       dt&        j0                  v rN	 dd l}t2        j4                  j=                  |      |j>                  _         nt        djC                  |             	 t        jD                  rBtG        jH                  | d      5 }|
jK                  dd|jM                                d d d        ntO        || ||||d       dgt&        _        	 d d d        y # t        t        t
        f$ r Y Ew xY w# t        $ r( t        d       t               j!                  d       Y y w xY w# t        $ r Y w xY w# t        t        f$ r Y w xY w# t        $ r Y w xY w# 1 sw Y   xY w# dgt&        _        w xY w# 1 sw Y   y xY w)NTr2   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:

r   r   )	file_coder   multiprocessingrf   __mp_main__zmultiprocessing.processr   z$Working directory {} doesn't exist.
)encodingcythonr   Fr   r   r   )(r   r   decodeUnicodeError	TypeErrorri   r	   r   __umr__enabledrunr   
basestringr   r   r
   r}   r   r   rT   r   shlexsplitrE   rj   rl   rn   isdirchdirmultiprocessing.processabspathprocessORIGINAL_DIRrp   
has_cythonior   run_cell_magicr   r   )r   r%   r   r   r   r   r   r   canonic_filenamer   r   r   r   r   argr   r   s                    r(   r   r     s    MM(*??7+
 (#
4 <<==	!(DA	 ##8$	(I/@$-;?
 -6
I:{{4( %$% +-0[[-DM* ;;w/D ww}}T",;6?Aww @"//<
 >EEdKL
	!!WWX8 IA!002qvvxHI I )Xz9&1H279 tCH[- -9 )^4  	  *	+ 	##4#86   %i0  % I I tCH[- -s   I I7 1AK=$J+3K=<J;AK=2KK="'K,	"K +K,K=I43I47.J('J(+	J84K=7J88K=;K
K=KK=	KK=KK= K)	%K,,K::K==Lc           	      R   d}| t               } | yt               }|j                         rEdj                  t	        |             d|d|d|dz   }|j
                  j                  || d       yt        | d      }t        | |j                  |       ||||j                  d	       y)
z
    Debug filename
    args: command line arguments (string)
    wdir: working directory
    post_mortem: boolean, included for compatiblity with runfile
    TNz
runfile({}z, args=z, wdir=z, current_namespace=)r   )r   r   r%   r   r   r   r   )r   r   is_debuggingrp   reprr   enter_recursive_debuggerr   r   r   r   )	r   r%   r   r   r   r   shellr   debuggers	            r(   	debugfiler  w  s     (*ME X/d-// 	 	22(D	
 $Hd3%--h7/\\	
r)   c                 $    d}t        | ||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   s       r(   runcellr    s     h+1EEr)   c           
      ^   d}|t               }|y	 |j                  d      }t               }	 t        d      j                  | |      }|r|j                         dk(  rt        d       y|j                  j                  d	       t        |d
      }	||}nt        |      }t!        |d|	|dz         5 \  }
}t#        |||
|||d      cddd       S # t        t        t        f$ r Y w xY w# t        $ r( t        d       t               j                  d       Y yw xY w# 1 sw Y   yxY w)z9
    Execute a code cell with a given exec function.
    TNr2   r   zThis command failed to be executed because an error occurred while trying to get the cell code from Spyder's editor. The error was:

r   r   z(Nothing to execute, this cell is empty.
post_executeFr   r   )r   r   r   r   )r   r   r   r   ri   r   r   run_cellr   r
   r}   stripeventstriggerr   r   r   r   )r  r   r   r   r   r   r   r   	cell_coder   r   r   s               r(   r  r    sY    (*??7+
  MM	$#8Hh7 	 	)R/:;   0h7I ## 8$	(d$-;?
 76
IHj)%081577 7A )^4  	   - 	. 	##4#8.7 7s.   C C/ 6D#C,+C,/.D D #D,c                 j   d}|t               }|yt               }|j                         rSdj                  t	        |             dj                  t	        |            z   }|j
                  j                  ||d       yt        |d      }t        | ||j                  |      |j                  d       y)zDebug a cell.TNzruncell({}, z{})Fr   )r  r   r   r   r   )r   r   r   rp   r   r   r  r   r  r   r   )r  r   r   r   r  r   r  s          r(   	debugcellr    s     (*ME !!$x.1LLh() 	 	22(E	
 $He4%--h7\\	
r)   c                     | t               } | t        d      	 t        d      j                  |       }|S # t        $ r! t        j                         \  }}} ||      w xY 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.
    z'Could not get cell count from frontend.Tr   )r   RuntimeErrorr   
cell_countr   rT   r   )r   r  etyper   r   s        r(   r  r    so     (*HII%t4??I
 <<>ubEls	   8 *A"c                     t         j                  j                  d      } | r^t        j                  j                  | j                  t         j                               t         j                  j                  d| i       y y )NSPY_PYTHONPATH
PYTHONPATH)	rl   environgetrT   rn   extendr   pathsepupdate)pypaths    r(   set_spyder_pythonpathr  ,  sQ    ZZ^^,-FRZZ01


<01 r)   rB   )F)NFNF)TF)NNNNFF)	NNNNFFr   NN)NNNFF)NF)NFr   NN)r   r   r   loggingrl   r~   r   rT   r   warningsIPython.core.getipythonr   !spyder_kernels.comms.frontendcommr   *spyder_kernels.customize.namespace_managerr   "spyder_kernels.customize.spyderpdbr   r   spyder_kernels.customize.umrr   spyder_kernels.py3compatr	   r
   r   r   r   spyder_kernels.customize.utilsr   r   IPython.core.inputtransformer2r   r   r   IPython.core.inputsplitterr   	getLoggerr+   loggerhasattrr   r  r  IS_EXT_INTERPRETERHIDE_CMD_WINDOWSr   __builtin__builtinsImportErrorstrr   rm   localectypesgetdefaultlocale_t_cpintwindllkernel32SetConsoleCPSetConsoleOutputCP
ValueErrorr   r   
subprocessr    Popenr   sitecustomizeplatform
startswithr4   getfilesystemencodingsipqtypesetapirV   KeyErrorPyQt5r>   QApplicationr@   rD   PyQt4rH   rR   rK   rM   mainfilterwarningsDeprecationWarningr`   r\   r]   rc   r_   pandaspdoptionsdisplayr   RuntimeWarningmultiprocessing.spawnr   spawnget_preparation_datarh   rs   ry   get_terminal_sizer   r   r   r   r   r   r   r   r   r   spyder_runfiler  r  r  r  r  r  r3   r)   r(   <module>rY     sB    
 	  	 
  
   / > G J ;9 9 E
A A @ 
		8	$ sFtCH ZZ^^$>?6I ::>>.1V;  " 77d?s)&))&1C	c!"g,CMM""//4MM""55c: 77d?'MC*** C
 'J	 3<<""7+ !?C ::>>(v%6 	!ECJJua 	!


x 	;Y33 ; )+%/I	;U// ; )+%+E   4K 4 	H86H#79	) FJ	 #*BJJ H8n#7$FH H8n#:$FH		
 H8n#8$FH $ / 5 5 J J	, 6O2& 2  
 bjjnn5G&N
O!>	,, GL5:L+^& <@167 ?CGH/3Vx H%H @E %%
P  F$ HI/327j  
<  , ! 2  S  J$ I& 		  2  		0  
  0  		  		4  		*  		4  		  		L  s   O0 *P AP P P) ;P5 )Q )Q Q Q% 4AQ1  Q= .R	 0P ?P P
P PP PPP&%P&)P21P25P>=P>Q
	Q
QQQ"!Q"%Q.-Q.1Q:9Q:=RR	RR