
    yh:c                        S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  SSKJr  SS	KJrJr  SS
KJrJrJr  SSKJrJr  SSKJr  SSKJrJr  SSKJ r   SSK!J"r"J#r#  SSK$J%r%J&r&  SSK'J(r(  SSK)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1  SSK2J3r3J4r4J5r5  SSK6J7r7  SSK8J9r9J:r:   " S S\5      r;\ " S S\5      5       r< " S S\5      r=\R|                  " \=5        g)ak  A ZMQ-based subclass of InteractiveShell.

This code is meant to ease the refactoring of the base InteractiveShell into
something with a cleaner architecture for 2-process use, without actually
breaking InteractiveShell itself.  So we're doing something a bit ugly, where
we subclass and override what we want to fix.  Once this is working well, we
can go back to the base class and refactor the code for a cleaner inheritance
implementation that doesn't rely on so much monkeypatching.

But this lets us maintain a fully working IPython as we develop the new
machinery.  This should thus be thought of as scaffolding.
    N)Pathlocal)pageZMQExitAutocall)DisplayPublisher)
UsageError)InteractiveShellInteractiveShellABC)Magics
line_magicmagics_class)
CodeMagicsMacroToEditdefault_banner)
Javascriptdisplay)openpy)	arg_splitsystem)Sessionextract_header)jupyter_runtime_dir)AnyCBoolCBytesDictInstanceTypedefaultobserve)connect_qtconsoleget_connection_fileget_connection_info)ZMQShellDisplayHook)encode_images
json_cleanc                       \ rS rSrSr\" \SS9r\" SS9r	\
" 0 5      r\" S5      r\" 5       rS rS r\" S5      S	 5       r\S
 5       r   SS jrSS jrS rS rSrg)ZMQDisplayPublisher/   zBA display publisher that publishes data using a ZeroMQ PUB socket.T)
allow_nones   display_datac                 $    [        U5      U l        g)z%Set the parent for outbound messages.N)r   parent_headerselfparents     jc:\Users\julio\OneDrive\Documentos\Trabajo\IdeasFrscas\Cabanna\env\Lib\site-packages\ipykernel/zmqshell.py
set_parentZMQDisplayPublisher.set_parent<   s    +F3    c                 |    [         R                  R                  5         [         R                  R                  5         g)z!flush IO Streams prior to displayN)sysstdoutflushstderrr1   s    r3   _flush_streams"ZMQDisplayPublisher._flush_streams@   s"    



r6   _thread_localc                     [        5       $ )z#Initialize our thread local storager   r<   s    r3   _default_thread_local)ZMQDisplayPublisher._default_thread_localE   s     wr6   c                     [        U R                  S5      (       d  / U R                  l        U R                  R                  $ )Nhooks)hasattrr?   rD   r<   s    r3   _hooksZMQDisplayPublisher._hooksJ   s5    t))733')D$!!'''r6   Nc                    U R                  5         Uc  0 nUc  0 nU R                  X5        0 n[        U5      US'   X%S'   X5S'   U(       a  SOSnU R                  c   eU R                  R	                  U[        U5      U R                  S9nU R                   H  nU" U5      nUb  M    g   U R                  R                  U R                  UU R                  S9  g)	a  Publish a display-data message

Parameters
----------
data : dict
    A mime-bundle dict, keyed by mime-type.
metadata : dict, optional
    Metadata associated with the data.
transient : dict, optional, keyword-only
    Transient data that may only be relevant during a live display,
    such as display_id.
    Transient data should not be persisted to documents.
update : bool, optional, keyword-only
    If True, send an update_display_data message instead of display_data.
Ndatametadata	transientupdate_display_datadisplay_datar2   ident)r=   _validate_datar(   sessionmsgr)   r/   rF   send
pub_sockettopic)	r1   rI   rJ   rK   updatecontentmsg_typerS   hooks	            r3   publishZMQDisplayPublisher.publishQ   s    , 	HID+'-&
(,2(
 ||'''llxG)<TEWEWX
 KKDs)C{  
 	OO** 	 	
r6   c                 N   [        US9nU R                  5         U R                  c   eU R                  R                  S[	        U5      U R
                  S9nU R                   H  nU" U5      nUb  M    g   U R                  R                  U R                  UU R                  S9  g)a"  Clear output associated with the current execution (cell).

Parameters
----------
wait : bool (default: False)
    If True, the output will not be cleared immediately,
    instead waiting for the next display before clearing.
    This reduces bounce during repeated clear & display loops.

)waitNclear_outputrN   rO   )
dictr=   rR   rS   r)   r/   rF   rT   rU   rV   )r1   r^   rX   rS   rZ   s        r3   r_    ZMQDisplayPublisher.clear_output   s     D/||'''ll~z'/B4K]K]^ KKDs)C{  
 	OO** 	 	
r6   c                 :    U R                   R                  U5        g)a  
Registers a hook with the thread-local storage.

Parameters
----------
hook : Any callable object

Returns
-------
Either a publishable message, or `None`.
The DisplayHook objects must return a message from
the __call__ method if they still require the
`session.send` method to be called after transformation.
Returning `None` will halt that execution path, and
session.send will not be called.
N)rF   appendr1   rZ   s     r3   register_hook!ZMQDisplayPublisher.register_hook   s    " 	4 r6   c                 \     U R                   R                  U5        g! [         a     gf = f)z
Un-registers a hook with the thread-local storage.

