Example #1
0
 def send_signal(self, signal, *args):
     """Send method with *args."""
     msg = SignalMessage(self.path, self.interface,
                         signal)
     msg.set_no_reply(True)
     msg.append(*args)
     self.bus.send_message(msg)
def fire_signal_on_tube(q, tube, chatroom, dbus_stream_id, my_bus_name):
    signal = SignalMessage('/', 'foo.bar', 'baz')
    signal.append(42, signature='u')
    tube.send_message(signal)

    event = q.expect('stream-message', to=chatroom,
        message_type='groupchat')
    message = event.stanza

    data_nodes = xpath.queryForNodes('/message/data[@xmlns="%s"]' % ns.MUC_BYTESTREAM,
        message)
    assert data_nodes is not None
    assert len(data_nodes) == 1
    ibb_data = data_nodes[0]
    assert ibb_data['sid'] == dbus_stream_id
    binary = base64.b64decode(str(ibb_data))
    # little and big endian versions of: SIGNAL, NO_REPLY, protocol v1,
    # 4-byte payload
    assert binary.startswith('l\x04\x01\x01' '\x04\x00\x00\x00') or \
           binary.startswith('B\x04\x01\x01' '\x00\x00\x00\x04')
    # little and big endian versions of the 4-byte payload, UInt32(42)
    assert (binary[0] == 'l' and binary.endswith('\x2a\x00\x00\x00')) or \
           (binary[0] == 'B' and binary.endswith('\x00\x00\x00\x2a'))
    # XXX: verify that it's actually in the "sender" slot, rather than just
    # being in the message somewhere
    assert my_bus_name in binary
def send_dbus_message_to_alice(q, stream, dbus_tube_adr, bytestream):
    tube = Connection(dbus_tube_adr)
    signal = SignalMessage('/', 'foo.bar', 'baz')
    signal.append(42, signature='u')
    tube.send_message(signal)

    binary = bytestream.get_data()

    # little and big endian versions of: SIGNAL, NO_REPLY, protocol v1,
    # 4-byte payload
    assert binary.startswith('l\x04\x01\x01' '\x04\x00\x00\x00') or \
           binary.startswith('B\x04\x01\x01' '\x00\x00\x00\x04')
    # little and big endian versions of the 4-byte payload, UInt32(42)
    assert (binary[0] == 'l' and binary.endswith('\x2a\x00\x00\x00')) or \
           (binary[0] == 'B' and binary.endswith('\x00\x00\x00\x2a'))
    # XXX: verify that it's actually in the "sender" slot, rather than just
    # being in the message somewhere

    watch_tube_signals(q, tube)

    dbus_message = binary

    # Have the fake client send us a message all in one go...
    bytestream.send_data(dbus_message)
    q.expect('tube-signal', signal='baz', args=[42], tube=tube)

    # ... and a message one byte at a time ...
    for byte in dbus_message:
        bytestream.send_data(byte)
    q.expect('tube-signal', signal='baz', args=[42], tube=tube)

    # ... and two messages in one go
    bytestream.send_data(dbus_message + dbus_message)
    q.expect('tube-signal', signal='baz', args=[42], tube=tube)
    q.expect('tube-signal', signal='baz', args=[42], tube=tube)
Example #4
0
    def notify_dbus(self, option):
        from .options import OptionItem
        for location in self.locations:
            value = option.value
            if isinstance(option, OptionItem):
                signal = 'CONFIG_CHANGED'
            else:
                signal = 'CONFIG_EXTRA_CHANGED'
                if option.no_submit:
                    value = None

            message = SignalMessage(self.dbus_path, self.dbus_ns, signal)
            signature = 'ssv'
            if isinstance(value, dict) and not len(value):
                # emptry dicts can't be detected
                signature = 'a{ss}'
            elif isinstance(value, (tuple, list)) and not len(value):
                # empty lists can't be detected, so we assume
                # list of strings
                signature = "ssas"

            message.append(workspace_name(),
                           option.name,
                           value,
                           signature=signature)
            location[0].send_message(message)
