We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Use utf-8 encoding to open notebook file.
Currently,  `ipynb` file is opened by following code:

```
        with open(filename) as f:
            pass
```

https://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/notebook.py#L117

I suggest to open the file with `encoding="utf-8"`, otherwise the serve command will raise error on Windows system.

--- 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/application/handlers/notebook.py`
Content:
```
1 #-----------------------------------------------------------------------------
2 # Copyright (c) 2012 - 2019, Anaconda, Inc., and Bokeh Contributors.
3 # All rights reserved.
4 #
5 # The full license is in the file LICENSE.txt, distributed with this software.
6 #-----------------------------------------------------------------------------
7 ''' Provide a Bokeh Application Handler to build up documents by running
8 the code from Jupyter notebook (``.ipynb``) files.
9 
10 This handler is configured with the filename of a Jupyter notebook. When a
11 Bokeh application calls ``modify_doc``, the code from all the notebook cells
12 is collected and executed to process a new Document for a session. When the
13 notebook code is executed, the Document being modified will be available as
14 ``curdoc``, and any optionally provided ``args`` will be available as
15 ``sys.argv``.
16 
17 '''
18 
19 #-----------------------------------------------------------------------------
20 # Boilerplate
21 #-----------------------------------------------------------------------------
22 from __future__ import absolute_import, division, print_function, unicode_literals
23 
24 import re
25 import sys
26 import logging
27 log = logging.getLogger(__name__)
28 
29 #-----------------------------------------------------------------------------
30 # Imports
31 #-----------------------------------------------------------------------------
32 
33 # Standard library imports
34 
35 # External imports
36 
37 # Bokeh imports
38 from ...util.dependencies import import_required
39 from .code import CodeHandler
40 
41 #-----------------------------------------------------------------------------
42 # Globals and constants
43 #-----------------------------------------------------------------------------
44 
45 __all__ = (
46     'NotebookHandler',
47 )
48 
49 #-----------------------------------------------------------------------------
50 # General API
51 #-----------------------------------------------------------------------------
52 
53 #-----------------------------------------------------------------------------
54 # Dev API
55 #-----------------------------------------------------------------------------
56 
57 class NotebookHandler(CodeHandler):
58     ''' A Handler that uses code in a Jupyter notebook for modifying Bokeh
59     Documents.
60 
61     '''
62 
63     _logger_text = "%s: call to %s() ignored when running notebooks with the 'bokeh' command."
64 
65     _origin = "Notebook"
66 
67     def __init__(self, *args, **kwargs):
68         '''
69 
70         Keywords:
71             filename (str) : a path to a Jupyter notebook (".ipynb") file
72 
73         '''
74         nbformat = import_required('nbformat', 'The Bokeh notebook application handler requires Jupyter Notebook to be installed.')
75         nbconvert = import_required('nbconvert', 'The Bokeh notebook application handler requires Jupyter Notebook to be installed.')
76 
77         if 'filename' not in kwargs:
78             raise ValueError('Must pass a filename to NotebookHandler')
79 
80 
81         class StripMagicsProcessor(nbconvert.preprocessors.Preprocessor):
82             """
83             Preprocessor to convert notebooks to Python source while stripping
84             out all magics (i.e IPython specific syntax).
85             """
86 
87             _magic_pattern = re.compile(r'^\s*(?P<magic>%%\w\w+)($|(\s+))')
88 
89             def strip_magics(self, source):
90                 """
91                 Given the source of a cell, filter out all cell and line magics.
92                 """
93                 filtered=[]
94                 for line in source.splitlines():
95                     match = self._magic_pattern.match(line)
96                     if match is None:
97                         filtered.append(line)
98                     else:
99                         msg = 'Stripping out IPython magic {magic} in code cell {cell}'
100                         message = msg.format(cell=self._cell_counter, magic=match.group('magic'))
101                         log.warning(message)
102                 return '\n'.join(filtered)
103 
104             def preprocess_cell(self, cell, resources, index):
105                 if cell['cell_type'] == 'code':
106                     self._cell_counter += 1
107                     cell['source'] = self.strip_magics(cell['source'])
108                 return cell, resources
109 
110             def __call__(self, nb, resources):
111                 self._cell_counter = 0
112                 return self.preprocess(nb,resources)
113 
114         preprocessors=[StripMagicsProcessor()]
115         filename = kwargs['filename']
116 
117         with open(filename) as f:
118             nb = nbformat.read(f, nbformat.NO_CONVERT)
119             exporter = nbconvert.PythonExporter()
120 
121             for preprocessor in preprocessors:
122                 exporter.register_preprocessor(preprocessor)
123 
124             source, _ = exporter.from_notebook_node(nb)
125             source = source.replace('get_ipython().run_line_magic', '')
126             source = source.replace('get_ipython().magic', '')
127 
128             if sys.version_info.major == 2 and isinstance(source, unicode): # NOQA
129                 source = source.encode('utf-8')
130             kwargs['source'] = source
131 
132         super(NotebookHandler, self).__init__(*args, **kwargs)
133 
134 #-----------------------------------------------------------------------------
135 # Private API
136 #-----------------------------------------------------------------------------
137 
138 #-----------------------------------------------------------------------------
139 # Code
140 #-----------------------------------------------------------------------------
141
```
--- 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/application/handlers/notebook.py b/bokeh/application/handlers/notebook.py
--- a/bokeh/application/handlers/notebook.py
+++ b/bokeh/application/handlers/notebook.py
@@ -21,8 +21,6 @@
 #-----------------------------------------------------------------------------
 from __future__ import absolute_import, division, print_function, unicode_literals
 
-import re
-import sys
 import logging
 log = logging.getLogger(__name__)
 
@@ -31,6 +29,9 @@
 #-----------------------------------------------------------------------------
 
 # Standard library imports
+import io
+import re
+import sys
 
 # External imports
 
@@ -114,7 +115,7 @@
         preprocessors=[StripMagicsProcessor()]
         filename = kwargs['filename']
 
-        with open(filename) as f:
+        with io.open(filename, encoding="utf-8") as f:
             nb = nbformat.read(f, nbformat.NO_CONVERT)
             exporter = nbconvert.PythonExporter()

{"golden_diff": "diff --git a/bokeh/application/handlers/notebook.py b/bokeh/application/handlers/notebook.py\n--- a/bokeh/application/handlers/notebook.py\n+++ b/bokeh/application/handlers/notebook.py\n@@ -21,8 +21,6 @@\n #-----------------------------------------------------------------------------\n from __future__ import absolute_import, division, print_function, unicode_literals\n \n-import re\n-import sys\n import logging\n log = logging.getLogger(__name__)\n \n@@ -31,6 +29,9 @@\n #-----------------------------------------------------------------------------\n \n # Standard library imports\n+import io\n+import re\n+import sys\n \n # External imports\n \n@@ -114,7 +115,7 @@\n         preprocessors=[StripMagicsProcessor()]\n         filename = kwargs['filename']\n \n-        with open(filename) as f:\n+        with io.open(filename, encoding=\"utf-8\") as f:\n             nb = nbformat.read(f, nbformat.NO_CONVERT)\n             exporter = nbconvert.PythonExporter()\n", "issue": "Use utf-8 encoding to open notebook file.\nCurrently,  `ipynb` file is opened by following code:\r\n\r\n```\r\n        with open(filename) as f:\r\n            pass\r\n```\r\n\r\nhttps://github.com/bokeh/bokeh/blob/master/bokeh/application/handlers/notebook.py#L117\r\n\r\nI suggest to open the file with `encoding=\"utf-8\"`, otherwise the serve command will raise error on Windows system.\n", "before_files": [{"content": "#-----------------------------------------------------------------------------\n# Copyright (c) 2012 - 2019, Anaconda, Inc., and Bokeh Contributors.\n# All rights reserved.\n#\n# The full license is in the file LICENSE.txt, distributed with this software.\n#-----------------------------------------------------------------------------\n''' Provide a Bokeh Application Handler to build up documents by running\nthe code from Jupyter notebook (``.ipynb``) files.\n\nThis handler is configured with the filename of a Jupyter notebook. When a\nBokeh application calls ``modify_doc``, the code from all the notebook cells\nis collected and executed to process a new Document for a session. When the\nnotebook code is executed, the Document being modified will be available as\n``curdoc``, and any optionally provided ``args`` will be available as\n``sys.argv``.\n\n'''\n\n#-----------------------------------------------------------------------------\n# Boilerplate\n#-----------------------------------------------------------------------------\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nimport re\nimport sys\nimport logging\nlog = logging.getLogger(__name__)\n\n#-----------------------------------------------------------------------------\n# Imports\n#-----------------------------------------------------------------------------\n\n# Standard library imports\n\n# External imports\n\n# Bokeh imports\nfrom ...util.dependencies import import_required\nfrom .code import CodeHandler\n\n#-----------------------------------------------------------------------------\n# Globals and constants\n#-----------------------------------------------------------------------------\n\n__all__ = (\n    'NotebookHandler',\n)\n\n#-----------------------------------------------------------------------------\n# General API\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Dev API\n#-----------------------------------------------------------------------------\n\nclass NotebookHandler(CodeHandler):\n    ''' A Handler that uses code in a Jupyter notebook for modifying Bokeh\n    Documents.\n\n    '''\n\n    _logger_text = \"%s: call to %s() ignored when running notebooks with the 'bokeh' command.\"\n\n    _origin = \"Notebook\"\n\n    def __init__(self, *args, **kwargs):\n        '''\n\n        Keywords:\n            filename (str) : a path to a Jupyter notebook (\".ipynb\") file\n\n        '''\n        nbformat = import_required('nbformat', 'The Bokeh notebook application handler requires Jupyter Notebook to be installed.')\n        nbconvert = import_required('nbconvert', 'The Bokeh notebook application handler requires Jupyter Notebook to be installed.')\n\n        if 'filename' not in kwargs:\n            raise ValueError('Must pass a filename to NotebookHandler')\n\n\n        class StripMagicsProcessor(nbconvert.preprocessors.Preprocessor):\n            \"\"\"\n            Preprocessor to convert notebooks to Python source while stripping\n            out all magics (i.e IPython specific syntax).\n            \"\"\"\n\n            _magic_pattern = re.compile(r'^\\s*(?P<magic>%%\\w\\w+)($|(\\s+))')\n\n            def strip_magics(self, source):\n                \"\"\"\n                Given the source of a cell, filter out all cell and line magics.\n                \"\"\"\n                filtered=[]\n                for line in source.splitlines():\n                    match = self._magic_pattern.match(line)\n                    if match is None:\n                        filtered.append(line)\n                    else:\n                        msg = 'Stripping out IPython magic {magic} in code cell {cell}'\n                        message = msg.format(cell=self._cell_counter, magic=match.group('magic'))\n                        log.warning(message)\n                return '\\n'.join(filtered)\n\n            def preprocess_cell(self, cell, resources, index):\n                if cell['cell_type'] == 'code':\n                    self._cell_counter += 1\n                    cell['source'] = self.strip_magics(cell['source'])\n                return cell, resources\n\n            def __call__(self, nb, resources):\n                self._cell_counter = 0\n                return self.preprocess(nb,resources)\n\n        preprocessors=[StripMagicsProcessor()]\n        filename = kwargs['filename']\n\n        with open(filename) as f:\n            nb = nbformat.read(f, nbformat.NO_CONVERT)\n            exporter = nbconvert.PythonExporter()\n\n            for preprocessor in preprocessors:\n                exporter.register_preprocessor(preprocessor)\n\n            source, _ = exporter.from_notebook_node(nb)\n            source = source.replace('get_ipython().run_line_magic', '')\n            source = source.replace('get_ipython().magic', '')\n\n            if sys.version_info.major == 2 and isinstance(source, unicode): # NOQA\n                source = source.encode('utf-8')\n            kwargs['source'] = source\n\n        super(NotebookHandler, self).__init__(*args, **kwargs)\n\n#-----------------------------------------------------------------------------\n# Private API\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Code\n#-----------------------------------------------------------------------------\n", "path": "bokeh/application/handlers/notebook.py"}], "after_files": [{"content": "#-----------------------------------------------------------------------------\n# Copyright (c) 2012 - 2019, Anaconda, Inc., and Bokeh Contributors.\n# All rights reserved.\n#\n# The full license is in the file LICENSE.txt, distributed with this software.\n#-----------------------------------------------------------------------------\n''' Provide a Bokeh Application Handler to build up documents by running\nthe code from Jupyter notebook (``.ipynb``) files.\n\nThis handler is configured with the filename of a Jupyter notebook. When a\nBokeh application calls ``modify_doc``, the code from all the notebook cells\nis collected and executed to process a new Document for a session. When the\nnotebook code is executed, the Document being modified will be available as\n``curdoc``, and any optionally provided ``args`` will be available as\n``sys.argv``.\n\n'''\n\n#-----------------------------------------------------------------------------\n# Boilerplate\n#-----------------------------------------------------------------------------\nfrom __future__ import absolute_import, division, print_function, unicode_literals\n\nimport logging\nlog = logging.getLogger(__name__)\n\n#-----------------------------------------------------------------------------\n# Imports\n#-----------------------------------------------------------------------------\n\n# Standard library imports\nimport io\nimport re\nimport sys\n\n# External imports\n\n# Bokeh imports\nfrom ...util.dependencies import import_required\nfrom .code import CodeHandler\n\n#-----------------------------------------------------------------------------\n# Globals and constants\n#-----------------------------------------------------------------------------\n\n__all__ = (\n    'NotebookHandler',\n)\n\n#-----------------------------------------------------------------------------\n# General API\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Dev API\n#-----------------------------------------------------------------------------\n\nclass NotebookHandler(CodeHandler):\n    ''' A Handler that uses code in a Jupyter notebook for modifying Bokeh\n    Documents.\n\n    '''\n\n    _logger_text = \"%s: call to %s() ignored when running notebooks with the 'bokeh' command.\"\n\n    _origin = \"Notebook\"\n\n    def __init__(self, *args, **kwargs):\n        '''\n\n        Keywords:\n            filename (str) : a path to a Jupyter notebook (\".ipynb\") file\n\n        '''\n        nbformat = import_required('nbformat', 'The Bokeh notebook application handler requires Jupyter Notebook to be installed.')\n        nbconvert = import_required('nbconvert', 'The Bokeh notebook application handler requires Jupyter Notebook to be installed.')\n\n        if 'filename' not in kwargs:\n            raise ValueError('Must pass a filename to NotebookHandler')\n\n\n        class StripMagicsProcessor(nbconvert.preprocessors.Preprocessor):\n            \"\"\"\n            Preprocessor to convert notebooks to Python source while stripping\n            out all magics (i.e IPython specific syntax).\n            \"\"\"\n\n            _magic_pattern = re.compile(r'^\\s*(?P<magic>%%\\w\\w+)($|(\\s+))')\n\n            def strip_magics(self, source):\n                \"\"\"\n                Given the source of a cell, filter out all cell and line magics.\n                \"\"\"\n                filtered=[]\n                for line in source.splitlines():\n                    match = self._magic_pattern.match(line)\n                    if match is None:\n                        filtered.append(line)\n                    else:\n                        msg = 'Stripping out IPython magic {magic} in code cell {cell}'\n                        message = msg.format(cell=self._cell_counter, magic=match.group('magic'))\n                        log.warning(message)\n                return '\\n'.join(filtered)\n\n            def preprocess_cell(self, cell, resources, index):\n                if cell['cell_type'] == 'code':\n                    self._cell_counter += 1\n                    cell['source'] = self.strip_magics(cell['source'])\n                return cell, resources\n\n            def __call__(self, nb, resources):\n                self._cell_counter = 0\n                return self.preprocess(nb,resources)\n\n        preprocessors=[StripMagicsProcessor()]\n        filename = kwargs['filename']\n\n        with io.open(filename, encoding=\"utf-8\") as f:\n            nb = nbformat.read(f, nbformat.NO_CONVERT)\n            exporter = nbconvert.PythonExporter()\n\n            for preprocessor in preprocessors:\n                exporter.register_preprocessor(preprocessor)\n\n            source, _ = exporter.from_notebook_node(nb)\n            source = source.replace('get_ipython().run_line_magic', '')\n            source = source.replace('get_ipython().magic', '')\n\n            if sys.version_info.major == 2 and isinstance(source, unicode): # NOQA\n                source = source.encode('utf-8')\n            kwargs['source'] = source\n\n        super(NotebookHandler, self).__init__(*args, **kwargs)\n\n#-----------------------------------------------------------------------------\n# Private API\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Code\n#-----------------------------------------------------------------------------\n", "path": "bokeh/application/handlers/notebook.py"}]}