We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add --file for :debug-pyeval
Just like with `:jseval`, it'd be nice if `:debug-pyeval` had a `--file` to allow for multi-line code.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `qutebrowser/misc/utilcmds.py`
Content:
```
1 # vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
2 
3 # Copyright 2014-2017 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
4 #
5 # This file is part of qutebrowser.
6 #
7 # qutebrowser is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # qutebrowser is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with qutebrowser.  If not, see <http://www.gnu.org/licenses/>.
19 
20 """Misc. utility commands exposed to the user."""
21 
22 import functools
23 import os
24 import signal
25 import traceback
26 
27 try:
28     import hunter
29 except ImportError:
30     hunter = None
31 
32 import sip
33 from PyQt5.QtCore import QUrl
34 # so it's available for :debug-pyeval
35 from PyQt5.QtWidgets import QApplication  # pylint: disable=unused-import
36 
37 from qutebrowser.browser import qutescheme
38 from qutebrowser.utils import log, objreg, usertypes, message, debug, utils
39 from qutebrowser.commands import cmdutils, runners, cmdexc
40 from qutebrowser.config import config, configdata
41 from qutebrowser.misc import consolewidget
42 
43 
44 @cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)
45 @cmdutils.argument('win_id', win_id=True)
46 def later(ms: int, command, win_id):
47     """Execute a command after some time.
48 
49     Args:
50         ms: How many milliseconds to wait.
51         command: The command to run, with optional args.
52     """
53     if ms < 0:
54         raise cmdexc.CommandError("I can't run something in the past!")
55     commandrunner = runners.CommandRunner(win_id)
56     app = objreg.get('app')
57     timer = usertypes.Timer(name='later', parent=app)
58     try:
59         timer.setSingleShot(True)
60         try:
61             timer.setInterval(ms)
62         except OverflowError:
63             raise cmdexc.CommandError("Numeric argument is too large for "
64                                       "internal int representation.")
65         timer.timeout.connect(
66             functools.partial(commandrunner.run_safely, command))
67         timer.timeout.connect(timer.deleteLater)
68         timer.start()
69     except:
70         timer.deleteLater()
71         raise
72 
73 
74 @cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)
75 @cmdutils.argument('win_id', win_id=True)
76 def repeat(times: int, command, win_id):
77     """Repeat a given command.
78 
79     Args:
80         times: How many times to repeat.
81         command: The command to run, with optional args.
82     """
83     if times < 0:
84         raise cmdexc.CommandError("A negative count doesn't make sense.")
85     commandrunner = runners.CommandRunner(win_id)
86     for _ in range(times):
87         commandrunner.run_safely(command)
88 
89 
90 @cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)
91 @cmdutils.argument('win_id', win_id=True)
92 @cmdutils.argument('count', count=True)
93 def run_with_count(count_arg: int, command, win_id, count=1):
94     """Run a command with the given count.
95 
96     If run_with_count itself is run with a count, it multiplies count_arg.
97 
98     Args:
99         count_arg: The count to pass to the command.
100         command: The command to run, with optional args.
101         count: The count that run_with_count itself received.
102     """
103     runners.CommandRunner(win_id).run(command, count_arg * count)
104 
105 
106 @cmdutils.register()
107 def message_error(text):
108     """Show an error message in the statusbar.
109 
110     Args:
111         text: The text to show.
112     """
113     message.error(text)
114 
115 
116 @cmdutils.register()
117 @cmdutils.argument('count', count=True)
118 def message_info(text, count=1):
119     """Show an info message in the statusbar.
120 
121     Args:
122         text: The text to show.
123         count: How many times to show the message
124     """
125     for _ in range(count):
126         message.info(text)
127 
128 
129 @cmdutils.register()
130 def message_warning(text):
131     """Show a warning message in the statusbar.
132 
133     Args:
134         text: The text to show.
135     """
136     message.warning(text)
137 
138 
139 @cmdutils.register()
140 def clear_messages():
141     """Clear all message notifications."""
142     message.global_bridge.clear_messages.emit()
143 
144 
145 @cmdutils.register(debug=True)
146 @cmdutils.argument('typ', choices=['exception', 'segfault'])
147 def debug_crash(typ='exception'):
148     """Crash for debugging purposes.
149 
150     Args:
151         typ: either 'exception' or 'segfault'.
152     """
153     if typ == 'segfault':
154         os.kill(os.getpid(), signal.SIGSEGV)
155         raise Exception("Segfault failed (wat.)")
156     else:
157         raise Exception("Forced crash")
158 
159 
160 @cmdutils.register(debug=True)
161 def debug_all_objects():
162     """Print a list of  all objects to the debug log."""
163     s = debug.get_all_objects()
164     log.misc.debug(s)
165 
166 
167 @cmdutils.register(debug=True)
168 def debug_cache_stats():
169     """Print LRU cache stats."""
170     prefix_info = configdata.is_valid_prefix.cache_info()
171     # pylint: disable=protected-access
172     render_stylesheet_info = config._render_stylesheet.cache_info()
173     # pylint: enable=protected-access
174 
175     history_info = None
176     try:
177         from PyQt5.QtWebKit import QWebHistoryInterface
178         interface = QWebHistoryInterface.defaultInterface()
179         if interface is not None:
180             history_info = interface.historyContains.cache_info()
181     except ImportError:
182         pass
183 
184     tabbed_browser = objreg.get('tabbed-browser', scope='window',
185                                 window='last-focused')
186     # pylint: disable=protected-access
187     tab_bar = tabbed_browser.tabBar()
188     tabbed_browser_info = tab_bar._minimum_tab_size_hint_helper.cache_info()
189     # pylint: enable=protected-access
190 
191     log.misc.debug('is_valid_prefix: {}'.format(prefix_info))
192     log.misc.debug('_render_stylesheet: {}'.format(render_stylesheet_info))
193     log.misc.debug('history: {}'.format(history_info))
194     log.misc.debug('tab width cache: {}'.format(tabbed_browser_info))
195 
196 
197 @cmdutils.register(debug=True)
198 def debug_console():
199     """Show the debugging console."""
200     try:
201         con_widget = objreg.get('debug-console')
202     except KeyError:
203         log.misc.debug('initializing debug console')
204         con_widget = consolewidget.ConsoleWidget()
205         objreg.register('debug-console', con_widget)
206 
207     if con_widget.isVisible():
208         log.misc.debug('hiding debug console')
209         con_widget.hide()
210     else:
211         log.misc.debug('showing debug console')
212         con_widget.show()
213 
214 
215 @cmdutils.register(debug=True, maxsplit=0, no_cmd_split=True)
216 def debug_trace(expr=""):
217     """Trace executed code via hunter.
218 
219     Args:
220         expr: What to trace, passed to hunter.
221     """
222     if hunter is None:
223         raise cmdexc.CommandError("You need to install 'hunter' to use this "
224                                   "command!")
225     try:
226         eval('hunter.trace({})'.format(expr))
227     except Exception as e:
228         raise cmdexc.CommandError("{}: {}".format(e.__class__.__name__, e))
229 
230 
231 @cmdutils.register(maxsplit=0, debug=True, no_cmd_split=True)
232 def debug_pyeval(s, quiet=False):
233     """Evaluate a python string and display the results as a web page.
234 
235     Args:
236         s: The string to evaluate.
237         quiet: Don't show the output in a new tab.
238     """
239     try:
240         r = eval(s)
241         out = repr(r)
242     except Exception:
243         out = traceback.format_exc()
244 
245     qutescheme.pyeval_output = out
246     if quiet:
247         log.misc.debug("pyeval output: {}".format(out))
248     else:
249         tabbed_browser = objreg.get('tabbed-browser', scope='window',
250                                     window='last-focused')
251         tabbed_browser.openurl(QUrl('qute://pyeval'), newtab=True)
252 
253 
254 @cmdutils.register(debug=True)
255 def debug_set_fake_clipboard(s=None):
256     """Put data into the fake clipboard and enable logging, used for tests.
257 
258     Args:
259         s: The text to put into the fake clipboard, or unset to enable logging.
260     """
261     if s is None:
262         utils.log_clipboard = True
263     else:
264         utils.fake_clipboard = s
265 
266 
267 @cmdutils.register()
268 @cmdutils.argument('win_id', win_id=True)
269 @cmdutils.argument('count', count=True)
270 def repeat_command(win_id, count=None):
271     """Repeat the last executed command.
272 
273     Args:
274         count: Which count to pass the command.
275     """
276     mode_manager = objreg.get('mode-manager', scope='window', window=win_id)
277     if mode_manager.mode not in runners.last_command:
278         raise cmdexc.CommandError("You didn't do anything yet.")
279     cmd = runners.last_command[mode_manager.mode]
280     commandrunner = runners.CommandRunner(win_id)
281     commandrunner.run(cmd[0], count if count is not None else cmd[1])
282 
283 
284 @cmdutils.register(debug=True, name='debug-log-capacity')
285 def log_capacity(capacity: int):
286     """Change the number of log lines to be stored in RAM.
287 
288     Args:
289        capacity: Number of lines for the log.
290     """
291     if capacity < 0:
292         raise cmdexc.CommandError("Can't set a negative log capacity!")
293     else:
294         log.ram_handler.change_log_capacity(capacity)
295 
296 
297 @cmdutils.register(debug=True)
298 @cmdutils.argument('level', choices=sorted(
299     (level.lower() for level in log.LOG_LEVELS),
300     key=lambda e: log.LOG_LEVELS[e.upper()]))
301 def debug_log_level(level: str):
302     """Change the log level for console logging.
303 
304     Args:
305         level: The log level to set.
306     """
307     log.change_console_formatter(log.LOG_LEVELS[level.upper()])
308     log.console_handler.setLevel(log.LOG_LEVELS[level.upper()])
309 
310 
311 @cmdutils.register(debug=True)
312 def debug_log_filter(filters: str):
313     """Change the log filter for console logging.
314 
315     Args:
316         filters: A comma separated list of logger names. Can also be "none" to
317                  clear any existing filters.
318     """
319     if log.console_filter is None:
320         raise cmdexc.CommandError("No log.console_filter. Not attached "
321                                   "to a console?")
322 
323     if filters.strip().lower() == 'none':
324         log.console_filter.names = None
325         return
326 
327     if not set(filters.split(',')).issubset(log.LOGGER_NAMES):
328         raise cmdexc.CommandError("filters: Invalid value {} - expected one "
329                                   "of: {}".format(filters,
330                                                   ', '.join(log.LOGGER_NAMES)))
331 
332     log.console_filter.names = filters.split(',')
333 
334 
335 @cmdutils.register()
336 @cmdutils.argument('current_win_id', win_id=True)
337 def window_only(current_win_id):
338     """Close all windows except for the current one."""
339     for win_id, window in objreg.window_registry.items():
340 
341         # We could be in the middle of destroying a window here
342         if sip.isdeleted(window):
343             continue
344 
345         if win_id != current_win_id:
346             window.close()
347 
348 
349 @cmdutils.register()
350 def nop():
351     """Do nothing."""
352     return
353 
354 
355 @cmdutils.register()
356 @cmdutils.argument('win_id', win_id=True)
357 def version(win_id):
358     """Show version information."""
359     tabbed_browser = objreg.get('tabbed-browser', scope='window',
360                                 window=win_id)
361     tabbed_browser.openurl(QUrl('qute://version'), newtab=True)
362
```
--- 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/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py
--- a/qutebrowser/misc/utilcmds.py
+++ b/qutebrowser/misc/utilcmds.py
@@ -229,18 +229,33 @@
 
 
 @cmdutils.register(maxsplit=0, debug=True, no_cmd_split=True)
