
    -et                       U d Z ddlmZ ddlZ ej        e          ZddlmZm	Z	m
Z
mZmZmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZmZ er4ddl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Z,er$ee-e&         df         Z.de/d<   e
de	f         Z0de/d<    G d d          Z1 G d d          Z2 G d d          Z3 G d d          Z4 G d d          Z5 G d  d!          Z6 G d" d#          Z7 G d$ d%          Z8 G d& d'          Z9 G d( d)          Z: G d* d+e:e          Z; G d, d-e;          Z< G d. d/e;          Z= G d0 d1e;          Z> G d2 d3e;          Z? G d4 d5e;          Z@ G d6 d7e;          ZA G d8 d9e;          ZB G d: d;e;          ZC G d< d=e:          ZD G d> d?e:          ZEe
e:gdf         ZFdS )@a)   Provide events that represent various changes to Bokeh Documents.

These events are used internally to signal changes to Documents. For
information about user-facing (e.g. UI or tool) events, see the reference
for :ref:`bokeh.events`.

These events are employed for incoming and outgoing websocket messages and
internally for triggering callbacks. For example, the sequence of events that
happens when a user calls a Document API or sets a property resulting in a
"patch event" to the Document:

.. code-block::

    user invokes Document API
        -> Document API triggers event objects
        -> registered callbacks are executed
        -> Sesssion callback generates JSON message from event object
        -> Session sends JSON message over websocket

But events may also be triggered from the client, and arrive as JSON messages
over the transport layer, which is why the JSON handling and Document API must
be separated. Consider the alternative sequence of events:

.. code-block::

    Session recieves JSON message over websocket
        -> Document calls event.handle_json
        -> handle_json invokes appropriate Document API
        -> Document API triggers event objects
        -> registered callbacks are executed
        -> Session callback suppresses outgoing event

As a final note, message "ping-pong" is avoided by recording a "setter" when
events objects are created. If the session callback notes the event setter is
itself, then no further action (e.g. sending an outgoing change event identical
to the incoming event it just processed) is taken.

    )annotationsN)TYPE_CHECKINGAnyCallableClassVarUnioncast   )Serializable
