def __init__(self, conn=None, object_path=None, bus_name=None):
        """Constructor. Either conn or bus_name is required; object_path
        is also required.

        :Parameters:
            `conn` : dbus.connection.Connection or None
                The connection on which to export this object.

                If None, use the Bus associated with the given ``bus_name``.
                If there is no ``bus_name`` either, the object is not
                initially available on any Connection.

                For backwards compatibility, if an instance of
                dbus.service.BusName is passed as the first parameter,
                this is equivalent to passing its associated Bus as
                ``conn``, and passing the BusName itself as ``bus_name``.

            `object_path` : str or None
                A D-Bus object path at which to make this Object available
                immediately. If this is not None, a `conn` or `bus_name` must
                also be provided.

            `bus_name` : dbus.service.BusName or None
                Represents a well-known name claimed by this process. A
                reference to the BusName object will be held by this
                Object, preventing the name from being released during this
                Object's lifetime (unless it's released manually).
        """
        if object_path is not None:
            _dbus_bindings.validate_object_path(object_path)

        if isinstance(conn, BusName):
            # someone's using the old API; don't gratuitously break them
            bus_name = conn
            conn = bus_name.get_bus()
        elif conn is None:
            if bus_name is not None:
                # someone's using the old API but naming arguments, probably
                conn = bus_name.get_bus()

        #: Either an object path, None or _MANY
        self._object_path = None
        #: Either a dbus.connection.Connection, None or _MANY
        self._connection = None
        #: A list of tuples (Connection, object path, False) where the False
        #: is for future expansion (to support fallback paths)
        self._locations = []
        #: Lock protecting `_locations`, `_connection` and `_object_path`
        self._locations_lock = thread.allocate_lock()

        #: True if this is a fallback object handling a whole subtree.
        self._fallback = False

        self._name = bus_name

        if conn is None and object_path is not None:
            raise TypeError('If object_path is given, either conn or bus_name '
                            'is required')
        if conn is not None and object_path is not None:
            self.add_to_connection(conn, object_path)
    def __init__(self, conn=None, object_path=None, bus_name=None):
        """Constructor. Either conn or bus_name is required; object_path
        is also required.

        :Parameters:
            `conn` : dbus.connection.Connection or None
                The connection on which to export this object.

                If None, use the Bus associated with the given ``bus_name``.
                If there is no ``bus_name`` either, the object is not
                initially available on any Connection.

                For backwards compatibility, if an instance of
                dbus.service.BusName is passed as the first parameter,
                this is equivalent to passing its associated Bus as
                ``conn``, and passing the BusName itself as ``bus_name``.

            `object_path` : str or None
                A D-Bus object path at which to make this Object available
                immediately. If this is not None, a `conn` or `bus_name` must
                also be provided.

            `bus_name` : dbus.service.BusName or None
                Represents a well-known name claimed by this process. A
                reference to the BusName object will be held by this
                Object, preventing the name from being released during this
                Object's lifetime (unless it's released manually).
        """
        if object_path is not None:
            _dbus_bindings.validate_object_path(object_path)

        if isinstance(conn, BusName):
            # someone's using the old API; don't gratuitously break them
            bus_name = conn
            conn = bus_name.get_bus()
        elif conn is None:
            if bus_name is not None:
                # someone's using the old API but naming arguments, probably
                conn = bus_name.get_bus()

        #: Either an object path, None or _MANY
        self._object_path = None
        #: Either a dbus.connection.Connection, None or _MANY
        self._connection = None
        #: A list of tuples (Connection, object path, False) where the False
        #: is for future expansion (to support fallback paths)
        self._locations = []
        #: Lock protecting `_locations`, `_connection` and `_object_path`
        self._locations_lock = thread.allocate_lock()

        #: True if this is a fallback object handling a whole subtree.
        self._fallback = False

        self._name = bus_name

        if conn is None and object_path is not None:
            raise TypeError('If object_path is given, either conn or bus_name '
                            'is required')
        if conn is not None and object_path is not None:
            self.add_to_connection(conn, object_path)
    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]
