
    Mh                         d dl Z d dlmZmZmZmZ dZ G d de          Z G d dej	                  Z
d Z G d	 d
e          ZdS )    N)jsonlog	messagingutil<   c                        e Zd Z fdZ xZS )ComponentNotAvailablec                 Z    t                                          |j         d           d S )Nz is not available)super__init____name__)selftype	__class__s     Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/debugpy/adapter/components.pyr   zComponentNotAvailable.__init__   s,    DM<<<=====    )r   
__module____qualname__r   __classcell__r   s   @r   r	   r	      s8        > > > > > > > > >r   r	   c                        e Zd ZdZd fd	Zd Zed             Zed             Zed             Z	d Z
ed	             Zd
 Z xZS )	Componenta  A component managed by a debug adapter: client, launcher, or debug server.

    Every component belongs to a Session, which is used for synchronization and
    shared data.

    Every component has its own message channel, and provides message handlers for
    that channel. All handlers should be decorated with @Component.message_handler,
    which ensures that Session is locked for the duration of the handler. Thus, only
    one handler is running at any given time across all components, unless the lock
    is released explicitly or via Session.wait_for().

    Components report changes to their attributes to Session, allowing one component
    to wait_for() a change caused by another component.
    Nc                 B    |d u |d u z  sJ 	 |j                             d          }|s
J d            	 |j                                          n# |j                                          w xY wt                                                       | _        |>t                     |_        t          j	        |           }|
                                 n't                     x|_        |j        _         |_        | _        d _         xj         fdgz  c_        d S )NF)blockingz6__init__ of a Component subclass must lock its SessionTc                  6    j                                         S N)sessionnotify_changed)_r   s    r   <lambda>z$Component.__init__.<locals>.<lambda>:   s    dl&A&A&C&C r   )lockacquirereleaser   r   r   strnamer   JsonMessageChannelstartstreamhandlerschannelis_connected	observers)r   r   r(   r*   	lock_heldr   s   `    r   r   zComponent.__init__"   s$   $7d?3333	#,,e,<<IVVVVVVVL  """"GL  """"?d))FK264@@GMMOOOO14T:GL7>.#G  	CCCCDDs   'A A,c                 J    t          |           j         d| j        j         dS )N[])r   r   r   idr   s    r   __str__zComponent.__str__<   s&    t**%::::::r   c                     | j         j        S r   )r   clientr2   s    r   r5   zComponent.client?       |""r   c                     | j         j        S r   )r   launcherr2   s    r   r8   zComponent.launcherC   s    |$$r   c                     | j         j        S r   )r   serverr2   s    r   r:   zComponent.serverG   r6   r   c                 &     | j         j        |i |S r   )r   wait_for)r   argskwargss      r   r<   zComponent.wait_forK   s    $t|$d5f555r   c                 F     t          j                    fd            }|S )a  Applied to a message handler to automatically lock and unlock the session
        for its duration, and to validate the session state.

        If the handler raises ComponentNotAvailable or JsonIOError, converts it to
        Message.cant_handle().
        c                    	 | j         5   | |          cd d d            S # 1 swxY w Y   d S # t          $ r}|                    d|d          d }~wt          j        $ r*}|j        |u r |                    |           Y d }~d S d }~wt          j        $ r'}|                    d|j        j	        d          d }~ww xY w)N{0}T)silentz{0} disconnected unexpectedly)
r   r	   cant_handler   MessageHandlingErrorcause	propagateJsonIOErrorr(   r%   )r   messageexcfs      r   lock_and_handlez2Component.message_handler.<locals>.lock_and_handleW   sN   \ , ,1T7++, , , , , , , , , , , , , , , , , ,( C C C))%T)BBB1 + + +9''MM'*********(   ))3SZ_T *   sD   0 #0 '0 '0 
CAC$B		C"B==C)	functoolswraps)rJ   rK   s   ` r   message_handlerzComponent.message_handlerN   s;     
			 	 	 	 
		  r   c                     | j         5  d| _        | j                             d                    |                      d d d            d S # 1 swxY w Y   d S )NFz{0} has disconnected)r   r+   finalizeformatr2   s    r   
