ó
    Ñ]jÒ3  ã                   ó†   • S r SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
Jr  SSKJr  SSKJr   " S S	\5      r " S
 S5      rg)zaDisplayhook for IPython.

This defines a callable class that IPython uses for `sys.displayhook`.
é    N)ÚConfigurable)ÚInstanceÚFloat)Úwarné   )ÚHistoryOutputc                   óê   ^ • \ rS rSrSr\" SSS9r\" SSS9r\" S5      r	SU 4S jjr
\S	 5       rS
 rS r\S 5       rS r\S 5       rS rS rSrSSS jjrS rS rS rS rSS jrS rS rSrU =r$ )ÚDisplayHooké   z¹The custom IPython displayhook to replace sys.displayhook.

This class does many things, but the basic idea is that it is a callable
that gets called anytime user code returns a value.
z1IPython.core.interactiveshell.InteractiveShellABCT)Ú
allow_nonez-IPython.core.interactiveshell.ExecutionResultgš™™™™™É?c                 ó~  >• [         [        U ]
  " S
SU0UD6  SU l        SnUS::  a
  SU l        SnO#X$:  a  SU l        Sn[        SU-  SS9  OSU l        X l        Xl        Su  U l        U l	        U l
        U R                  U R                  U R                  S	.nU R                  R                  R                  U5        g )NÚshellFé   r   z6caching was disabled (min value for cache size is %s).)Ú
stacklevelr   ©Ú r   r   ©Ú_Ú__Ú___© )Úsuperr
   Ú__init__Ú
_is_activeÚdo_full_cacher   Ú
cache_sizer   r   r   r   Úuser_nsÚupdate)Úselfr   r   ÚkwargsÚcache_size_minÚ
to_user_nsÚ	__class__s         €ÚU/home/mande/repo/quber/.venv/lib/python3.13/site-packages/IPython/core/displayhook.pyr   ÚDisplayHook.__init__&   s½   ø€ ÜŒk˜4Ò)Ñ@°Ð@¸Ò@ØˆŒØˆØ˜‹?Ø!"ˆDÔØ‰JØÓ(Ø!"ˆDÔØˆJÜÐIØñ Ø+,ó.ð "#ˆDÔà$Œð Œ
à"*ÑˆŒˆtŒw�t”xð Ÿ&™& d§g¡g°D·H±HÑ=ˆ
Ø�
‰
×Ñ×!Ñ! *Õ-ó    c                 ó4   • U R                   R                  S-
  $ )Nr   )r   Úexecution_count©r   s    r$   Úprompt_countÚDisplayHook.prompt_count@   s   € à�z‰z×)Ñ)¨AÑ-Ð-r&   c                 óÎ   • S[         R                  ;   aA   U R                  R                  S   nXR                  La  gU R                  R                  S	 gg! [
         a     gf = f)z3Check if the user has set the '_' variable by hand.r   N)Úbuiltin_modÚ__dict__r   r   r   ÚKeyError)r   Ú
user_values     r$   Úcheck_for_underscoreÚ DisplayHook.check_for_underscoreI   sc   € ð
 ”+×&Ñ&Ó&ðØ!ŸZ™Z×/Ñ/°Ñ4�
Ø§V¡VÒ+ØØ—J‘J×&Ñ& sÑ+ð 'øô ó Ùðús   –'A ¾A Á
A$Á#A$c                 óŒ   •  U R                   R                  R                  S   nU R	                  U5      $ ! [         a     gf = f)z2Should we silence the display hook because of ';'?éÿÿÿÿF)r   Úhistory_managerÚinput_hist_parsedÚ
IndexErrorÚsemicolon_at_end_of_expression)r   Úcells     r$   ÚquietÚDisplayHook.quietW   sH   € ð	Ø—:‘:×-Ñ-×?Ñ?ÀÑCˆDð
 ×2Ñ2°4Ó8Ð8øô	 ó 	áð	ús   ‚#6 ¶