Parameters
----------
hook : Any callable object which has previously been
    registered as a hook.

Returns
-------
bool - `True` if the hook was removed, `False` if it wasn't
    found.
TF)rF   remove
ValueErrorrd   s     r3   unregister_hook#ZMQDisplayPublisher.unregister_hook   s.    	KKt$ 		s    
++r/   )NNFF)__name__
__module____qualname____firstlineno____doc__r    r   rR   r   rU   r   r/   r   rV   r?   r4   r=   r"   rA   propertyrF   r[   r_   re   rj   __static_attributes__ r6   r3   r+   r+   /   s    Lw40G%JHM?#E
 EM4
 _  ( ( 5
n
8!&r6   r+   c                      \ rS rSrSr\SS j5       r\S 5       r\R                  S:X  a  \" S5      " \5      r
\S 5       r\" S	5      " \5      r\R                  S
:X  a  \S 5       r\S 5       r\S 5       r\S 5       rSrg)KernelMagics   zKernel magics.Nc                 ~   U=(       d    SS/nU R                  US5      u  p4 [        R                  " U R                  XCU5      u  pVn[        [        U5      R                  5       5      nSXVS.nU R                  c   eU R                  R                  R                  U5        g! [         a    [        S5         gf = f)aW  Bring up an editor and execute the resulting code.

Usage:
  %edit [options] [args]

%edit runs an external text editor. You will need to set the command for
this editor via the ``TerminalInteractiveShell.editor`` option in your
configuration file before it will work.

This command allows you to conveniently edit multi-line code right in
your IPython session.

If called without arguments, %edit opens up an empty editor with a
temporary file and will execute the contents of this file when you
close it (don't forget to save it!).

Options:

-n <number>
  Open the editor at a specified line number. By default, the IPython
  editor hook uses the unix syntax 'editor +N filename', but you can
  configure this by providing your own modified hook if your favorite
  editor supports line-number specifications with a different syntax.

-p
  Call the editor with the same data as the previous time it was used,
  regardless of how long ago (in your current session) it was.

-r
  Use 'raw' input. This option only applies to input taken from the
  user's history.  By default, the 'processed' history is used, so that
  magics are loaded in their transformed version to valid Python.  If
  this option is given, the raw input as typed as the command line is
  used instead.  When you exit the editor, it will be executed by
  IPython's own processor.

Arguments:

If arguments are given, the following possibilities exist:

- The arguments are numbers or pairs of colon-separated numbers (like
  1 4:8 9). These are interpreted as lines of previous input to be
  loaded into the editor. The syntax is the same of the %macro command.

- If the argument doesn't start with a number, it is evaluated as a
  variable and its contents loaded into the editor. You can thus edit
  any string which contains python code (including the result of
  previous edits).

- If the argument is the name of an object (other than a string),
  IPython will try to locate the file where it was defined and open the
  editor at the point where it is defined. You can use ``%edit function``
  to load an editor exactly at the point where 'function' is defined,
  edit it and have the file be executed automatically.

  If the object is a macro (see %macro for details), this opens up your
  specified editor with a temporary file containing the macro's data.
  Upon exit, the macro is reloaded with the contents of the file.

  Note: opening at an exact line is only supported under Unix, and some
  editors (like kedit and gedit up to Gnome 2.8) do not understand the
  '+NUMBER' parameter necessary for this feature. Good editors like
  (X)Emacs, vi, jed, pico and joe all do.

- If the argument is not found as a variable, IPython will look for a
  file with that name (adding .py if necessary) and load it into the
  editor. It will execute its contents with execfile() when you exit,
  loading any code in the file into your interactive namespace.

Unlike in the terminal, this is designed to use a GUI editor, and we do
not know when it has closed. So the file you edit will not be
automatically executed or printed.

Note that %edit is also available through the alias %ed.
 zprn:z5Macro editing not yet implemented in 2-process model.N
edit_magic)sourcefilenameline_number)parse_optionsr   _find_edit_targetshellr   printstrr   resolvepayload_managerwrite_payload)	r1   parameter_s	last_calloptsargsr}   lineno_payloads	            r3   editKernelMagics.edit   s    Z )"b	''V<
	",">">tzz4W`"aHa tH~--/0)xWzz%%%

