コード例 #1
0
    def call_async(self, bus_name, object_path, dbus_interface, method, signature, args, reply_handler, error_handler, timeout = -1.0, utf8_strings = False, byte_arrays = False, require_main_loop = True):
        if object_path == LOCAL_PATH:
            raise DBusException('Methods may not be called on the reserved path %s' % LOCAL_PATH)
        if dbus_interface == LOCAL_IFACE:
            raise DBusException('Methods may not be called on the reserved interface %s' % LOCAL_IFACE)
        get_args_opts = {'utf8_strings': utf8_strings,
         'byte_arrays': byte_arrays}
        message = MethodCallMessage(destination=bus_name, path=object_path, interface=dbus_interface, method=method)
        try:
            message.append(signature=signature, *args)
        except Exception as e:
            logging.basicConfig()
            _logger.error('Unable to set arguments %r according to signature %r: %s: %s', args, signature, e.__class__, e)
            raise

        if reply_handler is None and error_handler is None:
            self.send_message(message)
            return
        if reply_handler is None:
            reply_handler = _noop
        if error_handler is None:
            error_handler = _noop

        def msg_reply_handler(message):
            if isinstance(message, MethodReturnMessage):
                reply_handler(*message.get_args_list(**get_args_opts))
            elif isinstance(message, ErrorMessage):
                error_handler(DBusException(name=message.get_error_name(), *message.get_args_list()))
            else:
                error_handler(TypeError('Unexpected type for reply message: %r' % message))

        return self.send_message_with_reply(message, msg_reply_handler, timeout, require_main_loop=require_main_loop)
コード例 #2
0
    def call_blocking(self, bus_name, object_path, dbus_interface, method,
                      signature, args, timeout=-1.0, utf8_strings=False,
                      byte_arrays=False):
        """Call the given method, synchronously.
        :Since: 0.81.0
        """
        if object_path == LOCAL_PATH:
            raise DBusException('Methods may not be called on the reserved '
                                'path %s' % LOCAL_PATH)
        if dbus_interface == LOCAL_IFACE:
            raise DBusException('Methods may not be called on the reserved '
                                'interface %s' % LOCAL_IFACE)
        # no need to validate other args - MethodCallMessage ctor will do

        get_args_opts = {'utf8_strings': utf8_strings,
                         'byte_arrays': byte_arrays}

        message = MethodCallMessage(destination=bus_name,
                                    path=object_path,
                                    interface=dbus_interface,
                                    method=method)
        # Add the arguments to the function
        try:
            message.append(signature=signature, *args)
        except Exception, e:
            logging.basicConfig()
            _logger.error('Unable to set arguments %r according to '
                          'signature %r: %s: %s',
                          args, signature, e.__class__, e)
            raise
コード例 #3
0
    def call_blocking(self,
                      bus_name,
                      object_path,
                      dbus_interface,
                      method,
                      signature,
                      args,
                      timeout=-1.0,
                      byte_arrays=False,
                      **kwargs):
        """Call the given method, synchronously.
        :Since: 0.81.0
        """
        if object_path == LOCAL_PATH:
            raise DBusException('Methods may not be called on the reserved '
                                'path %s' % LOCAL_PATH)
        if dbus_interface == LOCAL_IFACE:
            raise DBusException('Methods may not be called on the reserved '
                                'interface %s' % LOCAL_IFACE)
        # no need to validate other args - MethodCallMessage ctor will do

        get_args_opts = dict(byte_arrays=byte_arrays)
        if is_py2:
            get_args_opts['utf8_strings'] = kwargs.get('utf8_strings', False)
        elif 'utf8_strings' in kwargs:
            raise TypeError("unexpected keyword argument 'utf8_strings'")

        message = MethodCallMessage(destination=bus_name,
                                    path=object_path,
                                    interface=dbus_interface,
                                    method=method)
        # Add the arguments to the function
        try:
            message.append(signature=signature, *args)
        except Exception as e:
            logging.basicConfig()
            _logger.error(
                'Unable to set arguments %r according to '
                'signature %r: %s: %s', args, signature, e.__class__, e)
            raise

        # make a blocking call
        reply_message = self.send_message_with_reply_and_block(
            message, timeout)
        args_list = reply_message.get_args_list(**get_args_opts)
        if len(args_list) == 0:
            return None
        elif len(args_list) == 1:
            return args_list[0]
        else:
            return tuple(args_list)