Example #4
0
    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]
Example #5
0
 def __init__(self, conn = None, bus_name = None, object_path = None, introspect = True, follow_name_owner_changes = False, **kwargs):
     bus = kwargs.pop('bus', None)
     if bus is not None:
         if conn is not None:
             raise TypeError('conn and bus cannot both be specified')
         conn = bus
         from warnings import warn
         warn('Passing the bus parameter to ProxyObject by name is deprecated: please use positional parameters', DeprecationWarning, stacklevel=2)
     named_service = kwargs.pop('named_service', None)
     if named_service is not None:
         if bus_name is not None:
             raise TypeError('bus_name and named_service cannot both be specified')
         bus_name = named_service
         from warnings import warn
         warn('Passing the named_service parameter to ProxyObject by name is deprecated: please use positional parameters', DeprecationWarning, stacklevel=2)
     if kwargs:
         raise TypeError('ProxyObject.__init__ does not take these keyword arguments: %s' % ', '.join(kwargs.iterkeys()))
     if follow_name_owner_changes:
         conn._require_main_loop()
     self._bus = conn
     if bus_name is not None:
         _dbus_bindings.validate_bus_name(bus_name)
     self._named_service = self._requested_bus_name = bus_name
     _dbus_bindings.validate_object_path(object_path)
     self.__dbus_object_path__ = object_path
     if not follow_name_owner_changes:
         self._named_service = conn.activate_name_owner(bus_name)
     self._pending_introspect = None
     self._pending_introspect_queue = []
     self._introspect_method_map = {}
     self._introspect_lock = RLock()
     if not introspect or self.__dbus_object_path__ == LOCAL_PATH:
         self._introspect_state = self.INTROSPECT_STATE_DONT_INTROSPECT
     else:
         self._introspect_state = self.INTROSPECT_STATE_INTROSPECT_IN_PROGRESS
         self._pending_introspect = self._Introspect()
Example #6
0
    def __init__(self,
                 conn=None,
                 bus_name=None,
                 object_path=None,
                 introspect=True,
                 follow_name_owner_changes=False,
                 **kwargs):
        """Initialize the proxy object.

        :Parameters:
            `conn` : `dbus.connection.Connection`
                The bus or connection on which to find this object.
                The keyword argument `bus` is a deprecated alias for this.
            `bus_name` : str
                A bus name for the application owning the object, to be used
                as the destination for method calls and the sender for
                signal matches. The keyword argument ``named_service`` is a
                deprecated alias for this.
            `object_path` : str
                The object path at which the application exports the object
            `introspect` : bool
                If true (default), attempt to introspect the remote
                object to find out supported methods and their signatures
            `follow_name_owner_changes` : bool
                If true (default is false) and the `bus_name` is a
                well-known name, follow ownership changes for that name
        """
        bus = kwargs.pop('bus', None)
        if bus is not None:
            if conn is not None:
                raise TypeError('conn and bus cannot both be specified')
            conn = bus
            from warnings import warn
            warn(
                'Passing the bus parameter to ProxyObject by name is '
                'deprecated: please use positional parameters',
                DeprecationWarning,
                stacklevel=2)
        named_service = kwargs.pop('named_service', None)
        if named_service is not None:
            if bus_name is not None:
                raise TypeError('bus_name and named_service cannot both be '
                                'specified')
            bus_name = named_service
            from warnings import warn
            warn(
                'Passing the named_service parameter to ProxyObject by name '
                'is deprecated: please use positional parameters',
                DeprecationWarning,
                stacklevel=2)
        if kwargs:
            raise TypeError('ProxyObject.__init__ does not take these '
                            'keyword arguments: %s' %
                            ', '.join(kwargs.iterkeys()))

        if follow_name_owner_changes:
            # we don't get the signals unless the Bus has a main loop
            # XXX: using Bus internals
            conn._require_main_loop()

        self._bus = conn

        if bus_name is not None:
            _dbus_bindings.validate_bus_name(bus_name)
        # the attribute is still called _named_service for the moment,
        # for the benefit of telepathy-python
        self._named_service = self._requested_bus_name = bus_name

        _dbus_bindings.validate_object_path(object_path)
        self.__dbus_object_path__ = object_path

        if not follow_name_owner_changes:
            self._named_service = conn.activate_name_owner(bus_name)

        #PendingCall object for Introspect call
        self._pending_introspect = None
        #queue of async calls waiting on the Introspect to return
        self._pending_introspect_queue = []
        #dictionary mapping method names to their input signatures
        self._introspect_method_map = {}

        # must be a recursive lock because block() is called while locked,
        # and calls the callback which re-takes the lock
        self._introspect_lock = RLock()

        if not introspect or self.__dbus_object_path__ == LOCAL_PATH:
            self._introspect_state = self.INTROSPECT_STATE_DONT_INTROSPECT
        else:
            self._introspect_state = self.INTROSPECT_STATE_INTROSPECT_IN_PROGRESS

            self._pending_introspect = self._Introspect()
