
    Mh,                    &   d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZmZmZ ddlmZ  G d de          Z G d d	ee          Z G d
 de          Z G d dej                  Zd Z G d de          Z G d de          Z e            Z	  G d de          Z G d de          Z G d de          Z G d de          Z  G d de!          Z" G d de"          Z# G d d e          Z$ G d! d"e          Z%dS )#zAn implementation of the session and presentation layers as used in the Debug
Adapter Protocol (DAP): channels and their lifetime, JSON messages, requests,
responses, and events.

https://microsoft.github.io/debug-adapter-protocol/overview#base-protocol
    )annotationsN)jsonlogutil)hide_thread_from_debuggerc                  "     e Zd ZdZ fdZ xZS )JsonIOErrorzDIndicates that a read or write operation on JsonIOStream has failed.c                    |                     d          }|                     dd           }t          |          s|t          |          g} t                      j        |i | || _        	 || _        d S )Nstreamcause)poplenstrsuper__init__r   r   )selfargskwargsr   r   	__class__s        X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/debugpy/common/messaging.pyr   zJsonIOError.__init__   s~    H%%

7D))4yy 	 U.JJ<D$)&)))	 
//    __name__
__module____qualname____doc__r   __classcell__r   s   @r   r	   r	      s>        NN0 0 0 0 0 0 0 0 0r   r	   c                  "     e Zd ZdZ fdZ xZS )NoMoreMessagesz`Indicates that there are no more messages that can be read from or written
    to a stream.
    c                b    t          |          r|ndg} t                      j        |i | d S )NzNo more messages)r   r   r   )r   r   r   r   s      r   r   zNoMoreMessages.__init__7   s=    4yy:tt'9&:$)&)))))r   r   r   s   @r   r    r    2   sB         * * * * * * * * *r   r    c                      e Zd ZdZdZej        Z	 ej        Z		 e
dd            Ze
dd            Ze
dd            Zdd fd	Zd
 Zej        fdZd ZddZddZd ZdS )JsonIOStreamzImplements a JSON value stream over two byte streams (input and output).

    Each value is encoded as a DAP packet, with metadata headers and a JSON payload.
    i stdioc                X     | t           j        j        t           j        j        |          S )zlCreates a new instance that receives messages from sys.stdin, and sends
        them to sys.stdout.
        )sysstdinbufferstdout)clsnames     r   
from_stdiozJsonIOStream.from_stdioJ   s"    
 s39#SZ%6===r   c                0     | |j         |j        |          S )ztCreates a new instance that receives messages from process.stdin, and sends
        them to process.stdout.
        )r)   r'   )r*   processr+   s      r   from_processzJsonIOStream.from_processQ   s    
 s7>7=$777r   Nc                                         d           |t                    }                    dd          }fd} | ||||          S )zFCreates a new instance that sends and receives messages over a socket.Nrwbr   c                     	                       t          j                   n# t          $ r Y nw xY w                                  d S N)shutdownsocket	SHUT_RDWR	Exceptionclose)socks   r   cleanupz)JsonIOStream.from_socket.<locals>.cleanupf   sQ    f.////   JJLLLLLs   # 
00)
settimeoutreprmakefile)r*   r9   r+   	socket_ior:   s    `   r   from_socketzJsonIOStream.from_socketX   sm     	<::D MM%++		 	 	 	 	 s9iw777r   c                     d S r3    rA   r   r   <lambda>zJsonIOStream.<lambda>o   s    $ r   c                `    |d|d|}|| _         || _        || _        || _        d| _        dS )a  Creates a new JsonIOStream.

        reader must be a BytesIO-like object, from which incoming messages will be
        read by read_json().

        writer must be a BytesIO-like object, into which outgoing messages will be
        written by write_json().

        cleanup must be a callable; it will be invoked without arguments when the
        stream is closed.

        reader.readline() must treat "
" as the line terminator, and must leave ""
        as is - it must not replace "
" with "
" automatically, as TextIO does.
        Nzreader=z	, writer=F)r+   _reader_writer_cleanup_closed)r   readerwriterr+   r:   s        r   r   zJsonIOStream.__init__o   sE      <:V::::D	r   c                   | j         rdS d| _         t          j        d| j                   	 	 	 | j                                         | j        | j        ur| j                                         n-# | j        | j        ur| j                                         w w xY w|                                  dS # |                                  w xY w# t          $ r t          j	        d| j                   Y dS w xY w)z.Closes the stream, the reader, and the writer.NTzClosing {0} message streamz&Error while closing {0} message stream)
rG   r   debugr+   rE   r8   rD   rF   r7   reraise_exceptionr   s    r   r8   zJsonIOStream.close   s    < 	F	.	:::	W -L&&(((|4<77**,,, |4<77**,,,, 8  	W 	W 	W!"JDIVVVVVV	Ws5   A/ (B2 /*BB2 C 2CC $C32C3c                (     |d| j         ||          S )Nz{0} {1} {2}r+   )r   dirdataloggers       r   _log_messagezJsonIOStream._log_message   s    vmTYT:::r   c                   d}	 	 ||                                 z  }n0# t          $ r#}t          t          |          |           d }~ww xY w|st          |           |                    d          r|dd         }|S })Nr   Tr   s   
r   )readliner7   r    r   endswith)r   rH   lineexcs       r   
_read_linezJsonIOStream._read_line   s    		<))) < < <$SXXd;;;;< 2$D1111}}W%% AbDz		s    
A
AA
c                    ||n                                  } j        }t          j         j        |          }d fd	}g i }	 	  |            }n# t
          $ r |r |d           n Y nw xY w|dgz  |dk    rn|                    d          \  }}}	|	||<   X	 t          |d	                   }
d
|
cxk    r j        k    s	n t          nA# t          t          f$ r- 	 t          d          # t
          $ r  |             Y nw xY wY nw xY wt                    }|
}|d
k    r}	 |                    |          }|st          n0# t
          $ r#}t          t!          |                     d}~ww xY w                    |           |t          |          z  }|d
k    }|d
k    sJ d                    |d                   }	 |                    d          }n# t
          $ r  |             Y nw xY w	 |                    |          }n# t
          $ r  |             Y nw xY w                     d|           |S )zRead a single JSON value from reader.

        Returns JSON value as parsed by decoder.decode(), or raises NoMoreMessages
        if there are no more values to be read.
        N c                    | r| dz  } | dz  } d                                                   d          }d                     d |D                       }t          j        | g|R j        |d| d S )Nz

z{name} -->
{raw_lines}r      