Serializer   )	ColumnDataChangedColumnsPatchedColumnsStreamedDocumentPatchedMessageSentModelChanged	RootAddedRootRemovedTitleChanged)	TypeAlias)Setter)Model)DataDict)	BufferRef)SessionCallback)Document)Patches)ColumnDataChangedEventColumnsStreamedEventColumnsPatchedEventDocumentChangedEventDocumentPatchedEventModelChangedEventRootAddedEventRootRemovedEventSessionCallbackAddedSessionCallbackRemovedTitleChangedEventMessageSentEventr   Buffers.Invokerc                      e Zd ZddZdS )DocumentChangedMixineventr"   returnNonec                    d S N selfr/   s     5lib/python3.11/site-packages/bokeh/document/events.py_document_changedz&DocumentChangedMixin._document_changed             N)r/   r"   r0   r1   )__name__
__module____qualname__r8   r4   r:   r7   r.   r.   ~           IIIIIIr:   r.   c                      e Zd ZddZdS )DocumentPatchedMixinr/   r#   r0   r1   c                    d S r3   r4   r5   s     r7   _document_patchedz&DocumentPatchedMixin._document_patched   r9   r:   N)r/   r#   r0   r1   )r;   r<   r=   rB   r4   r:   r7   r@   r@      r>   r:   r@   c                      e Zd ZddZdS )DocumentMessageSentMixinr/   r*   r0   r1   c                    d S r3   r4   r5   s     r7   _document_message_sentz/DocumentMessageSentMixin._document_message_sent   r9   r:   N)r/   r*   r0   r1   )r;   r<   r=   rF   r4   r:   r7   rD   rD      s        JJJJJJr:   rD   c                      e Zd ZddZdS )DocumentModelChangedMixinr/   r$   r0   r1   c                    d S r3   r4   r5   s     r7   _document_model_changedz1DocumentModelChangedMixin._document_model_changed   r9   r:   N)r/   r$   r0   r1   )r;   r<   r=   rJ   r4   r:   r7   rH   rH      s        LLLLLLr:   rH   c                      e Zd ZddZdS )ColumnDataChangedMixinr/   r   r0   r1   c                    d S r3   r4   r5   s     r7   _column_data_changedz+ColumnDataChangedMixin._column_data_changed   r9   r:   N)r/   r   r0   r1   )r;   r<   r=   rN   r4   r:   r7   rL   rL      s        NNNNNNr:   rL   c                      e Zd ZddZdS )ColumnsStreamedMixinr/   r    r0   r1   c                    d S r3   r4   r5   s     r7   _columns_streamedz&ColumnsStreamedMixin._columns_streamed   r9   r:   N)r/   r    r0   r1   )r;   r<   r=   rR   r4   r:   r7   rP   rP      r>   r:   rP   c                      e Zd ZddZdS )ColumnsPatchedMixinr/   r!   r0   r1   c                    d S r3   r4   r5   s     r7   _columns_patchedz$ColumnsPatchedMixin._columns_patched   r9   r:   N)r/   r!   r0   r1   )r;   r<   r=   rV   r4   r:   r7   rT   rT      s        GGGGGGr:   rT   c                      e Zd ZddZdS )SessionCallbackAddedMixinr/   r'   r0   r1   c                    d S r3   r4   r5   s     r7   _session_callback_addedz1SessionCallbackAddedMixin._session_callback_added   r9   r:   N)r/   r'   r0   r1   )r;   r<   r=   rZ   r4   r:   r7   rX   rX      s        OOOOOOr:   rX   c                      e Zd ZddZdS )SessionCallbackRemovedMixinr/   r(   r0   r1   c                    d S r3   r4   r5   s     r7   _session_callback_removedz5SessionCallbackRemovedMixin._session_callback_removed   r9   r:   N)r/   r(   r0   r1   )r;   r<   r=   r^   r4   r:   r7   r\   r\      s        SSSSSSr:   r\   c                  L    e Zd ZU dZded<   ded<   ded<   dddZddZddZdS )r"   zX Base class for all internal events representing a change to a
    Bokeh Document.

    r   documentSetter | NonesetterInvoker | Nonecallback_invokerNr0   r1   c                0    || _         || _        || _        dS )a  

        Args:
            document (Document) :
                A Bokeh document that is to be updated.

            setter (ClientSession or ServerSession or None, optional) :
                This is used to prevent "boomerang" updates to Bokeh apps.
                (default: None)

                In the context of a Bokeh server application, incoming updates
                to properties will be annotated with the session that is
                doing the updating. This value is propagated through any
                subsequent change notifications that the update triggers.
                The session can compare the event setter to itself, and
                suppress any updates that originate from itself.

            callback_invoker (callable, optional) :
                A callable that will invoke any Model callbacks that should
                be executed in response to the change that triggered this
                event. (default: None)

        N)r`   rb   rd   )r6   r`   rb   rd   s       r7   __init__zDocumentChangedEvent.__init__   s     0 ! 0r:   r/   boolc                    dS )


        Fr4   r5   s     r7   combinezDocumentChangedEvent.combine   s	     ur:   receiverr   c                z    t          |d          r*t          t          |                              |            dS dS )z Dispatch handling of this event to a receiver.

        This method will invoke ``receiver._document_changed`` if it exists.

        r8   N)hasattrr	   r.   r8   )r6   rk   s     r7   dispatchzDocumentChangedEvent.dispatch   sI     8011 	I%x00BB4HHHHH	I 	Ir:   NN)r`   r   rb   ra   rd   rc   r0   r1   r/   r"   r0   rg   rk   r   r0   r1   )r;   r<   r=   __doc____annotations__rf   rj   rn   r4   r:   r7   r"   r"      s          
 $$$$1 1 1 1 18   I I I I I Ir:   r"   c                  |     e Zd ZU dZded<   i Zded<   d Zd fdZddZe	dd            Z
e	dd            Z xZS )r#   z] A Base class for events that represent updating Bokeh Models and
    their properties.

    zClassVar[str]kindz/ClassVar[dict[str, type[DocumentPatchedEvent]]]	_handlersc                $    | | j         | j        <   d S r3   )rv   ru   )clss    r7   __init_subclass__z&DocumentPatchedEvent.__init_subclass__   s    "%chr:   rk   r   r0   r1   c                    t                                          |           t          |d          r*t          t          |                              |            dS dS )z Dispatch handling of this event to a receiver.

        This method will invoke ``receiver._document_patched`` if it exists.

        rB   N)superrn   rm   r	   r@   rB   r6   rk   	__class__s     r7   rn   zDocumentPatchedEvent.dispatch   b     	"""8011 	I%x00BB4HHHHH	I 	Ir:   
serializerr   r   c                    t                      )z Create a JSON representation of this event suitable for sending
        to clients.

        *Sub-classes must implement this method.*

        Args:
            serializer (Serializer):

        NotImplementedErrorr6   r   s     r7   to_serializablez$DocumentPatchedEvent.to_serializable   s     "###r:   docr   	event_reprb   ra   c                    |                     d          }t          j                            |d          }|t	          d|d           |d| |d|}|                    | |           dS )ri   ru   Nzunknown patch event type '')r`   rb   r4   )popr#   rv   getRuntimeError_handle_event)r   r   rb   
