Module to store shared code.
Functions and classes are put here when they are meant to be reused in different parts of the program. Some of them were built just for internal use, but others (listed bellow) can also be incorporated in user code as well (for example, in the crawler code).
Manage logging and printing of messages.
Provides a unified and common infrastructure for information output in different parts of the program, besides abstracting low level details about output operations.
Default configuration values. If no local value has been specified for an option in an instance, the value defined here for that option is used instead.
Mandatory configuration values. If a value for an option here is None, the handler respects the instance local configuration value for that option (or the default configuration value if no local value has been specified). Otherwise, the value specified here overrides any local value.
Constructor.
Root logger configuration is done here using logging.basicConfig(). This means that loggingFileName and defaultLoggingLevel parameters are defined by the first module in an import hierarchy that instantiate an EchoHandler object, as subsequent calls to logging.basicConfig() have no effect. So, for example, when running the client, it is the first module to instantiate an EchoHandler object. The client module imports the crawler module, but as crawler is the second module in the hierarchy, it will use the root logger configuration defined in client, despite any local settings of loggingFileName and defaultLoggingLevel.
See also
Python’s built-in logging module documentation.
Extract and store configurations.
The configurations are extracted from configurationsDictionary and stored in separate instance variables. Each configuration has a default value, defined in defaultConfig, so it is possible to use EchoHandler without specifying any of them. The values of mandatoryConfig are also checked here and, if set, override the values given in configurationsDictionary, as well as default values.
Log and/or print a message.
Convert a string to a boolean.