""009  	IJ	s   %B$ $B<;B<c                     U R                   c   e[        R                  S:X  a  U R                   R                  S5        gU R                   R                  S5        g)zClear the terminal.Nposixclearcls)r   osnamer   r1   arg_ss     r3   r   KernelMagics.clear:  sD     zz%%%77gJJg&JJe$r6   ntr   c                 j   U(       d  Sn[        U5      eUR                  S5      (       a>  U R                  c   eU R                  R                  [        R
                  " USS95      nO$[        U5       nUR                  5       nSSS5        [        R                  " W5        g! , (       d  f       N%= f)zKShow a file through the pager.

Files ending in .py are syntax-highlighted.zMissing filename.z.pyNF)skip_encoding_cookie)	r
   endswithr   
pycolorizer   read_py_fileopenreadr   )r1   r   rS   contfids        r3   lessKernelMagics.lessI  s    
 %CS/!>>%  ::)))::(()<)<UY^)_`Dexxz 		$ s   4B$$
B2morer   c                     U R                   c   e[        R                  " U R                   R                  SU-  SS95        g)z=Find the man page for the given command and display in pager.Nzman %s | col -bF)split)r   r   	getoutputr   s     r3   manKernelMagics.man_  s:     ::)))IIdjj**+<u+DE*RSr6   c                 p    [        5       n[        SS9n[        5       [        [        U5      R                  5      :X  a  [        U5      R                  n[        U[        5      (       d   e[        US-   5        [        SU S	35        g! [         a"  n[        R                  " SU-  SS9   SnAgSnAff = f)
a?  Print information for connecting other clients to this kernel

It will print the contents of this session's connection file, as well as
shortcuts for local clients.

In the simplest case, when called from the most recently launched kernel,
secondary clients can be connected, simply with:

$> jupyter <app> --existing

F)unpackz!Could not get connection info: %r   
stacklevelN
zPaste the above JSON into a file, and connect with:
    $> jupyter <app> --existing <file>
or, if you are local, you can connect with just:
    $> jupyter <app> --existing zj
or even just:
    $> jupyter <app> --existing
if this is the most recent Jupyter kernel you have started.)r%   r&   	Exceptionwarningswarnr   r   r   r2   r   
isinstancer   )r1   r   connection_fileinfoes        r3   connect_infoKernelMagics.connect_infoe  s    	13O&e4D  C_(=(D(D$EE"?388O$$$$$dTk/ 0?.? @JK	
  	MM=AaP	s   B	 	
B5B00B5c                     S[         R                  ;   a  SSKJn  U" 5          [	        [        U[        R                  S:H  5      S9  g	! [         a"  n[        R                  " SU-  SS9   S	nAg	S	nAff = f)
zzOpen a qtconsole connected to this kernel.

Useful for connecting a qtconsole to running notebooks, for better
debugging.
ipyparallelr   )bind_kernelr   )argvzCould not start qtconsole: %rr   r   N)r8   modulesr   r   r$   r   r   r   r   r   r   )r1   r   r   r   s       r3   	qtconsoleKernelMagics.qtconsole  s\     CKK'/M	9UBGGw4F#GH 	MM9A=!L	s   $A 
A4A//A4c                      [        U5      nSU-  n[        [	        SU-  5      S/S9  U(       a  [        SU-  5        g[        S5        g! [         a  n[        SU-  5      UeSnAff = f)	a  Set the autosave interval in the notebook (in seconds).

The default value is 120, or two minutes.
``%autosave 0`` will disable autosave.

This magic only has an effect when called from the notebook interface.
It has no effect when called in a startup file.
z&%%autosave requires an integer, got %rNi  z*IPython.notebook.set_autosave_interval(%i)zapplication/javascript)includezAutosaving every %i secondszAutosave disabled)intri   r
   r   r   r   )r1   r   intervalr   millisecondss        r3   autosaveKernelMagics.autosave  s|    	V5zH
 hClRS-.	
 /(:;%&  	VEMNTUU	Vs   A 
A)A$$A)ru   )rz   N)rn   ro   rp   rq   rr   r   r   r   r   r   r   r   r   r   r   r   r   rt   ru   r6   r3   rw   rw      s     \: \:B % % 
ww$&    fd#D 
ww'		T 
	T
 "
 "
H  ( ' 'r6   rw   c                     ^  \ rS rSrSr\" \5      r\" \5      r	\
" 5       r\
" 5       r\
" 5       r\" S5      S 5       r\" S5      r\" S5      r\" \5      r\" S5      S 5       r\" S5      S	 5       rS
rS rS rSS jrU 4S jrS r\S 5       r \ RB                  S 5       r S r"U 4S jr#S r$SS jr%S r&S r'U 4S jr(S r)S r*\*r+Sr,U =r-$ )ZMQInteractiveShelli  z'A subclass of InteractiveShell for ZMQ.banner1c                     [         $ Nr   r<   s    r3   _default_banner1$ZMQInteractiveShell._default_banner1  s    r6   Fexiterc                     [        U 5      $ r   r   r<   s    r3   _default_exiter#ZMQInteractiveShell._default_exiter  s    t$$r6   exit_nowc                 b   US   (       a  [        U R                  S5      (       a2  U R                  R                  nUR                  SUR                  5        U R                  R
                  (       a<  [        U R                  R
                  SS5      nU(       a  U" U R                  5        gggg)z"stop eventloop when exit_now firesnewio_loopg?	exit_hookN)rE   kernelr   
call_laterstop	eventloopgetattr)r1   changeloopr   s       r3   _update_exit_now$ZMQInteractiveShell._update_exit_now  s     %=t{{I..{{**TYY/{{$$#DKK$9$9;M	dkk*  %	 r6   Nc                 p    SSK Jn   U" U5        Xl        g! [         a  n[	        SU-  5      UeSnAff = f)zEnable a given guil.   )
enable_guiz%sN)
eventloopsr   active_eventloopri   r
   )r1   guireal_enable_guir   s       r3   r   ZMQInteractiveShell.enable_gui  s9    =	.C $'! 	.TAX&A-	.s    
505c                 `    [         R                  nSUS'   SUS'   SUS'   SUS'   SUS'   SUS	'   g
)z!Configure the user's environment.zxterm-colorTERM1CLICOLORFORCE_COLORCLICOLOR_FORCEcatPAGER	GIT_PAGERN)r   environ)r1   envs     r3   init_environment$ZMQInteractiveShell.init_environment  sG    jj#FJ M # G Kr6   c                     [        SU5      n[        U[        5      (       a  UOSU0n[        SUUS9nU R                  c   eU R                  R	                  U5        g)aE  Print a string, piping through a pager.