event_kind	event_clsr/   s         r7   handle_eventz!DocumentPatchedEvent.handle_event   s    
 ]]6**
(266z4HH	KJKKKLLL	C3vCCCCU+++++r:   r/   c                    t                      r3   r   r   r/   s     r7   r   z"DocumentPatchedEvent._handle_event   s    !###r:   rq   )r   r   r0   r   )r   r   r   r   rb   ra   r0   r1   )r   r   r/   r#   r0   r1   )r;   r<   r=   rr   rs   rv   ry   rn   r   staticmethodr   r   __classcell__r}   s   @r7   r#   r#      s          
 ACICCCC& & &I I I I I I
$ 
$ 
$ 
$ 
, 
, 
, \
, $ $ $ \$ $ $ $ $r:   r#   c                  X     e Zd ZdZdZ	 dd fdZd fdZddZedd            Z	 xZ
S )r*   z

    r   Nr`   r   msg_typestrmsg_dataAny | bytesrb   ra   rd   rc   c                j    t                                          |||           || _        || _        d S r3   )r{   rf   r   r   )r6   r`   r   r   rb   rd   r}   s         r7   rf   zMessageSentEvent.__init__  s2    6+;<<<  r:   rk   r   r0   r1   c                    t                                          |           t          |d          r*t          t          |                              |            d S d S )NrF   )r{   rn   rm   r	   rD   rF   r|   s     r7   rn   zMessageSentEvent.dispatch  s`    """8566 	R)844KKDQQQQQ	R 	Rr:   r   r   c                j    t          | j        | j        |                    | j                            S )N)ru   r   r   )r   ru   r   encoder   r   s     r7   r   z MessageSentEvent.to_serializable  s6    ]&&t}55
 
 
 	
r:   r   r/   c                z    | j         j                            |j        g           }|D ]} ||j                   d S r3   )	callbacks_message_callbacksr   r   r   )r   r/   message_callbackscbs       r7   r   zMessageSentEvent._handle_event  sN    M<@@QSTT# 	 	BBu~	 	r:   ro   )
r`   r   r   r   r   r   rb   ra   rd   rc   rq   )r   r   r0   r   )r   r   r/   r*   r0   r1   r;   r<   r=   rr   ru   rf   rn   r   r   r   r   r   s   @r7   r*   r*      s          D NR! ! ! ! ! ! !R R R R R R

 
 
 
    \    r:   r*   c                  `     e Zd ZdZdZ	 dd fdZd dZd! fdZd"dZe	d#d            Z
 xZS )$r$   zc A concrete event representing updating an attribute and value of a
    specific Bokeh Model.

    r   Nr`   r   modelr   attrr   newr   rb   ra   rd   rc   c                x    t                                          |||           || _        || _        || _        dS )al  

        Args:
            document (Document) :
                A Bokeh document that is to be updated.

            model (Model) :
                A Model to update

            attr (str) :
                The name of the attribute to update on the model.

            new (object) :
                The new value of the attribute

            setter (ClientSession or ServerSession or None, optional) :
                This is used to prevent "boomerang" updates to Bokeh apps.
                (default: None)

                See :class:`~bokeh.document.events.DocumentChangedEvent`
                for more details.

            callback_invoker (callable, optional) :
                A callable that will invoke any Model callbacks that should
                be executed in response to the change that triggered this
                event. (default: None)


        N)r{   rf   r   r   r   )r6   r`   r   r   r   rb   rd   r}   s          r7   rf   zModelChangedEvent.__init__"  s;    > 	6+;<<<
	r:   r/   r"   r0   rg   c                    t          |t                    sdS | j        |j        k    rdS | j        |j        k    rdS | j        |j        k    r*| j        |j        k    r|j        | _        |j        | _        dS dS ri   FT)
isinstancer$   rb   r`   r   r   r   rd   r5   s     r7   rj   zModelChangedEvent.combineF  s     %!233 	5 ;%,&&5=EN**5J%+%%DI,C,CyDH$)$:D!4ur:   rk   r1   c                    t                                          |           t          |d          r*t          t          |                              |            dS dS )z Dispatch handling of this event to a receiver.

        This method will invoke ``receiver._document_model_changed`` if it exists.

        rJ   N)r{   rn   rm   r	   rH   rJ   r|   s     r7   rn   zModelChangedEvent.dispatch[  sb     	"""8677 	T*H55MMdSSSSS	T 	Tr:   r   r   c                    t          | j        | j        j        | j        |                    | j                            S )z Create a JSON representation of this event suitable for sending
        to clients.

        Args:
            serializer (Serializer):

        )ru   r   r   r   )r   ru   r   refr   r   r   r   s     r7   r   z!ModelChangedEvent.to_serializablee  s?     IJNI%%dh//	
 
 
 	
r:   r   c                j    |j         }|j        }|j        }|                    |||j                   d S N)rb   )r   r   r   set_from_jsonrb   )r   r/   r   r   values        r7   r   zModelChangedEvent._handle_eventt  s:    z	D%=====r:   ro   )r`   r   r   r   r   r   r   r   rb   ra   rd   rc   rp   rq   )r   r   r0   r   )r   r   r/   r$   r0   r1   )r;   r<   r=   rr   ru   rf   rj   rn   r   r   r   r   r   s   @r7   r$   r$     s         
 D NR" " " " " " "H   *T T T T T T
 
 
 
 > > > \> > > > >r:   r$   c                  Z     e Zd ZdZdZ	 	 dd fdZd  fdZd!dZed"d            Z	 xZ
S )#r   z A concrete event representing efficiently replacing *all*
    existing data for a :class:`~bokeh.models.sources.ColumnDataSource`

    r   Nr`   r   r   r   r   r   dataDataDict | Nonecolslist[str] | Nonerb   ra   rd   rc   c                    t                                          |||           || _        || _        || _        || _        dS )a]  

        Args:
            document (Document) :
                A Bokeh document that is to be updated.

            column_source (ColumnDataSource) :

            cols (list[str]) :
                optional explicit list of column names to update. If None, all
                columns will be updated (default: None)

            setter (ClientSession or ServerSession or None, optional) :
                This is used to prevent "boomerang" updates to Bokeh apps.
                (default: None)

                See :class:`~bokeh.document.events.DocumentChangedEvent`
                for more details.

            callback_invoker (callable, optional) :
                A callable that will invoke any Model callbacks that should
                be executed in response to the change that triggered this
                event. (default: None)


        N)r{   rf   r   r   r   r   )	r6   r`   r   r   r   r   rb   rd   r}   s	           r7   rf   zColumnDataChangedEvent.__init__  sB    8 	6+;<<<
					r:   rk   r   r0   r1   c                    t                                          |           t          |d          r*t          t          |                              |            dS dS )z Dispatch handling of this event to a receiver.

        This method will invoke ``receiver._column_data_changed`` if it exists.

        rN   N)r{   rn   rm   r	   rL   rN   r|   s     r7   rn   zColumnDataChangedEvent.dispatch  sb     	"""8344 	N'22GGMMMMM	N 	Nr:   r   r   c           	     "   | j         | j         nt          | j        | j                  | j        }|fd|D             t          | j        | j        j        | j        |                              |                    |                    S )a   Create a JSON representation of this event suitable for sending
        to clients.

        .. code-block:: python

            {
                'kind'          : 'ColumnDataChanged'
                'column_source' : <reference to a CDS>
                'data'          : <new data to steam to column_source>
                'cols'          : <specific columns to update>
            }

        Args:
            serializer (Serializer):

        Nc                D    i | ]}                     |          x|S r3   )r   ).0colr   r   s     r7   
