diff options
author | Barry Warsaw <barry@python.org> | 2011-12-15 19:37:23 -0500 |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2011-12-15 19:37:23 -0500 |
commit | ef05d294e85978cf96a86535321cf914b605fa48 (patch) | |
tree | 0c9f5a67aed327134f8a1e76b08e7972846b1efc | |
parent | 8e87ac365f6b08c0617985488dd5d27148c9281d (diff) | |
download | dbus-python-ef05d294e85978cf96a86535321cf914b605fa48.tar.gz |
Fix the match rule semantics so that a match rule of "arg0='/'" does not match
object paths in Python3, as per Simon's review comments.
-rw-r--r-- | dbus/connection.py | 18 | ||||
-rwxr-xr-x | test/test-standalone.py | 19 |
2 files changed, 28 insertions, 9 deletions
diff --git a/dbus/connection.py b/dbus/connection.py index f4124bd..e2361ec 100644 --- a/dbus/connection.py +++ b/dbus/connection.py @@ -28,17 +28,18 @@ import threading import weakref from _dbus_bindings import ( - Connection as _Connection, LOCAL_IFACE, LOCAL_PATH, - validate_bus_name, validate_error_name, validate_interface_name, - validate_member_name, validate_object_path) + Connection as _Connection, LOCAL_IFACE, LOCAL_PATH, validate_bus_name, + validate_interface_name, validate_member_name, validate_object_path) from dbus.exceptions import DBusException from dbus.lowlevel import ( ErrorMessage, HANDLER_RESULT_NOT_YET_HANDLED, MethodCallMessage, MethodReturnMessage, SignalMessage) from dbus.proxies import ProxyObject -from dbus._compat import is_py2 +from dbus._compat import is_py2, is_py3 -if is_py2: +if is_py3: + from _dbus_bindings import String +else: from _dbus_bindings import UTF8String @@ -185,14 +186,13 @@ class SignalMatch(object): if self._int_args_match is not None: # extracting args with utf8_strings and byte_arrays is less work kwargs = dict(byte_arrays=True) + arg_type = (String if is_py3 else UTF8String) if is_py2: kwargs['utf8_strings'] = True args = message.get_args_list(**kwargs) for index, value in self._int_args_match.items(): if (index >= len(args) - or (not isinstance(args[index], UTF8String) - if is_py2 - else False) + or not isinstance(args[index], arg_type) or args[index] != value): return False @@ -540,7 +540,7 @@ class Connection(_Connection): for cb in self.__call_on_disconnection: try: cb(self) - except Exception as e: + except Exception: # basicConfig is a no-op if logging is already configured logging.basicConfig() _logger.error('Exception in handler for Disconnected ' diff --git a/test/test-standalone.py b/test/test-standalone.py index 48cbe09..22e8444 100755 --- a/test/test-standalone.py +++ b/test/test-standalone.py @@ -344,6 +344,25 @@ class TestMessageMarshalling(unittest.TestCase): 'should fail') +class TestMatching(unittest.TestCase): + def setUp(self): + from _dbus_bindings import SignalMessage + from dbus.connection import SignalMatch + self._message = SignalMessage('/', 'a.b', 'c') + class FakeConn(object): pass + def ignore_cb(*args, **kws): pass + self._match = SignalMatch(FakeConn(), None, '/', None, None, + ignore_cb, arg0='/') + + def test_string_match(self): + self._message.append('/', signature='s') + self.assertTrue(self._match.maybe_handle_message(self._message)) + + def test_object_path_no_match(self): + self._message.append('/', signature='o') + self.assertFalse(self._match.maybe_handle_message(self._message)) + + if __name__ == '__main__': # Python 2.6 doesn't accept a `verbosity` keyword. kwargs = {} |