Python configparser.ConfigParser.get() Examples
The following are 17
code examples of configparser.ConfigParser.get().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
configparser.ConfigParser
, or try the search function
.
Example #1
Source File: config.py From biweeklybudget with GNU Affero General Public License v3.0 | 6 votes |
def is_secure_option(self, section, option): """Test an option to see if it is secured or not. :param section: section id :type section: string :param option: option name :type option: string :rtype: boolean otherwise. """ if not self.has_section(section): return False if not self.has_option(section, option): return False if ConfigParser.get(self, section, option) == self._secure_placeholder: return True return False
Example #2
Source File: testutils.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def getstringlist(self, section, option): "Coerce option to a list of strings or return unchanged if that fails." value = ConfigParser.get(self, section, option) # This seems to allow for newlines inside values # of the config file, but be careful!! val = value.replace('\n', '') if self.pat.match(val): return eval(val) else: return value # This class as suggested by /F with an additional hook # to be able to filter filenames.
Example #3
Source File: configparser.py From BentoML with Apache License 2.0 | 6 votes |
def get(self, section, key=None, **kwargs): # pylint:disable=arguments-differ """ A simple hierachical config access, priority order: 1. environment var 2. user config file 3. bentoml default config file """ if key is None: key = section section = 'core' section = str(section).lower() key = str(key).lower() env_var = self._env_var_name(section, key) if env_var in os.environ: return os.environ[env_var] if ConfigParser.has_option(self, section, key): return ConfigParser.get(self, section, key, **kwargs) else: raise BentoMLConfigException( "section/key '{}/{}' not found in BentoML config".format(section, key) )
Example #4
Source File: parser.py From pibooth with MIT License | 6 votes |
def save(self, default=False): """Save the current or default values into the configuration file. """ LOGGER.info("Generate the configuration file in '%s'", self.filename) dirname = osp.dirname(self.filename) if not osp.isdir(dirname): os.makedirs(dirname) with io.open(self.filename, 'w', encoding="utf-8") as fp: for section, options in DEFAULT.items(): fp.write("[{}]\n".format(section)) for name, value in options.items(): if default: val = value[0] else: val = self.get(section, name) fp.write("# {}\n{} = {}\n\n".format(value[1], name, val)) self.handle_autostart()
Example #5
Source File: unicode_aware.py From wot-teamspeak-mod with GNU Lesser General Public License v2.1 | 5 votes |
def get(self, section, option, *args, **kwargs): demand_unicode(section) demand_unicode(option) return to_unicode(ParentConfigParser.get(self, section, option, *args, **kwargs))
Example #6
Source File: __init__.py From bazarr with GNU General Public License v3.0 | 5 votes |
def get(self, section, option, raw=False, vars=None, fallback=None): try: # Strip out quotes from the edges return configparser.get(self, section, option).strip('"\'') except NoOptionError: return None
Example #7
Source File: __init__.py From bazarr with GNU General Public License v3.0 | 5 votes |
def __getattr__(self, name, raw=False, vars=None): """Fetch a value via the object handler""" if name not in simpleconfigparser.Section.__dict__: return self.parser.get(self.section, name, raw, vars)
Example #8
Source File: __init__.py From bazarr with GNU General Public License v3.0 | 5 votes |
def __getitem__(self, name, raw=False, vars=None): """Fetch a value via the dict handler""" if name not in simpleconfigparser.Section.__dict__: return self.parser.get(self.section, name, raw, vars)
Example #9
Source File: parser.py From pibooth with MIT License | 5 votes |
def getpath(self, section, option): """Get a path from config, evaluate the absolute path from configuration file path. :param section: config section name :type section: str :param option: option name :type option: str """ return self._get_abs_path(self.get(section, option))
Example #10
Source File: parser.py From pibooth with MIT License | 5 votes |
def gettyped(self, section, option): """Get a value from config and try to convert it in a native Python type (using the :py:mod:`ast` module). :param section: config section name :type section: str :param option: option name :type option: str """ value = self.get(section, option) try: return ast.literal_eval(value) except (ValueError, SyntaxError): return value
Example #11
Source File: parser.py From pibooth with MIT License | 5 votes |
def get(self, section, option, **kwargs): """Override the default function of ConfigParser to add a default value if section or option is not found. :param section: config section name :type section: str :param option: option name :type option: str """ if self.has_section(section) and self.has_option(section, option): return ConfigParser.get(self, section, option, **kwargs) return str(DEFAULT[section][option][0])
Example #12
Source File: testutils.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def printLocation(depth=1): if sys._getframe(depth).f_locals.get('__name__')=='__main__': outDir = outputfile('') if outDir!=_OUTDIR: print('Logs and output files written to folder "%s"' % outDir)
Example #13
Source File: config.py From biweeklybudget with GNU Affero General Public License v3.0 | 5 votes |
def encrypt_account(self, id): """Make sure that certain fields are encrypted.""" for key in self.secured_field_names: value = self.parser.get(id, key) self.parser.set_secure(id, key, value) return self
Example #14
Source File: config.py From biweeklybudget with GNU Affero General Public License v3.0 | 5 votes |
def get(self, section, option, *args): """Get option value from section. If an option is secure, populates the plain text.""" if self.is_secure_option(section, option) and self.keyring_available: s_option = "%s%s" % (section, option) if self._unsaved.get(s_option, [''])[0] == 'set': res = self._unsaved[s_option][1] else: res = keyring.get_password(self.keyring_name, s_option) else: res = ConfigParser.get(self, section, option, *args) if res == '!!False!!': return False return res
Example #15
Source File: config.py From biweeklybudget with GNU Affero General Public License v3.0 | 5 votes |
def set_secure(self, section, option, value): """Set an option and mark it as secure. Any subsequent uses of 'set' or 'get' will also now know that this option is secure as well. """ if self.keyring_available: s_option = "%s%s" % (section, option) self._unsaved[s_option] = ('set', value) value = self._secure_placeholder ConfigParser.set(self, section, option, value)
Example #16
Source File: config.py From biweeklybudget with GNU Affero General Public License v3.0 | 5 votes |
def items(self, section): """Get all items for a section. Subclassed, to ensure secure items come back with the unencrypted data. :param section: section id :type section: string """ items = [] for k, v in ConfigParser.items(self, section): if self.is_secure_option(section, k): v = self.get(section, k) if v == '!!False!!': v = False items.append((k, v)) return items
Example #17
Source File: parser.py From pibooth with MIT License | 4 votes |
def gettuple(self, section, option, types, extend=0): """Get a list of values from config. The values type shall be in the list of authorized types. This method permits to get severals values from the same configuration option. If the option contains one value (with acceptable type), a tuple with one element is created and returned. :param section: config section name :type section: str :param option: option name :type option: str :param types: list of authorized types :type types: list :param extend: extend the tuple with the last value until length is reached :type extend: int """ values = self.gettyped(section, option) types, color, path = self._get_authorized_types(types) if not isinstance(values, (tuple, list)): if not isinstance(values, types): raise ValueError("Invalid config value [{}][{}]={}".format(section, option, values)) values = (values,) else: # Check if one value is given or if it is a list of value if color and len(values) == 3 and all(isinstance(elem, int) for elem in values): values = (values,) elif not all(isinstance(elem, types) for elem in values): raise ValueError("Invalid config value [{}][{}]={}".format(section, option, values)) if path: new_values = [] for v in values: if isinstance(v, basestring): new_values.append(self._get_abs_path(v)) else: new_values.append(v) values = tuple(new_values) while len(values) < extend: values += (values[-1],) return values