<dictcomp>z:ColumnDataChangedEvent.to_serializable.<locals>.<dictcomp>  s/    WWW3DHHSMM3I52VC2V2V2Vr:   )ru   r   r   r   r   )	r   getattrr   r   r   r   ru   r   r   )r6   r   r   r   r   s      @@r7   r   z&ColumnDataChangedEvent.to_serializable  s    " !I1tyywtz497U7UyWWWWW$WWWD IJNI%%d++%%d++
 
 
 	
r:   r   r/   c                j    |j         }|j        }|j        }|                    |||j                   d S r   )r   r   r   r   rb   )r   r/   r   r   r   s        r7   r   z$ColumnDataChangedEvent._handle_event  s:    zzD$u|<<<<<r:   )NNNN)r`   r   r   r   r   r   r   r   r   r   rb   ra   rd   rc   rq   )r   r   r0   r   )r   r   r/   r   r0   r1   r   r   s   @r7   r   r   {  s         
 D\`lp             DN N N N N N
 
 
 
> = = = \= = = = =r:   r   c                  d     e Zd ZU dZdZded<   	 dd  fdZd! fdZd"dZe	d#d            Z
 xZS )$r    z| A concrete event representing efficiently streaming new data
    to a :class:`~bokeh.models.sources.ColumnDataSource`

    r   r   r   Nr`   r   r   r   r   r   DataDict | pd.DataFramerollover
