B
    ‹æ@\V4  ã               @   sÔ   d Z ddlmZmZmZmZ ddlZe e¡Z	ddl
Z
ddlZddlmZmZmZ ddlmZmZ G dd„ deƒZeƒ Ze ¡ dk	r¦ee ¡ ƒd	k r¦ddlZe d
¡ e ¡ rÌe ¡ dkrÌddlZe d¡ dZdS )aþ   Control global configuration options with environment variables.
A global settings object that other parts of Bokeh can refer to.

``BOKEH_ALLOW_WS_ORIGIN`` --- List of websocket origins allowed to access bokeh.

  Comma separated list of domains that need to access bokeh websocket interface.
  This can also be provided using the --allow-websocket-origin parameter.

  Note: This option overrides the --allow-websocket-origin flag

``BOKEH_BROWSER`` --- What browser to use when opening plots.

  Valid values are any of the browser names understood by the python
  standard library webbrowser_ module.

``BOKEH_DEV`` --- Whether to use development mode.

  This uses absolute paths to development (non-minified) BokehJS components,
  sets logging to ``debug``, makes generated HTML and JSON human-readable,
  etc.

  This is a meta variable equivalent to the following environment variables:

  - ``BOKEH_BROWSER=none``
  - ``BOKEH_LOG_LEVEL=debug``
  - ``BOKEH_MINIFIED=false``
  - ``BOKEH_PRETTY=true``
  - ``BOKEH_PY_LOG_LEVEL=debug``
  - ``BOKEH_RESOURCES=absolute-dev``

  Accepted values are ``yes``/``no``, ``true``/``false`` or ``0``/``1``.

  .. note::
    When running server and notebook examples, the ``BOKEH_RESOURCES``
    setting that ``BOKEH_DEV`` sets will cause rendering problems.

    We recommend manually setting ``BOKEH_RESOURCES`` to ``server``
    for server work, and ``inline`` for notebooks (other
    :class:`~bokeh.resources.Resources` settings may also work)

``BOKEH_DOCS_CDN`` --- What version of BokehJS to use when building sphinx.

  See :ref:`bokeh.resources` module reference for full details.

``BOKEH_DOCS_VERSION`` --- What version of Bokeh to show when building sphinx docs locally.

  Useful for re-deployment purposes.

  Set to ``"local"`` to use a locally built dev version of BokehJS.

  .. note::
      This variable is only used when building documentation from the
      development version.

``BOKEH_DOCS_CSS_SERVER`` --- Where to get the CSS stylesheet from.

  By default use CSS from bokehplots.com

  .. note::
      This variable is only used when building documentation from the
      development version.

  Set to ``"local"`` to use a locally built dev version of BokehJS.

``BOKEH_LOG_LEVEL`` --- The BokehJS console logging level to use.

  Valid values are, in order of increasing severity:

  - ``trace``
  - ``debug``
  - ``info``
  - ``warn``
  - ``error``
  - ``fatal``

  The default logging level is ``info``.

  .. note::
      When running server examples, it is the value of this
      ``BOKEH_LOG_LEVEL`` that is set for the server that matters.

``BOKEH_MINIFIED`` --- Whether to emit minified JavaScript for ``bokeh.js``.

  Accepted values are ``yes``/``no``, ``true``/``false`` or ``0``/``1``.

``BOKEH_PRETTY`` --- Whether to emit "pretty printed" JSON.

  Accepted values are ``yes``/``no``, ``true``/``false`` or ``0``/``1``.

``BOKEH_PY_LOG_LEVEL`` --- The Python logging level to set.

  As in the JS side, valid values are, in order of increasing severity:

  - ``trace``
  - ``debug``
  - ``info``
  - ``warn``
  - ``error``
  - ``fatal``
  - ``none``

  The default logging level is ``none``.

``BOKEH_RESOURCES`` --- What kind of BokehJS resources to configure.

  For example:  ``inline``, ``cdn``, ``server``. See the
  :class:`~bokeh.core.resources.Resources` class reference for full details.

``BOKEH_ROOTDIR`` --- Root directory to use with ``relative`` resources.

  See the :class:`~bokeh.resources.Resources` class reference for full
  details.

``BOKEH_SIMPLE_IDS`` --- Whether to generate human-friendly object IDs.

  Accepted values are ``yes``/``no``, ``true``/``false`` or ``0``/``1``.
  Normally Bokeh generates UUIDs for object identifiers. Setting this variable
  to an affirmative value will result in more friendly simple numeric IDs
  counting up from 1000.

``BOKEH_VERSION`` --- What version of BokehJS to use with ``cdn`` resources.

  See the :class:`~bokeh.resources.Resources` class reference for full details.

