o
    à›hx  ã                   @   sb   d dl Z d dlmZmZmZmZ dZG dd„ deƒZG dd„ dej	ƒZ
dd	„ ZG d
d„ deƒZdS )é    N)ÚjsonÚlogÚ	messagingÚutilé<   c                       s   e Zd Z‡ fdd„Z‡  ZS )ÚComponentNotAvailablec                    s   t ƒ  |j› d�¡ d S )Nz is not available)ÚsuperÚ__init__Ú__name__)ÚselfÚtype©Ú	__class__© úPc:\Users\shubh\Videos\agent\nova\Lib\site-packages\debugpy/adapter/components.pyr	      s   zComponentNotAvailable.__init__)r
   Ú
__module__Ú__qualname__r	   Ú__classcell__r   r   r   r   r      s    r   c                       sj   e Zd ZdZd‡ fdd„	Zdd„ Zedd„ ƒZed	d
„ ƒZedd„ ƒZ	dd„ Z
edd„ ƒZdd„ Z‡  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                    sÂ   |d u |d u A s
J ‚z|j jdd�}|sJ dƒ‚W |j  ¡  n|j  ¡  w tƒ  ¡  |ˆ _|d u rAtˆ ƒ|_t 	|ˆ ¡}| 
¡  ntˆ ƒ |_|j_ˆ |_|ˆ _dˆ _ˆ  j‡ fdd„g7  _d S )NF)Úblockingz6__init__ of a Component subclass must lock its SessionTc                     s
   ˆ j  ¡ S ©N)ÚsessionZnotify_changed)Ú_©r   r   r   Ú<lambda>:   s   
 z$Component.__init__.<locals>.<lambda>)ÚlockÚacquireÚreleaser   r	   r   ÚstrÚnamer   ZJsonMessageChannelÚstartÚstreamÚhandlersÚchannelÚis_connectedZ	observers)r   r   r!   r#   Ú	lock_heldr   r   r   r	   "   s    


zComponent.__init__c                 C   s   t | ƒj› d| jj› d�S )Nú[ú])r   r
   r   Úidr   r   r   r   Ú__str__<   s   zComponent.__str__c                 C   ó   | j jS r   )r   Úclientr   r   r   r   r+   ?   ó   zComponent.clientc                 C   r*   r   )r   Úlauncherr   r   r   r   r-   C   r,   zComponent.launcherc                 C   r*   r   )r   Úserverr   r   r   r   r.   G   r,   zComponent.serverc                 O   s   | j j|i |¤ŽS r   )r   Úwait_for)r   ÚargsÚkwargsr   r   r   r/   K   s   zComponent.wait_forc                    s   t  ˆ ¡‡ fd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              
      sÊ   z| j � ˆ | |ƒW  d   ƒ W S 1 sw   Y  W d S  ty0 } z|jd|dd�‚d }~w tjyN } z|j|u r>‚ | |¡ W Y d }~d S d }~w tjyd } z
|jd|jj	dd�‚d }~ww )Nú{0}T)Zsilentz{0} disconnected unexpectedly)
r   r   Zcant_handler   ÚMessageHandlingErrorÚcauseÚ	propagateZJsonIOErrorr!   r   )r   ÚmessageÚexc©Úfr   r   Úlock_and_handleW   s$   (ÿ€
€
ÿ€ÿz2Component.message_handler.<locals>.lock_and_handle)Ú	functoolsÚwraps)r9   r:   r   r8   r   Úmessage_handlerN   s   	zComponent.message_handlerc                 C   sD   | j � d| _| j  d | ¡¡ W d   ƒ d S 1 sw   Y  d S )NFz{0} has disconnected)r   r$   ÚfinalizeÚformatr   r   r   r   Ú
disconnectj   s   "þzComponent.disconnect)NN)r
   r   r   Ú__doc__r	   r)   Úpropertyr+   r-   r.   r/   Ústaticmethodr=   r@   r   r   r   r   r   r      s    



r   c                    s(   G ‡ fdd„dt ƒ}‡‡fdd„‰ |ƒ S )Nc                       s,   e Zd ZdZ‡ fdd„ ZZdd„  ZZdS )zmissing.<locals>.MissingzoA dummy component that raises ComponentNotAvailable whenever some
        attribute is accessed on it.
        c                    s   ˆ ƒ S r   r   )r   r   ©Úreportr   r   r   v   s    z!missing.<locals>.Missing.<lambda>c                 S   s   dS )NFr   r   r   r   r   r   w   s    N)r
   r   r   rA   Ú__getattr__Ú__setattr__Ú__bool__Ú__nonzero__r   rD   r   r   ÚMissingq   s    rJ   c               
      s>   zt ˆƒ‚ ty }  zt d| ˆ ¡ W Y d } ~ d S d } ~ ww )Nz
{0} in {1})r   Ú	Exceptionr   Zreraise_exception)r7   )r   r   r   r   rE   y   s   €ÿzmissing.<locals>.report)Úobject)r   r   rJ   r   )rE   r   r   r   Úmissingp   s   rM   c                   @   s.   e Zd ZdZi Z	 dd„ Zdd„ Zdd„ ZdS )	ÚCapabilitiesz±A 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                 C   s¾   |  d¡s| d¡sJ ‚|| _|j}| j ¡ D ]?\}}| |d¡}t|ƒs*t 	|¡}z||ƒ}W n t
yF } z
| dt |¡|¡‚d}~ww |dksRJ |› d�ƒ‚|| |< qt d| ¡ dS )zÿParses 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.
        Z
initializer   z{0} {1}Nz5 must provide a default value for missing properties.r2   )Z
is_requestZis_responseÚ	componentÚpayloadÚ
PROPERTIESÚitemsÚgetÚcallabler   ÚdefaultrK   Z
isnt_validÚreprr   Údebug)r   rO   r6   rP   r   ÚvalidateÚvaluer7   r   r   r   r	   ’   s$   
€ÿ
ÿ
zCapabilities.__init__c                 C   s   t | ƒj› dt t| ƒ¡› �S )Nz: )r   r
   r   rV   Údictr   r   r   r   Ú__repr__¯   s   zCapabilities.__repr__c                 G   s2   |D ]}| | st  | j› dt |¡› �¡‚qd S )Nz does not have capability )r   r3   rO   r   rV   )r   ÚkeysÚkeyr   r   r   Úrequire²   s   ÿÿÿzCapabilities.requireN)r
   r   r   rA   rQ   r	   r[   r^   r   r   r   r   rN   ‚   s    	rN   )r;   Zdebugpy.commonr   r   r   r   ZACCEPT_CONNECTIONS_TIMEOUTrK   r   Z
Observabler   rM   rZ   rN   r   r   r   r   Ú<module>   s   ^