Browse Source

Fixed recover_special_codes() sometimes returning the wrong thing

Stephen Downward 1 year ago
parent
commit
9793f1c761
1 changed files with 17 additions and 8 deletions
  1. 17 8
      kiss/util.py

+ 17 - 8
kiss/util.py

@ -37,14 +37,23 @@ def recover_special_codes(escaped_codes):
37 37
    replaced by FESC code and FESC_TFEND is replaced by FEND code."
38 38
    - http://en.wikipedia.org/wiki/KISS_(TNC)#Description
39 39
    """
40
    return escaped_codes.replace(
41
        kiss.FESC_TFESC,
42
        kiss.FESC
43
    ).replace(
44
        kiss.FESC_TFEND,
45
        kiss.FEND
46
    )
47
40
    out = bytearray()
41
    i = 0
42
    while i < len(escaped_codes):
43
        if escaped_codes[i] == kiss.FESC[0] and i + 1 < len(escaped_codes):
44
            if escaped_codes[i + 1] == kiss.TFESC[0]:
45
                out.append(kiss.FESC[0])
46
                i += 1 #Skips over the next byte, which would be the TFESC
47
            elif escaped_codes[i + 1] == kiss.TFEND[0]:
48
                out.append(kiss.FEND[0])
49
                i += 1
50
            else:
51
                out.append(escaped_codes[i])
52
        else:
53
            out.append(escaped_codes[i])
54
        i += 1
55
56
    return out
48 57
49 58
def extract_ui(frame):
50 59
    """