def send_dbus_message_to_alice(q, stream, dbus_tube_adr, bytestream):
    tube = Connection(dbus_tube_adr)
    signal = SignalMessage('/', 'foo.bar', 'baz')
    signal.append(42, signature='u')
    tube.send_message(signal)

    binary = bytestream.get_data()

    # little and big endian versions of: SIGNAL, NO_REPLY, protocol v1,
    # 4-byte payload
    assert binary.startswith('l\x04\x01\x01' '\x04\x00\x00\x00') or \
           binary.startswith('B\x04\x01\x01' '\x00\x00\x00\x04')
    # little and big endian versions of the 4-byte payload, UInt32(42)
    assert (binary[0] == 'l' and binary.endswith('\x2a\x00\x00\x00')) or \
           (binary[0] == 'B' and binary.endswith('\x00\x00\x00\x2a'))
    # XXX: verify that it's actually in the "sender" slot, rather than just
    # being in the message somewhere

    watch_tube_signals(q, tube)

    dbus_message = binary

    # Have the fake client send us a message all in one go...
    bytestream.send_data(dbus_message)
    q.expect('tube-signal', signal='baz', args=[42], tube=tube)

    # ... and a message one byte at a time ...
    for byte in dbus_message:
        bytestream.send_data(byte)
    q.expect('tube-signal', signal='baz', args=[42], tube=tube)

    # ... and two messages in one go
    bytestream.send_data(dbus_message + dbus_message)
    q.expect('tube-signal', signal='baz', args=[42], tube=tube)
    q.expect('tube-signal', signal='baz', args=[42], tube=tube)
Example #6
0
    def notify_dbus(self, option):
        from .options import OptionItem
        for location in self.locations:
            value = option.value
            if isinstance(option, OptionItem):
                signal = 'CONFIG_CHANGED'
            else:
                signal = 'CONFIG_EXTRA_CHANGED'
                if option.no_submit:
                    value = None

            message = SignalMessage(self.dbus_path,
                                    self.dbus_ns,
                                    signal)
            signature = 'ssv'
            if isinstance(value, dict) and not len(value):
                # emptry dicts can't be detected
                signature = 'a{ss}'
            elif isinstance(value, (tuple, list)) and not len(value):
                # empty lists can't be detected, so we assume
                # list of strings
                signature = "ssas"

            message.append(workspace_name(),
                           option.name,
                           value,
                           signature=signature)
            location[0].send_message(message)
def emit_signal(object_path, interface, name, destination, signature, *args):
    message = SignalMessage(object_path, interface, name)
    message.append(*args, signature=signature)

    if destination is not None:
        message.set_destination(destination)

    dbus.SystemBus().send_message(message)
    def _set_state(self, new_state):
        self._state = new_state

        message = SignalMessage(self.object_path,
                                AVAHI_IFACE_ENTRY_GROUP,
                                'StateChanged')
        message.append(self._state, 'org.freedesktop.Avahi.Success',
                       signature='is')
        message.set_destination(self.client)

        dbus.SystemBus().send_message(message)
Example #9
0
    def emit_signal(self, name, *args):
        """
            emit the dbus signal called *name* with arguments.
        """

        if name not in self.__ipc_signals__:
            raise IpcError("Unknown signal: '%s'" % name)

        # Okay. Let's emit it.
        for location in self.locations:
            signature = self.__ipc_signals__[name]
            if not isinstance(signature, basestring):
                signature, interface = signature
            else:
                interface = self._interface
            message = SignalMessage(
                    self._path,
                    interface,
                    name)
            message.append(signature=signature, *args)
            location[0].send_message(message)
