Exscript.emulators.command module¶
Defines the behavior of commands by mapping commands to functions.
-
class
Exscript.emulators.command.
CommandSet
(strict=True)[source]¶ Bases:
future.types.newobject.newobject
A set of commands to be used by the Dummy adapter.
-
add
(command, response)[source]¶ Register a command/response pair.
The command may be either a string (which is then automatically compiled into a regular expression), or a pre-compiled regular expression object.
If the given response handler is a string, it is sent as the response to any command that matches the given regular expression. If the given response handler is a function, it is called with the command passed as an argument.
Parameters: - command (str|regex) – A string or a compiled regular expression.
- response (function|str) – A reponse, or a response handler.
-
add_from_file
(filename, handler_decorator=None)[source]¶ Wrapper around add() that reads the handlers from the file with the given name. The file is a Python script containing a list named ‘commands’ of tuples that map command names to handlers.
Parameters: - filename (str) – The name of the file containing the tuples.
- handler_decorator (function) – A function that is used to decorate each of the handlers in the file.
-