コード例 #4
0
    def call_async(self,
                   bus_name,
                   object_path,
                   dbus_interface,
                   method,
                   signature,
                   args,
                   reply_handler,
                   error_handler,
                   timeout=-1.0,
                   utf8_strings=False,
                   byte_arrays=False,
                   require_main_loop=True):
        """Call the given method, asynchronously.

        If the reply_handler is None, successful replies will be ignored.
        If the error_handler is None, failures will be ignored. If both
        are None, the implementation may request that no reply is sent.

        :Returns: The dbus.lowlevel.PendingCall.
        :Since: 0.81.0
        """
        if object_path == LOCAL_PATH:
            raise DBusException('Methods may not be called on the reserved '
                                'path %s' % LOCAL_PATH)
        if dbus_interface == LOCAL_IFACE:
            raise DBusException('Methods may not be called on the reserved '
                                'interface %s' % LOCAL_IFACE)
        # no need to validate other args - MethodCallMessage ctor will do

        get_args_opts = {
            'utf8_strings': utf8_strings,
            'byte_arrays': byte_arrays
        }

        message = MethodCallMessage(destination=bus_name,
                                    path=object_path,
                                    interface=dbus_interface,
                                    method=method)
        # Add the arguments to the function
        try:
            message.append(signature=signature, *args)
        except Exception, e:
            logging.basicConfig()
            _logger.error(
                'Unable to set arguments %r according to '
                'signature %r: %s: %s', args, signature, e.__class__, e)
            raise
コード例 #5
0
    def call_async(self, path, method_name, *args, **kwargs):
        """
        Calls a method with method_name under the subpath of path async.

        The reply_handler and error_handler keyword arguments are 
        called on success or error.

        """

        if path:
            fpath = "%s/%s" % (self._path, path)
        else:
            fpath = self._path

        ns = fpath.replace("/", ".")[1:]

        if 'signature' in kwargs:
            sig = kwargs['signature']
        else:
            sig = MethodCallMessage.guess_signature(*args)

        reply_handler = kwargs.pop('reply_handler', None)
        error_handler = kwargs.pop('error_handler', None)

        return self._conn.call_async(self._bus_name, fpath, ns, method_name,
                                     sig, args, reply_handler, error_handler,
                                     **kwargs)
コード例 #6
0
ファイル: pdbus.py プロジェクト: fermat618/pida
    def call_async(self, path, method_name, *args, **kwargs):
        """
        Calls a method with method_name under the subpath of path async.

        The reply_handler and error_handler keyword arguments are 
        called on success or error.

        """

        if path:
            fpath = "%s/%s" %(self._path, path)
        else:
            fpath = self._path

        ns = fpath.replace("/", ".")[1:]

        if 'signature' in kwargs:
            sig = kwargs['signature']
        else:
            sig = MethodCallMessage.guess_signature(*args)

        reply_handler = kwargs.pop('reply_handler', None)
        error_handler = kwargs.pop('error_handler', None)

        return self._conn.call_async(self._bus_name,
                                 fpath, 
                                 ns,
                                 method_name,
                                 sig,
                                 args,
                                 reply_handler,
                                 error_handler,
                                 **kwargs)
コード例 #7
0
ファイル: tools.py プロジェクト: Alberto-Beralix/Beralix
    def call_method(self, method, *args, **kwargs):
        """Call method with *args and **kwargs over dbus."""
        msg = MethodCallMessage(self.destination, self.path, self.interface,
                                method)
        msg.set_no_reply(True)
        # get the signature
        signature = kwargs.get('signature', None)
        if signature is not None:
            msg.append(signature=signature, *args)
        else:
            msg.append(*args)
        #gbet the reply/error handlers
        reply_handler = kwargs.get('reply_handler', None)
        error_handler = kwargs.get('error_handler', None)
        assert error_handler != None

        def parse_reply(message):
            """Handle the reply message."""
            if isinstance(message, ErrorMessage):
                return error_handler(DBusException(
                                    name=message.get_error_name(),
                                    *message.get_args_list()))
            args_list = message.get_args_list(utf8_strings=False,
                                                  byte_arrays=False)
            if reply_handler:
                if len(args_list) == 0:
                    reply_handler(None)
                elif len(args_list) == 1:
                    return reply_handler(args_list[0])
                else:
                    return reply_handler(tuple(args_list))
        return self.bus.send_message_with_reply(msg,
                                                reply_handler=parse_reply)
