We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
$ can get overridden in the Notebook 
It is (evidently) possible for other libraries to override `$`, and then our use of `$(function() ...)` as `js_wrapper` here:

https://github.com/bokeh/bokeh/blob/master/bokeh/resources.py#L248

is fragile, and can cause problems, specifically plots not reloading. This was reported here:

https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/7CJxL7cKxXs

@mattpap just changing to `Bokeh.$` seems to work fine. Do you have any other input?


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `bokeh/resources.py`
Content:
```
1 ''' The resources module provides the Resources class for easily configuring
2 how BokehJS code and CSS resources should be located, loaded, and embedded in
3 Bokeh documents.
4 
5 Also provides some pre-configured Resources objects:
6 
7 Attributes:
8     CDN : load minified BokehJS from CDN
9     INLINE : provide minified BokehJS from library static directory
10 
11 '''
12 
13 from os.path import abspath, join, normpath, realpath, relpath, split, splitext
14 import sys
15 import logging
16 logger = logging.getLogger(__name__)
17 
18 import six
19 
20 from . import __version__, settings
21 
22 def _server_static_dir():
23     return join(abspath(split(__file__)[0]), "server", "static")
24 
25 def _static_path(path):
26     path = normpath(join(_server_static_dir(), path))
27     if sys.platform == 'cygwin': path = realpath(path)
28     return path
29 
30 def _cdn_base_url():
31     return "http://cdn.pydata.org"
32 
33 def _get_cdn_urls(version=None, minified=True):
34     if version is None:
35         version = __version__.split('-')[0]
36     min = ".min" if minified else ""
37     base_url = _cdn_base_url()
38     result = {
39         'js_files'  : ['%s/bokeh-%s%s.js' % (base_url, version, min)],
40         'css_files' : ['%s/bokeh-%s%s.css' % (base_url, version, min)],
41         'messages'  : [],
42     }
43     if len(__version__.split('-')) > 1:
44         result['messages'].append({
45             "type" : "warn",
46             "text" : "Requesting CDN BokehJS version '%s' from Bokeh development version '%s'. This configuration is unsupported and may not work!" % (version, __version__)
47         })
48     return result
49 
50 def _get_server_urls(root_url, minified=True):
51     min = ".min" if minified else ""
52     result = {
53         'js_files'  : ['%sbokehjs/static/js/bokeh%s.js' % (root_url,  min)],
54         'css_files' : ['%sbokehjs/static/css/bokeh%s.css' % (root_url,  min)],
55         'messages'  : [],
56     }
57     return result
58 
59 
60 def _inline(paths):
61     strings = []
62     for path in paths:
63         begin = "/* BEGIN %s */" % path
64         middle = open(path, 'rb').read().decode("utf-8")
65         end = "/* END %s */" % path
66         strings.append(begin + '\n' + middle + '\n' + end)
67     return strings
68 
69 def _file_paths(files, minified):
70     if minified:
71         files = [ root + ".min" + ext for (root, ext) in map(splitext, files) ]
72     return [ _static_path(file) for file in files ]
73 
74 
75 class Resources(object):
76     ''' The Resources class encapsulates information relating to loading or
77     embedding BokehJS code and CSS.
78 
79     Args:
80         mode (str) : how should BokehJS be included in output
81 
82             See below for descriptions of available modes
83 
84         version (str, optional) : what version of BokejJS to load
85 
86             Only valid with the ``'cdn'`` mode
87 
88         root_dir (str, optional) : root directory for loading BokehJS resources
89 
90             Only valid with ``'relative'`` and ``'relative-dev'`` modes
91 
92         minified (bool, optional) : whether JavaScript and CSS should be minified or not (default: True)
93 
94         host (str, optional) : URL and port of Bokeh Server to load resources from
95 
96             Only valid with ``'server'`` and ``'server-dev'`` modes
97 
98     The following **mode** values are available for configuring a Resource object:
99 
100     * ``'inline'`` configure to provide entire BokehJS code and CSS inline
101     * ``'cdn'`` configure to load BokehJS code and CS from ``http://cdn.pydata.org``
102     * ``'server'`` configure to load from a Bokeh Server
103     * ``'server-dev'`` same as ``server`` but supports non-concatenated JS using ``requirejs``
104     * ``'relative'`` configure to load relative to the given directory
105     * ``'relative-dev'`` same as ``relative`` but supports non-concatenated JS using ``requirejs``
106     * ``'absolute'`` configure to load from the installed Bokeh library static directory
107     * ``'absolute-dev'`` same as ``absolute`` but supports non-concatenated JS using ``requirejs``
108 
109     Once configured, a Resource object exposes the following public attributes:
110 
111     Attributes:
112         logo_url : location of the BokehJS logo image
113         js_raw : any raw JS that needs to be placed inside ``<script>`` tags
114         css_raw : any raw CSS that needs to be places inside ``<style>`` tags
115         js_files : URLs of any JS files that need to be loaded by ``<script>`` tags
116         css_files : URLS od any CSS files that need to be loaed by ``<link>`` tags
117         messages : any informational messages concering this configuration
118 
119     These attributes are often useful as template parameters when embedding
120     Bokeh plots.
121 
122     '''
123 
124     _default_js_files = ["js/bokeh.js"]
125     _default_css_files = ["css/bokeh.css"]
126 
127     _default_js_files_dev = ['js/vendor/requirejs/require.js', 'js/config.js']
128     _default_css_files_dev = ['css/bokeh.css']
129 
130     _default_root_dir = "."
131     _default_root_url = "http://127.0.0.1:5006/"
132 
133     logo_url = "http://bokeh.pydata.org/_static/bokeh-transparent.png"
134 
135     def __init__(self, mode='inline', version=None, root_dir=None,
136                  minified=True, log_level="info", root_url=None):
137         self.mode = settings.resources(mode)
138         self.root_dir = settings.rootdir(root_dir)
139         self.version = settings.version(version)
140         self.minified = settings.minified(minified)
141         self.log_level = settings.log_level(log_level)
142         if root_url and not root_url.endswith("/"):
143             logger.warning("root_url should end with a /, adding one")
144             root_url = root_url + "/"
145         self._root_url = root_url
146         if mode not in ['inline', 'cdn', 'server', 'server-dev', 'relative', 'relative-dev', 'absolute', 'absolute-dev']:
147             raise ValueError("wrong value for 'mode' parameter, expected 'inline', 'cdn', 'server(-dev)', 'relative(-dev)' or 'absolute(-dev)', got %r" % self.mode)
148 
149         if self.root_dir and not mode.startswith("relative"):
150             raise ValueError("setting 'root_dir' makes sense only when 'mode' is set to 'relative'")
151 
152         if self.version and not mode.startswith('cdn'):
153             raise ValueError("setting 'version' makes sense only when 'mode' is set to 'cdn'")
154 
155         if root_url and not mode.startswith('server'):
156             raise ValueError("setting 'root_url' makes sense only when 'mode' is set to 'server'")
157 
158         self.dev = self.mode.endswith('-dev')
159         if self.dev:
160             self.mode = self.mode[:-4]
161 
162         js_paths = self._js_paths(dev=self.dev, minified=self.minified)
163         css_paths = self._css_paths(dev=self.dev, minified=self.minified)
164         base_url = _static_path("js")
165 
166         self._js_raw = []
167         self._css_raw = []
168         self.js_files = []
169         self.css_files = []
170         self.messages = []
171 
172         if self.mode == "inline":
173             self._js_raw = lambda: _inline(js_paths)
174             self._css_raw = lambda: _inline(css_paths)
175         elif self.mode == "relative":
176             root_dir = self.root_dir or self._default_root_dir
177             self.js_files = [ relpath(p, root_dir) for p in js_paths ]
178             self.css_files = [ relpath(p, root_dir) for p in css_paths ]
179             base_url = relpath(base_url, root_dir)
180         elif self.mode == "absolute":
181             self.js_files = list(js_paths)
182             self.css_files = list(css_paths)
183         elif self.mode == "cdn":
184             cdn = _get_cdn_urls(self.version, self.minified)
185             self.js_files = list(cdn['js_files'])
186             self.css_files = list(cdn['css_files'])
187             self.messages.extend(cdn['messages'])
188         elif self.mode == "server":
189             server = _get_server_urls(self.root_url, self.minified)
190             self.js_files = list(server['js_files'])
191             self.css_files = list(server['css_files'])
192             self.messages.extend(server['messages'])
193 
194         if self.dev:
195             require = 'require.config({ baseUrl: "%s" });' % base_url
196             self._js_raw.append(require)
197 
198     @property
199     def log_level(self):
200         return self._log_level
201 
202     @log_level.setter
203     def log_level(self, level):
204         valid_levels = [
205             "trace", "debug", "info", "warn", "error", "fatal"
206         ]
207         if level not in valid_levels:
208             raise ValueError("Unknown log level '%s', valid levels are: %s", str(valid_levels))
209         self._log_level = level
210 
211 
212     @property
213     def js_raw(self):
214         if six.callable(self._js_raw):
215             self._js_raw = self._js_raw()
216         if self.dev:
217             return self._js_raw
218         else:
219             return self._js_raw + ['Bokeh.set_log_level("%s");' % self.log_level]
220 
221     @property
222     def css_raw(self):
223         if six.callable(self._css_raw):
224             self._css_raw = self._css_raw()
225         return self._css_raw
226 
227     @property
228     def root_url(self):
229         if self._root_url:
230             return self._root_url
231         else:
232             return self._default_root_url
233 
234     def _js_paths(self, minified=True, dev=False):
235         files = self._default_js_files_dev if self.dev else self._default_js_files
236         return _file_paths(files, False if dev else minified)
237 
238     def _css_paths(self, minified=True, dev=False):
239         files = self._default_css_files_dev if self.dev else self._default_css_files
240         return _file_paths(files, False if dev else minified)
241 
242     @property
243     def js_wrapper(self):
244 
245         def pad(text, n=4):
246             return "\n".join([ " "*n + line for line in text.split("\n") ])
247 
248         wrapper = lambda code: '$(function() {\n%s\n});' % pad(code)
249 
250         if self.dev:
251             js_wrapper = lambda code: 'require(["jquery", "main"], function($, Bokeh) {\nBokeh.set_log_level("%s");\n%s\n});' % (self.log_level, pad(wrapper(code)))
252         else:
253             js_wrapper = wrapper
254 
255         return js_wrapper
256 
257     def _autoload_path(self, elementid):
258         return self.root_url + "bokeh/autoload.js/%s" % elementid
259 
260 CDN = Resources(mode="cdn")
261 
262 INLINE = Resources(mode="inline")
263
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/bokeh/resources.py b/bokeh/resources.py
--- a/bokeh/resources.py
+++ b/bokeh/resources.py
@@ -245,7 +245,7 @@
         def pad(text, n=4):
             return "\n".join([ " "*n + line for line in text.split("\n") ])
 
-        wrapper = lambda code: '$(function() {\n%s\n});' % pad(code)
+        wrapper = lambda code: 'Bokeh.$(function() {\n%s\n});' % pad(code)
 
         if self.dev:
             js_wrapper = lambda code: 'require(["jquery", "main"], function($, Bokeh) {\nBokeh.set_log_level("%s");\n%s\n});' % (self.log_level, pad(wrapper(code)))

{"golden_diff": "diff --git a/bokeh/resources.py b/bokeh/resources.py\n--- a/bokeh/resources.py\n+++ b/bokeh/resources.py\n@@ -245,7 +245,7 @@\n         def pad(text, n=4):\n             return \"\\n\".join([ \" \"*n + line for line in text.split(\"\\n\") ])\n \n-        wrapper = lambda code: '$(function() {\\n%s\\n});' % pad(code)\n+        wrapper = lambda code: 'Bokeh.$(function() {\\n%s\\n});' % pad(code)\n \n         if self.dev:\n             js_wrapper = lambda code: 'require([\"jquery\", \"main\"], function($, Bokeh) {\\nBokeh.set_log_level(\"%s\");\\n%s\\n});' % (self.log_level, pad(wrapper(code)))\n", "issue": "$ can get overridden in the Notebook \nIt is (evidently) possible for other libraries to override `$`, and then our use of `$(function() ...)` as `js_wrapper` here:\n\nhttps://github.com/bokeh/bokeh/blob/master/bokeh/resources.py#L248\n\nis fragile, and can cause problems, specifically plots not reloading. This was reported here:\n\nhttps://groups.google.com/a/continuum.io/forum/#!topic/bokeh/7CJxL7cKxXs\n\n@mattpap just changing to `Bokeh.$` seems to work fine. Do you have any other input?\n\n", "before_files": [{"content": "''' The resources module provides the Resources class for easily configuring\nhow BokehJS code and CSS resources should be located, loaded, and embedded in\nBokeh documents.\n\nAlso provides some pre-configured Resources objects:\n\nAttributes:\n    CDN : load minified BokehJS from CDN\n    INLINE : provide minified BokehJS from library static directory\n\n'''\n\nfrom os.path import abspath, join, normpath, realpath, relpath, split, splitext\nimport sys\nimport logging\nlogger = logging.getLogger(__name__)\n\nimport six\n\nfrom . import __version__, settings\n\ndef _server_static_dir():\n    return join(abspath(split(__file__)[0]), \"server\", \"static\")\n\ndef _static_path(path):\n    path = normpath(join(_server_static_dir(), path))\n    if sys.platform == 'cygwin': path = realpath(path)\n    return path\n\ndef _cdn_base_url():\n    return \"http://cdn.pydata.org\"\n\ndef _get_cdn_urls(version=None, minified=True):\n    if version is None:\n        version = __version__.split('-')[0]\n    min = \".min\" if minified else \"\"\n    base_url = _cdn_base_url()\n    result = {\n        'js_files'  : ['%s/bokeh-%s%s.js' % (base_url, version, min)],\n        'css_files' : ['%s/bokeh-%s%s.css' % (base_url, version, min)],\n        'messages'  : [],\n    }\n    if len(__version__.split('-')) > 1:\n        result['messages'].append({\n            \"type\" : \"warn\",\n            \"text\" : \"Requesting CDN BokehJS version '%s' from Bokeh development version '%s'. This configuration is unsupported and may not work!\" % (version, __version__)\n        })\n    return result\n\ndef _get_server_urls(root_url, minified=True):\n    min = \".min\" if minified else \"\"\n    result = {\n        'js_files'  : ['%sbokehjs/static/js/bokeh%s.js' % (root_url,  min)],\n        'css_files' : ['%sbokehjs/static/css/bokeh%s.css' % (root_url,  min)],\n        'messages'  : [],\n    }\n    return result\n\n\ndef _inline(paths):\n    strings = []\n    for path in paths:\n        begin = \"/* BEGIN %s */\" % path\n        middle = open(path, 'rb').read().decode(\"utf-8\")\n        end = \"/* END %s */\" % path\n        strings.append(begin + '\\n' + middle + '\\n' + end)\n    return strings\n\ndef _file_paths(files, minified):\n    if minified:\n        files = [ root + \".min\" + ext for (root, ext) in map(splitext, files) ]\n    return [ _static_path(file) for file in files ]\n\n\nclass Resources(object):\n    ''' The Resources class encapsulates information relating to loading or\n    embedding BokehJS code and CSS.\n\n    Args:\n        mode (str) : how should BokehJS be included in output\n\n            See below for descriptions of available modes\n\n        version (str, optional) : what version of BokejJS to load\n\n            Only valid with the ``'cdn'`` mode\n\n        root_dir (str, optional) : root directory for loading BokehJS resources\n\n            Only valid with ``'relative'`` and ``'relative-dev'`` modes\n\n        minified (bool, optional) : whether JavaScript and CSS should be minified or not (default: True)\n\n        host (str, optional) : URL and port of Bokeh Server to load resources from\n\n            Only valid with ``'server'`` and ``'server-dev'`` modes\n\n    The following **mode** values are available for configuring a Resource object:\n\n    * ``'inline'`` configure to provide entire BokehJS code and CSS inline\n    * ``'cdn'`` configure to load BokehJS code and CS from ``http://cdn.pydata.org``\n    * ``'server'`` configure to load from a Bokeh Server\n    * ``'server-dev'`` same as ``server`` but supports non-concatenated JS using ``requirejs``\n    * ``'relative'`` configure to load relative to the given directory\n    * ``'relative-dev'`` same as ``relative`` but supports non-concatenated JS using ``requirejs``\n    * ``'absolute'`` configure to load from the installed Bokeh library static directory\n    * ``'absolute-dev'`` same as ``absolute`` but supports non-concatenated JS using ``requirejs``\n\n    Once configured, a Resource object exposes the following public attributes:\n\n    Attributes:\n        logo_url : location of the BokehJS logo image\n        js_raw : any raw JS that needs to be placed inside ``<script>`` tags\n        css_raw : any raw CSS that needs to be places inside ``<style>`` tags\n        js_files : URLs of any JS files that need to be loaded by ``<script>`` tags\n        css_files : URLS od any CSS files that need to be loaed by ``<link>`` tags\n        messages : any informational messages concering this configuration\n\n    These attributes are often useful as template parameters when embedding\n    Bokeh plots.\n\n    '''\n\n    _default_js_files = [\"js/bokeh.js\"]\n    _default_css_files = [\"css/bokeh.css\"]\n\n    _default_js_files_dev = ['js/vendor/requirejs/require.js', 'js/config.js']\n    _default_css_files_dev = ['css/bokeh.css']\n\n    _default_root_dir = \".\"\n    _default_root_url = \"http://127.0.0.1:5006/\"\n\n    logo_url = \"http://bokeh.pydata.org/_static/bokeh-transparent.png\"\n\n    def __init__(self, mode='inline', version=None, root_dir=None,\n                 minified=True, log_level=\"info\", root_url=None):\n        self.mode = settings.resources(mode)\n        self.root_dir = settings.rootdir(root_dir)\n        self.version = settings.version(version)\n        self.minified = settings.minified(minified)\n        self.log_level = settings.log_level(log_level)\n        if root_url and not root_url.endswith(\"/\"):\n            logger.warning(\"root_url should end with a /, adding one\")\n            root_url = root_url + \"/\"\n        self._root_url = root_url\n        if mode not in ['inline', 'cdn', 'server', 'server-dev', 'relative', 'relative-dev', 'absolute', 'absolute-dev']:\n            raise ValueError(\"wrong value for 'mode' parameter, expected 'inline', 'cdn', 'server(-dev)', 'relative(-dev)' or 'absolute(-dev)', got %r\" % self.mode)\n\n        if self.root_dir and not mode.startswith(\"relative\"):\n            raise ValueError(\"setting 'root_dir' makes sense only when 'mode' is set to 'relative'\")\n\n        if self.version and not mode.startswith('cdn'):\n            raise ValueError(\"setting 'version' makes sense only when 'mode' is set to 'cdn'\")\n\n        if root_url and not mode.startswith('server'):\n            raise ValueError(\"setting 'root_url' makes sense only when 'mode' is set to 'server'\")\n\n        self.dev = self.mode.endswith('-dev')\n        if self.dev:\n            self.mode = self.mode[:-4]\n\n        js_paths = self._js_paths(dev=self.dev, minified=self.minified)\n        css_paths = self._css_paths(dev=self.dev, minified=self.minified)\n        base_url = _static_path(\"js\")\n\n        self._js_raw = []\n        self._css_raw = []\n        self.js_files = []\n        self.css_files = []\n        self.messages = []\n\n        if self.mode == \"inline\":\n            self._js_raw = lambda: _inline(js_paths)\n            self._css_raw = lambda: _inline(css_paths)\n        elif self.mode == \"relative\":\n            root_dir = self.root_dir or self._default_root_dir\n            self.js_files = [ relpath(p, root_dir) for p in js_paths ]\n            self.css_files = [ relpath(p, root_dir) for p in css_paths ]\n            base_url = relpath(base_url, root_dir)\n        elif self.mode == \"absolute\":\n            self.js_files = list(js_paths)\n            self.css_files = list(css_paths)\n        elif self.mode == \"cdn\":\n            cdn = _get_cdn_urls(self.version, self.minified)\n            self.js_files = list(cdn['js_files'])\n            self.css_files = list(cdn['css_files'])\n            self.messages.extend(cdn['messages'])\n        elif self.mode == \"server\":\n            server = _get_server_urls(self.root_url, self.minified)\n            self.js_files = list(server['js_files'])\n            self.css_files = list(server['css_files'])\n            self.messages.extend(server['messages'])\n\n        if self.dev:\n            require = 'require.config({ baseUrl: \"%s\" });' % base_url\n            self._js_raw.append(require)\n\n    @property\n    def log_level(self):\n        return self._log_level\n\n    @log_level.setter\n    def log_level(self, level):\n        valid_levels = [\n            \"trace\", \"debug\", \"info\", \"warn\", \"error\", \"fatal\"\n        ]\n        if level not in valid_levels:\n            raise ValueError(\"Unknown log level '%s', valid levels are: %s\", str(valid_levels))\n        self._log_level = level\n\n\n    @property\n    def js_raw(self):\n        if six.callable(self._js_raw):\n            self._js_raw = self._js_raw()\n        if self.dev:\n            return self._js_raw\n        else:\n            return self._js_raw + ['Bokeh.set_log_level(\"%s\");' % self.log_level]\n\n    @property\n    def css_raw(self):\n        if six.callable(self._css_raw):\n            self._css_raw = self._css_raw()\n        return self._css_raw\n\n    @property\n    def root_url(self):\n        if self._root_url:\n            return self._root_url\n        else:\n            return self._default_root_url\n\n    def _js_paths(self, minified=True, dev=False):\n        files = self._default_js_files_dev if self.dev else self._default_js_files\n        return _file_paths(files, False if dev else minified)\n\n    def _css_paths(self, minified=True, dev=False):\n        files = self._default_css_files_dev if self.dev else self._default_css_files\n        return _file_paths(files, False if dev else minified)\n\n    @property\n    def js_wrapper(self):\n\n        def pad(text, n=4):\n            return \"\\n\".join([ \" \"*n + line for line in text.split(\"\\n\") ])\n\n        wrapper = lambda code: '$(function() {\\n%s\\n});' % pad(code)\n\n        if self.dev:\n            js_wrapper = lambda code: 'require([\"jquery\", \"main\"], function($, Bokeh) {\\nBokeh.set_log_level(\"%s\");\\n%s\\n});' % (self.log_level, pad(wrapper(code)))\n        else:\n            js_wrapper = wrapper\n\n        return js_wrapper\n\n    def _autoload_path(self, elementid):\n        return self.root_url + \"bokeh/autoload.js/%s\" % elementid\n\nCDN = Resources(mode=\"cdn\")\n\nINLINE = Resources(mode=\"inline\")\n", "path": "bokeh/resources.py"}], "after_files": [{"content": "''' The resources module provides the Resources class for easily configuring\nhow BokehJS code and CSS resources should be located, loaded, and embedded in\nBokeh documents.\n\nAlso provides some pre-configured Resources objects:\n\nAttributes:\n    CDN : load minified BokehJS from CDN\n    INLINE : provide minified BokehJS from library static directory\n\n'''\n\nfrom os.path import abspath, join, normpath, realpath, relpath, split, splitext\nimport sys\nimport logging\nlogger = logging.getLogger(__name__)\n\nimport six\n\nfrom . import __version__, settings\n\ndef _server_static_dir():\n    return join(abspath(split(__file__)[0]), \"server\", \"static\")\n\ndef _static_path(path):\n    path = normpath(join(_server_static_dir(), path))\n    if sys.platform == 'cygwin': path = realpath(path)\n    return path\n\ndef _cdn_base_url():\n    return \"http://cdn.pydata.org\"\n\ndef _get_cdn_urls(version=None, minified=True):\n    if version is None:\n        version = __version__.split('-')[0]\n    min = \".min\" if minified else \"\"\n    base_url = _cdn_base_url()\n    result = {\n        'js_files'  : ['%s/bokeh-%s%s.js' % (base_url, version, min)],\n        'css_files' : ['%s/bokeh-%s%s.css' % (base_url, version, min)],\n        'messages'  : [],\n    }\n    if len(__version__.split('-')) > 1:\n        result['messages'].append({\n            \"type\" : \"warn\",\n            \"text\" : \"Requesting CDN BokehJS version '%s' from Bokeh development version '%s'. This configuration is unsupported and may not work!\" % (version, __version__)\n        })\n    return result\n\ndef _get_server_urls(root_url, minified=True):\n    min = \".min\" if minified else \"\"\n    result = {\n        'js_files'  : ['%sbokehjs/static/js/bokeh%s.js' % (root_url,  min)],\n        'css_files' : ['%sbokehjs/static/css/bokeh%s.css' % (root_url,  min)],\n        'messages'  : [],\n    }\n    return result\n\n\ndef _inline(paths):\n    strings = []\n    for path in paths:\n        begin = \"/* BEGIN %s */\" % path\n        middle = open(path, 'rb').read().decode(\"utf-8\")\n        end = \"/* END %s */\" % path\n        strings.append(begin + '\\n' + middle + '\\n' + end)\n    return strings\n\ndef _file_paths(files, minified):\n    if minified:\n        files = [ root + \".min\" + ext for (root, ext) in map(splitext, files) ]\n    return [ _static_path(file) for file in files ]\n\n\nclass Resources(object):\n    ''' The Resources class encapsulates information relating to loading or\n    embedding BokehJS code and CSS.\n\n    Args:\n        mode (str) : how should BokehJS be included in output\n\n            See below for descriptions of available modes\n\n        version (str, optional) : what version of BokejJS to load\n\n            Only valid with the ``'cdn'`` mode\n\n        root_dir (str, optional) : root directory for loading BokehJS resources\n\n            Only valid with ``'relative'`` and ``'relative-dev'`` modes\n\n        minified (bool, optional) : whether JavaScript and CSS should be minified or not (default: True)\n\n        host (str, optional) : URL and port of Bokeh Server to load resources from\n\n            Only valid with ``'server'`` and ``'server-dev'`` modes\n\n    The following **mode** values are available for configuring a Resource object:\n\n    * ``'inline'`` configure to provide entire BokehJS code and CSS inline\n    * ``'cdn'`` configure to load BokehJS code and CS from ``http://cdn.pydata.org``\n    * ``'server'`` configure to load from a Bokeh Server\n    * ``'server-dev'`` same as ``server`` but supports non-concatenated JS using ``requirejs``\n    * ``'relative'`` configure to load relative to the given directory\n    * ``'relative-dev'`` same as ``relative`` but supports non-concatenated JS using ``requirejs``\n    * ``'absolute'`` configure to load from the installed Bokeh library static directory\n    * ``'absolute-dev'`` same as ``absolute`` but supports non-concatenated JS using ``requirejs``\n\n    Once configured, a Resource object exposes the following public attributes:\n\n    Attributes:\n        logo_url : location of the BokehJS logo image\n        js_raw : any raw JS that needs to be placed inside ``<script>`` tags\n        css_raw : any raw CSS that needs to be places inside ``<style>`` tags\n        js_files : URLs of any JS files that need to be loaded by ``<script>`` tags\n        css_files : URLS od any CSS files that need to be loaed by ``<link>`` tags\n        messages : any informational messages concering this configuration\n\n    These attributes are often useful as template parameters when embedding\n    Bokeh plots.\n\n    '''\n\n    _default_js_files = [\"js/bokeh.js\"]\n    _default_css_files = [\"css/bokeh.css\"]\n\n    _default_js_files_dev = ['js/vendor/requirejs/require.js', 'js/config.js']\n    _default_css_files_dev = ['css/bokeh.css']\n\n    _default_root_dir = \".\"\n    _default_root_url = \"http://127.0.0.1:5006/\"\n\n    logo_url = \"http://bokeh.pydata.org/_static/bokeh-transparent.png\"\n\n    def __init__(self, mode='inline', version=None, root_dir=None,\n                 minified=True, log_level=\"info\", root_url=None):\n        self.mode = settings.resources(mode)\n        self.root_dir = settings.rootdir(root_dir)\n        self.version = settings.version(version)\n        self.minified = settings.minified(minified)\n        self.log_level = settings.log_level(log_level)\n        if root_url and not root_url.endswith(\"/\"):\n            logger.warning(\"root_url should end with a /, adding one\")\n            root_url = root_url + \"/\"\n        self._root_url = root_url\n        if mode not in ['inline', 'cdn', 'server', 'server-dev', 'relative', 'relative-dev', 'absolute', 'absolute-dev']:\n            raise ValueError(\"wrong value for 'mode' parameter, expected 'inline', 'cdn', 'server(-dev)', 'relative(-dev)' or 'absolute(-dev)', got %r\" % self.mode)\n\n        if self.root_dir and not mode.startswith(\"relative\"):\n            raise ValueError(\"setting 'root_dir' makes sense only when 'mode' is set to 'relative'\")\n\n        if self.version and not mode.startswith('cdn'):\n            raise ValueError(\"setting 'version' makes sense only when 'mode' is set to 'cdn'\")\n\n        if root_url and not mode.startswith('server'):\n            raise ValueError(\"setting 'root_url' makes sense only when 'mode' is set to 'server'\")\n\n        self.dev = self.mode.endswith('-dev')\n        if self.dev:\n            self.mode = self.mode[:-4]\n\n        js_paths = self._js_paths(dev=self.dev, minified=self.minified)\n        css_paths = self._css_paths(dev=self.dev, minified=self.minified)\n        base_url = _static_path(\"js\")\n\n        self._js_raw = []\n        self._css_raw = []\n        self.js_files = []\n        self.css_files = []\n        self.messages = []\n\n        if self.mode == \"inline\":\n            self._js_raw = lambda: _inline(js_paths)\n            self._css_raw = lambda: _inline(css_paths)\n        elif self.mode == \"relative\":\n            root_dir = self.root_dir or self._default_root_dir\n            self.js_files = [ relpath(p, root_dir) for p in js_paths ]\n            self.css_files = [ relpath(p, root_dir) for p in css_paths ]\n            base_url = relpath(base_url, root_dir)\n        elif self.mode == \"absolute\":\n            self.js_files = list(js_paths)\n            self.css_files = list(css_paths)\n        elif self.mode == \"cdn\":\n            cdn = _get_cdn_urls(self.version, self.minified)\n            self.js_files = list(cdn['js_files'])\n            self.css_files = list(cdn['css_files'])\n            self.messages.extend(cdn['messages'])\n        elif self.mode == \"server\":\n            server = _get_server_urls(self.root_url, self.minified)\n            self.js_files = list(server['js_files'])\n            self.css_files = list(server['css_files'])\n            self.messages.extend(server['messages'])\n\n        if self.dev:\n            require = 'require.config({ baseUrl: \"%s\" });' % base_url\n            self._js_raw.append(require)\n\n    @property\n    def log_level(self):\n        return self._log_level\n\n    @log_level.setter\n    def log_level(self, level):\n        valid_levels = [\n            \"trace\", \"debug\", \"info\", \"warn\", \"error\", \"fatal\"\n        ]\n        if level not in valid_levels:\n            raise ValueError(\"Unknown log level '%s', valid levels are: %s\", str(valid_levels))\n        self._log_level = level\n\n\n    @property\n    def js_raw(self):\n        if six.callable(self._js_raw):\n            self._js_raw = self._js_raw()\n        if self.dev:\n            return self._js_raw\n        else:\n            return self._js_raw + ['Bokeh.set_log_level(\"%s\");' % self.log_level]\n\n    @property\n    def css_raw(self):\n        if six.callable(self._css_raw):\n            self._css_raw = self._css_raw()\n        return self._css_raw\n\n    @property\n    def root_url(self):\n        if self._root_url:\n            return self._root_url\n        else:\n            return self._default_root_url\n\n    def _js_paths(self, minified=True, dev=False):\n        files = self._default_js_files_dev if self.dev else self._default_js_files\n        return _file_paths(files, False if dev else minified)\n\n    def _css_paths(self, minified=True, dev=False):\n        files = self._default_css_files_dev if self.dev else self._default_css_files\n        return _file_paths(files, False if dev else minified)\n\n    @property\n    def js_wrapper(self):\n\n        def pad(text, n=4):\n            return \"\\n\".join([ \" \"*n + line for line in text.split(\"\\n\") ])\n\n        wrapper = lambda code: 'Bokeh.$(function() {\\n%s\\n});' % pad(code)\n\n        if self.dev:\n            js_wrapper = lambda code: 'require([\"jquery\", \"main\"], function($, Bokeh) {\\nBokeh.set_log_level(\"%s\");\\n%s\\n});' % (self.log_level, pad(wrapper(code)))\n        else:\n            js_wrapper = wrapper\n\n        return js_wrapper\n\n    def _autoload_path(self, elementid):\n        return self.root_url + \"bokeh/autoload.js/%s\" % elementid\n\nCDN = Resources(mode=\"cdn\")\n\nINLINE = Resources(mode=\"inline\")\n", "path": "bokeh/resources.py"}]}