def waitfor(self, msg, timeout=0.5):
    if self._closed:
        raise Exception('Mock engine waitfor called after cleanup.')
    msg = msg.rstrip()
    expected = self.expected[self.event]
    if (expected[0] not in ['r', 'raise']):
        raise Exception(('Mock engine waitfor called when expecting, %s' % (expected,)))
    responses = []
    while ((expected[0] == 'r') and (expected[1] != msg)):
        responses.append(expected[1])
        self.event += 1
        expected = self.expected[self.event]
    if ((expected[0] == 'r') and (msg == expected[1])):
        responses.append(expected[1])
    elif (expected[0] == 'send_response'):
        pass
    elif (expected[0] == 'raise'):
        self.event += 1
        raise expected[1]()
    else:
        raise Exception(('Mock engine waitfor called with unexpected message (%s)' % (msg,)))
    self.event += 1
    return responses
def waitfor(self, msg, timeout=0.5):
    if self._closed:
        raise Exception('Mock engine waitfor called after cleanup.')
    msg = msg.rstrip()
    expected = self.expected[self.event]
    if (expected[0] not in ['r', 'raise']):
        raise Exception(('Mock engine waitfor called when expecting, %s' % (expected,)))
    responses = []
    while ((expected[0] == 'r') and (expected[1] != msg)):
        responses.append(expected[1])
        self.event += 1
        expected = self.expected[self.event]
    if ((expected[0] == 'r') and (msg == expected[1])):
        responses.append(expected[1])
    elif (expected[0] == 'send_response'):
        pass
    elif (expected[0] == 'raise'):
        self.event += 1
        raise expected[1]()
    else:
        raise Exception(('Mock engine waitfor called with unexpected message (%s)' % (msg,)))
    self.event += 1
    return responses