Пример #1
0
 def _interpolate(self, section, option, value, d):
     if isinstance(value, basestring):
         value = self._interpolate_environment_variables(value)
     elif isinstance(value, dict):
         for i in value:
             value[i] = self._interpolate_environment_variables(value[i])
     else:
         for i in range(0, len(value)):
             value[i] = self._interpolate_environment_variables(value[i])
     value = SafeConfigParser._interpolate(self, section, option, value, d)
     return value
Пример #2
0
 def _interpolate(self, section, option, value, d):
     if isinstance(value, basestring):
         value = self._interpolate_environment_variables(value)
     elif isinstance(value, dict):
         for i in value:
             value[i] = self._interpolate_environment_variables(value[i])
     else:
         for i in range(0, len(value)):
             value[i] = self._interpolate_environment_variables(value[i])
     value = SafeConfigParser._interpolate(self, section, option, value, d)
     return value
Пример #3
0
def diff_ini(first, second, diff=None, existing_only=False):
    """Diff ini files

    Generate a parser with any value in the second that is different in the first.
    Returns a ConfigParser.
    Takes interpolation into account. Does not include values that disappeared."""
    from ConfigParser import _Chainmap
    first = asParser(first)
    second = asParser(second)
    # TODO: Look at first both in raw and formatted versions
    diff = diff or Parser()
    interpolating = SafeConfigParser()
    for section in second.sections():
        if section != 'DEFAULT' and not first.has_section(section):
            if not existing_only:
                diff.add_section(section)
                for option in second.options(section):
                    value = second.get(section, option)
                    diff.set(section, option, value)
        else:
            vars = _Chainmap(second._sections[section],
                             first._sections[section], second._defaults,
                             first._defaults)
            for option, value2 in second.items(section):
                if not first.has_option(section, option):
                    if not existing_only:
                        ensureSection(diff, section)
                        diff.set(section, option, value2)
                    continue
                value1 = first.get(section, option)
                if value1 != value2 and '%(' in value1:
                    # try to interpolate, and see if it would amount to the same.
                    try:
                        value1 = interpolating._interpolate(
                            section, option, value1, vars)
                    except Exception as e:
                        pass
                if value1 != value2:
                    ensureSection(diff, section)
                    diff.set(section, option, value2)
    return diff
Пример #4
0
 def _interpolate(self, section, option, rawval, args):
     d = self.extravars() if '__extra__' not in args else args
     if args and args != d:
         for key, value in args.items():
             d[self.optionxform(key)] = value
     return SafeConfigParser._interpolate(self, section, option, rawval, d)
Пример #5
0
 def _interpolate(self, section, option, value, d):
     return SafeConfigParser._interpolate(
         self, section, option,
         self._interpolate_environment_variables(value), d)
Пример #6
0
 def _interpolate(self, section, option, rawval, defs):
     if self._DEFAULT_INTERPOLATION is None:
         return SafeConfigParser._interpolate(self, section, option,
                                              rawval, defs)
     return self._DEFAULT_INTERPOLATION.before_get(
         self, section, option, rawval, defs)
Пример #7
0
 def _interpolate(self, section, option, value, d):
     return SafeConfigParser._interpolate(self, section, option, self._interpolate_environment_variables(value), d)
Пример #8
0
 def _interpolate(self, section, option, rawval, defs):
     if self._DEFAULT_INTERPOLATION is None:
         return SafeConfigParser._interpolate(self, section, option, rawval, defs)
     return self._DEFAULT_INTERPOLATION.before_get(self, section, option, rawval, defs)