def test_get_proxy_object_class_default_args(self, gdpc, tcpc): """_get_proxy_object_class should pass the correct arguments to _get_default_proxy_class""" tcpc.return_value = None obj_id = 123 path = '/path/to/DefaultSelector' object_registry._get_proxy_object_class(obj_id, path, None) gdpc.assert_called_once_with(obj_id, xpathselect.get_classname_from_path(path))
def _get_details_from_state_data(state_data): """Get details from a state data array. Returns class name, path, and state dictionary. """ object_path, object_state = state_data return ( get_classname_from_path(object_path), object_path.encode('utf-8'), object_state, )
def validate_dbus_object(cls, path, state): if (version.LooseVersion(autopilot.version) >= version.LooseVersion('1.5')): # TODO there's an autopilot branch that will put the function in a # public module. Update this once the branch is released. # --elopio - 2014-05-16 from autopilot.introspection import _xpathselect name = _xpathselect.get_classname_from_path(path) else: name = dbus.get_classname_from_path(path) if name == 'Dialog': if 'noAccountDialog' == state['objectName'][1]: return True return False
def validate_dbus_object(cls, path, _state): """Return whether this class is the appropriate proxy object class for a given dbus path and state. The default version matches the name of the dbus object and the class. Subclasses of CustomProxyObject can override it to define a different validation method. :param path: The dbus path of the object to check :param state: The dbus state dict of the object to check (ignored in default implementation) :returns: Whether this class is appropriate for the dbus object """ state_name = xpathselect.get_classname_from_path(path) if isinstance(state_name, str): state_name = state_name.encode('utf-8') class_name = cls.__name__.encode('utf-8') return state_name == class_name
def _get_proxy_object_class(object_id, path, state): """Return a custom proxy class, from the object registry or the default. This function first inspects the object registry using the object_id passed in. The object_id will be unique to all custom proxy classes for the same application. If that fails, we create a class on the fly based on the default class. :param object_id: The _id attribute of the class doing the lookup. This is used to index into the object registry to retrieve the dict of proxy classes to try. :param path: dbus path :param state: dbus state :returns: appropriate custom proxy class :raises ValueError: if more than one class in the dict matches """ class_type = _try_custom_proxy_classes(object_id, path, state) return class_type or _get_default_proxy_class( object_id, get_classname_from_path(path))
def _get_application_name_from_dbus_address(cls, dbus_address): """Return the application name from a dbus_address object.""" return get_classname_from_path( dbus_address.introspection_iface.GetState('/')[0][0])
def test_multiple_elements(self): self.assertEqual("Baz", xpathselect.get_classname_from_path("/Foo/Bar/Baz"))
def test_single_element_with_path(self): self.assertEqual("Foo", xpathselect.get_classname_from_path("/Foo"))