c              3  4   K   | ]}t          |          V  d S r3   )r<   ).0rY   s     r   	<genexpr>zTJsonIOStream.read_json.<locals>.log_message_and_reraise_exception.<locals>.<genexpr>   s(      !C!C$t**!C!C!C!C!C!Cr   )r+   	raw_lines)joinsplitr   rL   r+   )format_stringr   r   rd   
raw_chunksr   s       r   !log_message_and_reraise_exceptionzAJsonIOStream.read_json.<locals>.log_message_and_reraise_exception   s     ('66M,,22599I		!C!C!C!C!CCCI! $ +/9	 MS    r   Tz$Error while reading message headers:r_   r      :s   Content-Lengthr   z%Content-Length is missing or invalid:rU   utf-8z-->)r]   )json_decoder_factoryrD   	functoolspartialr[   r7   	partitionintMAX_BODY_SIZE
ValueErrorKeyErrorIOErrorr   readEOFErrorr    r   appendre   decoderS   )r   decoderrH   	read_lineri   headersrY   key_valuelength
body_startbody_remainingchunkrZ   bodyrh   s   `               @r   	read_jsonzJsonIOStream.read_json   sL    %0''d6O6O6Q6Q%dov>>	

	 
	 
	 
	 
	 
	 
	 
	! y{{ 
 
 

  55>    	 
 4-'Js{{ NN400MCE GCL)	!,	4!2344F55554#55555   6*% 	4 	4 	44EFFF 4 4 41133333433		4 __
q  <N33 #"N# < < <$SXXd;;;;< e$$$c%jj(N q   """"xx
:;;/00	0;;w''DD 	0 	0 	0--/////	0	0>>$''DD 	0 	0 	0--/////	0 	%&&&s~   	
A A0/A0!0C D$C33D
D	D

DD+E
 

E7E22E7G# #G:9G:>H H+*H+c                   | j         rt          |           ||n|                                 }| j        }	 |                    |          }n?# t
          $ r2 |                     dt          |          t          j	                   Y nw xY w|                    d          }dt          |           d                    d          }||z   }d	}	 |t          |          k     r7|                    ||d                   }|||z  }|t          |          k     7|                                 nE# t
          $ r8}	|                     d|t          j                   t          | |	
          d}	~	ww xY w|                     d|           dS )ziWrite a single JSON value into writer.

        Value is written as encoded by encoder.encode().
        rU   Nz<--)rR   rk   zContent-Length: z

asciir   )r   r   )rG   r    json_encoder_factoryrE   encoder7   rS   r<   r   rL   r   writeflushswallow_exceptionr	   )
r   r~   encoderrI   r   headerrQ   data_writtenwrittenrZ   s
             r   
write_jsonzJsonIOStream.write_json  s    < 	. !----$0''d6O6O6Q6Q	P>>%((DD 	P 	P 	PeT%[[9NOOOOO	P{{7##7CII777>>wGG}	6T** ,,tLMM':;;& G+L T** LLNNNN 	6 	6 	6eU33HIIIT5555	6 	%'''''s*   A 9B
	B
AD/ /
E193E,,E1c                @    t          |           j         d| j        dS N()typer   r+   rM   s    r   __repr__zJsonIOStream.__repr__3  $    t**%66	6666r   )r$   r3   )r   r   r   r   rq   r   JsonDecoderrl   JsonEncoderr   classmethodr,   r/   r?   r   r8   r   rK   rS   r[   r   r   r   rA   r   r   r#   r#   <   s1        
 M+3+4> > > [> 8 8 8 [8 8 8 8 [8, -1,,    2W W W2 .1Y ; ; ; ;  Y Y Y Yv%( %( %( %(N7 7 7 7 7r   r#   c                       e Zd ZdZd fd	Z fdZd	dZd Z eej	        j
                  Z
 eej	        j                  Z eej	        j                  Z[ xZS )
MessageDicta  A specialized dict that is used for JSON message payloads - Request.arguments,
    Response.body, and Event.body.

    For all members that normally throw KeyError when a requested key is missing, this
    dict raises InvalidMessageError instead. Thus, a message handler can skip checks
    for missing properties, and just work directly with the payload on the assumption
    that it is valid according to the protocol specification; if anything is missing,
    it will be reported automatically in the proper manner.

    If the value for the requested key is itself a dict, it is returned as is, and not
    automatically converted to MessageDict. Thus, to enable convenient chaining - e.g.
    d["a"]["b"]["c"] - the dict must consistently use MessageDict instances rather than
    vanilla dicts for all its values, recursively. This is guaranteed for the payload
    of all freshly received messages (unless and until it is mutated), but there is no
    such guarantee for outgoing messages.
    Nc                    |t          |t                    sJ |!t                                                       n!t                                          |           || _        d S r3   )
isinstanceMessager   r   message)r   r   itemsr   s      r   r   zMessageDict.__init__I  sa    *Wg">">=GGGGU###	 	r   c                    	 t          t          j        |                     S # t          $ r# t	                                                      cY S w xY wr3   )formatr   r<   r7   r   r   )r   r   s    r   r   zMessageDict.__repr__Y  sU    	&$)D//*** 	& 	& 	&77##%%%%%	&s    $ *AAFc                    |sd }ndt          |t                    st          |t                    rt          j        ||          }n#t          |          st          j        |          }|                     |d          }	  ||          }n# t          t          f$ rl}| j
        t          n| j
        }t          |          }|                    d          sd|z   }|                    dt          j        |          |          d}~ww xY w|S )aI  Like get(), but with validation.

        The item is first retrieved as if with self.get(key, default=()) - the default
        value is () rather than None, so that JSON nulls are distinguishable from
        missing properties.

        If optional=True, and the value is (), it's returned as is. Otherwise, the
        item is validated by invoking validate(item) on it.

        If validate=False, it's treated as if it were (lambda x: x) - i.e. any value
        is considered valid, and is returned unchanged. If validate is a type or a
        tuple, it's treated as json.of_type(validate). Otherwise, if validate is not
        callable(), it's treated as json.default(validate).

        If validate() returns successfully, the item is substituted with the value
        it returns - thus, the validator can e.g. replace () with a suitable default
        value for the property.

        If validate() raises TypeError or ValueError, raises InvalidMessageError with
        the same text that applies_to(self.messages).

        See debugpy.common.json for reusable validators.
        c                    | S r3   rA   )xs    r   rB   z&MessageDict.__call__.<locals>.<lambda>y  s     r   )optionalrA   N[ z{0}{1})r   r   tupler   of_typecallabledefaultget	TypeErrorrr   r   r   r   
startswith
isnt_validr<   )r   r|   validater   r~   rZ   r   errs           r   __call__zMessageDict.__call___  s   2  	."{HH$'' 	.:h+F+F 	.|Hx@@@HH(## 	.|H--Hb!!	DHUOOEE:& 	D 	D 	D!%!5gg4<Gc((C>>#&&  Ci$$Xty~~sCCC	D s   B DA'DDc                      fd}|S )Nc                    	  | |g|R i |S # t           $ r, | j        t          n| j        }|                    d|          w xY w)Nzmissing property {0!r})rs   r   r   r   )r   r|   r   r   r   funcs        r   wrapz,MessageDict._invalid_if_no_key.<locals>.wrap  ss    HtD#7777777 H H H%)\%9''t|(()A3GGGHs	    6ArA   )r   r   s   ` r   _invalid_if_no_keyzMessageDict._invalid_if_no_key  s(    	H 	H 	H 	H 	H r   r3   )F)r   r   r   r   r   r   r   r   collectionsOrderedDict__getitem____delitem__r   r   r   s   @r   r   r   7  s         "      & & & & &) ) ) )V   %$[%<%HIIK$$[%<%HIIK