.. _webbrowser: https://docs.python.org/2/library/webbrowser.html
é    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literalsN)ÚjoinÚabspathÚisdiré   )ÚROOT_DIRÚ
bokehjsdirc               @   sZ  e Zd ZdZdZdZedd„ ƒZdIdd„Zed	d
„ ƒZ	edd„ ƒZ
dd„ ZdJdd„ZdKdd„ZdLdd„ZdMdd„ZdNdd„ZdOdd„ZdPdd„ZdQdd„ZdRdd „ZdSd!d"„ZdTd#d$„ZdUd%d&„ZdVd(d)„ZdWd*d+„ZdXd,d-„ZdYd.d/„ZdZd0d1„Zd2d3„ Zd[d4d5„Zd\d7d8„Zd9d:„ Z d;d<„ Z!d=d>„ Z"d?d@„ Z#d]dAdB„Z$d^dCdD„Z%dEdF„ Z&d_dGdH„Z'dS )`Ú	_SettingszK A class to collect global, overridable Bokeh configuration settings.

    ZBOKEH_Fc             C   s   t jS )N)ÚosÚenviron)Úself© r   ú-lib/python3.7/site-packages/bokeh/settings.pyÚ_environ¸   s    z_Settings._environNc             C   s   | j  | j| |¡S )N)r   ÚgetÚ_prefix)r   ÚkeyÚdefaultr   r   r   Ú_get¼   s    z_Settings._getc             C   s   |   dd¡S )NZDEVF)Ú	_get_bool)r   r   r   r   Ú_is_dev¿   s    z_Settings._is_devc             C   s   | j S )N)r   )r   r   r   r   ÚdevÃ   s    z_Settings.devc             C   s   |d k	r| j r|S |S )N)r   )r   r   r   r   r   r   Ú_dev_or_defaultÉ   s    z_Settings._dev_or_defaultc             C   s   |   ||  ||¡¡S )N)r   r   )r   r   r   r   r   r   r   Ú_get_strÌ   s    z_Settings._get_strc             C   s   t |  ||  ||¡¡ƒS )N)Úintr   r   )r   r   r   r   r   r   r   Ú_get_intÏ   s    z_Settings._get_intc             C   s\   |   |¡}|d kr |  ||¡}n8| ¡ dkr2d}n&| ¡ dkrDd}ntd|| j|f ƒ‚|S )N)ÚtrueZyesZonÚ1T)ZfalseZnoZoffÚ0Fz*invalid value %r for boolean property %s%s)r   r   ÚlowerÚ
ValueErrorr   )r   r   r   r   Úvaluer   r   r   r   Ò   s    
z_Settings._get_boolc             C   s>   |   |¡}|d kr |  ||¡}n|   ||  ||¡¡ d¡}|S )Nú,)r   r   Úsplit)r   r   r   r   r$   r   r   r   Ú	_get_listà   s
    
z_Settings._get_listc             C   s   |   d|d¡S )zX Set the default browser that Bokeh should use to show documents
        with.

        ZBROWSERÚnone)r   )r   r   r   r   r   Úbrowserê   s    z_Settings.browserc             C   s   |   d|d¡S )zh Set (override) the type of resources that Bokeh should use when
        outputting documents.

        Z	RESOURCESzabsolute-dev)r   )r   r   r   r   r   Ú	resourcesñ   s    z_Settings.resourcesc             C   s   |   d|¡S )z; Set the root directory for "relative" resources.

        ZROOTDIR)r   )r   r   r   r   r   Úrootdirø   s    z_Settings.rootdirc             C   s   |   d|¡S )z> Set (override) the standard reported Bokeh version.

        ZVERSION)r   )r   r   r   r   r   Úversionþ   s    z_Settings.versionc             C   s   |   d|¡S )zb Set the version of BokehJS should use for CDN resources when
        building the docs.

        ZDOCS_CDN)r   )r   r   r   r   r   Údocs_cdn  s    z_Settings.docs_cdnc             C   s   |   d|¡S )z8 Set the version to use for building the docs.

        ZDOCS_VERSION)r   )r   r   r   r   r   Údocs_version  s    z_Settings.docs_versionc             C   s   |   d|d¡S )zC Set whether Bokeh should use minified BokehJS resources.

        ZMINIFIEDF)r   )r   r   r   r   r   Úminified  s    z_Settings.minifiedc             C   s   |   d|d¡S )z9 Set the log level for JavaScript BokehJS code.

        Z	LOG_LEVELÚdebug)r   )r   r   r   r   r   Ú	log_level  s    z_Settings.log_levelr(   c             C   s6   |   d|d¡}tjtjtjtjtjtjddœ}|| S )z3 Set the log level for python Bokeh code.

        ZPY_LOG_LEVELr0   N)Ztracer0   ÚinfoÚwarnÚerrorZfatalr(   )r   ÚloggingZTRACEÚDEBUGÚINFOZWARNINGZERRORZCRITICAL)r   r   ÚlevelZLEVELSr   r   r   Úpy_log_level  s    z_Settings.py_log_levelc             C   s   |   d|d¡S )z= Set whether JSON strings should be pretty-printed.

        ZPRETTYT)r   )r   r   r   r   r   Úpretty+  s    z_Settings.prettyc             C   s   |   d|d¡S )zF Set whether Bokeh should generate simple numeric model IDs.

        Z
