
    ^jC                     |    d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	m
Z
  G d d      Z G d d	      Z G d
 d      Zy)zIO capturing utilities.    N)StringIO)TracebackType)AnyListOptionalTypec                   R    e Zd ZddZd Zd ZddZd Zd Zd Z	d	 Z
d
 Zd Zd Zy)
RichOutputNc                 T    |xs i | _         |xs i | _        |xs i | _        || _        y Ndatametadata	transientupdate)selfr   r   r   r   s        N/opt/ringagent/.cad-venv/lib/python3.12/site-packages/IPython/utils/capture.py__init__zRichOutput.__init__   s*    JB	 B"b    c                 x    ddl m}  || j                  | j                  | j                  | j
                         y )Nr   )publish_display_datar   )IPython.displayr   r   r   r   r   )r   r   s     r   displayzRichOutput.display   s'    8$))dmm'+~~dkk	Kr   c                     || j                   vry | j                   |   }|| j                  v r|| j                  |   fS |S r   r   r   )r   mimer   s      r   _repr_mime_zRichOutput._repr_mime_   sC    tyy yy4== t,,,Kr   c                 2    | j                   | j                  fS r   r   )r   includeexcludes      r   _repr_mimebundle_zRichOutput._repr_mimebundle_'   s    yy$--''r   c                 $    | j                  d      S )Nz	text/htmlr   r   s    r   _repr_html_zRichOutput._repr_html_*       ,,r   c                 $    | j                  d      S )Nz
text/latexr#   r$   s    r   _repr_latex_zRichOutput._repr_latex_-       --r   c                 $    | j                  d      S )Nzapplication/jsonr#   r$   s    r   _repr_json_zRichOutput._repr_json_0   s     233r   c                 $    | j                  d      S )Nzapplication/javascriptr#   r$   s    r   _repr_javascript_zRichOutput._repr_javascript_3   s     899r   c                 $    | j                  d      S )Nz	image/pngr#   r$   s    r   
_repr_png_zRichOutput._repr_png_6   r&   r   c                 $    | j                  d      S )Nz
image/jpegr#   r$   s    r   _repr_jpeg_zRichOutput._repr_jpeg_9   r)   r   c                 $    | j                  d      S )Nzimage/svg+xmlr#   r$   s    r   
_repr_svg_zRichOutput._repr_svg_<   s    00r   )NNNF)NN)__name__
__module____qualname__r   r   r   r!   r%   r(   r+   r-   r/   r1   r3    r   r   r
   r
      s:    K
(-.4:-.1r   r
   c            	           e Zd ZdZ	 ddee   dee   deee      fdZd Z	e
defd	       Ze
defd
       Ze
d        Zd ZeZy)
CapturedIOa  Simple object for containing captured stdout/err and rich display StringIO objects

    Each instance `c` has three attributes:

    - ``c.stdout`` : standard output as a string
    - ``c.stderr`` : standard error as a string
    - ``c.outputs``: a list of rich display outputs

    Additionally, there's a ``c.show()`` method which will print all of the
    above in the same order, and can be invoked simply via ``c()``.
    Nstdoutstderroutputsc                 6    || _         || _        |g }|| _        y r   )_stdout_stderr_outputs)r   r:   r;   r<   s       r   r   zCapturedIO.__init__M   s#     ?Gr   c                     | j                   S r   )r:   r$   s    r   __str__zCapturedIO.__str__Y   s    {{r   returnc                 P    | j                   sy| j                   j                         S )zCaptured standard output )r>   getvaluer$   s    r   r:   zCapturedIO.stdout\   !     ||||$$&&r   c                 P    | j                   sy| j                   j                         S )zCaptured standard errorrE   )r?   rF   r$   s    r   r;   zCapturedIO.stderrc   rG   r   c                 R    | j                   D cg c]  }t        di | c}S c c}w )a  A list of the captured rich display outputs, if any.

        If you have a CapturedIO object ``c``, these can be displayed in IPython
        using::

            from IPython.display import display
            for o in c.outputs:
                display(o)
        r7   )r@   r
   r   kargss     r   r<   zCapturedIO.outputsj   s$     37--A$e$AAAs   $c                 t   t         j                  j                  | j                         t         j                  j                  | j                         t         j                  j	                          t         j                  j	                          | j
                  D ]  }t        di |j                           y)z0write my output to sys.stdout/err as appropriateNr7   )sysr:   writer;   flushr@   r
   r   rJ   s     r   showzCapturedIO.showw   su    

%

%



]] 	*E'')	*r   r   )r4   r5   r6   __doc__r   r   r   r   r   rB   propertystrr:   r;   r<   rP   __call__r7   r   r   r9   r9   @   s    
  (,	
 "
  "
  $s)$	
  ' ' ' ' ' ' 
B 
B* Hr   r9   c                   j    e Zd ZdZdZdZdZddededefdZde	fdZ
d	eee      d
ee   dee   fdZy)capture_outputz(context manager for capturing stdout/errTr:   r;   r   c                 <    || _         || _        || _        d | _        y r   )r:   r;   r   shell)r   r:   r;   r   s       r   r   zcapture_output.__init__   s    
r   rC   c                    ddl m} ddlm} ddlm} t        j                  | _        t        j                  | _
        | j                  r& |       | _        | j                  d | _        d| _        d x}x}}| j                  rt               x}t        _        | j                  rt               x}t        _	        | j                  r| j                  j                  | _         |       | j                  _        | j                  j                  j                   }t        j"                  | _         || j                  |      t        _        t'        |||      S )Nr   )get_ipython)CapturingDisplayPublisher)CapturingDisplayHookF)rX   r<   )IPython.core.getipythonrZ   IPython.core.displaypubr[   IPython.core.displayhookr\   rM   r:   
sys_stdoutr;   
sys_stderrr   rX   save_display_pubr   display_pubr<   displayhooksave_display_hookr9   )r   rZ   r[   r\   r:   r;   r<   s          r   	__enter__zcapture_output.__enter__   s    7EA****<<$DJzz!(,%$$(((';;"**,FSZ;;"**,FSZ<<$(JJ$:$:D!%>%@DJJ"jj,,44G%(__D"2;BDCO &&'22r   exc_type	exc_value	tracebackc                     | j                   t        _        | j                  t        _        | j
                  r>| j                  r1| j                  | j                  _        | j                  t        _
        y y y r   )r`   rM   r:   ra   r;   r   rX   rb   rc   re   rd   )r   rg   rh   ri   s       r   __exit__zcapture_output.__exit__   sK    __
__
<<DJJ%)%:%:DJJ""44CO '<r   N)TTT)r4   r5   r6   rQ   r:   r;   r   boolr   r9   rf   r   r   BaseExceptionr   rk   r7   r   r   rV   rV      ss    2FFGt $ d 3: 3:5$}*=!> 58TaKb 5ow  yF  pG 5r   rV   )rQ   rM   ior   typesr   typingr   r   r   r   r
   r9   rV   r7   r   r   <module>rq      s;        , ,+1 +1\@ @F.5 .5r   