[48
9
9Cr   r   c                      4 dk    r.t           t                    rt           t                    sJ  S  fd}t          d           | _         S )zoJSON validator for message payload.

    If that value is missing or null, it is treated as if it were {}.
    NrA   c                    | _         d S r3   )r   )r   r~   s    r   associate_withz _payload.<locals>.associate_with  s    r   )r   dictr   r   )r~   r   s   ` r   _payloadr     su     Ub[[eT"" 	2e[11111          E)ELr   c                  n    e Zd ZdZddZd Zd Zedd            Zd	 Z	d
 Z
d Zd Zd Zd Zd Zd ZdS )r   zRepresents a fully parsed incoming or outgoing message.

    https://microsoft.github.io/debug-adapter-protocol/specification#protocolmessage
    Nc                2    || _         || _        	 || _        d S r3   )channelseqr   )r   r   r   r   s       r   r   zMessage.__init__  s(    	
 		 	r   c                `    | j         t          j        | j                   nt          |           S r3   )r   r<   rM   s    r   __str__zMessage.__str__  s&    '+y'<ty###$t**Lr   c                    t           )zA brief description of the message that is enough to identify it.

        Examples:
        '#1 request "launch" from IDE'
        '#2 response to #1 request "launch" from IDE'.
        NotImplementedErrorrM   s    r   describezMessage.describe  s
     "!r   returnr   c                    t           )zePayload of the message - self.body or self.arguments, depending on the
        message type.
        r   rM   s    r   payloadzMessage.payload  s
    
 "!r   c                     | j         |i |S )zSame as self.payload(...).r   r   r   r   s      r   r   zMessage.__call__  s    t|T,V,,,r   c                    || j         v S )zSame as (key in self.payload).r   )r   r|   s     r   __contains__zMessage.__contains__  s    dl""r   c                N    t          | t                    sdS |dk    p| j        |v S )zGReturns True if this message is an Event of one of the specified types.FrA   )r   Eventevent)r   r   s     r   is_eventzMessage.is_event  s/    $&& 	5{1djE11r   c                N    t          | t                    sdS |dk    p| j        |v S )zHReturns True if this message is a Request of one of the specified types.FrA   )r   Requestcommandr   r   s     r   
is_requestzMessage.is_request  s/    $(( 	5"}7 77r   c                X    t          | t                    sdS |dk    p| j        j        |v S )zgReturns True if this message is a Response to a request of one of the
        specified types.
        FrA   )r   Responserequestr   r   s     r   is_responsezMessage.is_response  s4     $)) 	5"}? 4 ??r   c                    t          |t                    sJ |                    dd          } |j        |i |} ||| |          }t	          | t
                    r|                     |           |S )ai  Returns a new exception of the specified type from the point at which it is
        invoked, with the specified formatted message as the reason.

        The resulting exception will have its cause set to the Message object on which
        error() was called. Additionally, if that message is a Request, a failure
        response is immediately sent.
        silentF)
issubclassMessageHandlingErrorr   r   r   r   respond)r   exc_typerg   r   r   r   reasonrZ   s           r   errorzMessage.error  s     ($899999He,,%%t6v66hvtV,,dG$$ 	LL
r   c                .     | j         t          g|R i |S )z-Same as self.error(InvalidMessageError, ...).)r   InvalidMessageErrorr   s      r   r   zMessage.isnt_valid  s%    tz-???????r   c                .     | j         t          g|R i |S )z.Same as self.error(MessageHandlingError, ...).)r   r   r   s      r   cant_handlezMessage.cant_handle  s%    tz.@@@@@@@r   r3   )r   r   )r   r   r   r   r   r   r   propertyr   r   r   r   r   r   r   r   r   rA   r   r   r   r     s         
   M M M" " " " " " X"- - -# # #2 2 28 8 8@ @ @  &@ @ @A A A A Ar   r   c                  \     e Zd ZdZd fd	Zd Zed             Zed             Z	d Z
 xZS )	r   a  Represents an incoming event.

    https://microsoft.github.io/debug-adapter-protocol/specification#event

    It is guaranteed that body is a MessageDict associated with this Event, and so
    are all the nested dicts in it. If "body" was missing or null in JSON, body is
    an empty dict.

    To handle the event, JsonMessageChannel tries to find a handler for this event in
    JsonMessageChannel.handlers. Given event="X", if handlers.X_event exists, then it
    is the specific handler for this event. Otherwise, handlers.event must exist, and
    it is the generic handler for this event. A missing handler is a fatal error.

    No further incoming messages are processed until the handler returns, except for
    responses to requests that have wait_for_response() invoked on them.

    To report failure to handle the event, the handler must raise an instance of
    MessageHandlingError that applies_to() the Event object it was handling. Any such
    failure is logged, after which the message loop moves on to the next message.

    Helper methods Message.isnt_valid() and Message.cant_handle() can be used to raise
    the appropriate exception type that applies_to() the Event object.
    Nc                    t                                          |||           || _        t          |t                    r%t          |d          r|                    |            || _        d S Nr   )r   r   r   r   r   hasattrr   r   )r   r   r   r   r   r   r   s         r   r   zEvent.__init__*  si    #t,,,
