<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def parse_str(text):
 """ Given a string of characters, for each normal ASCII character, yields a directive consisting of a 'putch' instruction followed by the character itself. If a valid ANSI escape sequence is detected within the string, the supported codes are translated into directives. For example ``\\033[42m`` would emit a directive of ``["background_color", "green"]``. Note that unrecognised escape sequences are silently ignored: Only reset, reverse colours and 8 foreground and background colours are supported. It is up to the consumer to interpret the directives and update its state accordingly. :param text: An ASCII string which may or may not include valid ANSI Color escape codes. :type text: str """

    prog = re.compile(r'^\033\[(\d+(;\d+)*)m', re.UNICODE)

    while text != "":
        result = prog.match(text)
        if result:
            for code in result.group(1).split(";"):
                directive = valid_attributes.get(int(code), None)
                if directive:
                    yield directive
            n = len(result.group(0))
            text = text[n:]
        else:
            yield ["putch", text[0]]
            text = text[1:]