コード例 #8
0
    def call_blocking(self, bus_name, object_path, dbus_interface, method,
                      signature, args, timeout=-1.0,
                      byte_arrays=False, **kwargs):
        """Call the given method, synchronously.
        :Since: 0.81.0
        """
        if object_path == LOCAL_PATH:
            raise DBusException('Methods may not be called on the reserved '
                                'path %s' % LOCAL_PATH)
        if dbus_interface == LOCAL_IFACE:
            raise DBusException('Methods may not be called on the reserved '
                                'interface %s' % LOCAL_IFACE)
        # no need to validate other args - MethodCallMessage ctor will do

        get_args_opts = dict(byte_arrays=byte_arrays)
        if is_py2:
            get_args_opts['utf8_strings'] = kwargs.get('utf8_strings', False)
        elif 'utf8_strings' in kwargs:
            raise TypeError("unexpected keyword argument 'utf8_strings'")

        message = MethodCallMessage(destination=bus_name,
                                    path=object_path,
                                    interface=dbus_interface,
                                    method=method)
        # Add the arguments to the function
        try:
            message.append(signature=signature, *args)
        except Exception as e:
            logging.basicConfig()
            _logger.error('Unable to set arguments %r according to '
                          'signature %r: %s: %s',
                          args, signature, e.__class__, e)
            raise

        # make a blocking call
        reply_message = self.send_message_with_reply_and_block(
            message, timeout)
        args_list = reply_message.get_args_list(**get_args_opts)
        if len(args_list) == 0:
            return None
        elif len(args_list) == 1:
            return args_list[0]
        else:
            return tuple(args_list)
コード例 #9
0
ファイル: connection.py プロジェクト: 274914765/python
    def call_async(
        self,
        bus_name,
        object_path,
        dbus_interface,
        method,
        signature,
        args,
        reply_handler,
        error_handler,
        timeout=-1.0,
        utf8_strings=False,
        byte_arrays=False,
        require_main_loop=True,
    ):
        """Call the given method, asynchronously.

        If the reply_handler is None, successful replies will be ignored.
        If the error_handler is None, failures will be ignored. If both
        are None, the implementation may request that no reply is sent.

        :Returns: The dbus.lowlevel.PendingCall.
        :Since: 0.81.0
        """
        if object_path == LOCAL_PATH:
            raise DBusException("Methods may not be called on the reserved " "path %s" % LOCAL_PATH)
        if dbus_interface == LOCAL_IFACE:
            raise DBusException("Methods may not be called on the reserved " "interface %s" % LOCAL_IFACE)
        # no need to validate other args - MethodCallMessage ctor will do

        get_args_opts = {"utf8_strings": utf8_strings, "byte_arrays": byte_arrays}

        message = MethodCallMessage(destination=bus_name, path=object_path, interface=dbus_interface, method=method)
        # Add the arguments to the function
        try:
            message.append(signature=signature, *args)
        except Exception, e:
            logging.basicConfig()
            _logger.error(
                "Unable to set arguments %r according to " "signature %r: %s: %s", args, signature, e.__class__, e
            )
            raise
コード例 #10
0
    def call_blocking(self,
                      bus_name,
                      object_path,
                      dbus_interface,
                      method,
                      signature,
                      args,
                      timeout=-1.0,
                      utf8_strings=False,
                      byte_arrays=False):
        """Call the given method, synchronously.
        :Since: 0.81.0
        """
        if object_path == LOCAL_PATH:
            raise DBusException('Methods may not be called on the reserved '
                                'path %s' % LOCAL_PATH)
        if dbus_interface == LOCAL_IFACE:
            raise DBusException('Methods may not be called on the reserved '
                                'interface %s' % LOCAL_IFACE)
        # no need to validate other args - MethodCallMessage ctor will do

        get_args_opts = {
            'utf8_strings': utf8_strings,
            'byte_arrays': byte_arrays
        }

        message = MethodCallMessage(destination=bus_name,
                                    path=object_path,
                                    interface=dbus_interface,
                                    method=method)
        # Add the arguments to the function
        try:
            message.append(signature=signature, *args)
        except Exception, e:
            logging.basicConfig()
            _logger.error(
                'Unable to set arguments %r according to '
                'signature %r: %s: %s', args, signature, e.__class__, e)
            raise
