summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2016-04-26 23:10:33 +0200
committerFlorian Bruhin <git@the-compiler.org>2016-04-30 14:42:44 +0200
commit26f4acb10adee7c63f7e41fa9fe573a2b35acf39 (patch)
tree773e11ea9706a87095a3afe931678961ba6703eb
parent991277e9de567fd2f59306d197afdc05c01fd6c2 (diff)
downloadqutebrowser-26f4acb10adee7c63f7e41fa9fe573a2b35acf39.tar.gz
qutebrowser-26f4acb10adee7c63f7e41fa9fe573a2b35acf39.zip
Split IPCServer.on_ready_read into two methods
-rw-r--r--qutebrowser/misc/ipc.py99
1 files changed, 50 insertions, 49 deletions
diff --git a/qutebrowser/misc/ipc.py b/qutebrowser/misc/ipc.py
index aa219fab7..1e3bcc4c1 100644
--- a/qutebrowser/misc/ipc.py
+++ b/qutebrowser/misc/ipc.py
@@ -288,6 +288,55 @@ class IPCServer(QObject):
self._socket.error.connect(self.on_error)
self._socket.disconnectFromServer()
+ def _handle_data(self, data):
+ """Handle data (as bytes) we got from on_ready_ready_read."""
+ try:
+ decoded = data.decode('utf-8')
+ except UnicodeDecodeError:
+ log.ipc.error("invalid utf-8: {}".format(
+ binascii.hexlify(data)))
+ self._handle_invalid_data()
+ return
+
+ log.ipc.debug("Processing: {}".format(decoded))
+ try:
+ json_data = json.loads(decoded)
+ except ValueError:
+ log.ipc.error("invalid json: {}".format(decoded.strip()))
+ self._handle_invalid_data()
+ return
+
+ for name in ('args', 'target_arg'):
+ if name not in json_data:
+ log.ipc.error("Missing {}: {}".format(name, decoded.strip()))
+ self._handle_invalid_data()
+ return
+
+ try:
+ protocol_version = int(json_data['protocol_version'])
+ except (KeyError, ValueError):
+ log.ipc.error("invalid version: {}".format(decoded.strip()))
+ self._handle_invalid_data()
+ return
+
+ if protocol_version != PROTOCOL_VERSION:
+ log.ipc.error("incompatible version: expected {}, got {}".format(
+ PROTOCOL_VERSION, protocol_version))
+ self._handle_invalid_data()
+ return
+
+ args = json_data['args']
+
+ target_arg = json_data['target_arg']
+ if target_arg is None:
+ # https://www.riverbankcomputing.com/pipermail/pyqt/2016-April/037375.html
+ target_arg = ''
+
+ cwd = json_data.get('cwd', '')
+ assert cwd is not None
+
+ self.got_args.emit(args, target_arg, cwd)
+
@pyqtSlot()
def on_ready_read(self):
"""Read json data from the client."""
@@ -302,55 +351,7 @@ class IPCServer(QObject):
self.got_raw.emit(data)
log.ipc.debug("Read from socket 0x{:x}: {}".format(
id(self._socket), data))
-
- try:
- decoded = data.decode('utf-8')
- except UnicodeDecodeError:
- log.ipc.error("invalid utf-8: {}".format(
- binascii.hexlify(data)))
- self._handle_invalid_data()
- return
-
- log.ipc.debug("Processing: {}".format(decoded))
- try:
- json_data = json.loads(decoded)
- except ValueError:
- log.ipc.error("invalid json: {}".format(decoded.strip()))
- self._handle_invalid_data()
- return
-
- for name in ('args', 'target_arg'):
- if name not in json_data:
- log.ipc.error("Missing {}: {}".format(name,
- decoded.strip()))
- self._handle_invalid_data()
- return
-
- try:
- protocol_version = int(json_data['protocol_version'])
- except (KeyError, ValueError):
- log.ipc.error("invalid version: {}".format(decoded.strip()))
- self._handle_invalid_data()
- return
-
- if protocol_version != PROTOCOL_VERSION:
- log.ipc.error("incompatible version: expected {}, "
- "got {}".format(
- PROTOCOL_VERSION, protocol_version))
- self._handle_invalid_data()
- return
-
- args = json_data['args']
-
- target_arg = json_data['target_arg']
- if target_arg is None:
- # https://www.riverbankcomputing.com/pipermail/pyqt/2016-April/037375.html
- target_arg = ''
-
- cwd = json_data.get('cwd', '')
- assert cwd is not None
-
- self.got_args.emit(args, target_arg, cwd)
+ self._handle_data(data)
self._timer.start()
@pyqtSlot()