dK(( 	&WT;K-L-L 	&%%%			r   c                Z    d| j          dt          j        | j                   d| j         S )N#z event  from )r   r   r<   r   r   rM   s    r   r   zEvent.describe3  s0    O48OODIdj$9$9OOOOOr   c                    | j         S r3   r   rM   s    r   r   zEvent.payload6  
    yr   c                     |dt                     } |dt                    } |dt                    }t          | ||||          }|                     ||j                   d S )Nr   r   r   r   )rp   r   r   r   _enqueue_handlers_handle)r   message_dictr   r   r   r   s         r   _parsezEvent._parse:  sk    l5#&&Wc**|FH--eTEEE!!'7?;;;;;r   c           	     T   | j         }|                    d| j                  }	 	  ||           }|5J dt          j        |           d|                                  d            d S # t          $ ri}|                    |           s t          j	        dt          j        |          |                                 t          |                     Y d }~d S d }~ww xY w# t          $ r> t          j        dt          j        |          |                                            Y d S w xY w)Nr   zHandler z tried to respond to .$Handler {0}
couldn't handle {1}:
{2} Handler {0}
couldn't handle {1}:)r   _get_handler_forr   r   	srcnameofr   r   
applies_tor   r   r   r7   rL   r   r   handlerresultrZ   s        r   r   zEvent._handleB  s[   ,**7DJ??	 NN^dnW55^^DMMOO^^^ #NNNN'   ~~d++ 	<N7++MMOOHH	          	 	 	!3w''     	s2   AA) )
C3ACC CC AD'&D'r3   )r   r   r   r   r   r   r   r   staticmethodr   r   r   r   s   @r   r   r     s         0     P P P   X < < \<      r   r   c                  b     e Zd ZdZd	 fd	Zd Zed             Zd Ze	d             Z
d Z xZS )
r   a_  Represents an incoming or an outgoing request.

    Incoming requests are represented directly by instances of this class.

    Outgoing requests are represented by instances of OutgoingRequest, which provides
    additional functionality to handle responses.

    For incoming requests, it is guaranteed that arguments is a MessageDict associated
    with this Request, and so are all the nested dicts in it. If "arguments" was missing
    or null in JSON, arguments is an empty dict.

    To handle the request, JsonMessageChannel tries to find a handler for this request
    in JsonMessageChannel.handlers. Given command="X", if handlers.X_request exists,
    then it is the specific handler for this request. Otherwise, handlers.request must
    exist, and it is the generic handler for this request. A missing handler is a fatal
    error.

    The handler is then invoked with the Request object as its sole argument.

    If the handler itself invokes respond() on the Request at any point, then it must
    not return any value.

    Otherwise, if the handler returns NO_RESPONSE, no response to the request is sent.
    It must be sent manually at some later point via respond().

    Otherwise, a response to the request is sent with the returned value as the body.

    To fail the request, the handler can return an instance of MessageHandlingError,
    or respond() with one, or raise one such that it applies_to() the Request object
    being handled.

    Helper methods Message.isnt_valid() and Message.cant_handle() can be used to raise
    the appropriate exception type that applies_to() the Request object.
    Nc                    t                                          |||           || _        t          |t                    r%t          |d          r|                    |            || _        d | _        d S r   )	r   r   r   r   r   r   r   	argumentsresponse)r   r   r   r   r  r   r   s         r   r   zRequest.__init__  sv    #t,,,i-- 	+')EU2V2V 	+$$T***"	 	r   c                Z    d| j          dt          j        | j                   d| j         S )Nr   	 request r   r   r   r<   r   r   rM   s    r   r   zRequest.describe  s0    S48SSdi&=&=SST\SSSr   c                    | j         S r3   )r  rM   s    r   r   zRequest.payload  s
    ~r   c                T   | j         J d| j        | j        d}t          |t                    rd|d<   t          |          |d<   nd|d<   ||i k    r||d<   | j                            |          5 }	 d d d            n# 1 swxY w Y   t          | j        || |          | _         d S )Nr  )r   request_seqr   Fsuccessr   Tr   )	r  r   r   r   r7   r   r   _send_messager   )r   r   dr   s       r   r   zRequest.respond  s    }$$$T\RRdI&& 	! AiLt99AiLLAiLDBJJ &	\''** 	c	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 sD$??s   3BBBc                     |dt                     } |dt                    } |dt                    }t          | ||||          }|                     ||j                   d S )Nr   r   r  r   )rp   r   r   r   r   r   )r   r   r   r   r  r   s         r   r   zRequest._parse  sk    l5#&&,y#.. Lh77	'3NNN!!'7?;;;;;r   c           	        | j         }|                    d| j                  }	 	  ||           }nw# t          $ rj}|                    |           s |}t          j        dt          j        |          | 	                                t          |                     Y d }~nd }~ww xY w|t          u rK| j        BJ d                    t          j        |          | 	                                                      d S | j        V|P|| j        j        u sDJ d                    t          j        |          | 	                                                      d S d S |BJ d                    t          j        |          | 	                                                      	 |                     |           d S # t           $ r> t          j        dt          j        |          | 	                                           Y d S w xY w# t$          $ r> t          j        dt          j        |          | 	                                           Y d S w xY w)Nr   r  z\Handler {0} for {1} must not return NO_RESPONSE if it has already invoked request.respond().z`Handler {0} for {1} must not return a response body if it has already invoked request.respond().z}Handler {0} for {1} must either call request.respond() before it returns, or return the response body, or return NO_RESPONSE.zLChannel was closed before the response from handler {0} to {1} could be sentr  )r   r  r   r   r  r   r   r   r  r   r   NO_RESPONSEr  r   r   r   r    warningr7   rL   r  s        r   r   zRequest._handle  s   ,**9dlCC1	 ' 	 	 	~~d++ 	<N7++MMOOHH	       		 $$},,117w//2 2 -,,,, *~4=3E)E)E)E99?w//: : *F)E)E~~)E)E ))SSYSYw//T T *))LL(((((%   Kfw//       	 	 	!3w''     	sa   1 H  
B%A B H   B%%AH  <AH  AH  F5 5AG=9H  <G==H   AIIr3   )r   r   r   r   r   r   r   r   r   r
  r   r   r   r   s   @r   r   r   d  s        ! !F     $T T T   X@ @ @  < < \<4 4 4 4 4 4 4r   r   c                  D     e Zd ZdZdxZZ fdZd Zd	dZd Z	d Z
 xZS )