コード例 #11
0
    def call_blocking(self, bus_name, object_path, dbus_interface, method, signature, args, timeout = -1.0, utf8_strings = False, byte_arrays = False):
        if object_path == LOCAL_PATH:
            raise DBusException('Methods may not be called on the reserved path %s' % LOCAL_PATH)
        if dbus_interface == LOCAL_IFACE:
            raise DBusException('Methods may not be called on the reserved interface %s' % LOCAL_IFACE)
        get_args_opts = {'utf8_strings': utf8_strings,
         'byte_arrays': byte_arrays}
        message = MethodCallMessage(destination=bus_name, path=object_path, interface=dbus_interface, method=method)
        try:
            message.append(signature=signature, *args)
        except Exception as e:
            logging.basicConfig()
            _logger.error('Unable to set arguments %r according to signature %r: %s: %s', args, signature, e.__class__, e)
            raise

        reply_message = self.send_message_with_reply_and_block(message, timeout)
        args_list = reply_message.get_args_list(**get_args_opts)
        if len(args_list) == 0:
            return None
        elif len(args_list) == 1:
            return args_list[0]
        else:
            return tuple(args_list)
コード例 #12
0
    def call(self, path, method_name, *args, **kwargs):
        """Calls a method with method_name under the subpath of path"""

        if path:
            fpath = "%s/%s" % (self._path, path)
        else:
            fpath = self._path

        ns = fpath.replace("/", ".")[1:]

        if 'signature' in kwargs:
            sig = kwargs['signature']
        else:
            sig = MethodCallMessage.guess_signature(*args)

        return self._conn.call_blocking(self._bus_name, fpath, ns, method_name,
                                        sig, args, **kwargs)
コード例 #13
0
ファイル: linux.py プロジェクト: CSRedRat/magicicada-client
    def call_method(self, method, *args, **kwargs):
        """Call method with *args and **kwargs over dbus."""
        msg = MethodCallMessage(self.destination, self.path, self.interface,
                                method)
        msg.set_no_reply(True)
        # get the signature
        signature = kwargs.get('signature', None)
        if signature is not None:
            msg.append(signature=signature, *args)
        else:
            msg.append(*args)

        d = defer.Deferred()

        def reply_handler(result):
            """Callback the returned deferred and call 'reply_handler'."""
            kwargs.get('reply_handler', lambda _: None)(result)
            d.callback(result)

        def error_handler(error):
            """Errback the returned deferred and call 'error_handler'."""
            kwargs.get('error_handler', lambda _: None)(error)
            d.errback(error)

        def parse_reply(message):
            """Handle the reply message."""
            if isinstance(message, ErrorMessage):
                exc = IPCError(name=message.get_error_name(),
                               info=message.get_args_list())
                return error_handler(exc)
            args_list = message.get_args_list(utf8_strings=False,
                                              byte_arrays=False)
            if len(args_list) == 0:
                reply_handler(None)
            elif len(args_list) == 1:
                reply_handler(args_list[0])
            else:
                reply_handler(tuple(args_list))

        self.bus.send_message_with_reply(msg, reply_handler=parse_reply)

        return d
コード例 #14
0
ファイル: pdbus.py プロジェクト: fermat618/pida
    def call(self, path, method_name, *args, **kwargs):
        """Calls a method with method_name under the subpath of path"""

        if path:
            fpath = "%s/%s" %(self._path, path)
        else:
            fpath = self._path

        ns = fpath.replace("/", ".")[1:]

        if 'signature' in kwargs:
            sig = kwargs['signature']
        else:
            sig = MethodCallMessage.guess_signature(*args)

        return self._conn.call_blocking(self._bus_name,
                                 fpath, 
                                 ns,
                                 method_name,
                                 sig,
                                 args,
                                 **kwargs)
