ó
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 d d l m Z d d l m Z d Z d
 e f d „  ƒ  YZ d S(   uR    Encapsulate handling of all Bokeh Protocol messages a Bokeh server may
receive.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   geni   (   t   ServerSessioni   (   t   ProtocolErroru   ProtocolHandlert   ProtocolHandlerc           B` s;   e  Z d  Z d „  Z e j d „  ƒ Z e j d „  ƒ Z RS(   u×   A Bokeh server may be expected to receive any of the following protocol
    messages:

    * ``EVENT``
    * ``PATCH-DOC``
    * ``PULL-DOC-REQ``
    * ``PUSH-DOC``
    * ``SERVER-INFO-REQ``

    The job of ``ProtocolHandler`` is to direct incoming messages to the right
    specialized handler for each message type. When the server receives a new
    message on a connection it will call ``handler`` with the message and the
    connection that the message arrived on. Most messages are ultimately
    handled by the ``ServerSession`` class, but some simpler messages types
    such as ``SERVER-INFO-REQ`` may be handled directly by ``ProtocolHandler``.

    Any unexpected messages will result in a ``ProtocolError``.

    c         C` s`   t  ƒ  |  _ t j |  j d <t j |  j d <t j |  j d <|  j |  j d <t j |  j d <d  S(   Nu   PULL-DOC-REQu   PUSH-DOCu	   PATCH-DOCu   SERVER-INFO-REQu   EVENT(   t   dictt	   _handlersR   t   pullt   pusht   patcht   _server_info_reqt   event(   t   self(    (    s<   lib/python2.7/site-packages/bokeh/server/protocol_handler.pyt   __init__B   s    c         c` sè   |  j  j | j | j f ƒ } | d k rB |  j  j | j ƒ } n  | d k ra t d | ƒ ‚ n  y | | | ƒ V} Wn] t k
 rÔ } t j d | | ƒ t j	 d | j
 | j d d ƒ| j | t | ƒ ƒ } n Xt j | ƒ ‚ d S(   uI   Delegate a received message to the appropriate handler.

        Args:
            message (Message) :
                The message that was receive that needs to be handled

            connection (ServerConnection) :
                The connection that received this message

        Raises:
            ProtocolError

        u   %s not expected on serveru   error handling message %r: %ru     message header %r content %rt   exc_infoi   N(   R	   t   gett   msgtypet   revisiont   NoneR   t	   Exceptiont   logt   errort   debugt   headert   contentt   reprR   t   Return(   R   t   messaget
   connectiont   handlert   workt   e(    (    s<   lib/python2.7/site-packages/bokeh/server/protocol_handler.pyt   handleK   s    c         C` s)   t  j | j j d | j d ƒ ƒ ‚ d  S(   Nu   SERVER-INFO-REPLYu   msgid(   R   R   t   protocolt   createR   (   R   R   R   (    (    s<   lib/python2.7/site-packages/bokeh/server/protocol_handler.pyR   k   s    (   t   __name__t
   __module__t   __doc__R   R   t	   coroutineR#   R   (    (    (    s<   lib/python2.7/site-packages/bokeh/server/protocol_handler.pyR   -   s   		 (   u   ProtocolHandler(   R(   t
   __future__R    R   R   R   t   loggingt	   getLoggerR&   R   t   tornadoR   t   sessionR   t   protocol.exceptionsR   t   __all__t   objectR   (    (    (    s<   lib/python2.7/site-packages/bokeh/server/protocol_handler.pyt   <module>
   s   "	