Split IPCServer.on_ready_read into two methods
This commit is contained in:
parent
7c3361d8da
commit
fd20b46b33
@ -288,21 +288,8 @@ class IPCServer(QObject):
|
||||
self._socket.error.connect(self.on_error)
|
||||
self._socket.disconnectFromServer()
|
||||
|
||||
@pyqtSlot()
|
||||
def on_ready_read(self):
|
||||
"""Read json data from the client."""
|
||||
if self._socket is None:
|
||||
# This happens when doing a connection while another one is already
|
||||
# active for some reason.
|
||||
log.ipc.warning("In on_ready_read with None socket!")
|
||||
return
|
||||
self._timer.stop()
|
||||
while self._socket is not None and self._socket.canReadLine():
|
||||
data = bytes(self._socket.readLine())
|
||||
self.got_raw.emit(data)
|
||||
log.ipc.debug("Read from socket 0x{:x}: {}".format(
|
||||
id(self._socket), data))
|
||||
|
||||
def _handle_data(self, data):
|
||||
"""Handle data (as bytes) we got from on_ready_ready_read."""
|
||||
try:
|
||||
decoded = data.decode('utf-8')
|
||||
except UnicodeDecodeError:
|
||||
@ -321,8 +308,7 @@ class IPCServer(QObject):
|
||||
|
||||
for name in ('args', 'target_arg'):
|
||||
if name not in json_data:
|
||||
log.ipc.error("Missing {}: {}".format(name,
|
||||
decoded.strip()))
|
||||
log.ipc.error("Missing {}: {}".format(name, decoded.strip()))
|
||||
self._handle_invalid_data()
|
||||
return
|
||||
|
||||
@ -334,8 +320,7 @@ class IPCServer(QObject):
|
||||
return
|
||||
|
||||
if protocol_version != PROTOCOL_VERSION:
|
||||
log.ipc.error("incompatible version: expected {}, "
|
||||
"got {}".format(
|
||||
log.ipc.error("incompatible version: expected {}, got {}".format(
|
||||
PROTOCOL_VERSION, protocol_version))
|
||||
self._handle_invalid_data()
|
||||
return
|
||||
@ -351,6 +336,22 @@ class IPCServer(QObject):
|
||||
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."""
|
||||
if self._socket is None:
|
||||
# This happens when doing a connection while another one is already
|
||||
# active for some reason.
|
||||
log.ipc.warning("In on_ready_read with None socket!")
|
||||
return
|
||||
self._timer.stop()
|
||||
while self._socket is not None and self._socket.canReadLine():
|
||||
data = bytes(self._socket.readLine())
|
||||
self.got_raw.emit(data)
|
||||
log.ipc.debug("Read from socket 0x{:x}: {}".format(
|
||||
id(self._socket), data))
|
||||
self._handle_data(data)
|
||||
self._timer.start()
|
||||
|
||||
@pyqtSlot()
|
||||
|
Loading…
Reference in New Issue
Block a user