int | Nonerb   ra   rd   rc   c                    t                                          |||           || _        || _        ddl}t          |j                  rfdj        D             | _        || _	        dS )av  

        Args:
            document (Document) :
                A Bokeh document that is to be updated.

            column_source (ColumnDataSource) :
                The data source to stream new data to.

            data (dict or DataFrame) :
                New data to stream.

                If a DataFrame, will be stored as ``{c: df[c] for c in df.columns}``

            rollover (int, optional) :
                A rollover limit. If the data source columns exceed this
                limit, earlier values will be discarded to maintain the
                column length under the limit.

            setter (ClientSession or ServerSession or None, optional) :
                This is used to prevent "boomerang" updates to Bokeh apps.
                (default: None)

                See :class:`~bokeh.document.events.DocumentChangedEvent`
                for more details.

            callback_invoker (callable, optional) :
                A callable that will invoke any Model callbacks that should
                be executed in response to the change that triggered this
                event. (default: None)

        r   Nc                "    i | ]}||         S r4   r4   )r   cr   s     r7   r   z1ColumnsStreamedEvent.__init__.<locals>.<dictcomp>  s    5551AtAw555r:   )
r{   rf   r   r   pandasr   	DataFramecolumnsr   r   )
r6   r`   r   r   r   r   rb   rd   pdr}   s
       `    r7   rf   zColumnsStreamedEvent.__init__  s    D 	6+;<<<
	 	dBL)) 	65555555D	 r:   rk   r   r0   r1   c                    t                                          |           t          |d          r*t          t          |                              |            dS dS )z Dispatch handling of this event to a receiver.

        This method will invoke ``receiver._columns_streamed`` if it exists.

        rR   N)r{   rn   rm   r	   rP   rR   r|   s     r7   rn   zColumnsStreamedEvent.dispatch  r~   r:   r   r   c                    t          | j        | j        j        | j        |                    | j                  | j                  S )a   Create a JSON representation of this event suitable for sending
        to clients.

        .. code-block:: python

            {
                'kind'          : 'ColumnsStreamed'
                'column_source' : <reference to a CDS>
                'data'          : <new data to steam to column_source>
                'rollover'      : <rollover limit>
            }

        Args:
            serializer (Serializer):

        )ru   r   r   r   r   )r   ru   r   r   r   r   r   r   r   s     r7   r   z$ColumnsStreamedEvent.to_serializable  sD    " yz~y!((33}
 
 
 	
r:   r   r/   c                    |j         }|j        }|dk    sJ |j        }|j        }|                    |||j                   d S Nr   )r   r   r   r   _streamrb   )r   r/   r   r   r   r   s         r7   r   z"ColumnsStreamedEvent._handle_event0  sI    zv~~~~z>dHel33333r:   )NNN)r`   r   r   r   r   r   r   r   r   r   rb   ra   rd   rc   rq   )r   r   r0   r   )r   r   r/   r    r0   r1   )r;   r<   r=   rr   ru   rs   rf   rn   r   r   r   r   r   s   @r7   r    r      s          
 DNNN ko,! ,! ,! ,! ,! ,! ,!\I I I I I I
 
 
 
