How to use the configparser.ConfigParser.get function in configparser

To help you get started, we’ve selected a few configparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Python-Markdown / markdown / tests / util.py View on Github external
def get(self, section, option):
        value = ConfigParser.get(self, section, option)
        if option == 'extensions':
            if len(value.strip()):
                return value.split(',')
            else:
                return []
        if value.lower() in ['yes', 'true', 'on', '1']:
            return True
        if value.lower() in ['no', 'false', 'off', '0']:
            return False
        return value
github maurosoria / dirsearch / lib / utils / DefaultConfigParser.py View on Github external
def safe_get(self, section, option, default, allowed=None):
		try:
			result = configparser.ConfigParser.get(self, section, option)
			if allowed is not None:
				return result if result in allowed else default
			else:
				return result
		except (configparser.NoSectionError, configparser.NoOptionError):
			return default
github werdeil / pibooth / pibooth / config.py View on Github external
def get(self, section, option, **kwargs):
        """Override the default function of ConfigParser to add a
        default value if section or option is not found.
        """
        if self.has_section(section) and self.has_option(section, option):
            return ConfigParser.get(self, section, option, **kwargs)
        return str(DEFAULT[section][option][0])
github SamSchott / maestral-dropbox / maestral / config / user.py View on Github external
section = self._check_section_option(section, option)

        if not self.has_section(section):
            if default is NoDefault:
                raise cp.NoSectionError(section)
            else:
                self.add_section(section)

        if not self.has_option(section, option):
            if default is NoDefault:
                raise cp.NoOptionError(option, section)
            else:
                self.set(section, option, default)
                return default

        value = cp.ConfigParser.get(self, section, option, raw=self.raw)
        # Use type of default_value to parse value correctly
        default_value = self.get_default(section, option)
        if isinstance(default_value, bool):
            value = ast.literal_eval(value)
        elif isinstance(default_value, float):
            value = float(value)
        elif isinstance(default_value, int):
            value = int(value)
        else:
            try:
                # lists, tuples, ...
                value = ast.literal_eval(value)
            except (SyntaxError, ValueError):
                pass
        return value
github cea-hpc / clustershell / lib / ClusterShell / Defaults.py View on Github external
def _parser_get_integer_tuple(parser, section, option, **kwargs):
    """
    Compatible converter for parsing tuple of integers until we can use
    converters from new ConfigParser (Python 3.5+).
    """
    return _converter_integer_tuple(
        ConfigParser.get(parser, section, option, **kwargs))
github eblot / pybootd / pybootd / util.py View on Github external
def get(self, section, option, default=None, raw=True, vars=None,
            fallback=None):
        """Return the section:option value if it exists, or the default value
           if either the section or the option is missing"""
        if not self.has_section(section):
            return default
        if not self.has_option(section, option):
            return default
        return ConfigParser.get(self, section, option, raw=raw, vars=vars,
                                fallback=fallback)
github SamSchott / maestral-dropbox / maestral / config / user.py View on Github external
section = self._check_section_option(section, option)

        if not self.has_section(section):
            if default is NoDefault:
                raise cp.NoSectionError(section)
            else:
                self.add_section(section)

        if not self.has_option(section, option):
            if default is NoDefault:
                raise cp.NoOptionError(option, section)
            else:
                self.set(section, option, default)
                return default

        value = cp.ConfigParser.get(self, section, option, raw=self.raw)
        # Use type of default_value to parse value correctly
        default_value = self.get_default(section, option)
        if isinstance(default_value, bool):
            value = ast.literal_eval(value)
        elif isinstance(default_value, float):
            value = float(value)
        elif isinstance(default_value, int):
            value = int(value)
        else:
            try:
                # lists, tuples, ...
                value = ast.literal_eval(value)
            except (SyntaxError, ValueError):
                pass
        return value
github CWatM / CWatM / cwatm / management_modules / configuration.py View on Github external
def get(self, section, option, raw=False, vars=None, **kwargs):
        """
        def get(self, section, option, raw=False, vars=None
        placeholder replacement

        :param section: section part of the settings file
        :param option: option part of the settings file
        :param raw:
        :param vars:
        :return:
        """

        #h1 = sys.tracebacklimit
        #sys.tracebacklimit = 0  # no long error message
        try:
           r_opt = configparser.ConfigParser.get(self, section, option, raw=True, vars=vars)
        except:
             print(section, option)
             closest = difflib.get_close_matches(option, list(binding.keys()))
             if not closest: closest = ["- no match -"]
             #msg = "No key with the name: \"" + option +" in " + section + "\" in the settings file: \"" + settingsfile[0] + "\"\n"
             msg = "Closest key to the required one is: \"" + closest[0] + "\""
             raise CWATMError(msg)


        #sys.tracebacklimit = h1   # set error message back to default
        if raw:
            return r_opt

        ret = r_opt
        re_newintp1 = r'\$\((\w*):(\w*)\)'  # other section
        re_newintp2 = r'\$\((\w*)\)'  # same section