diff options
Diffstat (limited to 'qutebrowser/misc/ipc.py')
-rw-r--r-- | qutebrowser/misc/ipc.py | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/qutebrowser/misc/ipc.py b/qutebrowser/misc/ipc.py index 8c5c05046..c94c67b29 100644 --- a/qutebrowser/misc/ipc.py +++ b/qutebrowser/misc/ipc.py @@ -26,11 +26,11 @@ import getpass import binascii import hashlib -from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, Qt -from PyQt5.QtNetwork import QLocalSocket, QLocalServer, QAbstractSocket +from qutebrowser.qt.core import pyqtSignal, pyqtSlot, QObject, Qt +from qutebrowser.qt.network import QLocalSocket, QLocalServer, QAbstractSocket import qutebrowser -from qutebrowser.utils import log, usertypes, error, standarddir, utils +from qutebrowser.utils import log, usertypes, error, standarddir, utils, debug from qutebrowser.qt import sip @@ -107,12 +107,12 @@ class SocketError(Error): """ super().__init__() self.action = action - self.code = socket.error() - self.message = socket.errorString() + self.code: QLocalSocket.LocalSocketError = socket.error() + self.message: str = socket.errorString() def __str__(self): - return "Error while {}: {} (error {})".format( - self.action, self.message, self.code) + return "Error while {}: {} ({})".format( + self.action, self.message, debug.qenum_key(QLocalSocket, self.code)) class ListenError(Error): @@ -131,12 +131,12 @@ class ListenError(Error): local_server: The QLocalServer which has the error set. """ super().__init__() - self.code = local_server.serverError() - self.message = local_server.errorString() + self.code: QAbstractSocket.SocketError = local_server.serverError() + self.message: str = local_server.errorString() def __str__(self): - return "Error while listening to IPC server: {} (error {})".format( - self.message, self.code) + return "Error while listening to IPC server: {} ({})".format( + self.message, debug.qenum_key(QAbstractSocket, self.code)) class AddressInUseError(ListenError): @@ -188,7 +188,7 @@ class IPCServer(QObject): self._atime_timer = usertypes.Timer(self, 'ipc-atime') self._atime_timer.setInterval(ATIME_INTERVAL) self._atime_timer.timeout.connect(self.update_atime) - self._atime_timer.setTimerType(Qt.VeryCoarseTimer) + self._atime_timer.setTimerType(Qt.TimerType.VeryCoarseTimer) self._server = QLocalServer(self) self._server.newConnection.connect(self.handle_connection) @@ -204,7 +204,7 @@ class IPCServer(QObject): # Thus, we only do so on Windows, and handle permissions manually in # listen() on Linux. log.ipc.debug("Calling setSocketOptions") - self._server.setSocketOptions(QLocalServer.UserAccessOption) + self._server.setSocketOptions(QLocalServer.SocketOption.UserAccessOption) else: # pragma: no cover log.ipc.debug("Not calling setSocketOptions") @@ -223,7 +223,7 @@ class IPCServer(QObject): self._remove_server() ok = self._server.listen(self._socketname) if not ok: - if self._server.serverError() == QAbstractSocket.AddressInUseError: + if self._server.serverError() == QAbstractSocket.SocketError.AddressInUseError: raise AddressInUseError(self._server) raise ListenError(self._server) @@ -248,7 +248,7 @@ class IPCServer(QObject): log.ipc.debug("Socket 0x{:x}: error {}: {}".format( id(self._socket), self._socket.error(), self._socket.errorString())) - if err != QLocalSocket.PeerClosedError: + if err != QLocalSocket.LocalSocketError.PeerClosedError: raise SocketError("handling IPC connection", self._socket) @pyqtSlot() @@ -273,13 +273,17 @@ class IPCServer(QObject): if socket.canReadLine(): log.ipc.debug("We can read a line immediately.") self.on_ready_read() - socket.error.connect(self.on_error) + + socket.errorOccurred.connect(self.on_error) + if socket.error() not in [ # type: ignore[operator] - QLocalSocket.UnknownSocketError, QLocalSocket.PeerClosedError]: + QLocalSocket.LocalSocketError.UnknownSocketError, + QLocalSocket.LocalSocketError.PeerClosedError + ]: log.ipc.debug("We got an error immediately.") self.on_error(socket.error()) # type: ignore[operator] socket.disconnected.connect(self.on_disconnected) - if socket.state() == QLocalSocket.UnconnectedState: + if socket.state() == QLocalSocket.LocalSocketState.UnconnectedState: log.ipc.debug("Socket was disconnected immediately.") self.on_disconnected() @@ -302,7 +306,7 @@ class IPCServer(QObject): log.ipc.error("Ignoring invalid IPC data from socket 0x{:x}.".format( id(self._socket))) self.got_invalid_data.emit() - self._socket.error.connect(self.on_error) + self._socket.errorOccurred.connect(self.on_error) self._socket.disconnectFromServer() def _handle_data(self, data): @@ -490,18 +494,18 @@ def send_to_running_instance(socketname, command, target_arg, *, socket=None): log.ipc.debug("Writing: {!r}".format(data)) socket.writeData(data) socket.waitForBytesWritten(WRITE_TIMEOUT) - if socket.error() != QLocalSocket.UnknownSocketError: + if socket.error() != QLocalSocket.LocalSocketError.UnknownSocketError: raise SocketError("writing to running instance", socket) socket.disconnectFromServer() - if socket.state() != QLocalSocket.UnconnectedState: + if socket.state() != QLocalSocket.LocalSocketState.UnconnectedState: socket.waitForDisconnected(CONNECT_TIMEOUT) return True else: - if socket.error() not in [QLocalSocket.ConnectionRefusedError, - QLocalSocket.ServerNotFoundError]: + if socket.error() not in [QLocalSocket.LocalSocketError.ConnectionRefusedError, + QLocalSocket.LocalSocketError.ServerNotFoundError]: raise SocketError("connecting to running instance", socket) - log.ipc.debug("No existing instance present (error {})".format( - socket.error())) + log.ipc.debug("No existing instance present ({})".format( + debug.qenum_key(QLocalSocket, socket.error()))) return False |