We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
HTML text can vanish in the Werkzeug interactive debugger
(I feel like I might have raised this bug before, but I can’t find it if I have.)

If you’re using the interactive debugger and you type a command includes something that looks like an HTML tag, it gets treated as literal HTML text. This causes it to disappear once you’ve finished the command, which makes for an inconsistent history.

Here’s a simple repro:

![screen shot 2016-11-07 at 07 25 38](https://cloud.githubusercontent.com/assets/301220/20049525/6b86fc32-a4bb-11e6-984b-c713b4796d08.png)

The HTML tag should continue to be visible after executing your command.

Python/Werkzeug versions, although I know I’ve seen this on older versions too:

```console
$ python --version
Python 3.5.0

$ pip freeze | grep Werkzeug
Werkzeug==0.11.10
```

--- END ISSUE ---

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

{"golden_diff": "diff --git a/werkzeug/debug/console.py b/werkzeug/debug/console.py\n--- a/werkzeug/debug/console.py\n+++ b/werkzeug/debug/console.py\n@@ -173,7 +173,7 @@\n                 del self.buffer[:]\n         finally:\n             output = ThreadedStream.fetch()\n-        return prompt + source + output\n+        return prompt + escape(source) + output\n \n     def runcode(self, code):\n         try:\n", "issue": "HTML text can vanish in the Werkzeug interactive debugger\n(I feel like I might have raised this bug before, but I can\u2019t find it if I have.)\r\n\r\nIf you\u2019re using the interactive debugger and you type a command includes something that looks like an HTML tag, it gets treated as literal HTML text. This causes it to disappear once you\u2019ve finished the command, which makes for an inconsistent history.\r\n\r\nHere\u2019s a simple repro:\r\n\r\n![screen shot 2016-11-07 at 07 25 38](https://cloud.githubusercontent.com/assets/301220/20049525/6b86fc32-a4bb-11e6-984b-c713b4796d08.png)\r\n\r\nThe HTML tag should continue to be visible after executing your command.\r\n\r\nPython/Werkzeug versions, although I know I\u2019ve seen this on older versions too:\r\n\r\n```console\r\n$ python --version\r\nPython 3.5.0\r\n\r\n$ pip freeze | grep Werkzeug\r\nWerkzeug==0.11.10\r\n```\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\n    werkzeug.debug.console\n    ~~~~~~~~~~~~~~~~~~~~~~\n\n    Interactive console support.\n\n    :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.\n    :license: BSD.\n\"\"\"\nimport sys\nimport code\nfrom types import CodeType\n\nfrom werkzeug.utils import escape\nfrom werkzeug.local import Local\nfrom werkzeug.debug.repr import debug_repr, dump, helper\n\n\n_local = Local()\n\n\nclass HTMLStringO(object):\n\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\n    \"\"\"Thread-local wrapper for sys.stdout for the interactive console.\"\"\"\n\n    def push():\n        if not isinstance(sys.stdout, ThreadedStream):\n            sys.stdout = ThreadedStream()\n        _local.stream = HTMLStringO()\n    push = staticmethod(push)\n\n    def fetch():\n        try:\n            stream = _local.stream\n        except AttributeError:\n            return ''\n        return stream.reset()\n    fetch = staticmethod(fetch)\n\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    displayhook = staticmethod(displayhook)\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\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    console.compile = func\n\n\nclass _InteractiveConsole(code.InteractiveInterpreter):\n\n    def __init__(self, globals, locals):\n        code.InteractiveInterpreter.__init__(self, locals)\n        self.globals = dict(globals)\n        self.globals['dump'] = dump\n        self.globals['help'] = helper\n        self.globals['__loader__'] = self.loader = _ConsoleLoader()\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 = self.more and '... ' or '>>> '\n        try:\n            source_to_eval = ''.join(self.buffer + [source])\n            if code.InteractiveInterpreter.runsource(self,\n                                                     source_to_eval, '<debugger>', 'single'):\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 + source + output\n\n    def runcode(self, code):\n        try:\n            eval(code, self.globals, self.locals)\n        except Exception:\n            self.showtraceback()\n\n    def showtraceback(self):\n        from werkzeug.debug.tbtools import get_current_traceback\n        tb = get_current_traceback(skip=1)\n        sys.stdout._write(tb.render_summary())\n\n    def showsyntaxerror(self, filename=None):\n        from werkzeug.debug.tbtools import get_current_traceback\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\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": "werkzeug/debug/console.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"\n    werkzeug.debug.console\n    ~~~~~~~~~~~~~~~~~~~~~~\n\n    Interactive console support.\n\n    :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.\n    :license: BSD.\n\"\"\"\nimport sys\nimport code\nfrom types import CodeType\n\nfrom werkzeug.utils import escape\nfrom werkzeug.local import Local\nfrom werkzeug.debug.repr import debug_repr, dump, helper\n\n\n_local = Local()\n\n\nclass HTMLStringO(object):\n\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\n    \"\"\"Thread-local wrapper for sys.stdout for the interactive console.\"\"\"\n\n    def push():\n        if not isinstance(sys.stdout, ThreadedStream):\n            sys.stdout = ThreadedStream()\n        _local.stream = HTMLStringO()\n    push = staticmethod(push)\n\n    def fetch():\n        try:\n            stream = _local.stream\n        except AttributeError:\n            return ''\n        return stream.reset()\n    fetch = staticmethod(fetch)\n\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    displayhook = staticmethod(displayhook)\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\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    console.compile = func\n\n\nclass _InteractiveConsole(code.InteractiveInterpreter):\n\n    def __init__(self, globals, locals):\n        code.InteractiveInterpreter.__init__(self, locals)\n        self.globals = dict(globals)\n        self.globals['dump'] = dump\n        self.globals['help'] = helper\n        self.globals['__loader__'] = self.loader = _ConsoleLoader()\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 = self.more and '... ' or '>>> '\n        try:\n            source_to_eval = ''.join(self.buffer + [source])\n            if code.InteractiveInterpreter.runsource(self,\n                                                     source_to_eval, '<debugger>', 'single'):\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            eval(code, self.globals, self.locals)\n        except Exception:\n            self.showtraceback()\n\n    def showtraceback(self):\n        from werkzeug.debug.tbtools import get_current_traceback\n        tb = get_current_traceback(skip=1)\n        sys.stdout._write(tb.render_summary())\n\n    def showsyntaxerror(self, filename=None):\n        from werkzeug.debug.tbtools import get_current_traceback\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\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": "werkzeug/debug/console.py"}]}