def run(self): """Run the REPL until EOF is reached.""" print(f"rfi version {rfi_version}") print("Type help and press enter for a list of commands.") print("Roll for initiative!") while not self.closing: try: user_input = self.session.prompt() cmd, *cmd_args = user_input.split() except (KeyboardInterrupt, ValueError): # Invalid input string continue except EOFError: break try: cmd_function = self._get_command_function(cmd) except AttributeError: print(f"Unknown command: {cmd}.") continue if not test_callable_args(cmd_function, cmd_args): print() print(f"Invalid usage of {cmd}.") print(f"Expected usage: {self.commands_usage[cmd]}") print(f"Type help {cmd} for more information.") print() continue try: cmd_function(*cmd_args) except ValueError as err: print(f"Error: {err}") print()
def is_dimension(value): """ Test whether the given value could be a valid dimension. (For usage in an assertion. It's not guaranteed in case of a callable.) """ if value is None: return True if callable(value): return test_callable_args(value, []) if isinstance(value, (int, Dimension)): return True return False
def __init__(self, func): assert callable(func) assert test_callable_args(func, []) self.func = func
def test_args(self, *args): """ Test whether this filter can be called with the following argument list. """ return test_callable_args(self.__call__, args)
def test_args(self, *a): return test_callable_args(self.func, a)