U
    /e                     @  s   d Z ddlmZ ddlZeeZddlmZm	Z	 ddl
mZmZ ddlmZmZ ddlmZ erzdd	lmZ d
dlmZ dZG dd deZG dd dedZG dd deZG dd deZG dd deZG dd deZG dd deZdS )z\ Provide a set of objects to represent different stages of a connection
to a Bokeh server.

    )annotationsN)ABCMetaabstractmethod)Enumauto)TYPE_CHECKINGAny   )ID)Message   )ClientConnection)CONNECTED_BEFORE_ACKCONNECTED_AFTER_ACKDISCONNECTEDErrorReasonNOT_YET_CONNECTEDWAITING_FOR_REPLYc                   @  s   e Zd Ze Ze Ze ZdS )r   N)__name__
__module____qualname__r   NO_ERRORZ
HTTP_ERRORNETWORK_ERROR r   r   7/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/client/states.pyr   9   s   r   c                   @  s    e Zd ZedddddZdS )Stater   None
connectionreturnc                   s   d S Nr   selfr   r   r   r   run@   s    z	State.runN)r   r   r   r   r#   r   r   r   r   r   >   s   r   )	metaclassc                   @  s    e Zd ZdZdddddZdS )r   z5 The ``ClientConnection`` is not yet connected.

    r   r   r   c                   s   |  I d H  d S r    )Z_connect_asyncr!   r   r   r   r#   I   s    zNOT_YET_CONNECTED.runNr   r   r   __doc__r#   r   r   r   r   r   D   s   r   c                   @  s    e Zd ZdZdddddZdS )r   zi The ``ClientConnection`` connected to a Bokeh server, but has not yet
    received an ACK from it.

    r   r   r   c                   s   |  I d H  d S r    )Z_wait_for_ackr!   r   r   r   r#   R   s    zCONNECTED_BEFORE_ACK.runNr%   r   r   r   r   r   L   s   r   c                   @  s    e Zd ZdZdddddZdS )r   za The ``ClientConnection`` connected to a Bokeh server, and has
    received an ACK from it.

    r   r   r   c                   s   |  I d H  d S r    )Z_handle_messagesr!   r   r   r   r#   [   s    zCONNECTED_AFTER_ACK.runNr%   r   r   r   r   r   U   s   r   c                   @  st   e Zd ZdZejddfdddddd	d
ZeddddZeddddZ	eddddZ
dddddZdS )r   z] The ``ClientConnection`` was connected to a Bokeh server, but is
    now disconnected.

    N r   z
int | Nonestrr   )reason
error_codeerror_detailr   c                 C  s   || _ || _|| _dS )z Constructs a DISCONNECT-State with given reason (``ErrorReason``
        enum), error id and additional information provided as string.

        N)_error_code_error_detail_error_reason)r"   r)   r*   r+   r   r   r   __init__d   s    zDISCONNECTED.__init__r   c                 C  s   | j S )zD The reason for the error encoded as an enumeration value.

        )r.   r"   r   r   r   error_reasonn   s    zDISCONNECTED.error_reasonc                 C  s   | j S )z8 Holds the error code, if any. None otherwise.

        )r,   r1   r   r   r   r*   u   s    zDISCONNECTED.error_codec                 C  s   | j S )zC Holds the error message, if any. Empty string otherwise.

        )r-   r1   r   r   r   r+   |   s    zDISCONNECTED.error_detailr   r   c                   s   d S r    r   r!   r   r   r   r#      s    zDISCONNECTED.run)r   r   r   r&   r   r   r/   propertyr2   r*   r+   r#   r   r   r   r   r   ^   s   
r   c                   @  s^   e Zd ZU dZded< dddddZedd	d
dZedd	ddZdddddZ	dS )r   z The ``ClientConnection`` has sent a message to the Bokeh Server which
    should generate a paired reply, and is waiting for the reply.

    zMessage[Any] | None_replyr
   r   )reqidr   c                 C  s   || _ d | _d S r    )_reqidr4   )r"   r5   r   r   r   r/      s    zWAITING_FOR_REPLY.__init__r0   c                 C  s   | j S )z? The reply from the server. (``None`` until the reply arrives) )r4   r1   r   r   r   reply   s    zWAITING_FOR_REPLY.replyc                 C  s   | j S )z, The request ID of the originating message. )r6   r1   r   r   r   r5      s    zWAITING_FOR_REPLY.reqidr   r   c                   st   |  I d H }|d kr.|ttjI d H  nBd|jkrb|jd | jkrb|| _|t	 I d H  n|
 I d H  d S )Nr5   )_pop_messageZ_transition_to_disconnectedr   r   r   headerr5   r4   Z_transitionr   _next)r"   r   messager   r   r   r#      s    zWAITING_FOR_REPLY.runN)
r   r   r   r&   __annotations__r/   r3   r7   r5   r#   r   r   r   r   r      s   
r   )r&   
__future__r   logging	getLoggerr   logabcr   r   enumr   r   typingr   r   Z
core.typesr
   Zprotocol.messager   r   r   __all__r   r   r   r   r   r   r   r   r   r   r   <module>   s$   
		(