2 4 4 4 \4 4 4 4 4r:   r    c                  X     e Zd ZdZdZ	 dd fdZd fdZddZed d            Z	 xZ
S )!r!   z A concrete event representing efficiently applying data patches
    to a :class:`~bokeh.models.sources.ColumnDataSource`

    r   Nr`   r   r   r   r   r   patchesr   rb   ra   rd   rc   c                x    t                                          |||           || _        || _        || _        dS )a  

        Args:
            document (Document) :
                A Bokeh document that is to be updated.

            column_source (ColumnDataSource) :
                The data source to apply patches to.

            patches (list) :

            setter (ClientSession or ServerSession or None, optional) :
                This is used to prevent "boomerang" updates to Bokeh apps.
                (default: None)

                See :class:`~bokeh.document.events.DocumentChangedEvent`
                for more details.

            callback_invoker (callable, optional) :
                A callable that will invoke any Model callbacks that should
                be executed in response to the change that triggered this
                event. (default: None)

        N)r{   rf   r   r   r   )r6   r`   r   r   r   rb   rd   r}   s          r7   rf   zColumnsPatchedEvent.__init__A  s;    4 	6+;<<<
	r:   rk   r   r0   r1   c                    t                                          |           t          |d          r*t          t          |                              |            dS dS )z Dispatch handling of this event to a receiver.

        This method will invoke ``receiver._columns_patched`` if it exists.

        rV   N)r{   rn   rm   r	   rT   rV   r|   s     r7   rn   zColumnsPatchedEvent.dispatch`  sb     	"""8/00 	G$h//@@FFFFF	G 	Gr:   r   r   c                    t          | j        | j        j        | j        |                    | j                            S )a   Create a JSON representation of this event suitable for sending
        to clients.

        .. code-block:: python

            {
                'kind'          : 'ColumnsPatched'
                'column_source' : <reference to a CDS>
                'patches'       : <patches to apply to column_source>
            }

        Args:
            serializer (Serializer):

        )ru   r   r   r   )r   ru   r   r   r   r   r   r   s     r7   r   z#ColumnsPatchedEvent.to_serializablej  s?      ijni ''55	
 
 
 	
r:   r   r/   c                v    |j         }|j        }|dk    sJ |j        }|                    ||j                   d S r   )r   r   r   patchrb   )r   r/   r   r   r   s        r7   r   z!ColumnsPatchedEvent._handle_event  s@    zv~~~~-GU\*****r:   ro   )r`   r   r   r   r   r   r   r   rb   ra   rd   rc   rq   )r   r   r0   r   )r   r   r/   r!   r0   r1   r   r   s   @r7   r!   r!   9  s         
 D NR      >G G G G G G
 
 
 
. + + + \+ + + + +r:   r!   c                  T     e Zd ZdZdZ	 dd fdZddZddZedd            Z	 xZ
S )r)   zS A concrete event representing a change to the title of a Bokeh
    Document.

    r   Nr`   r   titler   rb   ra   rd   rc   c                \    t                                          |||           || _        dS )a  

        Args:
            document (Document) :
                A Bokeh document that is to be updated.

            title (str) :
                The new title to set on the Document

            setter (ClientSession or ServerSession or None, optional) :
                This is used to prevent "boomerang" updates to Bokeh apps.
                (default: None)

                See :class:`~bokeh.document.events.DocumentChangedEvent`
                for more details.

            callback_invoker (callable, optional) :
                A callable that will invoke any Model callbacks that should
                be executed in response to the change that triggered this
                event. (default: None)


        N)r{   rf   r   )r6   r`   r   rb   rd   r}   s        r7   rf   zTitleChangedEvent.__init__  s-    2 	6+;<<<


