We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Local variables not available in debug console in version 1.0
Take this simple script:

```python
from werkzeug.wrappers import Request, Response

some_global_variable = True

@Request.application
def application(request):
    msg = 'Hello, World!'
    return Response(msg2)

if __name__ == '__main__':
    from werkzeug.serving import run_simple
    run_simple('localhost', 4000, application,
               use_reloader=True, use_debugger=True, use_evalex=True)
```

As expected, the application crashes when it tries to create the response because `msg2` doesn't exist. With version 0.16.1 and Python 3.8, I can view the value of the `msg` variable in the debug console. But if I upgrade to version 1.0, `msg` is no longer defined. Global variables are available, however. Here's a screenshot:

![image](https://user-images.githubusercontent.com/4453816/76369784-57a50500-62fa-11ea-97cf-98a0a65a44a4.png)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/werkzeug/debug/console.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 """
3     werkzeug.debug.console
4     ~~~~~~~~~~~~~~~~~~~~~~
5 
6     Interactive console support.
7 
8     :copyright: 2007 Pallets
9     :license: BSD-3-Clause
10 """
11 import code
12 import sys
13 from types import CodeType
14 
15 from ..local import Local
16 from ..utils import escape
17 from .repr import debug_repr
18 from .repr import dump
19 from .repr import helper
20 
21 
22 _local = Local()
23 
24 
25 class HTMLStringO(object):
26     """A StringO version that HTML escapes on write."""
27 
28     def __init__(self):
29         self._buffer = []
30 
31     def isatty(self):
32         return False
33 
34     def close(self):
35         pass
36 
37     def flush(self):
38         pass
39 
40     def seek(self, n, mode=0):
41         pass
42 
43     def readline(self):
44         if len(self._buffer) == 0:
45             return ""
46         ret = self._buffer[0]
47         del self._buffer[0]
48         return ret
49 
50     def reset(self):
51         val = "".join(self._buffer)
52         del self._buffer[:]
53         return val
54 
55     def _write(self, x):
56         if isinstance(x, bytes):
57             x = x.decode("utf-8", "replace")
58         self._buffer.append(x)
59 
60     def write(self, x):
61         self._write(escape(x))
62 
63     def writelines(self, x):
64         self._write(escape("".join(x)))
65 
66 
67 class ThreadedStream(object):
68     """Thread-local wrapper for sys.stdout for the interactive console."""
69 
70     @staticmethod
71     def push():
72         if not isinstance(sys.stdout, ThreadedStream):
73             sys.stdout = ThreadedStream()
74         _local.stream = HTMLStringO()
75 
76     @staticmethod
77     def fetch():
78         try:
79             stream = _local.stream
80         except AttributeError:
81             return ""
82         return stream.reset()
83 
84     @staticmethod
85     def displayhook(obj):
86         try:
87             stream = _local.stream
88         except AttributeError:
89             return _displayhook(obj)
90         # stream._write bypasses escaping as debug_repr is
91         # already generating HTML for us.
92         if obj is not None:
93             _local._current_ipy.locals["_"] = obj
94             stream._write(debug_repr(obj))
95 
96     def __setattr__(self, name, value):
97         raise AttributeError("read only attribute %s" % name)
98 
99     def __dir__(self):
100         return dir(sys.__stdout__)
101 
102     def __getattribute__(self, name):
103         if name == "__members__":
104             return dir(sys.__stdout__)
105         try:
106             stream = _local.stream
107         except AttributeError:
108             stream = sys.__stdout__
109         return getattr(stream, name)
110 
111     def __repr__(self):
112         return repr(sys.__stdout__)
113 
114 
115 # add the threaded stream as display hook
116 _displayhook = sys.displayhook
117 sys.displayhook = ThreadedStream.displayhook
118 
119 
120 class _ConsoleLoader(object):
121     def __init__(self):
122         self._storage = {}
123 
124     def register(self, code, source):
125         self._storage[id(code)] = source
126         # register code objects of wrapped functions too.
127         for var in code.co_consts:
128             if isinstance(var, CodeType):
129                 self._storage[id(var)] = source
130 
131     def get_source_by_code(self, code):
132         try:
133             return self._storage[id(code)]
134         except KeyError:
135             pass
136 
137 
138 def _wrap_compiler(console):
139     compile = console.compile
140 
141     def func(source, filename, symbol):
142         code = compile(source, filename, symbol)
143         console.loader.register(code, source)
144         return code
145 
146     console.compile = func
147 
148 
149 class _InteractiveConsole(code.InteractiveInterpreter):
150     def __init__(self, globals, locals):
151         locals = dict(globals)
152         locals.update(locals)
153         locals["dump"] = dump
154         locals["help"] = helper
155         locals["__loader__"] = self.loader = _ConsoleLoader()
156         code.InteractiveInterpreter.__init__(self, locals)
157         self.more = False
158         self.buffer = []
159         _wrap_compiler(self)
160 
161     def runsource(self, source):
162         source = source.rstrip() + "\n"
163         ThreadedStream.push()
164         prompt = "... " if self.more else ">>> "
165         try:
166             source_to_eval = "".join(self.buffer + [source])
167             if code.InteractiveInterpreter.runsource(
168                 self, source_to_eval, "<debugger>", "single"
169             ):
170                 self.more = True
171                 self.buffer.append(source)
172             else:
173                 self.more = False
174                 del self.buffer[:]
175         finally:
176             output = ThreadedStream.fetch()
177         return prompt + escape(source) + output
178 
179     def runcode(self, code):
180         try:
181             exec(code, self.locals)
182         except Exception:
183             self.showtraceback()
184 
185     def showtraceback(self):
186         from .tbtools import get_current_traceback
187 
188         tb = get_current_traceback(skip=1)
189         sys.stdout._write(tb.render_summary())
190 
191     def showsyntaxerror(self, filename=None):
192         from .tbtools import get_current_traceback
193 
194         tb = get_current_traceback(skip=4)
195         sys.stdout._write(tb.render_summary())
196 
197     def write(self, data):
198         sys.stdout.write(data)
199 
200 
201 class Console(object):
202     """An interactive console."""
203 
204     def __init__(self, globals=None, locals=None):
205         if locals is None:
206             locals = {}
207         if globals is None:
208             globals = {}
209         self._ipy = _InteractiveConsole(globals, locals)
210 
211     def eval(self, code):
212         _local._current_ipy = self._ipy
213         old_sys_stdout = sys.stdout
214         try:
215             return self._ipy.runsource(code)
216         finally:
217             sys.stdout = old_sys_stdout
218
```
--- 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/src/werkzeug/debug/console.py b/src/werkzeug/debug/console.py
--- a/src/werkzeug/debug/console.py
+++ b/src/werkzeug/debug/console.py
@@ -148,8 +148,9 @@
 
 class _InteractiveConsole(code.InteractiveInterpreter):
     def __init__(self, globals, locals):
-        locals = dict(globals)
-        locals.update(locals)
+        _locals = dict(globals)
+        _locals.update(locals)
+        locals = _locals
         locals["dump"] = dump
         locals["help"] = helper
         locals["__loader__"] = self.loader = _ConsoleLoader()

{"golden_diff": "diff --git a/src/werkzeug/debug/console.py b/src/werkzeug/debug/console.py\n--- a/src/werkzeug/debug/console.py\n+++ b/src/werkzeug/debug/console.py\n@@ -148,8 +148,9 @@\n \n class _InteractiveConsole(code.InteractiveInterpreter):\n     def __init__(self, globals, locals):\n-        locals = dict(globals)\n-        locals.update(locals)\n+        _locals = dict(globals)\n+        _locals.update(locals)\n+        locals = _locals\n         locals[\"dump\"] = dump\n         locals[\"help\"] = helper\n         locals[\"__loader__\"] = self.loader = _ConsoleLoader()\n", "issue": "Local variables not available in debug console in version 1.0\nTake this simple script:\r\n\r\n```python\r\nfrom werkzeug.wrappers import Request, Response\r\n\r\nsome_global_variable = True\r\n\r\n@Request.application\r\ndef application(request):\r\n    msg = 'Hello, World!'\r\n    return Response(msg2)\r\n\r\nif __name__ == '__main__':\r\n    from werkzeug.serving import run_simple\r\n    run_simple('localhost', 4000, application,\r\n               use_reloader=True, use_debugger=True, use_evalex=True)\r\n```\r\n\r\nAs expected, the application crashes when it tries to create the response because `msg2` doesn't exist. With version 0.16.1 and Python 3.8, I can view the value of the `msg` variable in the debug console. But if I upgrade to version 1.0, `msg` is no longer defined. Global variables are available, however. Here's a screenshot:\r\n\r\n![image](https://user-images.githubusercontent.com/4453816/76369784-57a50500-62fa-11ea-97cf-98a0a65a44a4.png)\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\n    werkzeug.debug.console\n    ~~~~~~~~~~~~~~~~~~~~~~\n\n    Interactive console support.\n\n    :copyright: 2007 Pallets\n    :license: BSD-3-Clause\n\"\"\"\nimport code\nimport sys\nfrom types import CodeType\n\nfrom ..local import Local\nfrom ..utils import escape\nfrom .repr import debug_repr\nfrom .repr import dump\nfrom .repr import helper\n\n\n_local = Local()\n\n\nclass HTMLStringO(object):\n    \"\"\"A StringO version that HTML escapes on write.\"\"\"\n\n    def __init__(self):\n        self._buffer = []\n\n    def isatty(self):\n        return False\n\n    def close(self):\n        pass\n\n    def flush(self):\n        pass\n\n    def seek(self, n, mode=0):\n        pass\n\n    def readline(self):\n        if len(self._buffer) == 0:\n            return \"\"\n        ret = self._buffer[0]\n        del self._buffer[0]\n        return ret\n\n    def reset(self):\n        val = \"\".join(self._buffer)\n        del self._buffer[:]\n        return val\n\n    def _write(self, x):\n        if isinstance(x, bytes):\n            x = x.decode(\"utf-8\", \"replace\")\n        self._buffer.append(x)\n\n    def write(self, x):\n        self._write(escape(x))\n\n    def writelines(self, x):\n        self._write(escape(\"\".join(x)))\n\n\nclass ThreadedStream(object):\n    \"\"\"Thread-local wrapper for sys.stdout for the interactive console.\"\"\"\n\n    @staticmethod\n    def push():\n        if not isinstance(sys.stdout, ThreadedStream):\n            sys.stdout = ThreadedStream()\n        _local.stream = HTMLStringO()\n\n    @staticmethod\n    def fetch():\n        try:\n            stream = _local.stream\n        except AttributeError:\n            return \"\"\n        return stream.reset()\n\n    @staticmethod\n    def displayhook(obj):\n        try:\n            stream = _local.stream\n        except AttributeError:\n            return _displayhook(obj)\n        # stream._write bypasses escaping as debug_repr is\n        # already generating HTML for us.\n        if obj is not None:\n            _local._current_ipy.locals[\"_\"] = obj\n            stream._write(debug_repr(obj))\n\n    def __setattr__(self, name, value):\n        raise AttributeError(\"read only attribute %s\" % name)\n\n    def __dir__(self):\n        return dir(sys.__stdout__)\n\n    def __getattribute__(self, name):\n        if name == \"__members__\":\n            return dir(sys.__stdout__)\n        try:\n            stream = _local.stream\n        except AttributeError:\n            stream = sys.__stdout__\n        return getattr(stream, name)\n\n    def __repr__(self):\n        return repr(sys.__stdout__)\n\n\n# add the threaded stream as display hook\n_displayhook = sys.displayhook\nsys.displayhook = ThreadedStream.displayhook\n\n\nclass _ConsoleLoader(object):\n    def __init__(self):\n        self._storage = {}\n\n    def register(self, code, source):\n        self._storage[id(code)] = source\n        # register code objects of wrapped functions too.\n        for var in code.co_consts:\n            if isinstance(var, CodeType):\n                self._storage[id(var)] = source\n\n    def get_source_by_code(self, code):\n        try:\n            return self._storage[id(code)]\n        except KeyError:\n            pass\n\n\ndef _wrap_compiler(console):\n    compile = console.compile\n\n    def func(source, filename, symbol):\n        code = compile(source, filename, symbol)\n        console.loader.register(code, source)\n        return code\n\n    console.compile = func\n\n\nclass _InteractiveConsole(code.InteractiveInterpreter):\n    def __init__(self, globals, locals):\n        locals = dict(globals)\n        locals.update(locals)\n        locals[\"dump\"] = dump\n        locals[\"help\"] = helper\n        locals[\"__loader__\"] = self.loader = _ConsoleLoader()\n        code.InteractiveInterpreter.__init__(self, locals)\n        self.more = False\n        self.buffer = []\n        _wrap_compiler(self)\n\n    def runsource(self, source):\n        source = source.rstrip() + \"\\n\"\n        ThreadedStream.push()\n        prompt = \"... \" if self.more else \">>> \"\n        try:\n            source_to_eval = \"\".join(self.buffer + [source])\n            if code.InteractiveInterpreter.runsource(\n                self, source_to_eval, \"<debugger>\", \"single\"\n            ):\n                self.more = True\n                self.buffer.append(source)\n            else:\n                self.more = False\n                del self.buffer[:]\n        finally:\n            output = ThreadedStream.fetch()\n        return prompt + escape(source) + output\n\n    def runcode(self, code):\n        try:\n            exec(code, self.locals)\n        except Exception:\n            self.showtraceback()\n\n    def showtraceback(self):\n        from .tbtools import get_current_traceback\n\n        tb = get_current_traceback(skip=1)\n        sys.stdout._write(tb.render_summary())\n\n    def showsyntaxerror(self, filename=None):\n        from .tbtools import get_current_traceback\n\n        tb = get_current_traceback(skip=4)\n        sys.stdout._write(tb.render_summary())\n\n    def write(self, data):\n        sys.stdout.write(data)\n\n\nclass Console(object):\n    \"\"\"An interactive console.\"\"\"\n\n    def __init__(self, globals=None, locals=None):\n        if locals is None:\n            locals = {}\n        if globals is None:\n            globals = {}\n        self._ipy = _InteractiveConsole(globals, locals)\n\n    def eval(self, code):\n        _local._current_ipy = self._ipy\n        old_sys_stdout = sys.stdout\n        try:\n            return self._ipy.runsource(code)\n        finally:\n            sys.stdout = old_sys_stdout\n", "path": "src/werkzeug/debug/console.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\n    werkzeug.debug.console\n    ~~~~~~~~~~~~~~~~~~~~~~\n\n    Interactive console support.\n\n    :copyright: 2007 Pallets\n    :license: BSD-3-Clause\n\"\"\"\nimport code\nimport sys\nfrom types import CodeType\n\nfrom ..local import Local\nfrom ..utils import escape\nfrom .repr import debug_repr\nfrom .repr import dump\nfrom .repr import helper\n\n\n_local = Local()\n\n\nclass HTMLStringO(object):\n    \"\"\"A StringO version that HTML escapes on write.\"\"\"\n\n    def __init__(self):\n        self._buffer = []\n\n    def isatty(self):\n        return False\n\n    def close(self):\n        pass\n\n    def flush(self):\n        pass\n\n    def seek(self, n, mode=0):\n        pass\n\n    def readline(self):\n        if len(self._buffer) == 0:\n            return \"\"\n        ret = self._buffer[0]\n        del self._buffer[0]\n        return ret\n\n    def reset(self):\n        val = \"\".join(self._buffer)\n        del self._buffer[:]\n        return val\n\n    def _write(self, x):\n        if isinstance(x, bytes):\n            x = x.decode(\"utf-8\", \"replace\")\n        self._buffer.append(x)\n\n    def write(self, x):\n        self._write(escape(x))\n\n    def writelines(self, x):\n        self._write(escape(\"\".join(x)))\n\n\nclass ThreadedStream(object):\n    \"\"\"Thread-local wrapper for sys.stdout for the interactive console.\"\"\"\n\n    @staticmethod\n    def push():\n        if not isinstance(sys.stdout, ThreadedStream):\n            sys.stdout = ThreadedStream()\n        _local.stream = HTMLStringO()\n\n    @staticmethod\n    def fetch():\n        try:\n            stream = _local.stream\n        except AttributeError:\n            return \"\"\n        return stream.reset()\n\n    @staticmethod\n    def displayhook(obj):\n        try:\n            stream = _local.stream\n        except AttributeError:\n            return _displayhook(obj)\n        # stream._write bypasses escaping as debug_repr is\n        # already generating HTML for us.\n        if obj is not None:\n            _local._current_ipy.locals[\"_\"] = obj\n            stream._write(debug_repr(obj))\n\n    def __setattr__(self, name, value):\n        raise AttributeError(\"read only attribute %s\" % name)\n\n    def __dir__(self):\n        return dir(sys.__stdout__)\n\n    def __getattribute__(self, name):\n        if name == \"__members__\":\n            return dir(sys.__stdout__)\n        try:\n            stream = _local.stream\n        except AttributeError:\n            stream = sys.__stdout__\n        return getattr(stream, name)\n\n    def __repr__(self):\n        return repr(sys.__stdout__)\n\n\n# add the threaded stream as display hook\n_displayhook = sys.displayhook\nsys.displayhook = ThreadedStream.displayhook\n\n\nclass _ConsoleLoader(object):\n    def __init__(self):\n        self._storage = {}\n\n    def register(self, code, source):\n        self._storage[id(code)] = source\n        # register code objects of wrapped functions too.\n        for var in code.co_consts:\n            if isinstance(var, CodeType):\n                self._storage[id(var)] = source\n\n    def get_source_by_code(self, code):\n        try:\n            return self._storage[id(code)]\n        except KeyError:\n            pass\n\n\ndef _wrap_compiler(console):\n    compile = console.compile\n\n    def func(source, filename, symbol):\n        code = compile(source, filename, symbol)\n        console.loader.register(code, source)\n        return code\n\n    console.compile = func\n\n\nclass _InteractiveConsole(code.InteractiveInterpreter):\n    def __init__(self, globals, locals):\n        _locals = dict(globals)\n        _locals.update(locals)\n        locals = _locals\n        locals[\"dump\"] = dump\n        locals[\"help\"] = helper\n        locals[\"__loader__\"] = self.loader = _ConsoleLoader()\n        code.InteractiveInterpreter.__init__(self, locals)\n        self.more = False\n        self.buffer = []\n        _wrap_compiler(self)\n\n    def runsource(self, source):\n        source = source.rstrip() + \"\\n\"\n        ThreadedStream.push()\n        prompt = \"... \" if self.more else \">>> \"\n        try:\n            source_to_eval = \"\".join(self.buffer + [source])\n            if code.InteractiveInterpreter.runsource(\n                self, source_to_eval, \"<debugger>\", \"single\"\n            ):\n                self.more = True\n                self.buffer.append(source)\n            else:\n                self.more = False\n                del self.buffer[:]\n        finally:\n            output = ThreadedStream.fetch()\n        return prompt + escape(source) + output\n\n    def runcode(self, code):\n        try:\n            exec(code, self.locals)\n        except Exception:\n            self.showtraceback()\n\n    def showtraceback(self):\n        from .tbtools import get_current_traceback\n\n        tb = get_current_traceback(skip=1)\n        sys.stdout._write(tb.render_summary())\n\n    def showsyntaxerror(self, filename=None):\n        from .tbtools import get_current_traceback\n\n        tb = get_current_traceback(skip=4)\n        sys.stdout._write(tb.render_summary())\n\n    def write(self, data):\n        sys.stdout.write(data)\n\n\nclass Console(object):\n    \"\"\"An interactive console.\"\"\"\n\n    def __init__(self, globals=None, locals=None):\n        if locals is None:\n            locals = {}\n        if globals is None:\n            globals = {}\n        self._ipy = _InteractiveConsole(globals, locals)\n\n    def eval(self, code):\n        _local._current_ipy = self._ipy\n        old_sys_stdout = sys.stdout\n        try:\n            return self._ipy.runsource(code)\n        finally:\n            sys.stdout = old_sys_stdout\n", "path": "src/werkzeug/debug/console.py"}]}