The documentation for ConfigParser recommends using the mapping protocol for all new projects instead of the legacy API.
This PR aims to change all cases of this pattern:
section = 'XXX'
# here self is a `ConfigParser` subclass instance
if self.has_section(section):
key = 'YYY'
if self.has_option(section, key):
var = self.get(section, key)
# do something with var
else:
# log
else:
# log and return
The goal is to use the following pattern instead:
section_key = 'XXX'
try:
section = self[section_key]
except KeyError:
# log and return
key = 'YYY'
try:
var = section[key]
except TypeError:
# log and return : not a section
except KeyError:
# log: no option YYY
# use var
I have also added several comments on parts of the code that could (theoretically) lead to a crash or security vulnerability
The documentation for ConfigParser recommends using the mapping protocol for all new projects instead of the legacy API.
This PR aims to change all cases of this pattern:
The goal is to use the following pattern instead:
I have also added several comments on parts of the code that could (theoretically) lead to a crash or security vulnerability