r:   r/   r"   r0   rg   c                    t          |t                    sdS | j        |j        k    rdS | j        |j        k    rdS |j        | _        |j        | _        dS r   )r   r)   rb   r`   r   rd   r5   s     r7   rj   zTitleChangedEvent.combine  s_     %!233 	5 ;%,&&5=EN**5[
 % 6tr:   r   r   c                8    t          | j        | j                  S )a%   Create a JSON representation of this event suitable for sending
        to clients.

        .. code-block:: python

            {
                'kind'  : 'TitleChanged'
                'title' : <new title to set>
            }

        Args:
            serializer (Serializer):

        )ru   r   )r   ru   r   r   s     r7   r   z!TitleChangedEvent.to_serializable  s%     IJ
 
 
 	
r:   r   r1   c                F    |                      |j        |j                   d S r3   )	set_titler   rb   r   s     r7   r   zTitleChangedEvent._handle_event  s     ek5<00000r:   ro   )r`   r   r   r   rb   ra   rd   rc   rp   )r   r   r0   r   )r   r   r/   r)   r0   r1   )r;   r<   r=   rr   ru   rf   rj   r   r   r   r   r   s   @r7   r)   r)     s         
 D NR      8   $
 
 
 
( 1 1 1 \1 1 1 1 1r:   r)   c                  J     e Zd ZdZdZdd fdZddZedd            Z xZ	S )r%   zq A concrete event representing a change to add a new Model to a
    Document's collection of "root" models.

    r   Nr`   r   r   r   rb   ra   rd   rc   r0   r1   c                \    t                                          |||           || _        dS )a  

        Args:
            document (Document) :
                A Bokeh document that is to be updated.

            model (Model) :
                The Bokeh Model to add as a Document root.

            setter (ClientSession or ServerSession or None, optional) :
                This is used to prevent "boomerang" updates to Bokeh apps.
                (default: None)

                See :class:`~bokeh.document.events.DocumentChangedEvent`
                for more details.

            callback_invoker (callable, optional) :
                A callable that will invoke any Model callbacks that should
                be executed in response to the change that triggered this
                event. (default: None)

        Nr{   rf   r   r6   r`   r   rb   rd   r}   s        r7   rf   zRootAddedEvent.__init__  s-    . 	6+;<<<


r:   r   r   c                ^    t          | j        |                    | j                            S )a&   Create a JSON representation of this event suitable for sending
        to clients.

        .. code-block:: python

            {
                'kind'  : 'RootAdded'
                'title' : <reference to a Model>
            }

        Args:
            serializer (Serializer):

        ru   r   )r   ru   r   r   r   s     r7   r   zRootAddedEvent.to_serializable  s3     I%%dj11
 
 
 	
r:   r   r/   c                J    |j         }|                     ||j                   d S r3   )r   add_rootrb   r   r/   r   s      r7   r   zRootAddedEvent._handle_event  s%    UEL)))))r:   ro   
r`   r   r   r   rb   ra   rd   rc   r0   r1   )r   r   r0   r   )r   r   r/   r%   r0   r1   
r;   r<   r=   rr   ru   rf   r   r   r   r   r   s   @r7   r%   r%     s         
 D      4
 
 
 
