+
    Ni2                     &   R t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHtH	t	H
t
HtHtHtHt ^ RIHt ^ RIHtHtHtHt ]'       d   ^ RIt^ RIHtHtHtHtHt ^ RIHtHtH t  M^ RI!t!R.t"]PF                  ! ]$4      t% ! R	 R4      t&R
 R lt'R R lt(R# )zzThis module defines the `IoManager` class
which manages I/O for file objects connected to an existing gdb process
or pty.
N)pformat)IOAnyDictListOptionalTupleUnion)gdbmiparser)DEFAULT_GDB_TIMEOUT_SEC/DEFAULT_TIME_TO_CHECK_FOR_ADDITIONAL_OUTPUT_SECUSING_WINDOWSGdbTimeoutError)POINTERWinErrorbyrefwindllwintypes)BOOLDWORDHANDLE	IoManagerc                      a  ] tR t^#t o ]3V 3R lR llt]R3V 3R lR lltV 3R lR ltV 3R lR	 lt	V 3R
 lR lt
]RR3V 3R lR lltRtV tR# )r   c          
      v   < V ^8  d   QhRS[ S[,          RS[ S[,          RS[S[ S[,          ,          RS[RR/# )   stdinstdoutstderr'time_to_check_for_additional_output_secreturnN)r   bytesr   float)format__classdict__s   "8/tmp/pip-target-e6j6ikcs/lib/python/pygdbmi/IoManager.py__annotate__IoManager.__annotate__$   sN     #, #,%y#, 5	#, E#	#,
 27#, 
#,    c                t   Wn         W n        W0n        V P                   P                  4       V n        V P                  P                  4       V n        V P                  '       d   V P                  P                  4       MRV n        . V n        V P                  '       d&   V P                  P                  V P
                  4       V P                  .V n	        RRRR/V n
        VV n        V P                  ^ 8  V n        \        V P                  4       V P                  '       d   \        V P                  4       R# R# )z
Manage I/O for file objects created before calling this class
This can be useful if the gdb process is managed elsewhere, or if a
pty is used.
r   Nr   )r   r   r   filenostdin_filenostdout_filenostderr_fileno	read_listappend
write_list_incomplete_outputr   _allow_overwrite_timeout_times_make_non_blocking)selfr   r   r   r   s   &&&&&r$   __init__IoManager.__init__$   s     
 JJ--/![[//159[[[T[[//1b$&;;;NN!!$"4"45,,-3;T8T2R3 	4 881< 	+ 	4;;';;;t{{+ r'   Tc                <   < V ^8  d   QhRS[ RS[RS[S[,          /# )r   timeout_secraise_error_on_timeoutr   )r!   boolr   r   )r"   r#   s   "r$   r%   r&   I   s-     $ $$ !%$ 
d	$r'   c                    V^ 8  d   \         P                  R4       ^ p\        '       d   V P                  V4      pMV P	                  V4      pV'       g   V'       d   \        RV,          4      hV# )az  Get response from GDB, and block while doing so. If GDB does not have any response ready to be read
by timeout_sec, an exception is raised.

Args:
    timeout_sec: Maximum time to wait for reponse. Must be >= 0. Will return after
    raise_error_on_timeout: Whether an exception should be raised if no response was found after timeout_sec

Returns:
    List of parsed GDB responses, returned from gdbmiparser.parse_response, with the
    additional key 'stream' which is either 'stdout' or 'stderr'

Raises:
    GdbTimeoutError: if response is not received within timeout_sec
    ValueError: if select returned unexpected file number
*timeout_sec was negative, replacing with 0z.Did not get response from gdb after %s seconds)loggerwarningr   _get_responses_windows_get_responses_unixr   )r4   r8   r9   retvals   &&& r$   get_gdb_responseIoManager.get_gdb_responseI   sd    * ?NNGHK=00=F--k:F0!@;N 
 Mr'   c                6   < V ^8  d   QhRS[ RS[S[,          /# r   r8   r   r!   r   r   )r"   r#   s   "r$   r%   r&   o   s        %  DJ  r'   c                
   \         P                   ! 4       V,           p. p . p V P                  P                  4        V P                  P                  4       P	                  RR4      pV P                  VR4      pV P                  e^    V P                  P                  4        V P                  P                  4       P	                  RR4      pW@P                  VR4      ,          pW4,          pV^ 8X  d    V# V'       dF   V P                  '       d4   \        \         P                   ! 4       V P                  ,           V4      pEK$  \         P                   ! 4       V8  g   EKA   V#   \         d     Li ; i  \         d     Li ; i)zLGet responses on windows. Assume no support for select and use a while loop.      
r   r   )timer   flushreadlinereplace_get_responses_listOSErrorr   r2   minr   )r4   r8   timeout_time_sec	responsesresponses_list
raw_outputs   &&    r$   r?    IoManager._get_responses_windowso   sK   99;4	N!!#![[113;;E5I
!%!9!9*h!O {{&KK%%'!%!5!5!7!?!?u!MJ"&>&>z8&TTN 'Ia   D$G$G$G#&IIK$"N"NN$$  //-    s%   AE# AE4 #E10E14FFc                6   < V ^8  d   QhRS[ RS[S[,          /# rE   rF   )r"   r#   s   "r$   r%   r&      s     + +u +d +r'   c                n   \         P                   ! 4       V,           p. p V\         P                   ! 4       ,
          pV^ 8:  d   ^ p\        P                  ! V P                  . . V4      w  p pRpV F  pWP                  8X  d8   V P                  P                  4        V P                  P                  4       p	Rp
MiWP                  8X  dH   V P                  f   Q hV P                  P                  4        V P                  P                  4       p	Rp
M\        RV,          4      hV P                  W4      pW7,          pK  	  V^ 8X  d    V# V'       dF   V P                  '       d4   \        \         P                   ! 4       V P                  ,           V4      pEKx  \         P                   ! 4       V8  g   EK   V# )zAGet responses on unix-like system. Use select to wait for output.Nr   r   z.Developer error. Got unexpected file number %d)rJ   selectr.   r,   r   rK   readr-   r   
ValueErrorrN   r2   rP   r   )r4   r8   rQ   rR   select_timeoutevents_rS   r*   rT   streams   &&         r$   r@   IoManager._get_responses_unix   sm   99;4	-		;N"!"!==RPLFAq!N ///KK%%'!%!1!1!3J%F111;;222KK%%'!%!1!1!3J%F %H6Q  "&!9!9*!M+	% !( a   D$G$G$G#&IIK$"N"NN$$ 
 //r'   c          	      R   < V ^8  d   QhRS[ RS[RS[S[S[S[3,          ,          /# )r   rT   r^   r   )r    strr   r   r   )r"   r#   s   "r$   r%   r&      s2     ! !!),!	d38n	!r'   c           	        . p\        WP                  P                  V4      4      w  q@P                  V&   V'       g   V# \        \	        R VP                  RR7      P                  R4      4      4      pV Fk  p\        P                  ! V4      '       d   K!  \        P                  ! V4      pW'R&   \        P                  R\        V4      4       VP                  V4       Km  	  V# )zGet parsed response list from string output
Args:
    raw_output (unicode): gdb output to parse
    stream (str): either stdout or stderr
c                     V # )N )xs   &r$   <lambda>/IoManager._get_responses_list.<locals>.<lambda>   s    Qr'   rM   )errors
r^   z%s)_buffer_incomplete_responsesr1   getlistfilterdecodesplitr
   response_is_finishedparse_responser=   debugr   r/   )r4   rT   r^   rR   _new_outputresponse_listresponseparsed_responses   &&&     r$   rN   IoManager._get_responses_list   s     +-	:V//33F;;
7--f5 ; 2 2) 2 D J J4 PQ

 &H//99"-"<"<X"F,2)T7?#;<  1 & r'   c                n   < V ^8  d   QhRS[ S[S[S[,          3,          RS[RS[RS[RS[S[,          /# )r   mi_cmd_to_writer8   r9   read_responser   )r	   ra   r   r!   r:   r   )r"   r#   s   "r$   r%   r&      sU     @ @sDI~.@ @ !%	@
 @ 
d@r'   c                "   V^ 8  d   \         P                  R4       ^ p\        V\        4      '       d   TpML\        V\        4      '       d   RP                  V4      pM$\        R\        \        V4      4      ,           4      h\         P                  RV4       VP                  R4      '       g   VR,           pMTp\        '       d   V P                  .pM&\        P                  ! . V P                  . V4      w  rpV Ft  p	WP                  8X  dF   V P                  P                  VP!                  4       4       V P                  P#                  4        KX  \         P%                  RV	,          4       Kv  	  VRJ d   V P'                  W#R7      # . # )a  Write to gdb process. Block while parsing responses from gdb for a maximum of timeout_sec.

Args:
    mi_cmd_to_write: String to write to gdb. If list, it is joined by newlines.
    timeout_sec: Maximum number of seconds to wait for response before exiting. Must be >= 0.
    raise_error_on_timeout: If read_response is True, raise error if no response is received
    read_response: Block and read response. If there is a separate thread running, this can be false, and the reading thread read the output.
Returns:
    List of parsed gdb responses if read_response is True, otherwise []
Raises:
    TypeError: if mi_cmd_to_write is not valid
r<   ri   z.The gdb mi command must a be str or list. Got zwriting: %szgot unexpected fileno %dT)r8   r9   )r=   r>   
isinstancera   rl   join	TypeErrortyperr   endswithr   r+   rX   r0   r   writeencoderK   errorrB   )
r4   ry   r8   r9   rz   mi_cmd_to_write_strmi_cmd_to_write_nloutputreadyr]   r*   s
   &&&&&     r$   r   IoManager.write   sV   ( ?NNGHK os++"1.."&))O"<@d?+,- 
 	]O4"++D11!4t!;!4=  ,,-K &b$//2{ SAA!F***

  !3!:!:!<= 

  "7&@A " D ((' )  
 Ir'   )r2   r1   r.   r   r-   r   r+   r   r,   r   r0   N)__name__
__module____qualname____firstlineno__r   r5   r   rB   r?   r@   rN   r   __static_attributes____classdictcell__)r#   s   @r$   r   r   #   sg      :i#, #,N 5'+$ $L   D+ +Z! !L 5'+"@ @ @r'   c          	          V ^8  d   QhR\         \        ,          R\         \        ,          R\        \         \        ,          \         \        ,          3,          /# )r   rT   bufr   )r   r    r   )r"   s   "r$   r%   r%   $  s>     # ##&.uo#
8E?HUO+,#r'   c                    V '       dc   V'       d   RP                  W.4      p RpRV 9  d   T pRp W3# V P                  R4      '       g"   V P                  R4      ^,           pWR pV RV p W3# )a  It is possible for some of gdb's output to be read before it completely finished its response.
In that case, a partial mi response was read, which cannot be parsed into structured data.
We want to ALWAYS parse complete mi records. To do this, we store a buffer of gdb's
output if the output did not end in a newline.

Args:
    raw_output: Contents of the gdb mi output
    buf (str): Buffered gdb response from the past. This is incomplete and needs to be prepended to
    gdb's next output.

Returns:
    (raw_output, buf)
r'   NrI   )r}   r   rindex)rT   r   remainder_offsets   && r$   rj   rj   $  s    " 3"34JC
"CJ  $$U++  *007!;./C#$5%56Jr'   c                (    V ^8  d   QhR\         RR/# )r   file_objr   N)r   )r"   s   "r$   r%   r%   J  s     < < < <r'   c                   \         '       d   \        \        4      p\        P                  ! ^4      p\        P
                  P                  p\        WV.Vn        \        Vn
        \        P                  ! V P                  4       4      p\        P
                  P                  V\        V4      RR4      pV^ 8X  d   \        \!        4       4      hR# \"        P"                  ! V \"        P$                  \&        P(                  4       R# )zmake file object non-blocking
Windows doesn't have the fcntl module, but someone on
stack overflow supplied this code as an answer, and it works
http://stackoverflow.com/a/34504971/2893090N)r   r   r   r   r   kernel32SetNamedPipeHandleStater   argtypesr   restypemsvcrtget_osfhandler*   r   rZ   r   fcntlF_SETFLos
O_NONBLOCK)r   LPDWORDPIPE_NOWAITr   hress   &     r$   r3   r3   J  s     }%.nnZ0"(//"I"I,2Gg+N(*.'  !23oo55a{9KTSWX!8XZ((  	HemmR]];r'   ))__doc__loggingr   rX   rJ   pprintr   typingr   r   r   r   r   r   r	   pygdbmir
   pygdbmi.constantsr   r   r   r   r   ctypesr   r   r   r   r   ctypes.wintypesr   r   r   r   __all__	getLoggerr   r=   r   rj   r3   rd   r'   r$   <module>r      s{     	    > > >   AA33 - 
		8	$~ ~B#L<r'   