def _verify_message( self, msg: QDBusMessage, expected_signature: str, expected_type: QDBusMessage.MessageType, ) -> None: """Check the signature/type of a received message. Raises DBusError if the signature doesn't match. """ assert expected_type not in [ QDBusMessage.ErrorMessage, QDBusMessage.InvalidMessage, ], expected_type if msg.type() == QDBusMessage.ErrorMessage: raise DBusError(msg) signature = msg.signature() if signature != expected_signature: raise Error( f"Got a message with signature {signature} but expected " f"{expected_signature} (args: {msg.arguments()})") typ = msg.type() if typ != expected_type: type_str = debug.qenum_key(QDBusMessage.MessageType, typ) expected_type_str = debug.qenum_key(QDBusMessage.MessageType, expected_type) raise Error( f"Got a message of type {type_str} but expected {expected_type_str}" f"(args: {msg.arguments()})")
def __init__(self, msg: QDBusMessage) -> None: assert msg.type() == QDBusMessage.ErrorMessage self.error = msg.errorName() self.error_message = msg.errorMessage() self.is_fatal = self.error not in self._NON_FATAL_ERRORS text = f"{self.error}: {self.error_message}" super().__init__(text)
def GetCapabilities(self, message: QDBusMessage) -> List[str]: assert not message.signature() assert not message.arguments() assert message.type() == QDBusMessage.MethodCallMessage capabilities = ["actions", "x-kde-origin-name"] if self.supports_body_markup: capabilities.append("body-markup") return capabilities
def _verify_message( self, msg: QDBusMessage, expected_signature: str, expected_type: QDBusMessage.MessageType, ) -> None: """Check the signature/type of a received message. Raises DBusError if the signature doesn't match. """ assert expected_type not in [ QDBusMessage.ErrorMessage, QDBusMessage.InvalidMessage, ], expected_type if msg.type() == QDBusMessage.ErrorMessage: err = msg.errorName() if err == "org.freedesktop.DBus.Error.NoReply": self.error.emit( msg.errorMessage()) # notification daemon is gone return raise Error(f"Got DBus error: {err} - {msg.errorMessage()}") signature = msg.signature() if signature != expected_signature: raise Error( f"Got a message with signature {signature} but expected " f"{expected_signature} (args: {msg.arguments()})") typ = msg.type() if typ != expected_type: type_str = debug.qenum_key(QDBusMessage.MessageType, typ) expected_type_str = debug.qenum_key(QDBusMessage.MessageType, expected_type) raise Error( f"Got a message of type {type_str} but expected {expected_type_str}" f"(args: {msg.arguments()})")
def Notify(self, dbus_message: QDBusMessage) -> int: assert dbus_message.signature() == 'susssasa{sv}i' assert dbus_message.type() == QDBusMessage.MethodCallMessage message = self._parse_notify_args(*dbus_message.arguments()) if message.replaces_id == 0: message_id = next(self._message_id_gen) else: message_id = message.replaces_id self.messages[message_id] = message self.last_id = message_id return message_id
def get_result(msg: QtDBus.QDBusMessage) -> Any: if msg.type() == msg.MessageType.ReplyMessage: return msg.arguments()[0] else: raise DBusException("DBus call failed: {}".format(msg.arguments()))
def CloseNotification(self, dbus_message: QDBusMessage) -> None: assert dbus_message.signature() == 'u' assert dbus_message.type() == QDBusMessage.MethodCallMessage message_id = dbus_message.arguments()[0] self.messages[message_id].closed_via_web = True