( * * * \* * * * *r:   r%   c                  J     e Zd ZdZdZdd fdZddZedd            Z xZ	S )r&   z| A concrete event representing a change to remove an existing Model
    from a Document's collection of "root" models.

    r   Nr`   r   r   r   rb   ra   rd   rc   r0   r1   c                \    t                                          |||           || _        dS )a  

        Args:
            document (Document) :
                A Bokeh document that is to be updated.

            model (Model) :
                The Bokeh Model to remove as a Document root.

            setter (ClientSession or ServerSession or None, optional) :
                This is used to prevent "boomerang" updates to Bokeh apps.
                (default: None)

                See :class:`~bokeh.document.events.DocumentChangedEvent`
                for more details.

            callback_invoker (callable, optional) :
                A callable that will invoke any Model callbacks that should
                be executed in response to the change that triggered this
                event. (default: None)


        Nr   r   s        r7   rf   zRootRemovedEvent.__init__  s-    0 	6+;<<<


r:   r   r   c                B    t          | j        | j        j                  S )a(   Create a JSON representation of this event suitable for sending
        to clients.

        .. code-block:: python

            {
                'kind'  : 'RootRemoved'
                'title' : <reference to a Model>
            }

        Args:
            serializer (Serializer):

        r   )r   ru   r   r   r   s     r7   r   z RootRemovedEvent.to_serializable5  s'     IJN
 
 
 	
r:   r   r/   c                J    |j         }|                     ||j                   d S r3   )r   remove_rootrb   r   s      r7   r   zRootRemovedEvent._handle_eventI  s%    u|,,,,,r:   ro   r   )r   r   r0   r   )r   r   r/   r&   r0   r1   r   r   s   @r7   r&   r&     s         
 D      6
 
 
 
( - - - \- - - - -r:   r&   c                  0     e Zd ZdZd fdZd fdZ xZS )r'   z A concrete event representing a change to add a new callback (e.g.
    periodic, timeout, or "next tick") to a Document.

    r`   r   callbackr   r0   r1   c                X    t                                          |           || _        dS )z

        Args:
            document (Document) :
                A Bokeh document that is to be updated.

            callback (SessionCallback) :
                The callback to add

        Nr{   rf   r   r6   r`   r   r}   s      r7   rf   zSessionCallbackAdded.__init__T  (     	""" r:   rk   r   c                    t                                          |           t          |d          r*t          t          |                              |            dS dS )z Dispatch handling of this event to a receiver.

        This method will invoke ``receiver._session_callback_added`` if
        it exists.

        rZ   N)r{   rn   rm   r	   rX   rZ   r|   s     r7   rn   zSessionCallbackAdded.dispatchb  sb     	"""8677 	T*H55MMdSSSSS	T 	Tr:   r`   r   r   r   r0   r1   rq   r;   r<   r=   rr   rf   rn   r   r   s   @r7   r'   r'   N  so         
! ! ! ! ! !	T 	T 	T 	T 	T 	T 	T 	T 	T 	Tr:   r'   c                  0     e Zd ZdZd fdZd fdZ xZS )r(   z A concrete event representing a change to remove an existing callback
    (e.g. periodic, timeout, or "next tick") from a Document.


    r`   r   r   r   r0   r1   c                X    t                                          |           || _        dS )z

        Args:
            document (Document) :
                A Bokeh document that is to be updated.

            callback (SessionCallback) :
                The callback to remove

        Nr   r   s      r7   rf   zSessionCallbackRemoved.__init__t  r   r:   rk   r   c                    t                                          |           t          |d          r*t          t          |                              |            dS dS )z Dispatch handling of this event to a receiver.

        This method will invoke ``receiver._session_callback_removed`` if
        it exists.

        r^   N)r{   rn   rm   r	   r\   r^   r|   s     r7   rn   zSessionCallbackRemoved.dispatch  sc     	"""8899 	X,h77QQRVWWWWW	X 	Xr:   r   rq   r   r   s   @r7   r(   r(   m  so         ! ! ! ! ! !	X 	X 	X 	X 	X 	X 	X 	X 	X 	Xr:   r(   )Grr   
__future__r   logging	getLoggerr;   logtypingr   r   r   r   r   r	   core.serializationr   r   jsonr   r   r   r   r   r   r   r   r   r   r   typing_extensionsr   core.has_propsr   r   r   models.sourcesr   protocol.messager   server.callbacksr   r`   r   r   __all__listr+   rs   r,   r.   r@   rD   rH   rL   rP   rT   rX   r\   r"   r#   r*   r$   r   r    r!   r)   r%   r&   r'   r(   DocumentChangeCallbackr4   r:   r7   <module>r
     s%  % % %T # " " " " " g!!                : 9 9 9 9 9 9 9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
++++++'''''')))))),,,,,,222222"""""".  ,tI45G5555!#s(+G++++J J J J J J J JJ J J J J J J JK K K K K K K KM M M M M M M MO O O O O O O OJ J J J J J J JH H H H H H H HP P P P P P P PT T T T T T T T3I 3I 3I 3I 3I 3I 3I 3Ij3$ 3$ 3$ 3$ 3$/ 3$ 3$ 3$j    +   >_> _> _> _> _>, _> _> _>BX= X= X= X= X=1 X= X= X=tb4 b4 b4 b4 b4/ b4 b4 b4HN+ N+ N+ N+ N+. N+ N+ N+`L1 L1 L1 L1 L1, L1 L1 L1\9* 9* 9* 9* 9*) 9* 9* 9*v:- :- :- :- :-+ :- :- :-xT T T T T/ T T T>X X X X X1 X X X@ "#7"8$">?   r:   