Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __readConfig(self):
try:
config = configparser.ConfigParser()
config.read(self.settingsFilename)
self.consumer_key = config.get('twitter', 'consumer_key')
self.consumer_secret_key = config.get('twitter', 'consumer_secret_key')
self.access_token = config.get('twitter', 'access_token')
self.access_secret_token = config.get('twitter', 'access_secret_token')
except configparser.NoSectionError:
sys.stderr.write("Could not open %s\n" % self.settingsFilename)
sys.stderr.write("Exiting...\n")
sys.exit(1)
spgnum = config.get('option', 'spgnum')
except (configparser.NoOptionError, configparser.NoSectionError):
spgnum = 'all'
if spgnum == '0':
spgnum = 0
elif spgnum == 'all':
pass
else:
spgnum = spglist(spgnum)
try:
load_struc_flag = config.getboolean('option', 'load_struc_flag')
except (configparser.NoOptionError, configparser.NoSectionError):
load_struc_flag = False
try:
stop_next_struc = config.getboolean('option', 'stop_next_struc')
except (configparser.NoOptionError, configparser.NoSectionError):
stop_next_struc = False
try:
recalc = config.get('option', 'recalc')
recalc = [int(x) for x in recalc.split()] # character --> integer
except (configparser.NoOptionError, configparser.NoSectionError):
recalc = []
if recalc:
for i in recalc:
if not 0 <= i < tot_struc:
raise ValueError('recalc must be non-negative int'
' and less than tot_struc')
try:
append_struc_ea = config.getboolean('option', 'append_struc_ea')
except (configparser.NoOptionError, configparser.NoSectionError):
append_struc_ea = False
try:
def get_level_related_map_information(self, level):
"""
Function that retrieves information about a specific level
:param level: Level wanted
:return: A tuple containing map configuration and an array containing filenames for the backgrounds
"""
section_name = "LEVEL" + str(level)
try:
level = self.config[section_name]
map_design = level["map"]
map_background = level["background_sprite"].split(',')
except configparser.NoSectionError:
print('Level is not loadable. Check if level exists in provided file.')
raise
return map_design, map_background
def _load(self):
self._load_config()
try:
self._consumer_key = self._config.get(API.CONFIG_HEADER, 'consumer_key')
self._access_token = self._config.get(API.CONFIG_HEADER, 'access_token')
self._username = self._config.get(API.CONFIG_HEADER, 'username')
except (configparser.NoSectionError, KeyError):
print('Please connect an account first, by running `pockyt reg` !')
sys.exit(1)
Get the config section as a dictionary
:param caller_file_path: file path of the caller, __file__
:param name: the section name in an .ini file
:return: configuration as dict
"""
init_file_path = get_ini_file_path(caller_file_path)
config = ConfigParser.from_files(init_file_path)
try:
return config.to_dict(section=name)
except NoSectionError:
raise NoSectionError(f"'{name}' is not a valid configuration in {init_file_path}")
monitor=False,
tester=True)
runningAgent = ASI.instance().getAgent(aname=aName)
if runningAgent is not None:
runningAgent['auto-startup'] = False
notif2 = ( 'agents', ( 'del', ASI.instance().getAgents() ) )
ESI.instance().notifyByUserTypes(body = notif2,
admin=True,
monitor=False,
tester=True)
# return OK
ret = self.context.CODE_OK
except ConfigParser.NoSectionError:
self.error( "agent not found: %s" % str(aName) )
ret = self.context.CODE_NOT_FOUND
except Exception as e:
self.error( "unable to delete default agent: %s" % str(e) )
ret = self.context.CODE_FAILED
return ret
value = value.strip()
if value != "None":
try:
value = base64.decodebytes(value.encode("utf-8")).decode(
'utf-8')
except Exception as exc:
logger.warning(
"Failed to decode work dir path ({})".format(value),
exc_info=exc
)
value = FS.safe(value)
else:
value = None
self.value = value
return
except (configparser.NoOptionError, configparser.NoSectionError):
pass
self.value = self.default_value_func()
# check if handlers have already been added to this logger
if not len(newLgr.handlers):
# handlers not added yet
# create file handler for log file
try:
logFile = cfg['logging']['logFile']
except (configparser.NoSectionError, configparser.NoOptionError, KeyError):
logFile = '/var/log/inquisition/app.log'
fileHandler = logging.FileHandler(logFile)
fileHandler.setLevel(logLvl)
# set output formatter
try:
# NOTE: we need to get the logFormat val with the raw flag set in order to avoid logging from interpolating
logFormat = cfg.get('logging', 'logFormat', raw=True)
except (configparser.NoSectionError, configparser.NoOptionError, KeyError):
logFormat = '%(asctime)s inquisition: [ %(levelname)s ] [ %(name)s ] %(message)s'
frmtr = logging.Formatter(logFormat)
fileHandler.setFormatter(frmtr)
# associate file handler w/ logger
newLgr.addHandler(fileHandler)
return newLgr
def set(self, section, option, value):
"""Set option in section to value.
If the given section exists, set the given option to the specified
value; otherwise raise NoSectionError.
"""
if section not in self:
raise configparser.NoSectionError
self[section][option] = value
def _parse_config(self):
"""Read in the supplied config file and update our local settings."""
self.log.debug('Loading config...')
self._config = configparser.ConfigParser()
self._config.read(self._config_file)
# Check if auth data was supplied. If it is, read it in and then remove
# it from our configuration object so its not used anywhere else.
try:
self.user = self._config.get('auth', 'user')
self.password = self._config.get('auth', 'password')
self._config.remove_section('auth')
except (configparser.NoOptionError, configparser.NoSectionError):
self.user = None
self.password = None