<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_code_num(s: str) -> Optional[int]: """ Get code number from an escape code. Raises InvalidEscapeCode if an invalid number is found. """

    if ';' in s:
        # Extended fore/back codes.
        numberstr = s.rpartition(';')[-1][:-1]
    else:
        # Fore, back, style, codes.
        numberstr = s.rpartition('[')[-1][:-1]

    num = try_parse_int(
        numberstr,
        default=None,
        minimum=0,
        maximum=255
    )
    if num is None:
        raise InvalidEscapeCode(numberstr)
    return num