Example #7
0
    def __init__(self, conn=None, bus_name=None, object_path=None,
                 introspect=True, follow_name_owner_changes=False, **kwargs):
        """Initialize the proxy object.

        :Parameters:
            `conn` : `dbus.connection.Connection`
                The bus or connection on which to find this object.
                The keyword argument `bus` is a deprecated alias for this.
            `bus_name` : str
                A bus name for the application owning the object, to be used
                as the destination for method calls and the sender for
                signal matches. The keyword argument ``named_service`` is a
                deprecated alias for this.
            `object_path` : str
                The object path at which the application exports the object
            `introspect` : bool
                If true (default), attempt to introspect the remote
                object to find out supported methods and their signatures
            `follow_name_owner_changes` : bool
                If true (default is false) and the `bus_name` is a
                well-known name, follow ownership changes for that name
        """
        bus = kwargs.pop('bus', None)
        if bus is not None:
            if conn is not None:
                raise TypeError('conn and bus cannot both be specified')
            conn = bus
            from warnings import warn
            warn('Passing the bus parameter to ProxyObject by name is '
                 'deprecated: please use positional parameters',
                 DeprecationWarning, stacklevel=2)
        named_service = kwargs.pop('named_service', None)
        if named_service is not None:
            if bus_name is not None:
                raise TypeError('bus_name and named_service cannot both be '
                                'specified')
            bus_name = named_service
            from warnings import warn
            warn('Passing the named_service parameter to ProxyObject by name '
                 'is deprecated: please use positional parameters',
                 DeprecationWarning, stacklevel=2)
        if kwargs:
            raise TypeError('ProxyObject.__init__ does not take these '
                            'keyword arguments: %s'
                            % ', '.join(kwargs.keys()))

        if follow_name_owner_changes:
            # we don't get the signals unless the Bus has a main loop
            # XXX: using Bus internals
            conn._require_main_loop()

        self._bus = conn

        if bus_name is not None:
            _dbus_bindings.validate_bus_name(bus_name)
        # the attribute is still called _named_service for the moment,
        # for the benefit of telepathy-python
        self._named_service = self._requested_bus_name = bus_name

        _dbus_bindings.validate_object_path(object_path)
        self.__dbus_object_path__ = object_path

        if not follow_name_owner_changes:
            self._named_service = conn.activate_name_owner(bus_name)

        #PendingCall object for Introspect call
        self._pending_introspect = None
        #queue of async calls waiting on the Introspect to return
        self._pending_introspect_queue = []
        #dictionary mapping method names to their input signatures
        self._introspect_method_map = {}

        # must be a recursive lock because block() is called while locked,
        # and calls the callback which re-takes the lock
        self._introspect_lock = RLock()

        if not introspect or self.__dbus_object_path__ == LOCAL_PATH:
            self._introspect_state = self.INTROSPECT_STATE_DONT_INTROSPECT
        else:
            self._introspect_state = self.INTROSPECT_STATE_INTROSPECT_IN_PROGRESS

            self._pending_introspect = self._Introspect()