OutgoingRequestzRepresents an outgoing request, for which it is possible to wait for a
    response to be received, and register a response handler.
    Nc                ^    t                                          ||||           g | _        d S r3   )r   r   _response_handlers)r   r   r   r   r  r   s        r   r   zOutgoingRequest.__init__  s/    #w	:::"$r   c                X    | j          dt          j        | j                   d| j         S )Nr  z to r  rM   s    r   r   zOutgoingRequest.describe  s.    (PPTYt|%<%<PP$,PPPr   Tc                    | j         5  | j        %| j         j                                         | j        %ddd           n# 1 swxY w Y   |r| j        j        s| j        j        | j        j        S )a  Waits until a response is received for this request, records the Response
        object for it in self.response, and returns response.body.

        If no response was received from the other party before the channel closed,
        self.response is a synthesized Response with body=NoMoreMessages().

        If raise_if_failed=True and response.success is False, raises response.body
        instead of returning.
        N)r   r  _handlers_enqueuedwaitr  r   )r   raise_if_faileds     r   wait_for_responsez!OutgoingRequest.wait_for_response  s     \ 	7 	7-'/44666 -'	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7  	%4=#8 	%-$$}!!s   -AAAc                    | j         5  | j                            |           |                                  ddd           dS # 1 swxY w Y   dS )a=  Registers a handler to invoke when a response is received for this request.
        The handler is invoked with Response as its sole argument.

        If response has already been received, invokes the handler immediately.

        It is guaranteed that self.response is set before the handler is invoked.
        If no response was received from the other party before the channel closed,
        self.response is a dummy Response with body=NoMoreMessages().

        The handler is always invoked asynchronously on an unspecified background
        thread - thus, the caller of on_response() can never be blocked or deadlocked
        by the handler.

        No further incoming messages are processed until the handler returns, except for
        responses to requests that have wait_for_response() invoked on them.
        N)r   r  rw   _enqueue_response_handlers)r   response_handlers     r   on_responsezOutgoingRequest.on_response  s    $ \ 	. 	.#**+;<<<++---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   /AAAc                    | j         d S fd}| j        d d          | j                            |           | j        d d = d S )Nc            
        D ]} 	 	  |            nu# t           $ rh}|                              s t          j        dt	          j        |                                           t          |                     Y d }~nd }~ww xY w# t          $ r= t          j	        dt	          j        |                                                      Y w xY wd S )Nr  r  )
r   r  r   r   r   r  r   r   r7   rL   )r  rZ   handlersr  s     r   run_handlersz@OutgoingRequest._enqueue_response_handlers.<locals>.run_handlers-  s    #  
))))/   "~~h77 "!	D N733$--//HH	        !   );w// ))++     s3   B

BAB<B
BB

ACC)r  r  r   r   )r   r-  r,  r  s     @@r   r'  z*OutgoingRequest._enqueue_response_handlers'  st    =F	 	 	 	 	 	* *111-&&x>>>#AAA&&&r   )T)r   r   r   r   r   r   r   r   r%  r)  r'  r   r   s   @r   r  r    s          FW% % % % %Q Q Q" " " "&. . .,' ' ' ' ' ' 'r   r  c                       e Zd ZdZd	 fd	Zd Zed             Zed             Zed             Z	e
d	d            Z xZS )
r   a^  Represents an incoming or an outgoing response to a Request.

    https://microsoft.github.io/debug-adapter-protocol/specification#response

    error_message corresponds to "message" in JSON, and is renamed for clarity.

    If success is False, body is None. Otherwise, it is a MessageDict associated
    with this Response, and so are all the nested dicts in it. If "body" was missing
    or null in JSON, body is an empty dict.

    If this is a response to an outgoing request, it will be handled by the handler
    registered via self.request.on_response(), if any.

    Regardless of whether there is such a handler, OutgoingRequest.wait_for_response()
    can also be used to retrieve and handle the response. If there is a handler, it is
    executed before wait_for_response() returns.

    No further incoming messages are processed until the handler returns, except for
    responses to requests that have wait_for_response() invoked on them.

    To report failure to handle the event, the handler must raise an instance of
    MessageHandlingError that applies_to() the Response object it was handling. Any
    such failure is logged, after which the message loop moves on to the next message.

    Helper methods Message.isnt_valid() and Message.cant_handle() can be used to raise
    the appropriate exception type that applies_to() the Response object.
    Nc                    t                                          |||           || _        	 t          |t                    r%t          |d          r|                    |            || _        d S r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   s         r   r   zResponse.__init__d  sr    #t,,,8dK(( 	&WT;K-L-L 	&%%%	
	 
	r   c                J    d| j          d| j                                         S )Nr   z response to )r   r   r   rM   s    r   r   zResponse.describey  s(    C48CC$,*?*?*A*ACCCr   c                    | j         S r3   r   rM   s    r   r   zResponse.payload|  r   r   c                8    t          | j        t                     S )z%Whether the request succeeded or not.)r   r   r7   rM   s    r   r  zResponse.success  s     di3333r   c                ,    | j         r| j        S | j        )zResult of the request. Returns the value of response.body, unless it
        is an exception, in which case it is raised instead.
        )r  r   rM   s    r   r	  zResponse.result  s    
 < 	9)Or   c                &   | |dt                     nd } |dt                     } |dt                    } |dt                    }||r |dt                    }nl |dt                    }t          }|                    t          j                  r(|t          t          j                  d          }t          } ||d          }	 | 5  | j	        
                    |          }	d}
