class FTPError(Exception): def __init__(self, message="An unknown error occured", code=-1): self.message = message self.code = code super().__init__(self.message) def parse_ftp_command(cmd): tokens = cmd.split(" ") if len(tokens) == 0: raise FTPError("No command issued!") command_name = tokens[0].upper() arguments = tokens[1:] return (command_name, arguments) def get_argument(args, name, index): try: return args[index] except IndexError: raise FTPError(f"Missing argument '{name}'", 2138)