
    bi                     P    d dl Z d dlZd dlZd dlmZ d dlmZ  G d de      Zd Z	y)    N)launcher)logc                   0    e Zd ZdZi Z	 d Zd Zd ZddZy)CaptureOutputzCaptures output from the specified file descriptor, and tees it into another
    file descriptor while generating DAP "output" events for it.
    c                    || j                   vsJ | | j                   |<   t        j                  d||       || _        || _        || _         t        j                  d      d      | _        |d | _	        nX|j                  | _	        |j                  }||dk(  rd}	 t        j                  |      | _        t        j                  d||       t!        j"                  | j$                  |
      | _        | j&                  j)                          y # t        $ r6 t        j                  d||d	       t        j                  d      | _        Y w xY w)NzCapturing {0} of {1}.zutf-8surrogateescape)errorscp65001zUsing encoding {0!r} for {1}z6Unsupported {0} encoding {1!r}; falling back to UTF-8.warning)level)targetname)	instancesr   infocategory_whose_fdcodecsgetincrementaldecoder_decoder_streambufferencoding
getencoder_encode	Exceptionswallow_exception	threadingThread_worker_worker_threadstart)selfwhoser   fdstreamr   s         R/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/debugpy/launcher/output.py__init__zCaptureOutput.__init__   s)   t~~---#'x ((E: =44W=EVW>DL!==DLH8y#8"M%00: 78L'..dllR!!#  :%%L#	  &009:s   D <EEc                 l    | j                   }|	 t        j                  |       y y # t        $ r Y y w xY w)N)r   oscloser   )r#   r%   s     r'   __del__zCaptureOutput.__del__7   s9    XX>   s   ' 	33c                     | j                   K	 t        j                  | j                   d      }t	        |      sn| j                  |       | j                   K| j                  dd       y # t        $ r Y w xY w)Ni       Tfinal)r   r*   readr   len_process_chunk)r#   ss     r'   r    zCaptureOutput._worker?   st    hh"GGDHHf- q6" hh" 	Ct,  s    A, ,	A87A8c                    | j                   j                  ||      }t        |      dk(  ry 	 t        j                  j                  d| j                  |j                  dd      d       | j                  y 	 | j                  |d      \  }}t        |      }d}||k  rp| j                  j                  ||d        }| j                  j                          |dk(  r't        j                  | j                         d | _        y ||z  }||k  roy y # t        $ r Y w xY w# t        $ r$ t!        j"                  d|| j                         Y y w xY w)	Nr/   r   outputz

)r   r6   r   zError printing {0!r} to {1})r   decoder2   r   channel
send_eventr   replacer   r   r   writeflushr*   r+   r   r   r   )r#   r4   r0   _sizeiwrittens          r'   r3   zCaptureOutput._process_chunkL   s7   MM  % 0q6Q;	''t}}		&RV@WX <<	S<<#45DAqq6DAd(,,,,QqrU3""$a< HHTXX&#DHW d(  		(  	S!!"?DMMR	Ss*   =D 9B
D  
D  	DD *EEN)F)	__name__
__module____qualname____doc__r   r(   r,   r    r3    r.   r'   r   r      s'     II $D-Sr.   r   c                      t         j                  j                         D ]@  \  } }t        j                  d| |j
                         |j                  j                          B y)z=Waits for all remaining output to be captured and propagated.z!Waiting for remaining {0} of {1}.N)r   r   itemsr   r   r   r!   join)r   instances     r'   wait_for_remaining_outputrK   m   sL    +55;;= '(4hP$$&'r.   )
r   r*   r   debugpyr   debugpy.commonr   objectr   rK   rF   r.   r'   <module>rO      s,   
  	   ]SF ]S@'r.   