d d d            n# 1 swxY w Y   n$# t          $ r t          | ||d	          }	d
}
Y nw xY w|s|	|_        t          | ||	||          }| 5  ||	_        |	                                 d d d            n# 1 swxY w Y   |
r|S |                    d|          )Nr   r  r   r  r   r   Tr   z	<unknown>Fr   z0request_seq={0} does not match any known request)rp   r   boolr   r   r   r   PREFIXr   _sent_requestsr   rs   r  r   r   r  r'  r   )r   r   r   r   r  r   r  error_messager   r   known_requestr  s               r   r   zResponse._parse  sU   +/<ll5#&&&d"l=#66,y#..,y$//< <#|FH55 ,Y < </ ++,?,FGG 3$1#6I6P2Q2Q2S2S$TM2Hxd;;;	" % %!044[AA $% % % % % % % % % % % % % % %  	" 	" 	" &g{G[QQG!MMM		"  	! DJGS'4lKKK 	1 	1'G..000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1  	O%%BK  sH   D C7+D 7C;;D >C;?D D$#D$E..E25E2r3   )r   r   r   r   r   r   r   r   r  r	  r
  r   r   r   s   @r   r   r   G  s         8     *D D D   X 4 4 X4   X ( ( ( \( ( ( ( (r   r   c                  (     e Zd ZdZ fdZd Z xZS )
DisconnectznA dummy message used to represent disconnect. It's always the last message
    received from any channel.
    c                L    t                                          |d            d S r3   )r   r   )r   r   r   s     r   r   zDisconnect.__init__  s#    $'''''r   c                    d| j          S )Nzdisconnect from )r   rM   s    r   r   zDisconnect.describe  s    0$,000r   )r   r   r   r   r   r   r   r   s   @r   r<  r<    sQ         ( ( ( ( (1 1 1 1 1 1 1r   r<  c                  D    e Zd ZdZddZd Zd Zd Zd Zd	 Z	d
 Z
d ZdS )r   a  Indicates that a message couldn't be handled for some reason.

    If the reason is a contract violation - i.e. the message that was handled did not
    conform to the protocol specification - InvalidMessageError, which is a subclass,
    should be used instead.

    If any message handler raises an exception not derived from this class, it will
    escape the message loop unhandled, and terminate the process.

    If any message handler raises this exception, but applies_to(message) is False, it
    is treated as if it was a generic exception, as desribed above. Thus, if a request
    handler issues another request of its own, and that one fails, the failure is not
    silently propagated. However, a request that is delegated via Request.delegate()
    will also propagate failures back automatically. For manual propagation, catch the
    exception, and call exc.propagate().

    If any event handler raises this exception, and applies_to(event) is True, the
    exception is silently swallowed by the message loop.

    If any request handler raises this exception, and applies_to(request) is True, the
    exception is silently swallowed by the message loop, and a failure response is sent
    with "message" set to str(reason).

    Note that, while errors are not logged when they're swallowed by the message loop,
    by that time they have already been logged by their __init__ (when instantiated).
    NFc                    || _         	 |t          |t                    sJ || _        	 |s'	 | # t          $ r t          j                     Y dS w xY wdS )a  Creates a new instance of this class, and immediately logs the exception.

        Message handling errors are logged immediately unless silent=True, so that the
        precise context in which they occured can be determined from the surrounding
        log entries.
        N)r   r   r   r   r   r   r   )r   r   r   r   s       r   r   zMessageHandlingError.__init__  s     	 }
5' : :}}}
	  	((
' ( ( (%''''''(	( 	(s   / AAc                R    t          | j        t          | j                  f          S r3   )hashr   idr   rM   s    r   __hash__zMessageHandlingError.__hash__  s    T["TZ..1222r   c                    t          |t                    st          S t          |           t          |          urt          S | j        |j        k    rdS | j        #|j        | j        j        |j        j        k    rdS dS )NFT)r   r   NotImplementedr   r   r   r   r   others     r   __eq__zMessageHandlingError.__eq__  sx    %!566 	"!!::T%[[((!!;%,&&5:!ek&=z~00utr   c                    | |k     S r3   rA   rG  s     r   __ne__zMessageHandlingError.__ne__  s    5=  r   c                *    t          | j                  S r3   )r   r   rM   s    r   r   zMessageHandlingError.__str__  s    4;r   c                    t          |           j        }| j        |d| j        dz  }n-|d| j        j        j        d| j        j        d| j        dz  }|S )Nzreason=r   zchannel=z, cause=z	, reason=)r   r   r   r   r   r+   r   )r   ss     r   r   zMessageHandlingError.__repr__  sm    JJ:+4;++++AAjDJ.3jjtz~jjZ^ZejjjjAr   c                &    | j         du p| j         |u S )zWhether this MessageHandlingError can be treated as a reason why the
        handling of message failed.

        If self.cause is None, this is always true.

        If self.cause is not None, this is only true if cause is message.
        N)r   r   r   s     r   r  zMessageHandlingError.applies_to  s     zT!:TZ7%::r   c                B     t          |           | j        |d          )z}Propagates this error, raising a new instance of the same class with the
        same reason, but a different cause.
        Tr5  )r   r   )r   	new_causes     r   	propagatezMessageHandlingError.propagate#  s#     d4jji====r   )NF)r   r   r   r   r   rD  rI  rK  r   r   r  rS  rA   r   r   r   r     s         6( ( ( (23 3 3
 
 
! ! !       ; ; ;> > > > >r   r   c                      e Zd ZdZdZ	 d ZdS )r   a  Indicates that an incoming message did not follow the protocol specification -
    for example, it was missing properties that are required, or the message itself
    is not allowed in the current state.

    Raised by MessageDict in lieu of KeyError for missing keys.
    zInvalid message: c                D    t           j        t          | j                  z   S r3   )r   r7  r   r   rM   s    r   r   zInvalidMessageError.__str__:  s    ")C,<,<<<r   N)r   r   r   r   r7  r   rA   r   r   r   r   *  s9          !F= = = = =r   r   c                      e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 ZdZd Zej        d             ZddZddZd Zd Zd Zd Zej        ej        ej        dZd Zd Zd Zd Zd Z dS )JsonMessageChannela|  Implements a JSON message channel on top of a raw JSON message stream, with
    support for DAP requests, responses, and events.

    The channel can be locked for exclusive use via the with-statement::

        with channel:
            channel.send_request(...)
            # No interleaving messages can be sent here from other threads.
            channel.send_event(...)
    Nc                4   || _         || _        ||n|j        | _        d| _        t	          j                    | _        d| _        t          j	        d          | _
        i | _        g | _        t	          j        | j                  | _        d | _        d | _        d S )NF   )r   r,  r+   started	threadingRLock_lockrG   	itertoolscount	_seq_iterr8  _handler_queue	Conditionr"  _handler_thread_parser_thread)r   r   r,  r+   s       r   r   zJsonMessageChannel.__init__J  s      ,DD&+	_&&
"++  "+"5dj"A"A#"r   c                    | j         S r3   rO   rM   s    r   r   zJsonMessageChannel.__str__X  s
    yr   c                @    t          |           j         d| j        dS r   r   rM   s    r   r   zJsonMessageChannel.__repr__[  r   r   c                8    | j                                          | S r3   )r]  acquirerM   s    r   	__enter__zJsonMessageChannel.__enter__^  s    
r   c                8    | j                                          d S r3   )r]  release)r   r   	exc_valueexc_tbs       r   __exit__zJsonMessageChannel.__exit__b  s    
r   c                    | 5  | j         s d| _         | j                                         ddd           dS # 1 swxY w Y   dS )a  Closes the underlying stream.

        This does not immediately terminate any handlers that are already executing,
        but they will be unable to respond. No new request or event handlers will
        execute after this method is called, even for messages that have already been
        received. However, response handlers will continue to executed for any request
        that is still pending, as will any handlers registered via on_response().
        TN)rG   r   r8   rM   s    r   r8   zJsonMessageChannel.closee  s      	$ 	$< $#!!###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   (8<<c                    | j         rJ d| _         t          j        | j        |  d          | _        t          | j                   d| j        _        | j                                         dS )a  Starts a message loop which parses incoming messages and invokes handlers
        for them on a background thread, until the channel is closed.

        Incoming messages, including responses to requests, will not be processed at
        all until this is invoked.
        Tz message parsertargetr+   N)rZ  r[  Thread_parse_incoming_messagesrd  r   daemonstartrM   s    r   rv  zJsonMessageChannel.starts  s}     <'.0$7O7O7O
 
 
 	"$"5666%)"!!#####r   c                   | j         }	 ||                                 n$# t          $ r t          j        d           Y nw xY w	 | j        }||                                 dS dS # t          $ r t          j        d           Y dS w xY w)z}Waits for the message loop to terminate, and for all enqueued Response
        message handlers to finish executing.
        Nz$Handled error joining parser thread.z%Handled error joining handler thread.)rd  re   AssertionErrorr   rK   rc  )r   parser_threadhandler_threads      r   r#  zJsonMessageChannel.wait  s     +	>(""$$$ 	> 	> 	>I<=====	>	?!1N)##%%%%% *) 	? 	? 	?I=>>>>>>	?s!     A AA& &BB)
r   r   r  r  r   r   r   r  r   r   c                D    | j         D ]}||vr||         }||= |||<   dS )z>Reorders items in a MessageDict such that it is more readable.N)_prettify_order)r   r   r|   r~   s       r   	_prettifyzJsonMessageChannel._prettify  sK    ' 	& 	&C,&& %ES! %L	& 	&r   c              #  8  K   d|vsJ | 5  t          | j                  }ddd           n# 1 swxY w Y   t          d|          }||d<   |                     |           | 5  |V  | j                            |           ddd           dS # 1 swxY w Y   dS )a  Sends a new message to the other party.

        Generates a new sequence number for the message, and provides it to the
        caller before the message is sent, using the context manager protocol::

            with send_message(...) as seq:
                # The message hasn't been sent yet.
                ...
            # Now the message has been sent.

        Safe to call concurrently for the same channel from different threads.
        r   N)nextr`  r   r}  r   r   )r   r   r   s      r   r  z JsonMessageChannel._send_message  s8      G#### 	' 	't~&&C	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' dG,,w 	, 	,IIIK""7+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   ,00#BBBc                    d|d}||i k    r||d<   |                      |          5 }t          | |||          }| ||           || j        |<   ddd           n# 1 swxY w Y   |S )a  Sends a new request, and returns the OutgoingRequest object for it.

        If arguments is None or {}, "arguments" will be omitted in JSON.

        If on_before_send is not None, invokes on_before_send() with the request
        object as the sole argument, before the request actually gets sent.

        Does not wait for response - use OutgoingRequest.wait_for_response().

        Safe to call concurrently for the same channel from different threads.
        r   )r   r   Nr  )r  r  r8  )r   r   r  on_before_sendr  r   r   s          r   send_requestzJsonMessageChannel.send_request  s     733 Y"__&AkN"" 	/c%dC)DDG)w''''.D$		/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/
 s   *AA"%A"c                    d|d}||i k    r||d<   |                      |          5  	 ddd           dS # 1 swxY w Y   dS )zSends a new event.

        If body is None or {}, "body" will be omitted in JSON.

        Safe to call concurrently for the same channel from different threads.
        r   )r   r   Nr   )r  )r   r   r   r  s       r   