disconnectzComponent.disconnectj   s    \ 	G 	G %DL!!"8"?"?"E"EFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   5A

AA)NN)r   r   r   __doc__r   r3   propertyr5   r8   r:   r<   staticmethodrN   rR   r   r   s   @r   r   r      s         E E E E E E4; ; ; # # X# % % X% # # X#6 6 6   \6G G G G G G Gr   r   c                 R      G fddt                     } fd |            S )Nc                   ,    e Zd ZdZ fdxZZd xZZdS )missing.<locals>.MissingzoA dummy component that raises ComponentNotAvailable whenever some
        attribute is accessed on it.
        c                                  S r    )r   r   reports     r   r    z!missing.<locals>.Missing.<lambda>v   s    VVXX r   c                     dS )NFrZ   r2   s    r   r    z!missing.<locals>.Missing.<lambda>w   s    e r   N)r   r   r   rS   __getattr____setattr____bool____nonzero__)r[   s   r   MissingrX   q   s;        	 	 %>$=$=$==k!3!33;;;r   ra   c                      	 t                    # t          $ r!} t          j        d|            Y d } ~ d S d } ~ ww xY w)Nz
{0} in {1})r	   	Exceptionr   reraise_exception)rI   r   r   s    r   r[   zmissing.<locals>.reporty   s\    	>'--- 	> 	> 	>!,W=========	>s    
=8=)object)r   r   ra   r[   s   `` @r   missingrf   p   se    4 4 4 4 4 4 4& 4 4 4> > > > > > 799r   c                   *    e Zd ZdZi Z	 d Zd Zd ZdS )CapabilitieszA collection of feature flags for a component. Corresponds to JSON properties
    in the DAP "initialize" request or response, other than those that identify the
    party.
    c                    |                     d          s|                    d          sJ || _        |j        }| j                                        D ]\  }}|                    |d          }t          |          st          j	        |          }	  ||          }n;# t          $ r.}|                    dt          j        |          |          d}~ww xY w|dk    sJ | d            || |<   t          j        d|            dS )zParses an "initialize" request or response and extracts the feature flags.

        For every "X" in self.PROPERTIES, sets self["X"] to the corresponding value
        from message.payload if it's present there, or to the default value otherwise.
        
initializerZ   z{0} {1}Nz5 must provide a default value for missing properties.rA   )
is_requestis_response	componentpayload
PROPERTIESitemsgetcallabler   defaultrc   
isnt_validreprr   debug)r   rm   rH   rn   r%   validatevaluerI   s           r   r   zCapabilities.__init__   s/    !!,//T73F3F|3T3TTTT"/"o3355 	 	ND(KKb))EH%% 2<11J  J J J((DIdOOSIIIJ QQQ DJJ	%s   B
C))CCc                 r    t          |           j         dt          j        t	          |                      S )Nz: )r   r   r   ru   dictr2   s    r   __repr__zCapabilities.__repr__   s/    t**%@@4::)>)>@@@r   c                     |D ]:}| |         s0t          j        | j         dt          j        |                     ;d S )Nz does not have capability )r   rD   rm   r   ru   )r   keyskeys      r   requirezCapabilities.require   s\     	 	C9 4~QQ3QQ  	 	r   N)r   r   r   rS   ro   r   r{   r   rZ   r   r   rh   rh      sZ         
 J  :A A A    r   rh   )rL   debugpy.commonr   r   r   r   ACCEPT_CONNECTIONS_TIMEOUTrc   r	   
Observabler   rf   rz   rh   rZ   r   r   <module>r      s   
     5 5 5 5 5 5 5 5 5 5 5 5   > > > > >I > > >
[G [G [G [G [G [G [G [G|  $5 5 5 5 54 5 5 5 5 5r   