def fire_signal_on_tube(q, tube, chatroom, dbus_stream_id, my_bus_name):
    signal = SignalMessage('/', 'foo.bar', 'baz')
    signal.append(42, signature='u')
    tube.send_message(signal)

    event = q.expect('stream-message', to=chatroom, message_type='groupchat')
    message = event.stanza

    data_nodes = xpath.queryForNodes(
        '/message/data[@xmlns="%s"]' % ns.MUC_BYTESTREAM, message)
    assert data_nodes is not None
    assert len(data_nodes) == 1
    ibb_data = data_nodes[0]
    assert ibb_data['sid'] == dbus_stream_id
    binary = base64.b64decode(str(ibb_data))
    # little and big endian versions of: SIGNAL, NO_REPLY, protocol v1,
    # 4-byte payload
    assert binary.startswith('l\x04\x01\x01' '\x04\x00\x00\x00') or \
           binary.startswith('B\x04\x01\x01' '\x00\x00\x00\x04')
    # little and big endian versions of the 4-byte payload, UInt32(42)
    assert (binary[0] == 'l' and binary.endswith('\x2a\x00\x00\x00')) or \
           (binary[0] == 'B' and binary.endswith('\x00\x00\x00\x2a'))
    # XXX: verify that it's actually in the "sender" slot, rather than just
    # being in the message somewhere
    assert my_bus_name in binary

    # Send another big signal which has to be split on 3 stanzas
    signal = SignalMessage('/', 'foo.bar', 'baz')
    signal.append('a' * 100000, signature='s')
    tube.send_message(signal)

    def wait_for_data(q):
        event = q.expect('stream-message',
                         to=chatroom,
                         message_type='groupchat')

        data_nodes = xpath.queryForNodes(
            '/message/data[@xmlns="%s"]' % ns.MUC_BYTESTREAM, event.stanza)
        ibb_data = data_nodes[0]

        return ibb_data['frag']

    frag = wait_for_data(q)
    assertEquals(frag, 'first')

    frag = wait_for_data(q)
    assertEquals(frag, 'middle')

    frag = wait_for_data(q)
    assertEquals(frag, 'last')
Example #11
0
    def unicastSignal(self, srcObjPath, srcInterface, desWellKnownName,
                      signature, member, *args):

        msg = SignalMessage(srcObjPath, srcInterface, member)
        msg.set_destination(desWellKnownName)
        msg.append(signature=signature, *args)
        self.getBus().send_message(msg)
Example #12
0
def emit_signal(object_path, interface, name, destination, signature, *args):
    message = SignalMessage(object_path, interface, name)
    message.append(*args, signature=signature)

    if destination is not None:
        message.set_destination(destination)

    dbus.SystemBus().send_message(message)
Example #13
0
        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 = SignalMessage(object_path, dbus_interface,
                                        member_name)
                message.append(signature=signature, *args)

                location[0].send_message(message)
Example #14
0
        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 = SignalMessage(object_path,
                                                       dbus_interface,
                                                       member_name)
                message.append(signature=signature, *args)

                location[0].send_message(message)
Example #15
0
    def _set_state(self, new_state):
        self._state = new_state

        message = SignalMessage(self.object_path, AVAHI_IFACE_ENTRY_GROUP,
                                'StateChanged')
        message.append(self._state,
                       'org.freedesktop.Avahi.Success',
                       signature='is')
        message.set_destination(self.client)

        dbus.SystemBus().send_message(message)
