@classmethod
    def fromMessages(klass, uuid, level, messages):
        startMessage = None
        endMessage = None
        children = []
        levelPrefix = level[:-1]

        for message in messages:
            if message[TASK_UUID_FIELD] != uuid:
                # Different task altogether:
                continue

            messageLevel = message[TASK_LEVEL_FIELD]

            if messageLevel[:-1] == levelPrefix:
                status = message.get(ACTION_STATUS_FIELD)
                if status == STARTED_STATUS:
                    startMessage = message
                elif status in COMPLETED_STATUSES:
                    endMessage = message
                else:
                    # Presumably a message in this action:
                    children.append(LoggedMessage(message))
            elif (len(messageLevel) == len(levelPrefix) + 2 and
                  messageLevel[:-2] == levelPrefix and
                  messageLevel[-1] == 1):
                # If start message level is [1], [1, 2, 1] implies first
                # message of a direct child.
                child = klass.fromMessages(
                    uuid, message[TASK_LEVEL_FIELD], messages)
                children.append(child)
        if startMessage is None or endMessage is None:
            raise ValueError(uuid, level)
        return klass(startMessage, endMessage, children)


    # PEP 8 variant:
Given a task uuid and level (identifying an action) and a list of
dataset/ETHPy150Open ClusterHQ/eliot/eliot/testing.py/LoggedAction.fromMessages