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')
Exemplo n.º 2
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)
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)
Exemplo n.º 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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
0
 def setUp(self):
     self.message = SignalMessage('/', defaults.DBUS_NAME, 'FinalMessage')