Пример #1
0
    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 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
Пример #4
0
 def __init__(self, func):
     assert callable(func)
     assert test_callable_args(func, [])
     self.func = func
Пример #5
0
 def test_args(self, *args):
     """
     Test whether this filter can be called with the following argument list.
     """
     return test_callable_args(self.__call__, args)
Пример #6
0
 def test_args(self, *a):
     return test_callable_args(self.func, a)
 def __init__(self, func):
     assert callable(func)
     assert test_callable_args(func, [])
     self.func = func
Пример #8
0
 def test_args(self, *args):
     """
     Test whether this filter can be called with the following argument list.
     """
     return test_callable_args(self.__call__, args)
Пример #9
0
 def test_args(self, *a):
     return test_callable_args(self.func, a)