[patch] [python] Revert get_object changes, redo following J5's recommendation

Simon McVittie simon.mcvittie at collabora.co.uk
Tue Jan 16 04:29:51 PST 2007


On Wed, 10 Jan 2007 at 20:28:30 +0000, Simon McVittie wrote:
> Do you think early or late binding should be the default (if it's an optional
> argument) or the less elaborate name (if it's a separate method), and do
> you have a better idea for the naming? follow_name_changes sounds good
> as the name of a keyword argument, at least if it's not the default.
> 
> Thinking about it, early binding should probably be the default, since
> the failure mode of using early binding when you wanted late binding is
> less confusing than the other way round (sticking to the old object even
> if the name is stolen, vs. having stateful communication disrupted by the
> well-known name being stolen and the new owner not knowing what you're
> talking about).

... so here's a patch to do that, with keyword argument
follow_name_owner_changes defaulting to False, and
get_object_by_unique_name removed. Thoughts/review?

From d9f3afff2a8404f73a9ac18b46e4020c18c35a8b Mon Sep 17 00:00:00 2001
From: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Tue, 16 Jan 2007 12:21:31 +0000
Subject: [PATCH] Rethink the API for get_object, defaulting to stateful communication.
- Revert addition of get_object_by_unique_name (introduced in 0.80rc1)
- Make get_object *not* follow name changes by default (a return to pre-0.80
  behaviour, and the same as 0.80rc1's get_object_by_unique_name())
- Add keyword argument follow_name_owner_changes (default is False) to make
  it follow name owner changes (like 0.80rc1's get_object())
---
 dbus/_dbus.py |   79 ++++++++++++++++++++++----------------------------------
 1 files changed, 31 insertions(+), 48 deletions(-)

diff --git a/dbus/_dbus.py b/dbus/_dbus.py
index 357e243..ec3f27d 100644
--- a/dbus/_dbus.py
+++ b/dbus/_dbus.py
@@ -368,20 +368,13 @@ class Bus(BusImplementation):
 
     get_starter = staticmethod(get_starter)
 
-    def get_object(self, named_service, object_path, introspect=True):
+    def get_object(self, named_service, object_path, introspect=True,
+                   follow_name_owner_changes=False):
         """Return a local proxy for the given remote object.
 
         Method calls on the proxy are translated into method calls on the
         remote object.
 
-        If the given object path is a well-known name (as opposed to a
-        unique name) the proxy will use the well-known name for
-        communication, meaning that if the owner of the well-known
-        name changes, the proxy will point to the new owner.
-
-        If state needs to be maintained between calls, use
-        `get_object_by_unique_name` instead.
-
         :Parameters:
             `named_service` : str
                 A bus name (either the unique name or a well-known name)
@@ -391,53 +384,43 @@ class Bus(BusImplementation):
             `introspect` : bool
                 If true (default), attempt to introspect the remote
                 object to find out supported methods and their signatures
-        :Returns: a `dbus.proxies.ProxyObject`
-        """
-        # FIXME: would be good to call _require_main_loop() here, since the
-        # name owner tracking won't work unless we're running a main loop,
-        # but since legacy code will call this method rather than
-        # _by_unique_name, that's not really feasible yet
-        return self.ProxyObjectClass(self, named_service, object_path, introspect=introspect)
+            `follow_name_owner_changes` : bool
+                If the object path is a well-known name and this parameter
+                is false (default), resolve the well-known name to the unique
+                name of its current owner and bind to that instead; if the
+                ownership of the well-known name changes in future,
+                keep communicating with the original owner.
+                This is necessary if the D-Bus API used is stateful.
 
-    def get_object_by_unique_name(self, named_service, object_path, introspect=True):
-        """Return a local proxy for the given remote object,
-        first resolving the given bus name to the unique name of
-        the current owner of that name.
+                If the object path is a well-known name and this parameter
+                is true, whenever the well-known name changes ownership in
+                future, bind to the new owner, if any.
 
-        Method calls on the proxy are translated into method calls on the
-        remote object.
+                If the given object path is a unique name, this parameter
+                has no effect.
 
-        If the given object path is a well-known name (as opposed to a
-        unique name) query the bus for the unique name of the application
-        currently owning that well-known name, and use that for
-        communication.
-
-        :Parameters:
-            `named_service` : str
-                A bus name (either the unique name or a well-known name)
-                of the application owning the object; if a well-known name,
-                will be converted to the owning unique name immediately
-            `object_path` : str
-                The object path of the desired object
-            `introspect` : bool
-                If true (default), attempt to introspect the remote
-                object to find out supported methods and their signatures
         :Returns: a `dbus.proxies.ProxyObject`
         :Raises `DBusException`: if resolving the well-known name to a
             unique name fails
         """
-
-        if named_service[:1] == ':' or named_service == BUS_DAEMON_NAME:
-            unique = named_service
+        if follow_name_owner_changes:
+            self._require_main_loop()   # we don't get the signals otherwise
+            return self.ProxyObjectClass(self, named_service, object_path,
+                                         introspect=introspect)
         else:
-            bus_object = self.ProxyObjectClass(self, BUS_DAEMON_NAME, BUS_DAEMON_PATH)
-            unique = bus_object.GetNameOwner(named_service,
-                                             dbus_interface=BUS_DAEMON_IFACE)
-            if not unique:
-                raise DBusException('Well-known name %r is not '
-                                    'present on %r', named_service, self)
-
-        return self.ProxyObjectClass(self, unique, object_path, introspect=introspect)
+            if named_service[:1] == ':' or named_service == BUS_DAEMON_NAME:
+                unique = named_service
+            else:
+                bus_object = self.ProxyObjectClass(self, BUS_DAEMON_NAME,
+                                                   BUS_DAEMON_PATH)
+                unique = bus_object.GetNameOwner(named_service,
+                                                 dbus_interface=BUS_DAEMON_IFACE)
+                if not unique:
+                    raise DBusException('Well-known name %r is not '
+                                        'present on %r', named_service, self)
+
+            return self.ProxyObjectClass(self, unique, object_path,
+                                         introspect=introspect)
 
     def add_signal_receiver(self, handler_function,
                                   signal_name=None,
-- 
1.4.4.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 266 bytes
Desc: Digital signature
Url : http://lists.freedesktop.org/archives/dbus/attachments/20070116/ae2ac4ec/attachment-0001.pgp


More information about the dbus mailing list