示例#1
0
def test_add_buffer(app_client, watcher):
    packet = str.encode(dump_event(return_value(), 1))
    app_client.protocol.add_buffer(packet)
    assert watcher.wait('return_value_success')
    assert watcher.wait('write')

    value = Value()
    value.value = 'Hello server!'
    value.errors = False
    value.node_call_id = 1
    assert app_client.write_data == str.encode(dump_value(value) + '~~~')
示例#2
0
def test_add_buffer(app_client, watcher):
    packet = str.encode(dump_event(return_value(), 1))
    app_client.protocol.add_buffer(packet)
    assert watcher.wait('return_value_success')
    assert watcher.wait('write')

    value = Value()
    value.value = 'Hello server!'
    value.errors = False
    value.node_call_id = 1
    assert app_client.write_data == str.encode(dump_value(value) + '~~~')
示例#3
0
def test_values():
    event = Event()
    event.test_meta = 1

    value = Value(event=event)
    value.value = 'foo'
    value.errors = False
    value.node_call_id = 1

    x, id, errors, meta = load_value(dump_value(value))

    assert value.value == x
    assert id == 1
    assert not errors
    assert meta['test_meta'] == event.test_meta
示例#4
0
def test_send(app_client, watcher):
    event = return_value()
    generator = app_client.protocol.send(event)
    next(generator)  # exec

    assert watcher.wait('write')
    assert app_client.write_data == str.encode(dump_event(event, 0) + '~~~')

    value = Value()
    value.value = 'Hello server!'
    value.errors = False
    value.node_call_id = 0
    app_client.protocol.add_buffer(str.encode(dump_value(value) + '~~~'))

    assert next(generator).getValue() == value.value
示例#5
0
def test_send(app_client, watcher):
    event = return_value()
    generator = app_client.protocol.send(event)
    next(generator)  # exec

    assert watcher.wait('write')
    assert app_client.write_data == str.encode(dump_event(event, 0) + '~~~')

    value = Value()
    value.value = 'Hello server!'
    value.errors = False
    value.node_call_id = 0
    app_client.protocol.add_buffer(str.encode(dump_value(value) + '~~~'))

    assert next(generator).getValue() == value.value
示例#6
0
def test_values():
    event = Event()
    event.test_meta = 1

    value = Value(event=event)
    value.value = 'foo'
    value.errors = False
    value.node_call_id = 1

    x, id, errors, meta = load_value(dump_value(value))

    assert value.value == x
    assert id == 1
    assert not errors
    assert meta['test_meta'] == event.test_meta
示例#7
0
    def __process_packet_call(self, packet):
        event, id = load_event(packet)

        if self.__receive_event_firewall and \
                not self.__receive_event_firewall(event, self.__sock):
            self.send_result(id, Value(event, self))
        else:
            event.success = True  # fire %s_success event
            event.success_channels = ('node_result', )
            event.node_call_id = id
            event.node_sock = self.__sock

            # convert byte to str
            event.args = [
                arg.decode('utf-8') if isinstance(arg, bytes) else arg
                for arg in event.args
            ]

            for i in event.kwargs:
                v = event.kwargs[i]
                index = i.decode('utf-8') if isinstance(i, bytes) else i
                value = v.decode('utf-8') if isinstance(v, bytes) else v

                del (event.kwargs[i])
                event.kwargs[index] = value

            self.fire(event, *event.channels)
示例#8
0
    def send(self, event):
        if self.__send_event_firewall and \
                not self.__send_event_firewall(event, self.__sock):
            yield Value(event, self)

        else:
            nid = self.__nid
            self.__nid += 1

            packet = dump_event(event, nid).encode('utf-8') + DELIMITER
            self.__send(packet)

            if not getattr(event, 'node_without_result', False):
                self.__events[nid] = event
                while not hasattr(self.__events[nid], 'remote_finish'):
                    yield

                del (self.__events[nid])
                yield event.value
示例#9
0
    def __process_packet_value(self, packet):
        value, id, error, meta = load_value(packet)

        if id in self.__events:
            # convert byte to str
            value = value.decode('utf-8') if isinstance(value,
                                                        bytes) else value
            error = error.decode('utf-8') if isinstance(error,
                                                        bytes) else error

            if not hasattr(self.__events[id], 'value') \
                    or not self.__events[id].value:
                self.__events[id].value = Value(self.__events[id], self)

            # save result
            self.__events[id].value.setValue(value)
            self.__events[id].errors = error
            self.__events[id].remote_finish = True

            for k, v in dict(meta).items():
                setattr(self.__events[id], k, v)