Each bot class is implemented as a context manager and has a basic configured logger attached. It can thus be instantiated in a clear and straightforward way. Here is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Note that, if a bot is used behind a proxy, it will use system's proxy settings. This behavior can be bypassed by using
no_proxy=True while instantiating the bot.
Each module is documented. Python's built-in
help function can thus be used to get help from an interactive console.
Each bot comes with the following features (in order of precedence), inherited from the template:
- Logging: A public method named
configuresets the logging level and attaches a logger to the bot. Logging can thus be reconfigured in the context of the bot. The verbose mode is a boolean and configures the bot for debugging if the value is false.
1 2 3 4
1 2 3
%(asctime)s [%(levelname)s] %(message)s
- System proxy settings: When the bot starts, it gets the system proxy settings to work with (
no_proxy=Falseby default). This behavior can be overridden by setting
1 2 3
- Pre/Post-computation: By default, when a bot is initialized, it tries to execute a public method named
precomputeif it exists. This allows to perform computations BEFORE the context of the bot is entered. Similarly, when a bot comes to the end of its execution, it tries to execute a public method named
postcomputeif it exists. This allows to perform computations AFTER bot's communication has ended, just before exiting the context.
1 2 3 4 5 6 7 8 9 10 11 12
Fail-open (the bot continues if the pre/post-computation fails and provides a warning)
- Pre/Post-amble: By default, when bot's context is entered, it tries to execute a public method named
preambleif it exists. This allows to play a preamble with the remote host to keep bot's context code clean. Similarly, when a bot comes to the end of its context, it tries to execute a public method named
postambleif it exists. This allows to perform actions before bot's communication has ended, thus before exiting the context.
1 2 3 4 5 6 7 8 9 10
Fail-close (the bot crashes if the preamble fails and displays the exception with its traceback)