-def debug_pyeval(s, quiet=False):
+def debug_pyeval(s, file=False, quiet=False):
     """Evaluate a python string and display the results as a web page.
 
     Args:
         s: The string to evaluate.
+        file: Interpret s as a path to file, also implies --quiet.
         quiet: Don't show the output in a new tab.
     """
-    try:
-        r = eval(s)
-        out = repr(r)
-    except Exception:
-        out = traceback.format_exc()
+    if file:
+        quiet = True
+        path = os.path.expanduser(s)
+        try:
+            with open(path, 'r', encoding='utf-8') as f:
+                s = f.read()
+        except OSError as e:
+            raise cmdexc.CommandError(str(e))
+        try:
+            exec(s)
+            out = "No error"
+        except Exception:
+            out = traceback.format_exc()
+    else:
+        try:
+            r = eval(s)
+            out = repr(r)
+        except Exception:
+            out = traceback.format_exc()
 
     qutescheme.pyeval_output = out
     if quiet:

{"golden_diff": "diff --git a/qutebrowser/misc/utilcmds.py b/qutebrowser/misc/utilcmds.py\n--- a/qutebrowser/misc/utilcmds.py\n+++ b/qutebrowser/misc/utilcmds.py\n@@ -229,18 +229,33 @@\n \n \n @cmdutils.register(maxsplit=0, debug=True, no_cmd_split=True)\n-def debug_pyeval(s, quiet=False):\n+def debug_pyeval(s, file=False, quiet=False):\n     \"\"\"Evaluate a python string and display the results as a web page.\n \n     Args:\n         s: The string to evaluate.\n+        file: Interpret s as a path to file, also implies --quiet.\n         quiet: Don't show the output in a new tab.\n     \"\"\"\n-    try:\n-        r = eval(s)\n-        out = repr(r)\n-    except Exception:\n-        out = traceback.format_exc()\n+    if file:\n+        quiet = True\n+        path = os.path.expanduser(s)\n+        try:\n+            with open(path, 'r', encoding='utf-8') as f:\n+                s = f.read()\n+        except OSError as e:\n+            raise cmdexc.CommandError(str(e))\n+        try:\n+            exec(s)\n+            out = \"No error\"\n+        except Exception:\n+            out = traceback.format_exc()\n+    else:\n+        try:\n+            r = eval(s)\n+            out = repr(r)\n+        except Exception:\n+            out = traceback.format_exc()\n \n     qutescheme.pyeval_output = out\n     if quiet:\n", "issue": "Add --file for :debug-pyeval\nJust like with `:jseval`, it'd be nice if `:debug-pyeval` had a `--file` to allow for multi-line code.\n", "before_files": [{"content": "# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:\n\n# Copyright 2014-2017 Florian Bruhin (The Compiler) <mail@qutebrowser.org>\n#\n# This file is part of qutebrowser.\n#\n# qutebrowser is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# qutebrowser is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with qutebrowser.  If not, see <http://www.gnu.org/licenses/>.\n\n\"\"\"Misc. utility commands exposed to the user.\"\"\"\n\nimport functools\nimport os\nimport signal\nimport traceback\n\ntry:\n    import hunter\nexcept ImportError:\n    hunter = None\n\nimport sip\nfrom PyQt5.QtCore import QUrl\n# so it's available for :debug-pyeval\nfrom PyQt5.QtWidgets import QApplication  # pylint: disable=unused-import\n\nfrom qutebrowser.browser import qutescheme\nfrom qutebrowser.utils import log, objreg, usertypes, message, debug, utils\nfrom qutebrowser.commands import cmdutils, runners, cmdexc\nfrom qutebrowser.config import config, configdata\nfrom qutebrowser.misc import consolewidget\n\n\n@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)\n@cmdutils.argument('win_id', win_id=True)\ndef later(ms: int, command, win_id):\n    \"\"\"Execute a command after some time.\n\n    Args:\n        ms: How many milliseconds to wait.\n        command: The command to run, with optional args.\n    \"\"\"\n    if ms < 0:\n        raise cmdexc.CommandError(\"I can't run something in the past!\")\n    commandrunner = runners.CommandRunner(win_id)\n    app = objreg.get('app')\n    timer = usertypes.Timer(name='later', parent=app)\n    try:\n        timer.setSingleShot(True)\n        try:\n            timer.setInterval(ms)\n        except OverflowError:\n            raise cmdexc.CommandError(\"Numeric argument is too large for \"\n                                      \"internal int representation.\")\n        timer.timeout.connect(\n            functools.partial(commandrunner.run_safely, command))\n        timer.timeout.connect(timer.deleteLater)\n        timer.start()\n    except:\n        timer.deleteLater()\n        raise\n\n\n@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)\n@cmdutils.argument('win_id', win_id=True)\ndef repeat(times: int, command, win_id):\n    \"\"\"Repeat a given command.\n\n    Args:\n        times: How many times to repeat.\n        command: The command to run, with optional args.\n    \"\"\"\n    if times < 0:\n        raise cmdexc.CommandError(\"A negative count doesn't make sense.\")\n    commandrunner = runners.CommandRunner(win_id)\n    for _ in range(times):\n        commandrunner.run_safely(command)\n\n\n@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)\n@cmdutils.argument('win_id', win_id=True)\n@cmdutils.argument('count', count=True)\ndef run_with_count(count_arg: int, command, win_id, count=1):\n    \"\"\"Run a command with the given count.\n\n    If run_with_count itself is run with a count, it multiplies count_arg.\n\n    Args:\n        count_arg: The count to pass to the command.\n        command: The command to run, with optional args.\n        count: The count that run_with_count itself received.\n    \"\"\"\n    runners.CommandRunner(win_id).run(command, count_arg * count)\n\n\n@cmdutils.register()\ndef message_error(text):\n    \"\"\"Show an error message in the statusbar.\n\n    Args:\n        text: The text to show.\n    \"\"\"\n    message.error(text)\n\n\n@cmdutils.register()\n@cmdutils.argument('count', count=True)\ndef message_info(text, count=1):\n    \"\"\"Show an info message in the statusbar.\n\n    Args:\n        text: The text to show.\n        count: How many times to show the message\n    \"\"\"\n    for _ in range(count):\n        message.info(text)\n\n\n@cmdutils.register()\ndef message_warning(text):\n    \"\"\"Show a warning message in the statusbar.\n\n    Args:\n        text: The text to show.\n    \"\"\"\n    message.warning(text)\n\n\n@cmdutils.register()\ndef clear_messages():\n    \"\"\"Clear all message notifications.\"\"\"\n    message.global_bridge.clear_messages.emit()\n\n\n@cmdutils.register(debug=True)\n@cmdutils.argument('typ', choices=['exception', 'segfault'])\ndef debug_crash(typ='exception'):\n    \"\"\"Crash for debugging purposes.\n\n    Args:\n        typ: either 'exception' or 'segfault'.\n    \"\"\"\n    if typ == 'segfault':\n        os.kill(os.getpid(), signal.SIGSEGV)\n        raise Exception(\"Segfault failed (wat.)\")\n    else:\n        raise Exception(\"Forced crash\")\n\n\n@cmdutils.register(debug=True)\ndef debug_all_objects():\n    \"\"\"Print a list of  all objects to the debug log.\"\"\"\n    s = debug.get_all_objects()\n    log.misc.debug(s)\n\n\n@cmdutils.register(debug=True)\ndef debug_cache_stats():\n    \"\"\"Print LRU cache stats.\"\"\"\n    prefix_info = configdata.is_valid_prefix.cache_info()\n    # pylint: disable=protected-access\n    render_stylesheet_info = config._render_stylesheet.cache_info()\n    # pylint: enable=protected-access\n\n    history_info = None\n    try:\n        from PyQt5.QtWebKit import QWebHistoryInterface\n        interface = QWebHistoryInterface.defaultInterface()\n        if interface is not None:\n            history_info = interface.historyContains.cache_info()\n    except ImportError:\n        pass\n\n    tabbed_browser = objreg.get('tabbed-browser', scope='window',\n                                window='last-focused')\n    # pylint: disable=protected-access\n    tab_bar = tabbed_browser.tabBar()\n    tabbed_browser_info = tab_bar._minimum_tab_size_hint_helper.cache_info()\n    # pylint: enable=protected-access\n\n    log.misc.debug('is_valid_prefix: {}'.format(prefix_info))\n    log.misc.debug('_render_stylesheet: {}'.format(render_stylesheet_info))\n    log.misc.debug('history: {}'.format(history_info))\n    log.misc.debug('tab width cache: {}'.format(tabbed_browser_info))\n\n\n@cmdutils.register(debug=True)\ndef debug_console():\n    \"\"\"Show the debugging console.\"\"\"\n    try:\n        con_widget = objreg.get('debug-console')\n    except KeyError:\n        log.misc.debug('initializing debug console')\n        con_widget = consolewidget.ConsoleWidget()\n        objreg.register('debug-console', con_widget)\n\n    if con_widget.isVisible():\n        log.misc.debug('hiding debug console')\n        con_widget.hide()\n    else:\n        log.misc.debug('showing debug console')\n        con_widget.show()\n\n\n@cmdutils.register(debug=True, maxsplit=0, no_cmd_split=True)\ndef debug_trace(expr=\"\"):\n    \"\"\"Trace executed code via hunter.\n\n    Args:\n        expr: What to trace, passed to hunter.\n    \"\"\"\n    if hunter is None:\n        raise cmdexc.CommandError(\"You need to install 'hunter' to use this \"\n                                  \"command!\")\n    try:\n        eval('hunter.trace({})'.format(expr))\n    except Exception as e:\n        raise cmdexc.CommandError(\"{}: {}\".format(e.__class__.__name__, e))\n\n\n@cmdutils.register(maxsplit=0, debug=True, no_cmd_split=True)\ndef debug_pyeval(s, quiet=False):\n    \"\"\"Evaluate a python string and display the results as a web page.\n\n    Args:\n        s: The string to evaluate.\n        quiet: Don't show the output in a new tab.\n    \"\"\"\n    try:\n        r = eval(s)\n        out = repr(r)\n    except Exception:\n        out = traceback.format_exc()\n\n    qutescheme.pyeval_output = out\n    if quiet:\n        log.misc.debug(\"pyeval output: {}\".format(out))\n    else:\n        tabbed_browser = objreg.get('tabbed-browser', scope='window',\n                                    window='last-focused')\n        tabbed_browser.openurl(QUrl('qute://pyeval'), newtab=True)\n\n\n@cmdutils.register(debug=True)\ndef debug_set_fake_clipboard(s=None):\n    \"\"\"Put data into the fake clipboard and enable logging, used for tests.\n\n    Args:\n        s: The text to put into the fake clipboard, or unset to enable logging.\n    \"\"\"\n    if s is None:\n        utils.log_clipboard = True\n    else:\n        utils.fake_clipboard = s\n\n\n@cmdutils.register()\n@cmdutils.argument('win_id', win_id=True)\n@cmdutils.argument('count', count=True)\ndef repeat_command(win_id, count=None):\n    \"\"\"Repeat the last executed command.\n\n    Args:\n        count: Which count to pass the command.\n    \"\"\"\n    mode_manager = objreg.get('mode-manager', scope='window', window=win_id)\n    if mode_manager.mode not in runners.last_command:\n        raise cmdexc.CommandError(\"You didn't do anything yet.\")\n    cmd = runners.last_command[mode_manager.mode]\n    commandrunner = runners.CommandRunner(win_id)\n    commandrunner.run(cmd[0], count if count is not None else cmd[1])\n\n\n@cmdutils.register(debug=True, name='debug-log-capacity')\ndef log_capacity(capacity: int):\n    \"\"\"Change the number of log lines to be stored in RAM.\n\n    Args:\n       capacity: Number of lines for the log.\n    \"\"\"\n    if capacity < 0:\n        raise cmdexc.CommandError(\"Can't set a negative log capacity!\")\n    else:\n        log.ram_handler.change_log_capacity(capacity)\n\n\n@cmdutils.register(debug=True)\n@cmdutils.argument('level', choices=sorted(\n    (level.lower() for level in log.LOG_LEVELS),\n    key=lambda e: log.LOG_LEVELS[e.upper()]))\ndef debug_log_level(level: str):\n    \"\"\"Change the log level for console logging.\n\n    Args:\n        level: The log level to set.\n    \"\"\"\n    log.change_console_formatter(log.LOG_LEVELS[level.upper()])\n    log.console_handler.setLevel(log.LOG_LEVELS[level.upper()])\n\n\n@cmdutils.register(debug=True)\ndef debug_log_filter(filters: str):\n    \"\"\"Change the log filter for console logging.\n\n    Args:\n        filters: A comma separated list of logger names. Can also be \"none\" to\n                 clear any existing filters.\n    \"\"\"\n    if log.console_filter is None:\n        raise cmdexc.CommandError(\"No log.console_filter. Not attached \"\n                                  \"to a console?\")\n\n    if filters.strip().lower() == 'none':\n        log.console_filter.names = None\n        return\n\n    if not set(filters.split(',')).issubset(log.LOGGER_NAMES):\n        raise cmdexc.CommandError(\"filters: Invalid value {} - expected one \"\n                                  \"of: {}\".format(filters,\n                                                  ', '.join(log.LOGGER_NAMES)))\n\n    log.console_filter.names = filters.split(',')\n\n\n@cmdutils.register()\n@cmdutils.argument('current_win_id', win_id=True)\ndef window_only(current_win_id):\n    \"\"\"Close all windows except for the current one.\"\"\"\n    for win_id, window in objreg.window_registry.items():\n\n        # We could be in the middle of destroying a window here\n        if sip.isdeleted(window):\n            continue\n\n        if win_id != current_win_id:\n            window.close()\n\n\n@cmdutils.register()\ndef nop():\n    \"\"\"Do nothing.\"\"\"\n    return\n\n\n@cmdutils.register()\n@cmdutils.argument('win_id', win_id=True)\ndef version(win_id):\n    \"\"\"Show version information.\"\"\"\n    tabbed_browser = objreg.get('tabbed-browser', scope='window',\n                                window=win_id)\n    tabbed_browser.openurl(QUrl('qute://version'), newtab=True)\n", "path": "qutebrowser/misc/utilcmds.py"}], "after_files": [{"content": "# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:\n\n# Copyright 2014-2017 Florian Bruhin (The Compiler) <mail@qutebrowser.org>\n#\n# This file is part of qutebrowser.\n#\n# qutebrowser is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# qutebrowser is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with qutebrowser.  If not, see <http://www.gnu.org/licenses/>.\n\n\"\"\"Misc. utility commands exposed to the user.\"\"\"\n\nimport functools\nimport os\nimport signal\nimport traceback\n\ntry:\n    import hunter\nexcept ImportError:\n    hunter = None\n\nimport sip\nfrom PyQt5.QtCore import QUrl\n# so it's available for :debug-pyeval\nfrom PyQt5.QtWidgets import QApplication  # pylint: disable=unused-import\n\nfrom qutebrowser.browser import qutescheme\nfrom qutebrowser.utils import log, objreg, usertypes, message, debug, utils\nfrom qutebrowser.commands import cmdutils, runners, cmdexc\nfrom qutebrowser.config import config, configdata\nfrom qutebrowser.misc import consolewidget\n\n\n@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)\n@cmdutils.argument('win_id', win_id=True)\ndef later(ms: int, command, win_id):\n    \"\"\"Execute a command after some time.\n\n    Args:\n        ms: How many milliseconds to wait.\n        command: The command to run, with optional args.\n    \"\"\"\n    if ms < 0:\n        raise cmdexc.CommandError(\"I can't run something in the past!\")\n    commandrunner = runners.CommandRunner(win_id)\n    app = objreg.get('app')\n    timer = usertypes.Timer(name='later', parent=app)\n    try:\n        timer.setSingleShot(True)\n        try:\n            timer.setInterval(ms)\n        except OverflowError:\n            raise cmdexc.CommandError(\"Numeric argument is too large for \"\n                                      \"internal int representation.\")\n        timer.timeout.connect(\n            functools.partial(commandrunner.run_safely, command))\n        timer.timeout.connect(timer.deleteLater)\n        timer.start()\n    except:\n        timer.deleteLater()\n        raise\n\n\n@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)\n@cmdutils.argument('win_id', win_id=True)\ndef repeat(times: int, command, win_id):\n    \"\"\"Repeat a given command.\n\n    Args:\n        times: How many times to repeat.\n        command: The command to run, with optional args.\n    \"\"\"\n    if times < 0:\n        raise cmdexc.CommandError(\"A negative count doesn't make sense.\")\n    commandrunner = runners.CommandRunner(win_id)\n    for _ in range(times):\n        commandrunner.run_safely(command)\n\n\n@cmdutils.register(maxsplit=1, no_cmd_split=True, no_replace_variables=True)\n@cmdutils.argument('win_id', win_id=True)\n@cmdutils.argument('count', count=True)\ndef run_with_count(count_arg: int, command, win_id, count=1):\n    \"\"\"Run a command with the given count.\n\n    If run_with_count itself is run with a count, it multiplies count_arg.\n\n    Args:\n        count_arg: The count to pass to the command.\n        command: The command to run, with optional args.\n        count: The count that run_with_count itself received.\n    \"\"\"\n    runners.CommandRunner(win_id).run(command, count_arg * count)\n\n\n@cmdutils.register()\ndef message_error(text):\n    \"\"\"Show an error message in the statusbar.\n\n    Args:\n        text: The text to show.\n    \"\"\"\n    message.error(text)\n\n\n@cmdutils.register()\n@cmdutils.argument('count', count=True)\ndef message_info(text, count=1):\n    \"\"\"Show an info message in the statusbar.\n\n    Args:\n        text: The text to show.\n        count: How many times to show the message\n    \"\"\"\n    for _ in range(count):\n        message.info(text)\n\n\n@cmdutils.register()\ndef message_warning(text):\n    \"\"\"Show a warning message in the statusbar.\n\n    Args:\n        text: The text to show.\n    \"\"\"\n    message.warning(text)\n\n\n@cmdutils.register()\ndef clear_messages():\n    \"\"\"Clear all message notifications.\"\"\"\n    message.global_bridge.clear_messages.emit()\n\n\n@cmdutils.register(debug=True)\n@cmdutils.argument('typ', choices=['exception', 'segfault'])\ndef debug_crash(typ='exception'):\n    \"\"\"Crash for debugging purposes.\n\n    Args:\n        typ: either 'exception' or 'segfault'.\n    \"\"\"\n    if typ == 'segfault':\n        os.kill(os.getpid(), signal.SIGSEGV)\n        raise Exception(\"Segfault failed (wat.)\")\n    else:\n        raise Exception(\"Forced crash\")\n\n\n@cmdutils.register(debug=True)\ndef debug_all_objects():\n    \"\"\"Print a list of  all objects to the debug log.\"\"\"\n    s = debug.get_all_objects()\n    log.misc.debug(s)\n\n\n@cmdutils.register(debug=True)\ndef debug_cache_stats():\n    \"\"\"Print LRU cache stats.\"\"\"\n    prefix_info = configdata.is_valid_prefix.cache_info()\n    # pylint: disable=protected-access\n    render_stylesheet_info = config._render_stylesheet.cache_info()\n    # pylint: enable=protected-access\n\n    history_info = None\n    try:\n        from PyQt5.QtWebKit import QWebHistoryInterface\n        interface = QWebHistoryInterface.defaultInterface()\n        if interface is not None:\n            history_info = interface.historyContains.cache_info()\n    except ImportError:\n        pass\n\n    tabbed_browser = objreg.get('tabbed-browser', scope='window',\n                                window='last-focused')\n    # pylint: disable=protected-access\n    tab_bar = tabbed_browser.tabBar()\n    tabbed_browser_info = tab_bar._minimum_tab_size_hint_helper.cache_info()\n    # pylint: enable=protected-access\n\n    log.misc.debug('is_valid_prefix: {}'.format(prefix_info))\n    log.misc.debug('_render_stylesheet: {}'.format(render_stylesheet_info))\n    log.misc.debug('history: {}'.format(history_info))\n    log.misc.debug('tab width cache: {}'.format(tabbed_browser_info))\n\n\n@cmdutils.register(debug=True)\ndef debug_console():\n    \"\"\"Show the debugging console.\"\"\"\n    try:\n        con_widget = objreg.get('debug-console')\n    except KeyError:\n        log.misc.debug('initializing debug console')\n        con_widget = consolewidget.ConsoleWidget()\n        objreg.register('debug-console', con_widget)\n\n    if con_widget.isVisible():\n        log.misc.debug('hiding debug console')\n        con_widget.hide()\n    else:\n        log.misc.debug('showing debug console')\n        con_widget.show()\n\n\n@cmdutils.register(debug=True, maxsplit=0, no_cmd_split=True)\ndef debug_trace(expr=\"\"):\n    \"\"\"Trace executed code via hunter.\n\n    Args:\n        expr: What to trace, passed to hunter.\n    \"\"\"\n    if hunter is None:\n        raise cmdexc.CommandError(\"You need to install 'hunter' to use this \"\n                                  \"command!\")\n    try:\n        eval('hunter.trace({})'.format(expr))\n    except Exception as e:\n        raise cmdexc.CommandError(\"{}: {}\".format(e.__class__.__name__, e))\n\n\n@cmdutils.register(maxsplit=0, debug=True, no_cmd_split=True)\ndef debug_pyeval(s, file=False, quiet=False):\n    \"\"\"Evaluate a python string and display the results as a web page.\n\n    Args:\n        s: The string to evaluate.\n        file: Interpret s as a path to file, also implies --quiet.\n        quiet: Don't show the output in a new tab.\n    \"\"\"\n    if file:\n        quiet = True\n        path = os.path.expanduser(s)\n        try:\n            with open(path, 'r', encoding='utf-8') as f:\n                s = f.read()\n        except OSError as e:\n            raise cmdexc.CommandError(str(e))\n        try:\n            exec(s)\n            out = \"No error\"\n        except Exception:\n            out = traceback.format_exc()\n    else:\n        try:\n            r = eval(s)\n            out = repr(r)\n        except Exception:\n            out = traceback.format_exc()\n\n    qutescheme.pyeval_output = out\n    if quiet:\n        log.misc.debug(\"pyeval output: {}\".format(out))\n    else:\n        tabbed_browser = objreg.get('tabbed-browser', scope='window',\n                                    window='last-focused')\n        tabbed_browser.openurl(QUrl('qute://pyeval'), newtab=True)\n\n\n@cmdutils.register(debug=True)\ndef debug_set_fake_clipboard(s=None):\n    \"\"\"Put data into the fake clipboard and enable logging, used for tests.\n\n    Args:\n        s: The text to put into the fake clipboard, or unset to enable logging.\n    \"\"\"\n    if s is None:\n        utils.log_clipboard = True\n    else:\n        utils.fake_clipboard = s\n\n\n@cmdutils.register()\n@cmdutils.argument('win_id', win_id=True)\n@cmdutils.argument('count', count=True)\ndef repeat_command(win_id, count=None):\n    \"\"\"Repeat the last executed command.\n\n    Args:\n        count: Which count to pass the command.\n    \"\"\"\n    mode_manager = objreg.get('mode-manager', scope='window', window=win_id)\n    if mode_manager.mode not in runners.last_command:\n        raise cmdexc.CommandError(\"You didn't do anything yet.\")\n    cmd = runners.last_command[mode_manager.mode]\n    commandrunner = runners.CommandRunner(win_id)\n    commandrunner.run(cmd[0], count if count is not None else cmd[1])\n\n\n@cmdutils.register(debug=True, name='debug-log-capacity')\ndef log_capacity(capacity: int):\n    \"\"\"Change the number of log lines to be stored in RAM.\n\n    Args:\n       capacity: Number of lines for the log.\n    \"\"\"\n    if capacity < 0:\n        raise cmdexc.CommandError(\"Can't set a negative log capacity!\")\n    else:\n        log.ram_handler.change_log_capacity(capacity)\n\n\n@cmdutils.register(debug=True)\n@cmdutils.argument('level', choices=sorted(\n    (level.lower() for level in log.LOG_LEVELS),\n    key=lambda e: log.LOG_LEVELS[e.upper()]))\ndef debug_log_level(level: str):\n    \"\"\"Change the log level for console logging.\n\n    Args:\n        level: The log level to set.\n    \"\"\"\n    log.change_console_formatter(log.LOG_LEVELS[level.upper()])\n    log.console_handler.setLevel(log.LOG_LEVELS[level.upper()])\n\n\n@cmdutils.register(debug=True)\ndef debug_log_filter(filters: str):\n    \"\"\"Change the log filter for console logging.\n\n    Args:\n        filters: A comma separated list of logger names. Can also be \"none\" to\n                 clear any existing filters.\n    \"\"\"\n    if log.console_filter is None:\n        raise cmdexc.CommandError(\"No log.console_filter. Not attached \"\n                                  \"to a console?\")\n\n    if filters.strip().lower() == 'none':\n        log.console_filter.names = None\n        return\n\n    if not set(filters.split(',')).issubset(log.LOGGER_NAMES):\n        raise cmdexc.CommandError(\"filters: Invalid value {} - expected one \"\n                                  \"of: {}\".format(filters,\n                                                  ', '.join(log.LOGGER_NAMES)))\n\n    log.console_filter.names = filters.split(',')\n\n\n@cmdutils.register()\n@cmdutils.argument('current_win_id', win_id=True)\ndef window_only(current_win_id):\n    \"\"\"Close all windows except for the current one.\"\"\"\n    for win_id, window in objreg.window_registry.items():\n\n        # We could be in the middle of destroying a window here\n        if sip.isdeleted(window):\n            continue\n\n        if win_id != current_win_id:\n            window.close()\n\n\n@cmdutils.register()\ndef nop():\n    \"\"\"Do nothing.\"\"\"\n    return\n\n\n@cmdutils.register()\n@cmdutils.argument('win_id', win_id=True)\ndef version(win_id):\n    \"\"\"Show version information.\"\"\"\n    tabbed_browser = objreg.get('tabbed-browser', scope='window',\n                                window=win_id)\n    tabbed_browser.openurl(QUrl('qute://version'), newtab=True)\n", "path": "qutebrowser/misc/utilcmds.py"}]}