
    f)                     ^    d Z ddlZddlmZ  G d de      Z G d de      Z G d d	e      Zy)
zIO capturing utilities.    N)StringIOc                   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        P/var/www/cvtools/html/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_.   s     233r   c                 $    | j                  d      S )Nzapplication/javascriptr   r   s    r   _repr_javascript_zRichOutput._repr_javascript_1   s     899r   c                 $    | j                  d      S )Nz	image/pngr   r   s    r   
_repr_png_zRichOutput._repr_png_4   r!   r   c                 $    | j                  d      S )Nz
image/jpegr   r   s    r   _repr_jpeg_zRichOutput._repr_jpeg_7   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*   r,   r.    r   r   r   r      s:    K
(-.4:-.1r   r   c                   X    e Zd ZdZd	dZd Zed        Ze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()``.
    Nc                 6    || _         || _        |g }|| _        y r   )_stdout_stderr_outputs)r   stdoutstderroutputss       r   r   zCapturedIO.__init__K   s!    ?Gr   c                     | j                   S r   )r9   r   s    r   __str__zCapturedIO.__str__R   s    {{r   c                 P    | j                   sy| j                   j                         S )zCaptured standard output )r6   getvaluer   s    r   r9   zCapturedIO.stdoutU   !     ||||$$&&r   c                 P    | j                   sy| j                   j                         S )zCaptured standard errorr?   )r7   r@   r   s    r   r:   zCapturedIO.stderr\   rA   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)
        r2   )r8   r   r   kargss     r   r;   zCapturedIO.outputsc   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 appropriateNr2   )sysr9   writer:   flushr8   r   r   rD   s     r   showzCapturedIO.showp   su    

%

%



]] 	*E'')	*r   r   )r/   r0   r1   __doc__r   r=   propertyr9   r:   r;   rJ   __call__r2   r   r   r4   r4   >   s[    
  ' ' ' ' 
B 
B* Hr   r4   c                   0    e Zd ZdZdZdZdZddZd Zd Z	y)capture_outputz(context manager for capturing stdout/errTc                 <    || _         || _        || _        d | _        y r   )r9   r:   r   shell)r   r9   r:   r   s       r   r   zcapture_output.__init__   s    
r   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)rQ   r;   )IPython.core.getipythonrS   IPython.core.displaypubrT   IPython.core.displayhookrU   rG   r9   
sys_stdoutr:   
sys_stderrr   rQ   save_display_pubr   display_pubr;   displayhooksave_display_hookr4   )r   rS   rT   rU   r9   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   c                     | j                   t        _        | j                  t        _        | j
                  r>| j                  r1| j                  | j                  _        | j                  t        _
        y y y r   )rY   rG   r9   rZ   r:   r   rQ   r[   r\   r^   r]   )r   exc_type	exc_value	tracebacks       r   __exit__zcapture_output.__exit__   sK    __
__
<<DJJ%)%:%:DJJ""44CO '<r   N)TTT)
r/   r0   r1   rK   r9   r:   r   r   r_   rd   r2   r   r   rO   rO   |   s#    2FFG3:5r   rO   )rK   rG   ior   objectr   r4   rO   r2   r   r   <module>rg      s6      +1 +1\; ;|.5V .5r   