def fire_signal_on_tube(q, tube, chatroom, dbus_stream_id, my_bus_name):
    signal = SignalMessage("/", "foo.bar", "baz")
    signal.append(42, signature="u")
    tube.send_message(signal)

    event = q.expect("stream-message", to=chatroom, message_type="groupchat")
    message = event.stanza

    data_nodes = xpath.queryForNodes('/message/data[@xmlns="%s"]' % ns.MUC_BYTESTREAM, message)
    assert data_nodes is not None
    assert len(data_nodes) == 1
    ibb_data = data_nodes[0]
    assert ibb_data["sid"] == dbus_stream_id
    binary = base64.b64decode(str(ibb_data))
    # little and big endian versions of: SIGNAL, NO_REPLY, protocol v1,
    # 4-byte payload
    assert binary.startswith("l\x04\x01\x01" "\x04\x00\x00\x00") or binary.startswith(
        "B\x04\x01\x01" "\x00\x00\x00\x04"
    )
    # little and big endian versions of the 4-byte payload, UInt32(42)
    assert (binary[0] == "l" and binary.endswith("\x2a\x00\x00\x00")) or (
        binary[0] == "B" and binary.endswith("\x00\x00\x00\x2a")
    )
    # XXX: verify that it's actually in the "sender" slot, rather than just
    # being in the message somewhere
    assert my_bus_name in binary

    # Send another big signal which has to be split on 3 stanzas
    signal = SignalMessage("/", "foo.bar", "baz")
    signal.append("a" * 100000, signature="s")
    tube.send_message(signal)

    def wait_for_data(q):
        event = q.expect("stream-message", to=chatroom, message_type="groupchat")

        data_nodes = xpath.queryForNodes('/message/data[@xmlns="%s"]' % ns.MUC_BYTESTREAM, event.stanza)
        ibb_data = data_nodes[0]

        return ibb_data["frag"]

    frag = wait_for_data(q)
    assertEquals(frag, "first")

    frag = wait_for_data(q)
    assertEquals(frag, "middle")

    frag = wait_for_data(q)
    assertEquals(frag, "last")
Example #17
0
class TestDBus(unittest.TestCase):
    def setUp(self):
        self.message = SignalMessage('/', defaults.DBUS_NAME, 'FinalMessage')

    def test_transcript_encode(self):
        pattern = models.Transcript.dbus_struct_signature()
        t = models.Transcript(
            words=['^', 'this'], confidence=-10, final=True, partial=False,
        )
        self.message.append(pattern, t.dbus_struct())

    def test_utterance_encode(self):

        pattern = models.Utterance.dbus_struct_signature()
        t = models.Transcript(
            words=['^', 'this'], confidence=-10, final=True, partial=False,
        )
        u = models.Utterance(
            transcripts=[t],
            messages=['a', 'b'],
            final=True,
            partial=False,
            utterance_number=4,
        )
        self.message.append(pattern, u.dbus_struct())

    def test_real_utterance_encode(self):
        self.message.append(
            '(iba(bdas))',
            (
                1593139040,
                True,
                [
                    (True, -14.70202922821045, ['testing']),
                    (True, -17.187391757965088, ['the', 'sting']),
                    (True, -17.871975898742676, ['thesting']),
                    (True, -18.0646390914917, ['theesting']),
                    (True, -18.168243408203125, ['teesting']),
                    (True, -18.567184448242188, ['thasting']),
                    (True, -18.66072368621826, ['thaesting']),
                    (True, -18.690112113952637, ['tasting']),
                    (True, -20.446099758148193, ['the', 'esting']),
                    (True, -20.985700607299805, ['t', 'esting']),
                    (True, -21.192089080810547, ['the', 'asting']),
                    (True, -21.913288116455078, ['te', 'esting']),
                    (True, -21.951452255249023, ['th', 'esting']),
                    (True, -22.788207054138184, ['ta', 'esting']),
                    (True, -23.690839767456055, ['tha', 'esting']),
                ],
            ),
        )
        self.message.append(
            '(iba(bdas))',
            (
                1593139920,
                True,
                [
                    (True, -10.453631401062012, ['h']),
                    (True, -10.928800582885742, ['e']),
                    (True, -11.342206478118896, ['n']),
                    (True, -12.607892513275146, ['he']),
                    (True, -13.158134460449219, ['d']),
                    (True, -13.176371097564697, ['u']),
                    (True, -13.342707633972168, ['a']),
                    (True, -14.17897891998291, ['m']),
                    (True, -14.235910892486572, ['hn']),
                    (True, -14.390232563018799, ['o']),
                    (True, -14.510844230651855, ['ne']),
                    (True, -15.418322563171387, ['hd']),
                    (True, -16.006152153015137, ['ho']),
                    (True, -17.820629596710205, ['hne']),
                ],
            ),
        )
Example #18
0
 def setUp(self):
     self.message = SignalMessage('/', defaults.DBUS_NAME, 'FinalMessage')