This version ignores the screen_lines and pager_cmd arguments and uses
IPython's payload system instead.

Parameters
----------
strg : str or mime-dict
    Text to page, or a mime-type keyed dict of already formatted data.
start : int
    Starting line at which to place the display.
r   z
text/plainr   )r|   rI   startN)maxr   r`   r   r   )r1   strgr   screen_lines	pager_cmdrI   r   s          r3   payloadpage_page$ZMQInteractiveShell.payloadpage_page  sb      Au!$--tL$3G

 ##///**73r6   c                    > [         TU ]  5         U R                  S[        R                  " U R
                  5      S5        g)zInitialize hooks.show_in_pagerc   N)super
init_hooksset_hookr   as_hookr   r1   	__class__s    r3   r  ZMQInteractiveShell.init_hooks  s-    ot||D4I4I'JBOr6   c                     g)z:Delay datapub init until request, for deprecation warningsNru   r<   s    r3   init_data_pub!ZMQInteractiveShell.init_data_pub       r6   c                 ,   [        U S5      (       dx  [        R                  " S[        SS9  U R	                  U S9U l        U R                  R                  U R
                  l        U R                  R                  U R
                  l        U R
                  $ )N	_data_pubzAInteractiveShell.data_pub is deprecated outside IPython parallel.r   r   rN   )	rE   r   r   DeprecationWarningdata_pub_classr  display_pubrR   rU   r<   s    r3   data_pubZMQInteractiveShell.data_pub#  su    t[))MMS" "000=DN%)%5%5%=%=DNN"(,(8(8(C(CDNN%~~r6   c                     Xl         g r   )r  )r1   pubs     r3   r  r  1  s    r6   c                     U R                   (       + U l        [        SU R                   S9nU R                  R	                  U5        g)zEngage the exit actions.ask_exit)r|   
keepkernelN)keepkernel_on_exitr   r`   r   r   )r1   r   s     r3   r  ZMQInteractiveShell.ask_exit5  s>     333..
 	**73r6   c                 2   > SU l         [        TU ]  " U0 UD6$ )zRun a cell.N)_last_tracebackr  run_cell)r1   r   kwargsr  s      r3   r  ZMQInteractiveShell.run_cell>  s     #w000r6   c                    [         R                  R                  5         [         R                  R                  5         U[	        UR
                  5      [	        U5      S.nU R                  nS nUR                  (       a  UR                  R                  SS5      nUR                  R                  UR                  S[        U5      UR                  US9  X0l        g )N)	tracebackenameevalues   execute_results   errorerrorrO   )r8   r9   r:   r;   r   rn   displayhookrV   replacerR   rT   rU   r)   r/   r  )r1   etyper"  stbexc_contentdhrV   s          r3   _showtraceback"ZMQInteractiveShell._showtracebackC  s    



 (&k
  88HH$$%6AE


MM{# 	 	
  #r6   c                 P    [        SUUS9nU R                  R                  U5        g)zOSend the specified text to the frontend to be presented at the next
input cell.set_next_input)r|   textr%  N)r`   r   r   )r1   r.  r%  r   s       r3   r-  "ZMQInteractiveShell.set_next_inputa  s-     #

 	**73r6   c                    Xl         U R                  R                  U5        U R                  R                  U5        [	        U S5      (       a  U R
                  R                  U5         [        R                  R                  U5         [        R                  R                  U5        g! [         a     N-f = f! [         a     gf = f)zFSet the parent header for associating output with its triggering inputr  N)
r/   r$  r4   r  rE   r  r8   r9   AttributeErrorr;   r0   s     r3   r4   ZMQInteractiveShell.set_parentk  s    ###F+##F+4%%MM$$V,	JJ!!&)	JJ!!&)  		  		s$   *B* 
B: *
B76B7:
CCc                     U R                   $ )zGet the parent header.rl   r<   s    r3   
get_parentZMQInteractiveShell.get_parent{  s    !!!r6   c                    > [         TU ]  5         U R                  [        5        U R                  R                  SS5        g)zInitialize magics.edr   N)r  init_magicsregister_magicsrw   magics_managerregister_aliasr  s    r3   r8  ZMQInteractiveShell.init_magics  s2    \***48r6   c                     g)zInitialize virtual environment.Nru   r<   s    r3   init_virtualenv#ZMQInteractiveShell.init_virtualenv  r  r6   c                    UR                  5       R                  S5      (       a  Sn[        U5      e[        R                  S:X  aJ  U R                  USS9nSSKJn  U" 5        nUb  S	U S
U 3n[        U5      U R                  S'   SSS5        g[        U R                  USS95      U R                  S'   g! , (       d  f       g= f)zCall the given cmd in a subprocess, piping stdout/err

Parameters
----------
cmd : str
    Command to execute (can not end in '&', as background processes are
    not supported.  Should not be a command that expects input
    other than simple text.
&z#Background processes not supported.win32r   )depthr   )AvoidUNCPathNzpushd z &&
_exit_code)
rstripr   OSErrorr8   platform
var_expandIPython.utils._process_win32rD  r   user_ns)r1   cmdrS   rD  paths        r3   system_piped ZMQInteractiveShell.system_piped  s     ::<  %% 8C#, <<7"//#Q//CA4#"4&C51C-3C[\*  
 *010M)NDLL&  s   #$B77
C)r  r  r   r   r/   )r   r   Nrm   ).rn   ro   rp   rq   rr   r!   r'   displayhook_classr+   display_pub_classr   r  r   r/   r"   r   r   readline_use
autoindentr    r   r   r   r#   r   r  r   r   r   r  r	  rs   r  setterr  r  r*  r-  r4   r4  r8  r>  rN  r   rt   __classcell__)r  s   @r3   r   r     s   10101UNUFEMY  <L uJo&FX% % Z	+ 	+ .!48P
I   __ 41
#<4 "9.!OH Fr6   r   )?rr   r   r8   r   pathlibr   	threadingr   IPython.corer   IPython.core.autocallr   IPython.core.displaypubr	   IPython.core.errorr
   IPython.core.interactiveshellr   r   IPython.core.magicr   r   r   IPython.core.magicsr   r   IPython.core.usager   IPython.displayr   r   IPython.utilsr   IPython.utils.processr   r   jupyter_client.sessionr   r   jupyter_core.pathsr   	traitletsr   r   r   r   r    r!   r"   r#   	ipykernelr$   r%   r&   ipykernel.displayhookr'   ipykernel.jsonutilr(   r)   r+   rw   r   registerru   r6   r3   <module>rj     s     
 
     1 4 ) O ? ? 7 - /   3 : 2 P P P Q Q 5 8Z* Zz k'6 k' k'\u* up   0 1r6   