def __init__(self, conn, sender, object_path, dbus_interface, member, handler, byte_arrays=False, sender_keyword=None, path_keyword=None, interface_keyword=None, member_keyword=None, message_keyword=None, destination_keyword=None, **kwargs): if member is not None: validate_member_name(member) if dbus_interface is not None: validate_interface_name(dbus_interface) if sender is not None: validate_bus_name(sender) if object_path is not None: validate_object_path(object_path) self._rule = None self._conn_weakref = weakref.ref(conn) self._sender = sender self._interface = dbus_interface self._member = member self._path = object_path self._handler = handler # if the connection is actually a bus, it's responsible for changing # this later self._sender_name_owner = sender if is_py2: self._utf8_strings = kwargs.pop('utf8_strings', False) elif 'utf8_strings' in kwargs: raise TypeError("unexpected keyword argument 'utf8_strings'") self._byte_arrays = byte_arrays self._sender_keyword = sender_keyword self._path_keyword = path_keyword self._member_keyword = member_keyword self._interface_keyword = interface_keyword self._message_keyword = message_keyword self._destination_keyword = destination_keyword self._args_match = kwargs if not kwargs: self._int_args_match = None else: self._int_args_match = {} for kwarg in kwargs: if not kwarg.startswith('arg'): raise TypeError('SignalMatch: unknown keyword argument %s' % kwarg) try: index = int(kwarg[3:]) except ValueError: raise TypeError('SignalMatch: unknown keyword argument %s' % kwarg) if index < 0 or index > 63: raise TypeError('SignalMatch: arg match index must be in ' 'range(64), not %d' % index) self._int_args_match[index] = kwargs[kwarg]
def __init__(self, conn, sender, object_path, dbus_interface, member, handler, byte_arrays=False, sender_keyword=None, path_keyword=None, interface_keyword=None, member_keyword=None, message_keyword=None, destination_keyword=None, **kwargs): if member is not None: validate_member_name(member) if dbus_interface is not None: validate_interface_name(dbus_interface) if sender is not None: validate_bus_name(sender) if object_path is not None: validate_object_path(object_path) self._rule = None self._conn_weakref = weakref.ref(conn) self._sender = sender self._interface = dbus_interface self._member = member self._path = object_path self._handler = handler # if the connection is actually a bus, it's responsible for changing # this later self._sender_name_owner = sender if 'utf8_strings' in kwargs: raise TypeError("unexpected keyword argument 'utf8_strings'") self._byte_arrays = byte_arrays self._sender_keyword = sender_keyword self._path_keyword = path_keyword self._member_keyword = member_keyword self._interface_keyword = interface_keyword self._message_keyword = message_keyword self._destination_keyword = destination_keyword self._args_match = kwargs if not kwargs: self._int_args_match = None else: self._int_args_match = {} for kwarg in kwargs: if not kwarg.startswith('arg'): raise TypeError('SignalMatch: unknown keyword argument %s' % kwarg) try: index = int(kwarg[3:]) except ValueError: raise TypeError('SignalMatch: unknown keyword argument %s' % kwarg) if index < 0 or index > 63: raise TypeError('SignalMatch: arg match index must be in ' 'range(64), not %d' % index) self._int_args_match[index] = kwargs[kwarg]
def __init__(self, proxy, connection, bus_name, object_path, method_name, iface): if object_path == LOCAL_PATH: raise DBusException('Methods may not be called on the reserved path %s' % LOCAL_PATH) self._proxy = proxy self._connection = connection self._named_service = bus_name self._object_path = object_path _dbus_bindings.validate_member_name(method_name) self._method_name = method_name if iface is not None: _dbus_bindings.validate_interface_name(iface) self._dbus_interface = iface
def __init__(self, proxy, connection, bus_name, object_path, method_name, iface): if object_path == LOCAL_PATH: raise DBusException('Methods may not be called on the reserved ' 'path %s' % LOCAL_PATH) # trust that the proxy, and the properties it had, are OK self._proxy = proxy self._connection = connection self._named_service = bus_name self._object_path = object_path # fail early if the method name is bad _dbus_bindings.validate_member_name(method_name) # the test suite relies on the existence of this property self._method_name = method_name # fail early if the interface name is bad if iface is not None: _dbus_bindings.validate_interface_name(iface) self._dbus_interface = iface
def decorator(func): member_name = func.__name__ _dbus_bindings.validate_member_name(member_name) def emit_signal(self, *args, **keywords): abs_path = None if path_keyword is not None: if self.SUPPORTS_MULTIPLE_OBJECT_PATHS: raise TypeError('path_keyword cannot be used on the ' 'signals of an object that supports ' 'multiple object paths') abs_path = keywords.pop(path_keyword, None) if (abs_path != self.__dbus_object_path__ and not self.__dbus_object_path__.startswith(abs_path + '/')): raise ValueError('Path %r is not below %r', abs_path, self.__dbus_object_path__) rel_path = None if rel_path_keyword is not None: rel_path = keywords.pop(rel_path_keyword, None) func(self, *args, **keywords) for location in self.locations: if abs_path is None: # non-deprecated case if rel_path is None or rel_path in ('/', ''): object_path = location[1] else: # will be validated by SignalMessage ctor in a moment object_path = location[1] + rel_path else: object_path = abs_path message = _dbus_bindings.SignalMessage(object_path, dbus_interface, member_name) message.append(signature=signature, *args) location[0].send_message(message) # end emit_signal args = inspect.getargspec(func)[0] args.pop(0) for keyword in rel_path_keyword, path_keyword: if keyword is not None: try: args.remove(keyword) except ValueError: raise ValueError('function has no argument "%s"' % keyword) if signature: sig = tuple(_dbus_bindings.Signature(signature)) if len(sig) > len(args): raise ValueError, 'signal signature is longer than the number of arguments provided' elif len(sig) < len(args): raise ValueError, 'signal signature is shorter than the number of arguments provided' emit_signal.__name__ = func.__name__ emit_signal.__doc__ = func.__doc__ emit_signal._dbus_is_signal = True emit_signal._dbus_interface = dbus_interface emit_signal._dbus_signature = signature emit_signal._dbus_args = args return emit_signal