send_eventzJsonMessageChannel.send_event  s     u--

AfI"" 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   7;;c                @     | j         |i |                                S )z-Same as send_request(...).wait_for_response())r  r%  r   s      r   r   zJsonMessageChannel.request  s&     t $1&11CCEEEr   c                   |                                 s|                                sJ |                                 r |                     |j        |j                  S |                     |j        |j                   dS )zSends a new message with the same type and payload.

        If it was a request, returns the new OutgoingRequest object for it.
        N)r   r   r  r   r  r  r   r   rP  s     r   rS  zJsonMessageChannel.propagate  sz    
 !!##9w'7'7'9'9999 	9$$W_g6GHHHOOGM7<88888r   c                    	 |                      |          }|                                r|                                }|S # t          $ r }|                     |           Y d}~dS d}~ww xY w)z~Like propagate(message).wait_for_response(), but will also propagate
        any resulting MessageHandlingError back.
        N)rS  r   r%  r   )r   r   r	  rZ   s       r   delegatezJsonMessageChannel.delegate   s    	#^^G,,F  "" 41133M# 	# 	# 	#MM'"""""""""	#s   >A 
A+A&&A+c                   t          j        d|            	 	 |                                  # t          $ r
}t          j        d| |           | 5  t	          |          }t          | j                                                  }|D ]?}t          d d|j	        |j
        d|d          }t                              | ||           @t          | j                  rJ |                     t          |           | j                   |                                  d d d            n# 1 swxY w Y   Y d }~d S Y d }~d S d }~ww xY w)Nz%Starting message loop for channel {0}Tz)Exiting message loop for channel {0}: {1}F)r   r  r   r  r   r   )r   rK   _parse_incoming_messager    r   listr8  valuesr   r   r   r   r   r   r   r<  _handle_disconnectr8   )r   rZ   err_messagesent_requestsr   response_jsons         r   rt  z+JsonMessageChannel._parse_incoming_messages  s   	94@@@	/,,.../  	 	 	IA4MMM  !#hh !%T%8%?%?%A%A B B, C CG$/#%+2;'.','2 	% 	%M OOD-cOBBBBt233333&&z$'7'79PQQQ

