U
    /e                  
   @  sP  U d Z ddlmZ ddlZeeZddlZddlm	Z	m
Z
mZmZmZmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& e	rddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. dZ/ed Z0eeeeee e"e$e&d	Z1de2d< G dd dZ3dS )z_ Implement and provide message protocols for communication between Bokeh
Servers and clients.

    )annotationsN)TYPE_CHECKINGAnyDictListTypeoverload)Literal   )ProtocolError)Message)ack)error)ok)	patch_doc)pull_doc_reply)pull_doc_req)push_doc)server_info_reply)server_info_req   )ID)Document)DocumentPatchedEvent)Fragment)Protocol)	ZACKERROROKz	PATCH-DOCzPULL-DOC-REPLYzPULL-DOC-REQzPUSH-DOCzSERVER-INFO-REPLYzSERVER-INFO-REQ%Dict[MessageType, Type[Message[Any]]]SPECc                   @  s8  e Zd ZU dZded< ddddZddd	d
ZeddddddZeddddddddZedddddddZed;ddddddd dZed!dd"dd#d$d%dZed&dd'dd(dZed)d"dd*d+d,dZed-ddd.dd/dZed0dd1dd2dZd3ddd4d5d6dZdddd4d7d8d9Z	d:S )<r   zG Provide a message factory for the Bokeh Server message protocol.

    r   	_messagesNone)returnc                 C  s
   t | _d S N)r   r    self r&   ;/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/protocol/__init__.py__init__g   s    zProtocol.__init__strc                 C  s   dS )Nz
Protocol()r&   r$   r&   r&   r'   __repr__j   s    zProtocol.__repr__zLiteral['ACK']r   r   )msgtypemetadatar"   c                 K  s   d S r#   r&   r%   r+   r,   r&   r&   r'   createm   s    zProtocol.createzLiteral['ERROR']r   r   )r+   
request_idtextr,   r"   c                 K  s   d S r#   r&   )r%   r+   r/   r0   r,   r&   r&   r'   r.   o   s    zLiteral['OK']r   )r+   r/   r,   r"   c                 K  s   d S r#   r&   r%   r+   r/   r,   r&   r&   r'   r.   q   s    .zLiteral['PATCH-DOC']zList[DocumentPatchedEvent]boolr   )r+   eventsuse_buffersr,   r"   c                 K  s   d S r#   r&   )r%   r+   r3   r4   r,   r&   r&   r'   r.   s   s    zLiteral['PULL-DOC-REPLY']r   r   )r+   r/   documentr,   r"   c                 K  s   d S r#   r&   )r%   r+   r/   r5   r,   r&   r&   r'   r.   u   s    zLiteral['PULL-DOC-REQ']r   c                 K  s   d S r#   r&   r-   r&   r&   r'   r.   w   s    zLiteral['PUSH-DOC']r   )r+   r5   r,   r"   c                 K  s   d S r#   r&   )r%   r+   r5   r,   r&   r&   r'   r.   y   s    zLiteral['SERVER-INFO-REPLY']r   c                 K  s   d S r#   r&   r1   r&   r&   r'   r.   {   s    zLiteral['SERVER-INFO-REQ']r   c                 K  s   d S r#   r&   r-   r&   r&   r'   r.   }   s    MessageTypezMessage[Any])r+   argskwargsr"   c                 O  s,   || j krtd|d| j | j||S )zg Create a new Message instance for the given type.

        Args:
            msgtype (str) :

        zUnknown message type z for Bokeh protocol)r    r   r.   )r%   r+   r7   r8   r&   r&   r'   r.      s    
)header_jsonmetadata_jsoncontent_jsonr"   c                 C  sB   t |}d|kr*td| td| j|d  |||S )z Create a Message instance assembled from json fragments.

        Args:
            header_json (``JSON``) :

            metadata_json (``JSON``) :

            content_json (``JSON``) :

        Returns:
            message

        r+   z Bad header with no msgtype was: zNo 'msgtype' in header)jsonloadslogr   r   r    assemble)r%   r9   r:   r;   headerr&   r&   r'   r?      s
    
zProtocol.assembleN).)
__name__
__module____qualname____doc____annotations__r(   r*   r   r.   r?   r&   r&   r&   r'   r   a   s0   
r   )4rD   
__future__r   logging	getLoggerrA   r>   r<   typingr   r   r   r   r   r   Ztyping_extensionsr	   
exceptionsr   messager   Zmessages.ackr   Zmessages.errorr   Zmessages.okr   Zmessages.patch_docr   Zmessages.pull_doc_replyr   Zmessages.pull_doc_reqr   Zmessages.push_docr   Zmessages.server_info_replyr   Zmessages.server_info_reqr   Z
core.typesr   Zdocument.documentr   Zdocument.eventsr   Zreceiverr   __all__r6   r   rE   r   r&   r&   r&   r'   <module>   sJ   
 
