Format: application/x-python-code
⬇ Download File (5.6 KB)
   1  o
   2  
   3  ��h)�@sLdZddlZddlmZGdd�de�ZGdd�de�ZGdd	�d	e�ZdS)
   4  zIO capturing utilities.�N)�StringIOc@sheZdZddd�Zdd�Zdd�Zdd	d
   5  �Zdd�Zd
   6  d�Zdd�Z	dd�Z
   7  dd�Zdd�Zdd�Z
   8  dS)�
   9  RichOutputNFcCs(|pi|_|pi|_|p
  10  i|_||_dS�N��data�metadata�	transient�update)�selfrrrr	�r�Kc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/capture.py�__init__s
  11  
  12  
  13  
  14  zRichOutput.__init__cCs(ddlm}||j|j|j|jd�dS)Nr)�publish_display_datar)�IPython.displayrrrrr	)r
  15  rrrr�displays
  16  
  17  �zRichOutput.displaycCs4||jvrdS|j|}||jvr||j|fS|Sr�rr)r
  18  �mimerrrr�_repr_mime_s
  19  
  20  
  21  zRichOutput._repr_mime_cCs|j|jfSrr)r
  22  �include�excluderrr�_repr_mimebundle_%szRichOutput._repr_mimebundle_cC�
  23  |�d�S)Nz	text/html�r�r
  24  rrr�_repr_html_(�
  25  zRichOutput._repr_html_cCr)Nz
  26  text/latexrrrrr�_repr_latex_+rzRichOutput._repr_latex_cCr)Nzapplication/jsonrrrrr�_repr_json_.rzRichOutput._repr_json_cCr)Nzapplication/javascriptrrrrr�_repr_javascript_1rzRichOutput._repr_javascript_cCr)Nz	image/pngrrrrr�
  27  _repr_png_4rzRichOutput._repr_png_cCr)Nz
  28  image/jpegrrrrr�_repr_jpeg_7rzRichOutput._repr_jpeg_cCr)Nz
  29  image/svg+xmlrrrrr�
  30  _repr_svg_:rzRichOutput._repr_svg_)NNNF)NN)�__name__�
  31  __module__�__qualname__r
  32  rrrrrrrrr r!rrrrrs
  33  
  34  	rc@sReZdZdZddd�Zdd�Zedd��Zed	d
  35  ��Zedd��Z	d
  36  d�Z
  37  e
  38  ZdS)�
  39  CapturedIOa�Simple object for containing captured stdout/err and rich display StringIO objects
  40  
  41      Each instance `c` has three attributes:
  42  
  43      - ``c.stdout`` : standard output as a string
  44      - ``c.stderr`` : standard error as a string
  45      - ``c.outputs``: a list of rich display outputs
  46  
  47      Additionally, there's a ``c.show()`` method which will print all of the
  48      above in the same order, and can be invoked simply via ``c()``.
  49      NcCs"||_||_|durg}||_dSr)�_stdout�_stderr�_outputs)r
  50  �stdout�stderr�outputsrrrr
  51  Ks
  52  
  53  zCapturedIO.__init__cCs|jSr)r)rrrr�__str__RszCapturedIO.__str__cC�|jsdS|j��S)zCaptured standard output�)r&�getvaluerrrrr)U�
  54  zCapturedIO.stdoutcCr-)zCaptured standard errorr.)r'r/rrrrr*\r0zCapturedIO.stderrcCsdd�|jD�S)aA list of the captured rich display outputs, if any.
  55  
  56          If you have a CapturedIO object ``c``, these can be displayed in IPython
  57          using::
  58  
  59              from IPython.display import display
  60              for o in c.outputs:
  61                  display(o)
  62          cSsg|]	}tdi|���qS)r)r)�.0�kargsrrr�
  63  <listcomp>nsz&CapturedIO.outputs.<locals>.<listcomp>)r(rrrrr+cszCapturedIO.outputscCsRtj�|j�tj�|j�tj��tj��|jD]}tdi|����qdS)z0write my output to sys.stdout/err as appropriateNr)�sysr)�writer*�flushr(rr)r
  64  r2rrr�showps
  65  
  66  
  67  �zCapturedIO.showr)r"r#r$�__doc__r
  68  r,�propertyr)r*r+r7�__call__rrrrr%>s
  69  
  70  
  71  
  72  	r%c@s6eZdZdZdZdZdZd
  73  dd�Zdd�Zdd�Z	d	S)�capture_outputz(context manager for capturing stdout/errTcCs||_||_||_d|_dSr)r)r*r�shell)r
  74  r)r*rrrrr
  75  �s
  76  zcapture_output.__init__cCs�ddlm}ddlm}ddlm}tj|_tj	|_
  77  |jr,|�|_|jdur,d|_
  78  d|_d}}}|jr;t�}t_|j	rDt�}t_	|jrb|jj|_
  79  |�|j_|jjj}tj|_||j|d�t_t|||�S)Nr)�get_ipython)�CapturingDisplayPublisher)�CapturingDisplayHookF)r<r+)ZIPython.core.getipythonr=ZIPython.core.displaypubr>ZIPython.core.displayhookr?r4r)�
  80  sys_stdoutr*�
  81  sys_stderrrr<�save_display_pubr�display_pubr+�displayhook�save_display_hookr%)r
  82  r=r>r?r)r*r+rrr�	__enter__�s0
  83  
  84  
  85  
  86  �zcapture_output.__enter__cCs:|jt_|jt_|jr|jr|j|j_|j	t_
  87  dSdSdSr)r@r4r)rAr*rr<rBrCrErD)r
  88  �exc_type�	exc_value�	tracebackrrr�__exit__�s
  89  �zcapture_output.__exit__N)TTT)
  90  r"r#r$r8r)r*rr
  91  rFrJrrrrr;|s
  92  r;)r8r4�ior�objectrr%r;rrrr�<module>s.>