/                          	s9   - ED=C
D&D=&D*	*D=-D*	.D==E)r   r   r  c           	          fd}fdg  j                             |          } j                             |          }t          |t                    sJ  |dt          j        ddd                    } j        |         }	  | |           d	S # t          $ rA}t          j
        d t          |          t          j        |                     Y d	}~d	S d	}~wt          $ rk}t          |t                    r|j          j         u r t          j        d
 t          j        |                     t!          j        d           Y d	}~d	S d	}~ww xY w)zReads incoming messages, parses them, and puts handlers into the queue
        for _run_handlers() to invoke, until the channel is closed.
        c                    t          d |           } d| v r                    |            | _                            |            | S )Nr   )r   r}  r   rw   )r  r   message_dictsr   s    r   object_hookz?JsonMessageChannel._parse_incoming_message.<locals>.object_hook;  sN    D!$$Azzq!!!-A  ###Hr   c                $    D ]}| |_         |`d S r3   )r   r   )r   r  r  s     r   r   zBJsonMessageChannel._parse_incoming_message.<locals>.associate_withM  s,    " % %#	$$% %r   )r  r   r   r   r  z3Failed to parse message in channel {0}: {1} in:
{2}Nz-Fatal error in channel {0} while parsing:
{1}rY  )r   rl   r   r   r   r   enum_message_parsersr   r   r   r   r<   r7   r    r   os_exit)	r   r  ry   r   msg_typeparserrZ   r   r  s	   `      @@r   r  z*JsonMessageChannel._parse_incoming_message3  s   	 	 	 	 	 	 	$	% 	% 	% 	% 	%
 +22{2KK{,,W55,44444<	'9j(Q(QRR&x0	F4&&&&&" 	 	 	IFC	,''	          	 	 	#~.. 3:3L3L!@	,''  
 HQKKKKKKKKK	s%   B 
E$6C  E-A EEc                   | 5  | j                             fd|D                        | j                                         t	          | j                   rW| j        Pt          j        | j        |  d          | _        t          | j                   | j        
                                 ddd           dS # 1 swxY w Y   dS )zEnqueues handlers for _run_handlers() to run.

        `what` is the Message being handled, and is used for logging purposes.

        If the background thread with _run_handlers() isn't running yet, starts it.
        c              3      K   | ]}|fV  	d S r3   rA   )rb   r  whats     r   rc   z7JsonMessageChannel._enqueue_handlers.<locals>.<genexpr>u  s'      &O&O7g&O&O&O&O&O&Or   Nz message handlerrq  )ra  extendr"  
notify_allr   rc  r[  rs  _run_handlersr   rv  )r   r  r,  s    ` r   r   z$JsonMessageChannel._enqueue_handlersl  s!     	- 	-&&&O&O&O&Oh&O&O&OOOO#..000 4&'' -D,@,H'0'7- 222( ( ($ *$*>???$**,,,'	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   B+B<<C C c                   	 | 5  | j         }ddd           n# 1 swxY w Y   |r| j                                         | 5  |s-t          | j                  s| j                                         | j        dd         }| j        dd= |r$t          |          sd| _        	 ddd           dS ddd           n# 1 swxY w Y   |D ]\  }}|r|t          j	        t          j	        fv r"t          j        d|                                          5  	  |             n8# t          $ r+ |                                  t!          j        d           Y nw xY wddd           n# 1 swxY w Y   n)zRuns enqueued handlers until the channel is closed, or until the handler
        queue is empty once the channel is closed.
        TNz/handling {0}/
rY  )rG   rd  re   r   ra  r"  r#  rc  r   r   r   r   prefixedr   r7   r8   r  r  )r   closedr,  r  r  s        r   r  z JsonMessageChannel._run_handlers  sw   
)	$ & && & & & & & & & & & & & & & & + #((***    3c$*=&>&> 3+00222  .qqq1'* #h-- 
 ,0D(                      " "* $ $g
  g%-)III\"4dmmooFF $ $$				$ $ $ $

$$ $ $ $ $ $ $ $ $ $ $ $ $ $ $G)	$sU    A"B;;B?B?E"
DE"2EE"EE""E&	)E&	c                   | 5  | j         }ddd           n# 1 swxY w Y   |dz   |z   |fD ]$}	 t          ||          c S # t          $ r Y !w xY wt          d                    t	          j        |          | ||                    )z2Returns the handler for a message of a given type.Nr}   z?handler object {0} for channel {1} has no handler for {2} {3!r})r,  getattrAttributeErrorr   r   r  )r   r   r+   r,  handler_names        r   r  z#JsonMessageChannel._get_handler_for  s      	% 	%}H	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% "CZ$.5 	 	Lx66666!    MTTx((	 
 
 	
s   A
AAc                    t          | j        dd           }	  |             d S # t          $ r, t          j        dt          j        |          |            Y d S w xY w)N
disconnectc                     d S r3   rA   rA   r   r   rB   z7JsonMessageChannel._handle_disconnect.<locals>.<lambda>  s    t r   z0Handler {0}
couldn't handle disconnect from {1}:)r  r,  r7   r   rL   r   r  )r   r  s     r   r  z%JsonMessageChannel._handle_disconnect  s}    $-||DD	GIIIII 	 	 	!Cw''     	s   
% 2AA)NNr3   )!r   r   r   r   r   r   r   ri  rn  r8   rv  r#  r|  r}  
contextlibcontextmanagerr  r  r  r   rS  r  rt  r   r   r   r   r  r  r   r  r  r  rA   r   r   rW  rW  >  s       	 	# # # #  7 7 7    $ $ $$ $ $&? ? ?&O& & & , , ,4   0   F F F	9 	9 	9
# 
# 
#  D >O 7 7 7r- - -:.$ .$ .$`
 
 
*	 	 	 	 	r   rW  c                      e Zd ZdZd ZdS )MessageHandlerszA simple delegating message handlers object for use with JsonMessageChannel.
    For every argument provided, the object gets an attribute with the corresponding
    name and value.
    c                \    |                                 D ]\  }}t          | ||           d S r3   )r   setattr)r   r   r+   r   s       r   r   zMessageHandlers.__init__  s<     ,,.. 	& 	&JD$D$%%%%	& 	&r   N)r   r   r   r   r   rA   r   r   r  r    s-         
& & & & &r   r  )&r   
__future__r   r   r  rm   r^  r  r5   r&   r[  debugpy.commonr   r   r   debugpy.common.utilr   rt   r	   rv   r    objectr#   r   r   r   r   r   r  r   r  r   r<  r7   r   r   rW  r  rA   r   r   <module>r     s  
  # " " " " "                 				  



     * * * * * * * * * * 9 9 9 9 9 90 0 0 0 0' 0 0 0.* * * * *[( * * *x7 x7 x7 x7 x76 x7 x7 x7va a a a a+) a a aH  .\A \A \A \A \Af \A \A \A~H H H H HG H H HV fhhI I I I Ig I I IXT' T' T' T' T'g T' T' T'nq q q q qw q q qh	1 	1 	1 	1 	1 	1 	1 	1`> `> `> `> `>9 `> `> `>F= = = = =. = = =(Y Y Y Y Y Y Y Yx& & & & &f & & & & &r   