Example #1
0
    def __init__(self, pattern, callback, messages):
        """
        Receiving a message matching PATTERN triggers a call to the on_incoming_message message with
        ADDRESS and MESSAGE.

        PATTERN is a python regular expression string.

        CALLBACK is called when PATTERN matches the incoming message footprint.  As an argument it
        receives MESSAGES.

        MESSAGES is a list with Message.Implementation instances.  These messages are effectively
        delayed until a message matching PATTERN is received.

        When a timeout is received this Trigger is removed MESSAGES are lost.
        """
        if __debug__:
            from message import Message
        assert isinstance(pattern, str)
        assert hasattr(callback, "__call__")
        assert isinstance(messages, list)
        assert len(messages) > 0
        assert not filter(lambda x: not isinstance(x, Message.Implementation), messages)
        if __debug__:
            dprint("create new trigger for ", len(messages), " messages")
            dprint("pattern: ", pattern)
        self._pattern = pattern
        self._search = expression_compile(pattern).search
        self._callback = callback
        self._messages = messages
Example #2
0
    def __init__(self, pattern, response_func, response_args, max_responses):
        """
        Receiving a message matching PATTERN triggers a call to RESPONSE_FUNC.

        PATTERN is a python regular expression string.

        RESPONSE_FUNC is called when PATTERN matches the incoming message footprint.  The first
        argument is the incoming message, following this are optional values from RESPONSE_ARGS.

        RESPONSE_ARGS is an optional tuple containing arguments passed to RESPONSE_ARGS.

        MAX_RESPONSES is a number.  Once MAX_RESPONSES messages are received no further calls are
        made to RESPONSE_FUNC.

        When a timeout is received and MAX_RESPONSES has not yet been reached, RESPONSE_FUNC is
        immediately called.  The first argument will be ('', -1), the second will be None, following
        this are the optional values from RESPONSE_FUNC.
        """
        assert isinstance(pattern, str)
        assert hasattr(response_func, "__call__")
        assert isinstance(response_args, tuple)
        assert isinstance(max_responses, int)
        assert max_responses > 0
        if __debug__:
            self._debug_pattern = pattern
            dprint("create new trigger for one callback")
            dprint("pattern: ", self._debug_pattern)
        self._search = expression_compile(pattern).search
        self._response_func = response_func
        self._response_args = response_args
        self._responses_remaining = max_responses
Example #3
0
    def __init__(self, pattern, callback, packets):
        """
        Receiving a message matching PATTERN triggers a call to the on_incoming_packet method with
        PACKETS.

        PATTERN is a python regular expression string.

        CALLBACK is called when PATTERN matches the incoming message footprint.  The only argument
        is PACKETS.

        PACKETS is a list containing (Candidate, packet) tuples.  These packets are effectively
        delayed until a message matching PATTERN was received.

        When a timeout is received this Trigger is removed and PACKETS are lost.
        """
        if __debug__:
            assert isinstance(pattern, str)
            assert hasattr(callback, "__call__")
            assert isinstance(packets, list)
            assert len(packets) > 0
            for packet in packets:
                assert isinstance(packet, tuple)
                assert len(packet) == 2
                assert isinstance(packet[0], Candidate)
                assert isinstance(packet[1], str)
        if __debug__:
            dprint("create new trigger for ", len(packets), " packets")
            dprint("pattern: ", pattern)
        self._pattern = pattern
        self._search = expression_compile(pattern).search
        self._callback = callback
        self._packets = packets