σ
mάJ]c           @` s[  d  Z  d d l m Z m Z m Z m Z d d l Z e j e  Z	 d d l
 m Z e d  Z d( Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d  e f d!     YZ d" e f d#     YZ d$ e f d%     YZ d& e f d'     YZ d S()   uν    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`.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   import_optionalu   pandasu   ColumnDataChangedEventu   ColumnsStreamedEventu   ColumnsPatchedEventu   DocumentChangedEventu   DocumentPatchedEventu   ModelChangedEventu   RootAddedEventu   RootRemovedEventu   SessionCallbackAddedu   SessionCallbackRemovedu   TitleChangedEventt   DocumentChangedEventc           B` s/   e  Z d  Z d d d  Z d   Z d   Z RS(   uX    Base class for all internal events representing a change to a
    Bokeh Document.

    c         C` s   | |  _  | |  _ | |  _ d S(   uΞ  

        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(   t   documentt   settert   callback_invoker(   t   selfR   R   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyt   __init__E   s    		c         C` s   t  S(   u
   

        (   t   False(   R	   t   event(    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyt   combinea   s    c         C` s#   t  | d  r | j |   n  d S(   u    Dispatch handling of this event to a receiver.

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

        u   _document_changedN(   t   hasattrt   _document_changed(   R	   t   receiver(    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyt   dispatchg   s    N(   t   __name__t
   __module__t   __doc__t   NoneR
   R   R   (    (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   ?   s   	t   DocumentPatchedEventc           B` s    e  Z d  Z d   Z d   Z RS(   u]    A Base class for events that represent updating Bokeh Models and
    their properties.

    c         C` s9   t  t |   j |  t | d  r5 | j |   n  d S(   u    Dispatch handling of this event to a receiver.

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

        u   _document_patchedN(   t   superR   R   R   t   _document_patched(   R	   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   v   s    c         C` s   t     d S(   uΧ   Create a JSON representation of this event suitable for sending
        to clients.

        *Sub-classes must implement this method.*

        Args:
            references (dict[str, Model]) :
                If the event requires references to certain models in order to
                function, they may be collected here.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

            buffers (set) :
                If the event needs to supply any additional Bokeh protocol
                buffers, they may be added to this set.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

        N(   t   NotImplementedError(   R	   t
   referencest   buffers(    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyt   generate   s    (   R   R   R   R   R   (    (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   p   s   	
t   ModelChangedEventc           B` s;   e  Z d  Z d d d d  Z d   Z d   Z d   Z RS(   u:   A concrete event representing updating an attribute and value of a
    specific Bokeh Model.

    This is the "standard" way of updating most Bokeh model attributes. For
    special casing situations that can optimized (e.g. streaming, etc.), a
    ``hint`` may be supplied that overrides normal mechanisms.

    c
   
      C` s   | d k r- t | t t f  r- | j } n  t t |   j | | |	  | |  _ | |  _	 | |  _
 | |  _ | |  _ | |  _ d S(   u  

        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.

            old (object) :
                The old value of the attribute

            new (object) :
                The new value of the attribute

            serializable_new (object) :
                A serialized (JSON) version of the new value. It may be
                ``None`` if a hint is supplied.

            hint (DocumentPatchedEvent, optional) :
                When appropriate, a secondary event may be supplied that
                modifies the normal update process. For example, in order
                to stream or patch data more efficiently than the standard
                update mechanism.

            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   t
   isinstancet   ColumnsStreamedEventt   ColumnsPatchedEventR   R   R   R
   t   modelt   attrt   oldt   newt   serializable_newt   hint(
   R	   R   R!   R"   R#   R$   R%   R&   R   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR
   ’   s    +!					c         C` s«   t  | t  s t S|  j | j k r) t S|  j | j k r? t S|  j r[ |  j j | j  S|  j | j k r§ |  j | j k r§ | j	 |  _	 | j
 |  _
 | j |  _ t St S(   u
   

        (   R   R   R   R   R   R&   R   R!   R"   R$   R%   R   t   True(   R	   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   Χ   s       	$c         C` s9   t  t |   j |  t | d  r5 | j |   n  d S(   u    Dispatch handling of this event to a receiver.

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

        u   _document_model_changedN(   R   R   R   R   t   _document_model_changed(   R	   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   ν   s    c         C` s₯   d d l  m } |  j d k	 r2 |  j j | |  S|  j } t | |   } |  j  | k ro | j |  j   n  | j |  i d d 6|  j  j	 d 6|  j
 d 6| d 6S(	   u€   Create a JSON representation of this event suitable for sending
        to clients.

        Args:
            references (dict[str, Model]) :
                If the event requires references to certain models in order to
                function, they may be collected here.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

            buffers (set) :
                If the event needs to supply any additional Bokeh protocol
                buffers, they may be added to this set.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

        i   (   t   collect_modelsu   ModelChangedu   kindu   modelu   attru   newN(   R!   R)   R&   R   R   R%   t   sett   discardt   updatet   refR"   (   R	   R   R   R)   t   valuet
   value_refs(    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   ψ   s    	

N(   R   R   R   R   R
   R   R   R   (    (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR      s
   5		t   ColumnDataChangedEventc           B` s2   e  Z d  Z d d d d  Z d   Z d   Z RS(   u    A concrete event representing efficiently replacing *all*
    existing data for a :class:`~bokeh.models.sources.ColumnDataSource`

    c         C` s2   t  t |   j | | |  | |  _ | |  _ d S(   u]  

        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   R0   R
   t   column_sourcet   cols(   R	   R   R1   R2   R   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR
   2  s    	c         C` s9   t  t |   j |  t | d  r5 | j |   n  d S(   u    Dispatch handling of this event to a receiver.

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

        u   _column_data_changedN(   R   R0   R   R   t   _column_data_changed(   R	   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   Q  s    c         C` sZ   d d l  m } | |  j j d | d |  j } i d d 6|  j j d 6| d 6|  j d	 6S(
   uΥ   Create a JSON representation of this event suitable for sending
        to clients.

        .. code-block:: python

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

        Args:
            references (dict[str, Model]) :
                If the event requires references to certain models in order to
                function, they may be collected here.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

            buffers (set) :
                If the event needs to supply any additional Bokeh protocol
                buffers, they may be added to this set.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.


        i   (   t   transform_column_source_dataR   R2   u   ColumnDataChangedu   kindu   column_sourceu   newu   cols(   t   util.serializationR4   R1   t   dataR2   R-   (   R	   R   R   R4   t	   data_dict(    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   [  s    !
N(   R   R   R   R   R
   R   R   (    (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR0   ,  s   	
R   c           B` s/   e  Z d  Z d d d  Z d   Z d   Z RS(   u|    A concrete event representing efficiently streaming new data
    to a :class:`~bokeh.models.sources.ColumnDataSource`

    c         ` so   t  t |   j | | |  | |  _ t rY t   t j  rY   f d     j D   n    |  _ | |  _	 d S(   ul  

        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) :
                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)

        c         ` s   i  |  ] }   | |  q S(    (    (   t   .0t   c(   R6   (    s4   lib/python2.7/site-packages/bokeh/document/events.pys
   <dictcomp>­  s   	 N(
   R   R   R
   R1   t   pdR   t	   DataFramet   columnsR6   t   rollover(   R	   R   R1   R6   R=   R   R   (    (   R6   s4   lib/python2.7/site-packages/bokeh/document/events.pyR
     s    !		c         C` s9   t  t |   j |  t | d  r5 | j |   n  d S(   u    Dispatch handling of this event to a receiver.

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

        u   _columns_streamedN(   R   R   R   R   t   _columns_streamed(   R	   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   ²  s    c         C` s,   i d d 6|  j  j d 6|  j d 6|  j d 6S(   uΖ   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:
            references (dict[str, Model]) :
                If the event requires references to certain models in order to
                function, they may be collected here.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

            buffers (set) :
                If the event needs to supply any additional Bokeh protocol
                buffers, they may be added to this set.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

        u   ColumnsStreamedu   kindu   column_sourceu   datau   rollover(   R1   R-   R6   R=   (   R	   R   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   Ό  s    

N(   R   R   R   R   R
   R   R   (    (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR     s   *	
R    c           B` s/   e  Z d  Z d d d  Z d   Z d   Z RS(   u    A concrete event representing efficiently applying data patches
    to a :class:`~bokeh.models.sources.ColumnDataSource`

    c         C` s2   t  t |   j | | |  | |  _ | |  _ d S(   u  

        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   R    R
   R1   t   patches(   R	   R   R1   R?   R   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR
   δ  s    	c         C` s9   t  t |   j |  t | d  r5 | j |   n  d S(   u    Dispatch handling of this event to a receiver.

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

        u   _columns_patchedN(   R   R    R   R   t   _columns_patched(   R	   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR     s    c         C` s"   i d d 6|  j  j d 6|  j d 6S(   u   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:
            references (dict[str, Model]) :
                If the event requires references to certain models in order to
                function, they may be collected here.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

            buffers (set) :
                If the event needs to supply any additional Bokeh protocol
                buffers, they may be added to this set.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

        u   ColumnsPatchedu   kindu   column_sourceu   patches(   R1   R-   R?   (   R	   R   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR     s    
N(   R   R   R   R   R
   R   R   (    (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR    ή  s   	
t   TitleChangedEventc           B` s/   e  Z d  Z d d d  Z d   Z d   Z RS(   uS    A concrete event representing a change to the title of a Bokeh
    Document.

    c         C` s)   t  t |   j | | |  | |  _ d S(   uΦ  

        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   RA   R
   t   title(   R	   R   RB   R   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR
   1  s    c         C` s[   t  | t  s t S|  j | j k r) t S|  j | j k r? t S| j |  _ | j |  _ t S(   u
   

        (   R   RA   R   R   R   RB   R   R'   (   R	   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   L  s       c         C` s   i d d 6|  j  d 6S(   u7   Create a JSON representation of this event suitable for sending
        to clients.

        .. code-block:: python

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

        Args:
            references (dict[str, Model]) :
                If the event requires references to certain models in order to
                function, they may be collected here.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

            buffers (set) :
                If the event needs to supply any additional Bokeh protocol
                buffers, they may be added to this set.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

        u   TitleChangedu   kindu   title(   RB   (   R	   R   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   [  s    
N(   R   R   R   R   R
   R   R   (    (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyRA   +  s   	t   RootAddedEventc           B` s&   e  Z d  Z d d d  Z d   Z RS(   uq    A concrete event representing a change to add a new Model to a
    Document's collection of "root" models.

    c         C` s)   t  t |   j | | |  | |  _ d S(   uέ  

        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   RC   R
   R!   (   R	   R   R!   R   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR
     s    c         C` s.   | j  |  j j    i d d 6|  j j d 6S(   u8   Create a JSON representation of this event suitable for sending
        to clients.

        .. code-block:: python

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

        Args:
            references (dict[str, Model]) :
                If the event requires references to certain models in order to
                function, they may be collected here.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

            buffers (set) :
                If the event needs to supply any additional Bokeh protocol
                buffers, they may be added to this set.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

        u	   RootAddedu   kindu   model(   R,   R!   R   R-   (   R	   R   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR     s    
N(   R   R   R   R   R
   R   (    (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyRC   y  s   t   RootRemovedEventc           B` s&   e  Z d  Z d d d  Z d   Z RS(   u|    A concrete event representing a change to remove an existing Model
    from a Document's collection of "root" models.

    c         C` s)   t  t |   j | | |  | |  _ d S(   uα  

        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)


        N(   R   RD   R
   R!   (   R	   R   R!   R   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR
   Ύ  s    c         C` s   i d d 6|  j  j d 6S(   u:   Create a JSON representation of this event suitable for sending
        to clients.

        .. code-block:: python

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

        Args:
            references (dict[str, Model]) :
                If the event requires references to certain models in order to
                function, they may be collected here.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

            buffers (set) :
                If the event needs to supply any additional Bokeh protocol
                buffers, they may be added to this set.

                **This is an "out" parameter**. The values it contains will be
                modified in-place.

        u   RootRemovedu   kindu   model(   R!   R-   (   R	   R   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   Ω  s    
N(   R   R   R   R   R
   R   (    (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyRD   Έ  s   t   SessionCallbackAddedc           B` s    e  Z d  Z d   Z d   Z RS(   u    A concrete event representing a change to add a new callback (e.g.
    periodic, timeout, or "next tick") to a Document.

    c         C` s#   t  t |   j |  | |  _ d S(   uΑ   

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

            callback (SessionCallback) :
                The callback to add

        N(   R   RE   R
   t   callback(   R	   R   RF   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR
   ύ  s    c         C` s9   t  t |   j |  t | d  r5 | j |   n  d S(   u    Dispatch handling of this event to a receiver.

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

        u   _session_callback_addedN(   R   RE   R   R   t   _session_callback_added(   R	   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR     s    (   R   R   R   R
   R   (    (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyRE   χ  s   	t   SessionCallbackRemovedc           B` s    e  Z d  Z d   Z d   Z RS(   u    A concrete event representing a change to remove an existing callback
    (e.g. periodic, timeout, or "next tick") from a Document.


    c         C` s#   t  t |   j |  | |  _ d S(   uΔ   

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

            callback (SessionCallback) :
                The callback to remove

        N(   R   RH   R
   RF   (   R	   R   RF   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR
     s    c         C` s9   t  t |   j |  t | d  r5 | j |   n  d S(   u    Dispatch handling of this event to a receiver.

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

        u   _session_callback_removedN(   R   RH   R   R   t   _session_callback_removed(   R	   R   (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyR   +  s    (   R   R   R   R
   R   (    (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyRH     s   	(   u   ColumnDataChangedEventu   ColumnsStreamedEventu   ColumnsPatchedEventu   DocumentChangedEventu   DocumentPatchedEventu   ModelChangedEventu   RootAddedEventu   RootRemovedEventu   SessionCallbackAddedu   SessionCallbackRemovedu   TitleChangedEventu   TitleChangedEvent(   R   t
   __future__R    R   R   R   t   loggingt	   getLoggerR   t   logt   util.dependenciesR   R:   t   __all__t   objectR   R   R   R0   R   R    RA   RC   RD   RE   RH   (    (    (    s4   lib/python2.7/site-packages/bokeh/document/events.pyt   <module>   s8   "           1(V\MN??