コード例 #15
0
    def call_async(self, bus_name, object_path, dbus_interface, method,
                   signature, args, reply_handler, error_handler,
                   timeout=-1.0, byte_arrays=False,
                   require_main_loop=True, **kwargs):
        """Call the given method, asynchronously.

        If the reply_handler is None, successful replies will be ignored.
        If the error_handler is None, failures will be ignored. If both
        are None, the implementation may request that no reply is sent.

        :Returns: The dbus.lowlevel.PendingCall.
        :Since: 0.81.0
        """
        if object_path == LOCAL_PATH:
            raise DBusException('Methods may not be called on the reserved '
                                'path %s' % LOCAL_PATH)
        if dbus_interface == LOCAL_IFACE:
            raise DBusException('Methods may not be called on the reserved '
                                'interface %s' % LOCAL_IFACE)
        # no need to validate other args - MethodCallMessage ctor will do

        get_args_opts = dict(byte_arrays=byte_arrays)
        if is_py2:
            get_args_opts['utf8_strings'] = kwargs.get('utf8_strings', False)
        elif 'utf8_strings' in kwargs:
            raise TypeError("unexpected keyword argument 'utf8_strings'")

        message = MethodCallMessage(destination=bus_name,
                                    path=object_path,
                                    interface=dbus_interface,
                                    method=method)
        # Add the arguments to the function
        try:
            message.append(signature=signature, *args)
        except Exception as e:
            logging.basicConfig()
            _logger.error('Unable to set arguments %r according to '
                          'signature %r: %s: %s',
                          args, signature, e.__class__, e)
            raise

        if reply_handler is None and error_handler is None:
            # we don't care what happens, so just send it
            self.send_message(message)
            return

        if reply_handler is None:
            reply_handler = _noop
        if error_handler is None:
            error_handler = _noop

        def msg_reply_handler(message):
            if isinstance(message, MethodReturnMessage):
                reply_handler(*message.get_args_list(**get_args_opts))
            elif isinstance(message, ErrorMessage):
                error_handler(DBusException(name=message.get_error_name(),
                                            *message.get_args_list()))
            else:
                error_handler(TypeError('Unexpected type for reply '
                                        'message: %r' % message))
        return self.send_message_with_reply(message, msg_reply_handler,
                                        timeout,
                                        require_main_loop=require_main_loop)
コード例 #16
0
    def call_async(self,
                   bus_name,
                   object_path,
                   dbus_interface,
                   method,
                   signature,
                   args,
                   reply_handler,
                   error_handler,
                   timeout=-1.0,
                   byte_arrays=False,
                   require_main_loop=True,
                   **kwargs):
        """Call the given method, asynchronously.

		If the reply_handler is None, successful replies will be ignored.
		If the error_handler is None, failures will be ignored. If both
		are None, the implementation may request that no reply is sent.

		:Returns: The dbus.lowlevel.PendingCall.
		:Since: 0.81.0
		"""
        if object_path == LOCAL_PATH:
            raise DBusException('Methods may not be called on the reserved '
                                'path %s' % LOCAL_PATH)
        if dbus_interface == LOCAL_IFACE:
            raise DBusException('Methods may not be called on the reserved '
                                'interface %s' % LOCAL_IFACE)
        # no need to validate other args - MethodCallMessage ctor will do

        get_args_opts = dict(byte_arrays=byte_arrays)
        if is_py2:
            get_args_opts['utf8_strings'] = kwargs.get('utf8_strings', False)
        elif 'utf8_strings' in kwargs:
            raise TypeError("unexpected keyword argument 'utf8_strings'")

        message = MethodCallMessage(destination=bus_name,
                                    path=object_path,
                                    interface=dbus_interface,
                                    method=method)
        # Add the arguments to the function
        try:
            message.append(signature=signature, *args)
        except Exception as e:
            logging.basicConfig()
            _logger.error(
                'Unable to set arguments %r according to '
                'signature %r: %s: %s', args, signature, e.__class__, e)
            raise

        if reply_handler is None and error_handler is None:
            # we don't care what happens, so just send it
            self.send_message(message)
            return

        if reply_handler is None:
            reply_handler = _noop
        if error_handler is None:
            error_handler = _noop

        def msg_reply_handler(message):
            if isinstance(message, MethodReturnMessage):
                reply_handler(*message.get_args_list(**get_args_opts))
            elif isinstance(message, ErrorMessage):
                error_handler(
                    DBusException(name=message.get_error_name(),
                                  *message.get_args_list()))
            else:
                error_handler(
                    TypeError('Unexpected type for reply '
                              'message: %r' % message))

        retInfo = self.send_message_with_reply(
            message,
            msg_reply_handler,
            timeout,
            require_main_loop=require_main_loop)
        self.flush()
        return retInfo