SIMPLE_IDST)r   )r   r   r   r   r   Ú
simple_ids1  s    z_Settings.simple_idsc             C   s   |   d|d¡S )z? Set whether validation should be performed strictly.

        ZSTRICTF)r   )r   r   r   r   r   Ústrict7  s    z_Settings.strictc             C   s   |   d|¡S )z} Set the secret key.

        Should be a long, cryptographically-random secret unique the
        Bokeh deployment.
        Z
SECRET_KEY)r   )r   r   r   r   r   Ú
secret_key=  s    z_Settings.secret_keyc             C   s6   t | dƒs0|  ¡ }|dkr"d| _nt |d¡| _| jS )z@ Return the secret_key, converted to bytes and cached.

        Ú_secret_key_bytesNzutf-8)Úhasattrr=   r>   ÚcodecsÚencode)r   r   r   r   r   Úsecret_key_bytesE  s    
z_Settings.secret_key_bytesc             C   s   |   d|¡S )z• Set whether the server should only allow sessions signed with
        our secret key.

        If True, BOKEH_SECRET_KEY must also be set.

        ZSIGN_SESSIONS)r   )r   r   r   r   r   Úsign_sessionsQ  s    z_Settings.sign_sessionsTc             C   s   |   d|¡S )zK Set whether Bokeh should perform validation checks on documents.

        ZVALIDATE_DOC)r   )r   r   r   r   r   Úperform_document_validationZ  s    z%_Settings.perform_document_validationc             C   s.   | j s| jr*tttdddƒƒ}t|ƒr*|S dS )zc The absolute path of the BokehJS source code in the installed
        Bokeh source tree.

        z..ZbokehjsÚsrcN)r   Údebugjsr   r   r
   r   )r   Úbokehjssrcdirr   r   r   rG   b  s
    z_Settings.bokehjssrcdirc             C   s   t | jp| jƒS )z


        )r   r   rF   )r   r   r   r   r   o  s    z_Settings.bokehjsdirc             C   sR   |   ¡ }g }x@t |¡D ]2\}}}x&|D ]}| d¡r(| t||ƒ¡ q(W qW |S )z1 The JS files in the BokehJS directory.

        z.js)r   r   ÚwalkÚendswithÚappendr   )r   r   Újs_filesÚrootÚdirnamesÚfilesÚfnamer   r   r   rK   u  s    

z_Settings.js_filesc             C   sR   |   ¡ }g }x@t |¡D ]2\}}}x&|D ]}| d¡r(| t||ƒ¡ q(W qW |S )z2 The CSS files in the BokehJS directory.

        z.css)r   r   rH   rI   rJ   r   )r   r   rK   rL   rM   rN   rO   r   r   r   Ú	css_files  s    

z_Settings.css_filesc             C   s   |   d|¡S )NZNODEJS_PATH)r   )r   r   r   r   r   Únodejs_path  s    z_Settings.nodejs_pathc             C   s   |   d|¡S )NZPHANTOMJS_PATH)r   )r   r   r   r   r   Úphantomjs_path  s    z_Settings.phantomjs_pathc             C   s   |   dd¡S )NZIGNORE_FILENAMEF)r   )r   r   r   r   Úignore_filename“  s    z_Settings.ignore_filenamec             C   s   |   d|¡S )NZALLOW_WS_ORIGIN)r'   )r   r   r   r   r   Úallowed_ws_origin–  s    z_Settings.allowed_ws_origin)N)N)N)N)N)N)N)N)N)N)N)N)N)r(   )N)N)N)N)F)T)N)N)N)(Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rF   Úpropertyr   r   r   r   r   r   r   r   r'   r)   r*   r+   r,   r-   r.   r/   r1   r9   r:   r;   r<   r=   rB   rC   rD   rG   r   rK   rP   rQ   rR   rS   rT   r   r   r   r   r   ®   sH   



















	


r   é    zuBOKEH_SECRET_KEY is recommended to have at least 32 bytes of entropy chosen with a cryptographically-random algorithmzBBOKEH_SECRET_KEY must be set if BOKEH_SIGN_SESSIONS is set to true)Úsettings)rX   Z
__future__r   r   r   r   r5   Z	getLoggerrU   Úlogr@   r   Úos.pathr   r   r   Z
util.pathsr
   r   Úobjectr   r[   r=   ÚlenÚwarningsr3   rC   Ú__all__r   r   r   r   Ú<module>„   s$   
 p