AÁAc                 óx  • [         R                  " U 5      n[        [        R                  " UR
                  5      5      n[        U5       Hl  nUS   [        R                  [        R                  [        R                  [        R                  4;   a  MJ  US   [        R                  :X  a  US   S:X  a    g  g   g)z=Parse Python expression and detects whether last token is ';'r   r   Ú;TFN)Ú_ioÚStringIOÚlistÚtokenizeÚgenerate_tokensÚreadlineÚreversedÚ	ENDMARKERÚNLÚNEWLINEÚCOMMENTÚOP)Ú
expressionÚsioÚtokensÚtokens       r$   r8   Ú*DisplayHook.semicolon_at_end_of_expressionc   sˆ   € ô �lŠl˜:Ó&ˆÜ”h×.Ò.¨s¯|©|Ó<Ó=ˆä˜fÖ%ˆEØ�Q‰xœH×.Ñ.´·±¼X×=MÑ=MÌx×O_ÑO_Ð`Ó`ÙØ�a‘œHŸK™KÓ'¨e°A©h¸#«oÙáò &r&   c                 ó   • SU l         g)z.Start the displayhook, initializing resources.TN©r   r)   s    r$   Ústart_displayhookÚDisplayHook.start_displayhookr   s	   € àˆ�r&   c                 ó   • U R                   $ ©NrP   r)   s    r$   Ú	is_activeÚDisplayHook.is_activev   s   € à�‰Ðr&   c                 ó  • [         R                  R                  U R                  R                  5        SR                  U R                  R                  S-
  5      nU R                  (       a   [         R                  R                  U5        gg)zaWrite the output prompt.

The default implementation simply writes the prompt to
``sys.stdout``.
z	Out[{}]: r   N)ÚsysÚstdoutÚwriter   Úseparate_outÚformatr(   r   )r   Ú	outprompts     r$   Úwrite_output_promptÚDisplayHook.write_output_promptz   s_   € ô 	�
‰
×Ñ˜Ÿ™×0Ñ0Ô1Ø×&Ñ& t§z¡z×'AÑ'AÀAÑ'EÓFˆ	Ø××Ü�J‰J×Ñ˜YÕ'ð r&   c                 óL   • U R                   R                  R                  U5      $ )a?  Compute format data of the object to be displayed.

The format data is a generalization of the :func:`repr` of an object.
In the default implementation the format data is a :class:`dict` of
key value pair where the keys are valid MIME types and the values
are JSON'able data structure containing the raw data for that MIME
type. It is up to frontends to determine pick a MIME to to use and
display that data in an appropriate manner.

This method only computes the format data for the object and should
NOT actually print or write that to a stream.

Parameters
----------
result : object
    The Python object passed to the display hook, whose format will be
    computed.

Returns
-------
(format_dict, md_dict) : dict
    format_dict is a :class:`dict` whose keys are valid MIME types and values are
    JSON'able raw data for that MIME type. It is recommended that
    all return values of this should always include the "text/plain"
    MIME type representation of the object.
    md_dict is a :class:`dict` with the same MIME type keys
    of metadata associated with each output.

)r   Údisplay_formatterr\   ©r   Úresults     r$   Úcompute_format_dataÚDisplayHook.compute_format_data†   s   € ð< �z‰z×+Ñ+×2Ñ2°6Ó:Ð:r&   Fc                 ó@  • SU;  a  gUS   nSU;   a  U R                   (       d  SU-   n [        U5        g! [         a]    [        UR                  [        R
                  R                  S5      R                  [        R
                  R                  5      5         gf = f)aº  Write the format data dict to the frontend.

This default version of this method simply writes the plain text
representation of the object to ``sys.stdout``. Subclasses should
override this method to send the entire `format_dict` to the
frontends.

Parameters
----------
format_dict : dict
    The format dict for the object passed to `sys.displayhook`.
md_dict : dict (optional)
    The metadata dict to be associated with the display data.
ú
text/plainNÚ
Úbackslashreplace)Úprompt_end_newlineÚprintÚUnicodeEncodeErrorÚencoderX   rY   ÚencodingÚdecode)r   Úformat_dictÚmd_dictÚresult_reprs       r$   Úwrite_format_dataÚDisplayHook.write_format_data©   s‘   € ð ˜{Ó*àð " ,Ñ/ˆØ�;Óð ×*×*à" [Ñ0�ð	jÜ�+ÕøÜ!ó 	jô �+×$Ñ$¤S§Z¡Z×%8Ñ%8Ð9KÓL×SÑSÔTW×T^ÑT^×TgÑTgÓhÖið	jús   ª6 ¶A$BÂBc                 óÌ  • U R                   (       GaÍ  XR                  R                  S   LGa°  [        U R                  R                  S   5      U R                   :¼  a!  U R                  (       a  U R                  5         Sn[        SS5       Vs/ s H  nSU-  PM
     sn HS  nX@R                  R                  ;  a  M  [        X5      U R                  R                  R                  U5      Ld  MQ  SnMU     U R                  U l
        U R                  U l	        Xl        S[        R                  ;  aC  U(       a<  U R                  R                  U R                  U R                  U R                  S.SS9  0 nU R                  (       aS  S	U R                  -  nXU'   U R                  R                  USS9  XR                  R                  S   U R                  '   g
g
g
g
s  snf )z7Update user_ns with various things like _, __, _1, etc.Ú_ohTr   é   r   Fr   )Úinteractivez_%sN)r   r   r   Úlenr   Ú
cull_cacheÚrangeÚgetattrÚgetr   r   r   r-   r.   Úpushr*   )r   rc   Úupdate_undersÚiÚundersÚto_mainÚ
new_results          r$   Úupdate_user_nsÚDisplayHook.update_user_nsÒ   s�  € ð �?�?ˆ?˜v¯Z©Z×-?Ñ-?ÀÑ-FÓFÜ�4—:‘:×%Ñ% eÑ,Ó-°·±Ó@ÀT×EW×EWØ—‘Ô!ð !ˆMÜ*/°°!¬*Ó5ª* Q˜3˜qœ5©*Ô5�Ø§¡×!3Ñ!3Ó3ÙÜ˜4Ó(°·
±
×0BÑ0B×0FÑ0FÀvÓ0NÔNØ$)’Mñ	 6ð —w‘wˆDŒHØ—f‘fˆDŒGØŒFàœ;×/Ñ/Ó/¶mØ—
‘
—‘ T§V¡VØ&*§g¡gØ&*§h¡hñ!0à=Bð  ñ Dð
 ˆGØ×!×!Ø" T×%6Ñ%6Ñ6�
Ø&,˜
Ñ#Ø—
‘
—‘ °U�Ñ;Ø?E—
‘
×"Ñ" 5Ñ)¨$×*;Ñ*;Ò<ð	 "ð5  Gˆ?ùò 6s   ÂG!c                 ó@   • U R                   b  XR                   l        g g rT   )Úexec_resultrc   rb   s     r$   Úfill_exec_resultÚDisplayHook.fill_exec_resultö   s   € Ø×ÑÑ'Ø&,×ÑÕ#ð (r&   c                 ó–  • U R                   R                  R                  U R                     R	                  [        SUS95        SU;  a  gU R                   R                  R                  (       a)  U R                   R                  R                  US   S5        US   U R                   R                  R                  U R                  '   g)zLog the output.Úexecute_result)Úoutput_typeÚbundlerg   NÚoutput)
r   r5   Úoutputsr*   Úappendr   ÚloggerÚ
log_outputÚ	log_writeÚoutput_hist_reprs)r   rp   s     r$   r’   ÚDisplayHook.log_outputú   s�   € à�
‰
×"Ñ"×*Ñ*¨4×+<Ñ+<Ñ=×DÑDÜÐ&6¸{ÑKô	
ð ˜{Ó*àØ�:‰:×Ñ×'×'Ø�J‰J×Ñ×'Ñ'¨°LÑ(AÀ8ÔLà4?ÀÑ4Mð 	�
‰
×"Ñ"×4Ñ4°T×5FÑ5FÒGr&   c                 ó´   • [         R                  R                  U R                  R                  5        [         R                  R                  5         SU l        g)z%Finish up all displayhook activities.FN)rX   rY   rZ   r   Úseparate_out2Úflushr   r)   s    r$   Úfinish_displayhookÚDisplayHook.finish_displayhook  s5   € ä�
‰
×Ñ˜Ÿ™×1Ñ1Ô2Ü�
‰
×ÑÔØˆ�r&   c                 ót  • U R                  5         Ub¥  U R                  5       (       d�  U R                  5         U R                  5         U R	                  U5      u  p#U R                  U5        U R                  U5        U(       a"  U R                  X#5        U R                  U5        U R                  5         ggg)z¤Printing with history cache management.

This is invoked every time the interpreter needs to print, and is
activated by setting the variable sys.displayhook to it.
N)
r1   r:   rQ   r^   rd   r„   rˆ   rs   r’   r™   ©r   rc   rp   rq   s       r$   Ú__call__ÚDisplayHook.__call__  s˜   € ð 	×!Ñ!Ô#ØÑ d§j¡j§l¡lØ×"Ñ"Ô$Ø×$Ñ$Ô&Ø#'×#;Ñ#;¸FÓ#CÑ ˆKØ×Ñ Ô'Ø×!Ñ! &Ô)ÞØ×&Ñ& {Ô<Ø—‘ Ô,Ø×#Ñ#Õ%ð '3Ðr&   c                 ó–  • U R                   R                  R                  S0 5      n[        U5      n[	        [        X R                  -  5      S5      n[        SR                  X#S95        [        [        U5      5       HG  u  pEXC:¼  a    gU R                   R                  R                  SU-  S5        UR                  US5        MI     g)z-Output cache is full, cull the oldest entriesrv   é   zVOutput cache limit (currently {sz} entries) hit.
Flushing oldest {cull_count} entries.)ÚszÚ
cull_countz_%iN)r   r   r}   ry   ÚmaxÚintÚcull_fractionr   r\   Ú	enumerateÚsortedÚpop)r   Úohr¡   r¢   r€   Úns         r$   rz   ÚDisplayHook.cull_cache  s¥   € à�Z‰Z×Ñ×#Ñ# E¨2Ó.ˆÜ�‹WˆÜœ˜R×"4Ñ"4Ñ4Ó5°qÓ9ˆ
Üð 5ß5;±V¸r°VÐ5Yô	[ô œf R›jÖ)‰DˆAØ‹ÙØ�J‰J×Ñ×"Ñ" 5¨1¡9¨dÔ3Ø�F‰F�1�dŽOò	 *r&   c                 óà  • U R                   (       d  [        S5      e[        SU R                  S-   5       HA  nS[	        U5      -   n U R
                  R                  U	  U R
                  R                  U	 MC     U R
                  R                  R                  SS 5      nUb  UR                  5         Su  U l        U l        U l        S[        R                  ;  aG  U R
                  R                  R!                  U R                  U R                  U R                  S.5        SS Kn[$        R&                  S:w  a  UR)                  5         g g ! [         a     Nûf = f! [         a     GM6  f = f)	NzJYou shouldn't have reached the cache flush if full caching is not enabled!r   r   rv   r   r   r   Úcli)r   Ú
ValueErrorr{   r*   Úreprr   Úuser_ns_hiddenr/   r   r}   Úclearr   r   r   r-   r.   r   ÚgcrX   ÚplatformÚcollect)r   rª   Úkeyr©   r²   s        r$   r˜   ÚDisplayHook.flush-  s7  € Ø×!×!Üð ?ó @ð @ô �q˜×*Ñ*¨QÑ.Ö/ˆAØ”d˜1“g‘+ˆCðØ—J‘J×-Ñ-¨cÐ2ðØ—J‘J×&Ñ& sÒ+ñ 0ð �Z‰Z×Ñ×#Ñ# E¨4Ó0ˆØ‰>Ø�H‰HŒJð %/Ñ!ˆŒ�”˜œà”k×*Ñ*Ó*Ø�J‰J×Ñ×%Ñ%¨4¯6©6°t·w±wÀTÇXÁXÑ&NÔOÛô �<‰<˜5Ó Ø�J‰J�Lð !øô) ó Ùðûô ó Ûðús$   ÁEÁ EÅ
EÅEÅ
E-Å,E-)r   r   r   r   r   r   r   )Niè  rT   )ÚreturnN) Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r‡   r   r¥   r   Úpropertyr*   r1   r:   Ústaticmethodr8   rQ   rU   r^   rd   rj   rs   r„   rˆ   r’   r™   r�   rz   r˜   Ú__static_attributes__Ú__classcell__)r#   s   @r$   r
   r
      sÈ   ø† ññ ÐHØ $ñ&€EáÐJØ&*ñ,€Ká˜#“J€M÷.ð4 ñ.ó ð.òò
9ð ñó ðòð ñó ðò
(ò;ðB Ðö'jòR"FòH-òNò ô&ò$÷ð r&   r
   c                   ó(   • \ rS rSrSS jrSS jrSrg)ÚCapturingDisplayHookiO  Nc                 ó&   • Xl         Uc  / nX l        g rT   )r   r�   )r   r   r�   s      r$   r   ÚCapturingDisplayHook.__init__P  s   € ØŒ
Ø‰?ØˆGØ�r&   c                 ó”   • Uc  g U R                   R                  R                  U5      u  p#U R                  R	                  X#S.5        g )N)ÚdataÚmetadata)r   ra   r\   r�   r�   rœ   s       r$   r�   ÚCapturingDisplayHook.__call__V  s<   € Ø‰>ØØ#Ÿz™z×;Ñ;×BÑBÀ6ÓJÑˆØ�‰×Ñ kÑHÕIr&   )r�   r   rT   )r¸   r¹   rº   r»   r   r�   r¿   r   r&   r$   rÂ   rÂ   O  s   † ô÷Jr&   rÂ   )r¼   Úbuiltinsr-   rX   Úior>   rA   Útraitlets.config.configurabler   Ú	traitletsr   r   Úwarningsr   Úhistoryr   r
   rÂ   r   r&   r$   Ú<module>rÏ      s?   ðñó Û 
Û Û å 6ß %Ý å "ôs�,ô s÷l	Jò Jr&   