Coding style fixes #1002
This commit is contained in:
parent
45c9768c16
commit
afc166a13e
@ -239,6 +239,14 @@ def process_pos_args(args, via_ipc=False, cwd=None, target_arg=None):
|
|||||||
args: A list of arguments to process.
|
args: A list of arguments to process.
|
||||||
via_ipc: Whether the arguments were transmitted over IPC.
|
via_ipc: Whether the arguments were transmitted over IPC.
|
||||||
cwd: The cwd to use for fuzzy_url.
|
cwd: The cwd to use for fuzzy_url.
|
||||||
|
target_arg: Command line argument received by a running instance via
|
||||||
|
ipc. If the --target argument was not specified, target_arg
|
||||||
|
will be an empty string instead of None. This behavior is
|
||||||
|
caused by the PyQt signal
|
||||||
|
``got_args = pyqtSignal(list, str, str)``
|
||||||
|
used in the misc.ipc.IPCServer class. PyQt converts the None
|
||||||
|
value into a null QString and then back to an empty python
|
||||||
|
string
|
||||||
"""
|
"""
|
||||||
if via_ipc and not args:
|
if via_ipc and not args:
|
||||||
win_id = mainwindow.get_window(via_ipc, force_window=True)
|
win_id = mainwindow.get_window(via_ipc, force_window=True)
|
||||||
@ -260,7 +268,7 @@ def process_pos_args(args, via_ipc=False, cwd=None, target_arg=None):
|
|||||||
open_target = target_arg
|
open_target = target_arg
|
||||||
else:
|
else:
|
||||||
open_target = config.get('general', 'new-instance-open-target')
|
open_target = config.get('general', 'new-instance-open-target')
|
||||||
win_id = mainwindow.get_window(via_ipc, open_target=open_target)
|
win_id = mainwindow.get_window(via_ipc, force_target=open_target)
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=win_id)
|
window=win_id)
|
||||||
log.init.debug("Startup URL {}".format(cmd))
|
log.init.debug("Startup URL {}".format(cmd))
|
||||||
|
@ -41,13 +41,14 @@ from qutebrowser.misc import crashsignal
|
|||||||
win_id_gen = itertools.count(0)
|
win_id_gen = itertools.count(0)
|
||||||
|
|
||||||
|
|
||||||
def get_window(via_ipc, force_window=False, force_tab=False, open_target=None):
|
def get_window(via_ipc, force_window=False, force_tab=False, force_target=None):
|
||||||
"""Helper function for app.py to get a window id.
|
"""Helper function for app.py to get a window id.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
via_ipc: Whether the request was made via IPC.
|
via_ipc: Whether the request was made via IPC.
|
||||||
force_window: Whether to force opening in a window.
|
force_window: Whether to force opening in a window.
|
||||||
force_tab: Whether to force opening in a tab.
|
force_tab: Whether to force opening in a tab.
|
||||||
|
force_target: Override the new-instance-open-target config
|
||||||
"""
|
"""
|
||||||
if force_window and force_tab:
|
if force_window and force_tab:
|
||||||
raise ValueError("force_window and force_tab are mutually exclusive!")
|
raise ValueError("force_window and force_tab are mutually exclusive!")
|
||||||
@ -55,7 +56,9 @@ def get_window(via_ipc, force_window=False, force_tab=False, open_target=None):
|
|||||||
# Initial main window
|
# Initial main window
|
||||||
return 0
|
return 0
|
||||||
window_to_raise = None
|
window_to_raise = None
|
||||||
if not open_target:
|
if force_target is not None:
|
||||||
|
open_target = force_target
|
||||||
|
else:
|
||||||
open_target = config.get('general', 'new-instance-open-target')
|
open_target = config.get('general', 'new-instance-open-target')
|
||||||
if (open_target == 'window' or force_window) and not force_tab:
|
if (open_target == 'window' or force_window) and not force_tab:
|
||||||
window = MainWindow()
|
window = MainWindow()
|
||||||
|
@ -287,7 +287,6 @@ class IPCServer(QObject):
|
|||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def on_ready_read(self):
|
def on_ready_read(self):
|
||||||
"""Read json data from the client."""
|
"""Read json data from the client."""
|
||||||
# pylint: disable=too-many-return-statements
|
|
||||||
if self._socket is None:
|
if self._socket is None:
|
||||||
# This happens when doing a connection while another one is already
|
# This happens when doing a connection while another one is already
|
||||||
# active for some reason.
|
# active for some reason.
|
||||||
@ -315,19 +314,12 @@ class IPCServer(QObject):
|
|||||||
self._handle_invalid_data()
|
self._handle_invalid_data()
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
for name in ('args', 'target_arg'):
|
||||||
args = json_data['args']
|
if name not in json_data:
|
||||||
except KeyError:
|
log.ipc.error("Missing {}: {}".format(name,
|
||||||
log.ipc.error("no args: {}".format(decoded.strip()))
|
decoded.strip()))
|
||||||
self._handle_invalid_data()
|
self._handle_invalid_data()
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
|
||||||
target_arg = json_data['target_arg']
|
|
||||||
except KeyError:
|
|
||||||
log.ipc.error("target arg missing: {}".format(decoded.strip()))
|
|
||||||
self._handle_invalid_data()
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
protocol_version = int(json_data['protocol_version'])
|
protocol_version = int(json_data['protocol_version'])
|
||||||
@ -344,7 +336,7 @@ class IPCServer(QObject):
|
|||||||
return
|
return
|
||||||
|
|
||||||
cwd = json_data.get('cwd', None)
|
cwd = json_data.get('cwd', None)
|
||||||
self.got_args.emit(args, target_arg, cwd)
|
self.got_args.emit(json_data['args'], json_data['target_arg'], cwd)
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def on_timeout(self):
|
def on_timeout(self):
|
||||||
@ -435,6 +427,7 @@ def send_to_running_instance(socketname, command, target_arg, *,
|
|||||||
Args:
|
Args:
|
||||||
socketname: The name which should be used for the socket.
|
socketname: The name which should be used for the socket.
|
||||||
command: The command to send to the running instance.
|
command: The command to send to the running instance.
|
||||||
|
target_arg: --target command line argument
|
||||||
socket: The socket to read data from, or None.
|
socket: The socket to read data from, or None.
|
||||||
legacy_name: The legacy name to first try to connect to.
|
legacy_name: The legacy name to first try to connect to.
|
||||||
|
|
||||||
|
@ -65,11 +65,11 @@ def get_argparser():
|
|||||||
parser.add_argument('-R', '--override-restore', help="Don't restore a "
|
parser.add_argument('-R', '--override-restore', help="Don't restore a "
|
||||||
"session even if one would be restored.",
|
"session even if one would be restored.",
|
||||||
action='store_true')
|
action='store_true')
|
||||||
parser.add_argument('--json-args', help=argparse.SUPPRESS)
|
|
||||||
parser.add_argument('--target', choices=['auto', 'tab', 'tab-bg',
|
parser.add_argument('--target', choices=['auto', 'tab', 'tab-bg',
|
||||||
'tab-silent', 'tab-bg-silent', 'window'],
|
'tab-silent', 'tab-bg-silent', 'window'],
|
||||||
help="How the urls should be opened if there is "
|
help="How URLs should be opened if there is already a "
|
||||||
"already a qutebrowser instance running.")
|
"qutebrowser instance running.")
|
||||||
|
parser.add_argument('--json-args', help=argparse.SUPPRESS)
|
||||||
|
|
||||||
debug = parser.add_argument_group('debug arguments')
|
debug = parser.add_argument_group('debug arguments')
|
||||||
debug.add_argument('-l', '--loglevel', dest='loglevel',
|
debug.add_argument('-l', '--loglevel', dest='loglevel',
|
||||||
|
@ -442,8 +442,8 @@ class TestHandleConnection:
|
|||||||
assert msg in all_msgs
|
assert msg in all_msgs
|
||||||
|
|
||||||
def test_read_line_immediately(self, qtbot, ipc_server, caplog):
|
def test_read_line_immediately(self, qtbot, ipc_server, caplog):
|
||||||
data = '{{"args": ["foo"], "target_arg": "tab", ' \
|
data = ('{{"args": ["foo"], "target_arg": "tab", '
|
||||||
'"protocol_version": {}}}\n'.format(ipc.PROTOCOL_VERSION)
|
'"protocol_version": {}}}\n'.format(ipc.PROTOCOL_VERSION))
|
||||||
socket = FakeSocket(data=data.encode('utf-8'))
|
socket = FakeSocket(data=data.encode('utf-8'))
|
||||||
|
|
||||||
ipc_server._server = FakeServer(socket)
|
ipc_server._server = FakeServer(socket)
|
||||||
@ -490,8 +490,8 @@ NEW_VERSION = str(ipc.PROTOCOL_VERSION + 1).encode('utf-8')
|
|||||||
(b'\x80\n', 'invalid utf-8'),
|
(b'\x80\n', 'invalid utf-8'),
|
||||||
(b'\n', 'invalid json'),
|
(b'\n', 'invalid json'),
|
||||||
(b'{"is this invalid json?": true\n', 'invalid json'),
|
(b'{"is this invalid json?": true\n', 'invalid json'),
|
||||||
(b'{"valid json without args": true}\n', 'no args'),
|
(b'{"valid json without args": true}\n', 'Missing args'),
|
||||||
(b'{"args": []}\n', 'target arg missing'),
|
(b'{"args": []}\n', 'Missing target_arg'),
|
||||||
(b'{"args": [], "target_arg": null, "protocol_version": ' + OLD_VERSION +
|
(b'{"args": [], "target_arg": null, "protocol_version": ' + OLD_VERSION +
|
||||||
b'}\n', 'incompatible version'),
|
b'}\n', 'incompatible version'),
|
||||||
(b'{"args": [], "target_arg": null, "protocol_version": ' + NEW_VERSION +
|
(b'{"args": [], "target_arg": null, "protocol_version": ' + NEW_VERSION +
|
||||||
|
Loading…
Reference in New Issue
Block a user