ó
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
 Z
 d d l 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(   ug    Bokeh Application Handler to look for Bokeh server lifecycle callbacks
in a specified Python module.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   _check_callbacki   (   t
   CodeRunner(   t   LifecycleHandleru   ServerLifecycleHandlert   ServerLifecycleHandlerc           B` sM   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z RS(   u?    Load a script which contains server lifecycle callbacks.

    c         ` sÊ   t  t ˆ  ƒ j | | Ž  d | k r4 t d ƒ ‚ n  | d } | j d g  ƒ } t j | d d ƒ j ƒ  } t | | | ƒ ˆ  _	 ˆ  j	 j
 sÆ ˆ  j	 j ƒ  ˆ  _ ‡  f d †  } ˆ  j	 j ˆ  j | ƒ n  d S(   u  

        Keyword Args:
            filename (str) : path to a module to load lifecycle callbacks from

            argv (list[str], optional) : a list of string arguments to use as
                ``sys.argv`` when the callback code is executed. (default: [])

        u   filenameu.   Must pass a filename to ServerLifecycleHandleru   argvu   ru   UTF-8c          ` sØ   ˆ  j  j }  d |  k r( |  d ˆ  _ n  d |  k rD |  d ˆ  _ n  d |  k r` |  d ˆ  _ n  d |  k r| |  d ˆ  _ n  t ˆ  j d d d ƒt ˆ  j d	 d d ƒt ˆ  j d
 d d ƒt ˆ  j d d d ƒd  S(   Nu   on_server_loadedu   on_server_unloadedu   on_session_createdu   on_session_destroyedu   server_contextt   whatu   session_context(   u   server_context(   u   server_context(   u   session_context(   u   session_context(   t   _modulet   __dict__t   _on_server_loadedt   _on_server_unloadedt   _on_session_createdt   _on_session_destroyedR   (   t   contents(   t   self(    sJ   lib/python2.7/site-packages/bokeh/application/handlers/server_lifecycle.pyt   extract_callbacksQ   s    N(   t   superR   t   __init__t
   ValueErrort   gett   codecst   opent   readR   t   _runnert   failedt
   new_moduleR	   t   run(   R   t   argst   kwargst   filenamet   argvt   sourceR   (    (   R   sJ   lib/python2.7/site-packages/bokeh/application/handlers/server_lifecycle.pyR   8   s    

c         C` s
   |  j  j S(   uE    If the handler fails, may contain a related error message.

        (   R   t   error(   R   (    (    sJ   lib/python2.7/site-packages/bokeh/application/handlers/server_lifecycle.pyR"   e   s    c         C` s
   |  j  j S(   uJ    If the handler fails, may contain a traceback or other details.

        (   R   t   error_detail(   R   (    (    sJ   lib/python2.7/site-packages/bokeh/application/handlers/server_lifecycle.pyR#   l   s    c         C` s
   |  j  j S(   u@    ``True`` if the lifecycle callbacks failed to execute

        (   R   R   (   R   (    (    sJ   lib/python2.7/site-packages/bokeh/application/handlers/server_lifecycle.pyR   s   s    c         C` s;   |  j  r d Sd t j j t j j |  j j ƒ ƒ d Sd S(   u_    The last path component for the basename of the path to the
        callback module.

        u   /i    N(   R   t   Nonet   ost   patht   splitextt   basenameR   (   R   (    (    sJ   lib/python2.7/site-packages/bokeh/application/handlers/server_lifecycle.pyt   url_path|   s    	(	   t   __name__t
   __module__t   __doc__R   t   propertyR"   R#   R   R)   (    (    (    sJ   lib/python2.7/site-packages/bokeh/application/handlers/server_lifecycle.pyR   3   s   	-	(   u   ServerLifecycleHandler(   R,   t
   __future__R    R   R   R   t   loggingt	   getLoggerR*   t   logR   R%   t   util.callback_managerR   t   code_runnerR   t	   lifecycleR   t   __all__R   (    (    (    sJ   lib/python2.7/site-packages/bokeh/application/handlers/server_lifecycle.pyt   <module>
   s   "