Remove ANSI escape codes from student result.
513285
def strip_ansi(state):
    """"""
    stu_res = _strip_ansi(state.student_result)

    return state.to_child(student_result = stu_res)
993288
def clean(docs=False, bytecode=False, extra=''):
    ''''''
    patterns = ['build', 'dist', 'cover', 'docs/_build', '**/*.pyc', '*.egg-info', '.tox', '**/__pycache__']
    for pattern in patterns:
        print('Removing {0}'.format(pattern))
        lrun('rm -rf {0}'.format(pattern))
509912
def strip_non_ascii(string):
    ''' '''
    stripped = (c for c in string if 0 < ord(c) < 127)
    return ''.join(stripped)
38944
def unaccentuate(s):
    
    return "".join(c for c in unicodedata.normalize("NFKD", s) if not unicodedata.combining(c))
486376
def decompose_code(code):
    
    code = "%-6s" % code
    ind1 = code[3:4]
    if ind1 == " ": ind1 = "_"
    ind2 = code[4:5]
    if ind2 == " ": ind2 = "_"
    subcode = code[5:6]
    if subcode == " ": subcode = None
    return (code[0:3], ind1, ind2, subcode)
261864
def fix_e713(self, result):
        """"""
        (line_index, offset, target) = get_index_offset_contents(result,
                                                                 self.source)

        # to convert once 'not in' -> 'in'
        before_target = target[:offset]
        target = target[offset:]
        match_notin = COMPARE_NEGATIVE_REGEX_THROUGH.search(target)
        notin_pos_start, notin_pos_end = 0, 0
        if match_notin:
            notin_pos_start = match_notin.start(1)
            notin_pos_end = match_notin.end()
            target = '{}{} {}'.format(
                target[:notin_pos_start], 'in', target[notin_pos_end:])

        # fix 'not in'
        match = COMPARE_NEGATIVE_REGEX.search(target)
        if match:
            if match.group(3) == 'in':
                pos_start = match.start(1)
                new_target = '{5}{0}{1} {2} {3} {4}'.format(
                    target[:pos_start], match.group(2), match.group(1),
                    match.group(3), target[match.end():], before_target)
                if match_notin:
                    # revert 'in' -> 'not in'
                    pos_start = notin_pos_start + offset
                    pos_end = notin_pos_end + offset - 4     # len('not ')
                    new_target = '{}{} {}'.format(
                        new_target[:pos_start], 'not in', new_target[pos_end:])
                self.source[line_index] = new_target
1198842
def clean(cls, cpf):
        
        """
        if isinstance(cpf, six.string_types):
            cpf = int(re.sub('[^0-9]', '', cpf))

        return '{0:011d}'.format(cpf)
1196724
def remove_bad():
    
    for line in sys.stdin:
        parts = line.strip().split("\t")
        if len(parts) == 1 and len(line.strip().split()) > 1:
            parts = line.strip().split()
        if line.strip() and len(parts) > 2 and int(parts[2]) > int(parts[1]):
            sys.stdout.write("\t".join(parts) + "\n")
428402
def _sanitize_output(
        self, output, strip_command=False, command_string=None, strip_prompt=False
    ):
        
        if self.ansi_escape_codes:
            output = self.strip_ansi_escape_codes(output)
        output = self.normalize_linefeeds(output)
        if strip_command and command_string:
            command_string = self.normalize_linefeeds(command_string)
            output = self.strip_command(command_string, output)
        if strip_prompt:
            output = self.strip_prompt(output)
        return output
997668
def strip_from_ansi_esc_sequences(text):
    
    # esc[ + values + control character
    # h, l, p commands are complicated, let's ignore them
    seq_regex = r"\x1b\[[0-9;]*[mKJusDCBAfH]"
    regex = re.compile(seq_regex)
    start = 0
    response = ""
    for match in regex.finditer(text):
        end = match.start()
        response += text[start:end]

        start = match.end()
    response += text[start:len(text)]
    return response
364843
def clean(cls, cnpj):
        
        """
        if isinstance(cnpj, six.string_types):
            cnpj = int(re.sub('[^0-9]', '', cnpj))

        return '{0:014d}'.format(cnpj)
742129
def unescape(str):
    """"""
    out = ''
    prev_backslash = False
    for char in str:
        if not prev_backslash and char == '\\':
            prev_backslash = True
            continue
        out += char
        prev_backslash = False
    return out
889036
def fix_e713(self, result):
        """"""
        (line_index, _, target) = get_index_offset_contents(result,
                                                            self.source)

        match = COMPARE_NEGATIVE_REGEX.search(target)
        if match:
            if match.group(3) == 'in':
                pos_start = match.start(1)
                self.source[line_index] = '{0}{1} {2} {3} {4}'.format(
                    target[:pos_start], match.group(2), match.group(1),
                    match.group(3), target[match.end():])
870248
def removeRandomLenPadding(str, blocksize=AES_blocksize):
  ''
  pad_len = ord(str[-1]) # last byte contains number of padding bytes
  assert pad_len < blocksize, 'padding error' 
  assert pad_len < len(str), 'padding error'
    
  return str[:-pad_len]
548863
def ansi(color, text):
    """"""
    code = COLOR_CODES[color]
    return '\033[1;{0}m{1}{2}'.format(code, text, RESET_TERM)
710148
def strip_accents(s):
    
    nfkd = unicodedata.normalize('NFKD', unicode(s))
    return u''.join(ch for ch in nfkd if not unicodedata.combining(ch))
527904
def sanitize_type(raw_type):
    """"""
    cleaned = get_printable(raw_type).strip()
    for bad in [
            r'__drv_aliasesMem', r'__drv_freesMem',
            r'__drv_strictTypeMatch\(\w+\)',
            r'__out_data_source\(\w+\)',
            r'_In_NLS_string_\(\w+\)',
            r'_Frees_ptr_', r'_Frees_ptr_opt_', r'opt_',
            r'\(Mem\) '
    ]:
        cleaned = re.sub(bad, '', cleaned).strip()
    if cleaned in ['_EXCEPTION_RECORD *', '_EXCEPTION_POINTERS *']:
        cleaned = cleaned.strip('_')
    cleaned = cleaned.replace('[]', '*')
    return cleaned