Return a value for configType section option, or default. If type is not None, return a value of that type. Also pass raw to the config parser. First try to return a valid value (including type) from a user configuration. If that fails, try the default configuratio
(self, configType, section, option, default=None, type=None,
warn_on_default=True, raw=False)
| 213 | return userDir |
| 214 | |
| 215 | def GetOption(self, configType, section, option, default=None, type=None, |
| 216 | warn_on_default=True, raw=False): |
| 217 | """Return a value for configType section option, or default. |
| 218 | |
| 219 | If type is not None, return a value of that type. Also pass raw |
| 220 | to the config parser. First try to return a valid value |
| 221 | (including type) from a user configuration. If that fails, try |
| 222 | the default configuration. If that fails, return default, with a |
| 223 | default of None. |
| 224 | |
| 225 | Warn if either user or default configurations have an invalid value. |
| 226 | Warn if default is returned and warn_on_default is True. |
| 227 | """ |
| 228 | try: |
| 229 | if self.userCfg[configType].has_option(section, option): |
| 230 | return self.userCfg[configType].Get(section, option, |
| 231 | type=type, raw=raw) |
| 232 | except ValueError: |
| 233 | warning = ('\n Warning: config.py - IdleConf.GetOption -\n' |
| 234 | ' invalid %r value for configuration option %r\n' |
| 235 | ' from section %r: %r' % |
| 236 | (type, option, section, |
| 237 | self.userCfg[configType].Get(section, option, raw=raw))) |
| 238 | _warn(warning, configType, section, option) |
| 239 | try: |
| 240 | if self.defaultCfg[configType].has_option(section,option): |
| 241 | return self.defaultCfg[configType].Get( |
| 242 | section, option, type=type, raw=raw) |
| 243 | except ValueError: |
| 244 | pass |
| 245 | #returning default, print warning |
| 246 | if warn_on_default: |
| 247 | warning = ('\n Warning: config.py - IdleConf.GetOption -\n' |
| 248 | ' problem retrieving configuration option %r\n' |
| 249 | ' from section %r.\n' |
| 250 | ' returning default value: %r' % |
| 251 | (option, section, default)) |
| 252 | _warn(warning, configType, section, option) |
| 253 | return default |
| 254 | |
| 255 | def SetOption(self, configType, section, option, value): |
| 256 | """Set section option to value in user config file.""" |