ó
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 m Z m Z d d l m Z d d l m Z d d l 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 Z d Z d e e f Z  d e! f d „  ƒ  YZ" d e" f d „  ƒ  YZ# d e" f d „  ƒ  YZ$ d e# e$ f d „  ƒ  YZ% d e! f d „  ƒ  YZ& e
 j' d ƒ Z( d „  Z) d e+ d „ Z, e+ d d „ Z- e% d d ƒ Z. e% d d  ƒ Z/ d& Z0 d S('   uZ   The resources module provides the Resources class for easily configuring
how BokehJS code and CSS resources should be located, loaded, and embedded in
Bokeh documents.

Also provides some pre-configured Resources objects.

Attributes:
    CDN : load minified BokehJS from CDN
    INLINE : provide minified BokehJS from library static directory

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   basenamet   joint   relpath(   t   string_typesi   (   t   __version__(   t   JS_RESOURCESt   CSS_RESOURCES(   t   Model(   t   settings(   t
   bokehjsdir(   t   generate_session_idu	   localhostiŽ  u   http://%s:%d/t   BaseResourcesc        	   B` s¤   e  Z d  Z e Z d d d e d d d d d „ Z e d „  ƒ Z	 e	 j
 d „  ƒ Z	 e d „  ƒ Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   u   .u   inlineu   infoc	      	   C` s+  | |  _  t |  d ƒ r' |  j |  _ n  t |  d ƒ rE |  j |  _ n  t j | ƒ |  _ ~ t j	 | ƒ |  _
 ~ t j | ƒ |  _ ~ t j | ƒ |  _ ~ t j | ƒ |  _ ~ | |  _ ~ | rÝ | j d ƒ rÝ | d } n  | |  _ |  j d k rt d |  j ƒ ‚ n  |  j
 r6|  j j d ƒ r6t d ƒ ‚ n  |  j ra|  j j d ƒ rat d ƒ ‚ n  | r‰|  j j d ƒ r‰t d ƒ ‚ n  |  j j d ƒ |  _ |  j rº|  j d  |  _ n  g  |  _ |  j d k rõ|  j ƒ  }	 |  j j |	 d ƒ n2 |  j d k r'|  j ƒ  }
 |  j j |
 d ƒ n  d  S(   Nu   _js_componentsu   _css_componentsu   /u   inlineu   cdnu   serveru
   server-devu   relativeu   relative-devu   absoluteu   absolute-devux   wrong value for 'mode' parameter, expected 'inline', 'cdn', 'server(-dev)', 'relative(-dev)' or 'absolute(-dev)', got %ruD   setting 'root_dir' makes sense only when 'mode' is set to 'relative'u>   setting 'version' makes sense only when 'mode' is set to 'cdn'uB   setting 'root_url' makes sense only when 'mode' is set to 'server'u   -deviüÿÿÿu   messages(   u   inlineu   cdnu   serveru
   server-devu   relativeu   relative-devu   absoluteu   absolute-dev(   t   _componentst   hasattrt   _js_componentst   js_componentst   _css_componentst   css_componentsR   t	   resourcest   modet   rootdirt   root_dirt   versiont   minifiedt	   log_levelt   path_versionert   endswitht	   _root_urlt
   ValueErrort
   startswitht   devt   messagest	   _cdn_urlst   extendt   _server_urls(   t   selfR   R   R   R   R   t   root_urlR   t
   componentst   cdnt   server(    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   __init__F   sN    	     	 			c         C` s   |  j  S(   N(   t
   _log_level(   R'   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyR   x   s    c         C` s^   d d d d d d g } | d  k p- | | k sQ t d j | t | ƒ ƒ ƒ ‚ n  | |  _ d  S(   Nu   traceu   debugu   infou   warnu   erroru   fatalu,   Unknown log level '{}', valid levels are: {}(   t   NoneR    t   formatt   strR-   (   R'   t   levelt   valid_levels(    (    s.   lib/python2.7/site-packages/bokeh/resources.pyR   |   s    !c         C` s!   |  j  d  k	 r |  j  S|  j Sd  S(   N(   R   R.   t   _default_root_url(   R'   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyR(   …   s    c         C` s\   | d k r |  j  n |  j } |  j d  k	 rX g  | D] } | |  j k r4 | ^ q4 } n  | S(   Nu   js(   R   R   R   R.   (   R'   t   kindR)   t   c(    (    s.   lib/python2.7/site-packages/bokeh/resources.pyR)   Ž   s    +c         C` s†   t  |  j ƒ } |  j r( |  j r( d n d } g  |  j | ƒ D] } d | | | f ^ q> } g  | D] } t | | | ƒ ^ qd } | S(   Nu   .minu    u   %s%s.%s(   R   R"   R   R)   R   (   R'   R4   t   bokehjs_dirR   t	   componentt   filest   filet   paths(    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   _file_paths”   s
    /%c         C` s¸   g  } x« t  t j j ƒ  d d „  ƒD]‹ \ } } t | | d ƒ } t | t ƒ rq | | k r° | j | ƒ q° q% t | t	 ƒ r% x- | D]" } | | k r‡ | j | ƒ q‡ q‡ Wq% q% W| S(   uI    Collect external resources set on resource_attr attribute of all models.t   keyc         S` s   |  d S(   Ni    (    (   t   arg(    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   <lambda>    t    N(
   t   sortedR   t   model_class_reverse_mapt   itemst   getattrR.   t
   isinstanceR   t   appendt   list(   R'   t   resource_attrt   external_resourcest   _t   clst   externalt   e(    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   _collect_external_resources›   s    +c         C` s   t  |  j |  j ƒ S(   N(   t   _get_cdn_urlsR   R   (   R'   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyR$   ­   s    c         C` s(   t  |  j |  j r t n |  j |  j ƒ S(   N(   t   _get_server_urlsR(   R"   t   FalseR   R   (   R'   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyR&   °   s    c   	      C` s>  |  j  | ƒ } g  g  } } |  j d k rP g  | D] } |  j | ƒ ^ q2 } nä |  j d k r– |  j pn |  j } g  | D] } t | | ƒ ^ qx } nž |  j d k r´ t | ƒ } n€ |  j d k rô |  j ƒ  } t | d |  j | ƒ | ƒ ƒ } n@ |  j d k r4|  j	 ƒ  } t | d |  j | ƒ | ƒ ƒ } n  | | f S(   Nu   inlineu   relativeu   absoluteu   cdnu   urlsu   server(
   R;   R   t   _inlineR   t   _default_root_dirR   RF   R$   R)   R&   (	   R'   R4   R:   R8   t   rawt   pathR   R*   R+   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   _resolve³   s     %%%%c         C` s^   d t  | ƒ } t | d ƒ  } | j ƒ  j d ƒ } Wd  QXd t  | ƒ } d | | | f S(   Nu   /* BEGIN %s */u   rbu   utf-8u   /* END %s */u   %s
%s
%s(   R   t   opent   readt   decode(   R'   RT   t   begint   ft   middlet   end(    (    s.   lib/python2.7/site-packages/bokeh/resources.pyRQ   Ç   s
    N(   t   __name__t
   __module__RR   t   DEFAULT_SERVER_HTTP_URLR3   R.   t   TrueR,   t   propertyR   t   setterR(   R)   R;   RM   R$   R&   RU   RQ   (    (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyR   B   s   		0								t   JSResourcesc           B` sG   e  Z d  Z d d d d g Z e d „  ƒ Z e d „  ƒ Z d „  Z RS(   uf   The Resources class encapsulates information relating to loading or embedding Bokeh Javascript.

    Args:
        mode (str) : How should Bokeh JS be included in output

            See below for descriptions of available modes

        version (str, optional) : what version of Bokeh JS to load

            Only valid with the ``'cdn'`` mode

        root_dir (str, optional) : root directory for loading Bokeh JS assets

            Only valid with ``'relative'`` and ``'relative-dev'`` modes

        minified (bool, optional) : whether JavaScript should be minified or not (default: True)

        root_url (str, optional) : URL and port of Bokeh Server to load resources from (default: None)

            If ``None``, absolute URLs based on the default server configuration will
            be generated.

            ``root_url`` can also be the empty string, in which case relative URLs,
            e.g., "static/css/bokeh.min.js", are generated.

            Only valid with ``'server'`` and ``'server-dev'`` modes

    The following **mode** values are available for configuring a Resource object:

    * ``'inline'`` configure to provide entire Bokeh JS and CSS inline
    * ``'cdn'`` configure to load Bokeh JS and CSS from ``http://cdn.pydata.org``
    * ``'server'`` configure to load from a Bokeh Server
    * ``'server-dev'`` same as ``server`` but supports non-minified assets
    * ``'relative'`` configure to load relative to the given directory
    * ``'relative-dev'`` same as ``relative`` but supports non-minified assets
    * ``'absolute'`` configure to load from the installed Bokeh library static directory
    * ``'absolute-dev'`` same as ``absolute`` but supports non-minified assets

    Once configured, a Resource object exposes the following public attributes:

    Attributes:
        css_raw : any raw CSS that needs to be places inside ``<style>`` tags
        css_files : URLs of any CSS files that need to be loaded by ``<link>`` tags
        messages : any informational messages concerning this configuration

    These attributes are often useful as template parameters when embedding
    Bokeh plots.

    u   bokehu   bokeh-widgetsu   bokeh-tablesu   bokeh-glc         C` s,   |  j  d ƒ \ } } |  j d ƒ } | | S(   Nu   jsu   __javascript__(   RU   RM   (   R'   R8   RI   RH   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   js_files  s    c         C` sX   |  j  d ƒ \ } } |  j d  k	 r; | j d |  j ƒ n  |  j rT | j d ƒ n  | S(   Nu   jsu   Bokeh.set_log_level("%s");u   Bokeh.settings.dev = true(   RU   R   R.   RE   R"   (   R'   RI   RS   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   js_raw  s    	c         C` s   t  j d |  j d |  j ƒ S(   NRe   Rd   (   R	   t   renderRe   Rd   (   R'   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt	   render_js  s    (   R]   R^   t   __doc__R   Ra   Rd   Re   Rg   (    (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyRc   Î   s
   1t   CSSResourcesc           B` sJ   e  Z d  Z g  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z RS(   uI   The CSSResources class encapsulates information relating to loading or embedding Bokeh client-side CSS.

    Args:
        mode (str) : how should Bokeh CSS be included in output

            See below for descriptions of available modes

        version (str, optional) : what version of Bokeh CSS to load

            Only valid with the ``'cdn'`` mode

        root_dir (str, optional) : root directory for loading BokehJS resources

            Only valid with ``'relative'`` and ``'relative-dev'`` modes

        minified (bool, optional) : whether CSS should be minified or not (default: True)

        root_url (str, optional) : URL and port of Bokeh Server to load resources from

            Only valid with ``'server'`` and ``'server-dev'`` modes

    The following **mode** values are available for configuring a Resource object:

    * ``'inline'`` configure to provide entire BokehJS code and CSS inline
    * ``'cdn'`` configure to load Bokeh CSS from ``http://cdn.pydata.org``
    * ``'server'`` configure to load from a Bokeh Server
    * ``'server-dev'`` same as ``server`` but supports non-minified CSS
    * ``'relative'`` configure to load relative to the given directory
    * ``'relative-dev'`` same as ``relative`` but supports non-minified CSS
    * ``'absolute'`` configure to load from the installed Bokeh library static directory
    * ``'absolute-dev'`` same as ``absolute`` but supports non-minified CSS

    Once configured, a Resource object exposes the following public attributes:

    Attributes:
        css_raw : any raw CSS that needs to be places inside ``<style>`` tags
        css_files : URLs of any CSS files that need to be loaded by ``<link>`` tags
        messages : any informational messages concerning this configuration

    These attributes are often useful as template parameters when embedding Bokeh plots.

    c         C` s,   |  j  d ƒ \ } } |  j d ƒ } | | S(   Nu   cssu   __css__(   RU   RM   (   R'   R8   RI   RH   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt	   css_filesL  s    c         C` s   |  j  d ƒ \ } } | S(   Nu   css(   RU   (   R'   RI   RS   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   css_rawR  s    c         C` s#   g  |  j  D] } t j | ƒ ^ q
 S(   N(   Rk   t   jsont   dumps(   R'   t   css(    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   css_raw_strW  s    c         C` s   t  j d |  j d |  j ƒ S(   NRk   Rj   (   R
   Rf   Rk   Rj   (   R'   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt
   render_css]  s    (	   R]   R^   Rh   R   Ra   Rj   Rk   Ro   Rp   (    (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyRi     s   *t	   Resourcesc           B` s   e  Z d  Z d „  Z RS(   u!   The Resources class encapsulates information relating to loading or
    embedding Bokeh Javascript and CSS.

    Args:
        mode (str) : how should Bokeh JS and CSS be included in output

            See below for descriptions of available modes

        version (str, optional) : what version of Bokeh JS and CSS to load

            Only valid with the ``'cdn'`` mode

        root_dir (str, optional) : root directory for loading Bokeh JS and CSS assets

            Only valid with ``'relative'`` and ``'relative-dev'`` modes

        minified (bool, optional) : whether JavaScript and CSS should be minified or not (default: True)

        root_url (str, optional) : URL and port of Bokeh Server to load resources from

            Only valid with ``'server'`` and ``'server-dev'`` modes

    The following **mode** values are available for configuring a Resource object:

    * ``'inline'`` configure to provide entire Bokeh JS and CSS inline
    * ``'cdn'`` configure to load Bokeh JS and CSS from ``http://cdn.pydata.org``
    * ``'server'`` configure to load from a Bokeh Server
    * ``'server-dev'`` same as ``server`` but supports non-minified assets
    * ``'relative'`` configure to load relative to the given directory
    * ``'relative-dev'`` same as ``relative`` but supports non-minified assets
    * ``'absolute'`` configure to load from the installed Bokeh library static directory
    * ``'absolute-dev'`` same as ``absolute`` but supports non-minified assets

    Once configured, a Resource object exposes the following public attributes:

    Attributes:
        js_raw : any raw JS that needs to be placed inside ``<script>`` tags
        css_raw : any raw CSS that needs to be places inside ``<style>`` tags
        js_files : URLs of any JS files that need to be loaded by ``<script>`` tags
        css_files : URLs of any CSS files that need to be loaded by ``<link>`` tags
        messages : any informational messages concerning this configuration

    These attributes are often useful as template parameters when embedding
    Bokeh plots.

    c         C` s   d |  j  ƒ  |  j ƒ  f S(   Nu   %s
%s(   Rp   Rg   (   R'   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyRf   ’  s    (   R]   R^   Rh   Rf   (    (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyRq   `  s   .t   _SessionCoordinatesc           B` sD   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z RS(   uN    Internal class used to parse kwargs for server URL, app_path, and session_id.c         K` sš   | j  d t ƒ |  _ |  j d  k r3 t d ƒ ‚ n  |  j d k rN t |  _ n  |  j j d ƒ ro t d ƒ ‚ n  |  j j d ƒ |  _ | j  d ƒ |  _ d  S(   Nu   urlu   url cannot be Noneu   defaultu   wsuI   url should be the http or https URL for the server, not the websocket URLu   /u
   session_id(   t   getR_   t   _urlR.   R    R!   t   rstript   _session_id(   R'   t   kwargs(    (    s.   lib/python2.7/site-packages/bokeh/resources.pyR,   ›  s    c         C` s   |  j  S(   N(   Rt   (   R'   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   url®  s    c         C` s%   |  j  d k r t ƒ  |  _  n  |  j  S(   u-    Session ID derived from the kwargs provided.N(   Rv   R.   R   (   R'   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt
   session_id²  s    c         C` s   |  j  S(   u   Session ID provided in kwargs, keeping it None if it hasn't been generated yet.

        The purpose of this is to preserve ``None`` as long as possible... in some cases
        we may never generate the session ID because we generate it on the server.
        (   Rv   (   R'   (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   session_id_allowing_none¹  s    (   R]   R^   Rh   R,   Ra   Rx   Ry   Rz   (    (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyRr   ™  s
   	u   ^(\d)+\.(\d)+\.(\d)+(dev|rc)c           C` s   d S(   Nu   https://cdn.pydata.org(    (    (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   _cdn_base_urlÄ  s    c         ` s  ˆ d  k r= t j ƒ  r' t j ƒ  ‰ q= t j d ƒ d ‰ n  | rI d n d ‰  t ƒ  ‰ d } d } t j ˆ ƒ ry | n | ‰ ˆ j d ƒ rž t	 j
 d	 ƒ n  ‡  ‡ ‡ ‡ f d
 †  ‰ i ‡ f d †  d 6g  d 6} t t j d ƒ ƒ d k r| d j i d d 6d ˆ t f d 6ƒ n  | S(   Nu   -i    u   .minu    u	   bokeh/devu   bokeh/releaseu   devu   rcuA   Getting CDN URL for local dev version will not produce usable URLc         ` s   d ˆ ˆ |  ˆ ˆ  | f S(   Nu   %s/%s/%s-%s%s.%s(    (   t   compR4   (   t   _mint   base_urlt	   containerR   (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   mk_urlÜ  s    c         ` s    g  |  D] } ˆ  | | ƒ ^ q S(   N(    (   R)   R4   R7   (   R€   (    s.   lib/python2.7/site-packages/bokeh/resources.pyR>   à  R?   u   urlsu   messagesi   u   warnu   typeu|   Requesting CDN BokehJS version '%s' from Bokeh development version '%s'. This configuration is unsupported and may not work!u   text(   u   devu   rc(   R.   R   t   docs_cdnR   t   splitR{   t   _DEV_PATt   matchR   t   logt   debugt   lenRE   (   R   R   t   dev_containert   rel_containert   result(    (   R}   R~   R   R€   R   s.   lib/python2.7/site-packages/bokeh/resources.pyRN   È  s*    	
c         ` sB   | r d n d ‰  ‡  ‡ ‡ f d †  ‰ i ‡ f d †  d 6g  d 6S(   Nu   .minu    c         ` s?   d | |  ˆ  | f } ˆ d  k	 r1 ˆ | ƒ } n  d ˆ | f S(   Nu
   %s/%s%s.%su   %sstatic/%s(   R.   (   R|   R4   RT   (   R}   R   R(   (    s.   lib/python2.7/site-packages/bokeh/resources.pyR€   ñ  s    c         ` s    g  |  D] } ˆ  | | ƒ ^ q S(   N(    (   R)   R4   R7   (   R€   (    s.   lib/python2.7/site-packages/bokeh/resources.pyR>   ø  R?   u   urlsu   messages(    (   R(   R   R   (    (   R}   R€   R   R(   s.   lib/python2.7/site-packages/bokeh/resources.pyRO   î  s
    R   u   cdnu   inlineu   CDNu   INLINEu	   Resourcesu   JSResourcesu   CSSResources(   u   CDNu   INLINEu	   Resourcesu   JSResourcesu   CSSResources(1   Rh   t
   __future__R    R   R   R   t   loggingt	   getLoggerR]   R…   t   reRl   t   os.pathR   R   R   t   sixR   R?   R   t   core.templatesR	   R
   t   modelR   R   t
   util.pathsR   t   util.session_idR   t   DEFAULT_SERVER_HOSTt   DEFAULT_SERVER_PORTR_   t   objectR   Rc   Ri   Rq   Rr   t   compileRƒ   R{   R.   R`   RN   RO   t   CDNt   INLINEt   __all__(    (    (    s.   lib/python2.7/site-packages/bokeh/resources.pyt   <module>   s@   "ŒND9)	&    