try:
    from ConfigParser import ConfigParser
except ImportError:
    # ConfigParser module has been renamed to configparser in python 3
    from configparser import ConfigParser

from lib.irma.configuration.config import Configuration, ConfigurationSection
from lib.irma.common.exceptions import IrmaConfigurationError
from lib.irma.common.objects import AttributeDictionary

class IniConfiguration(Configuration):
    """Windows ini-like configuration file parser."""

    def __init__(self, cfg_file):
        """@param cfg_file: file path of the configuration file."""
        config = ConfigParser()
        config.read(cfg_file)

        for section in config.sections():
            setattr(self, section, ConfigurationSection())
            for name, raw_value in config.items(section):
                try:
                    value = config.getboolean(section, name)
                except ValueError:
                    try:
                        value = config.getint(section, name)
                    except ValueError:
                        value = config.get(section, name)
                setattr(getattr(self, section), name, value)

@@ -173,16 +173,77 @@
 gParser%0A
+from lib.irma.common.exceptions import IrmaConfigurationError
 %0Afrom li
@@ -316,126 +316,8 @@
 tion
-%0Afrom lib.irma.common.exceptions import IrmaConfigurationError%0Afrom lib.irma.common.objects import AttributeDictionary
 %0A%0Acl
@@ -698,19 +698,8 @@
 name
-, raw_value
  in 
@@ -709,12 +709,14 @@
 fig.
-item
+option
 s(se
@@ -1084,8 +1084,1880 @@
  value)%0A
+%0Aclass TemplatedConfiguration(Configuration):%0A    %22%22%22Windows ini-like configuration file parser with template for required keys and their types.%22%22%22%0A    boolean = 0%0A    integer = 1%0A    string = 2%0A%0A    def __init__(self, cfg_file, template):%0A        %22%22%22%0A        @param cfg_file: file path of the configuration file.%0A        @param template: list of tuples with %7Bsection:(key_name, key_type)%7D%0A        %22%22%22%0A        config = ConfigParser()%0A        config.read(cfg_file)%0A        for section in template.keys():%0A            # Check if section is present in ini file%0A            if section not in config.sections():%0A                raise IrmaConfigurationError(%22file %3C%25s%3E missing section %5B%25s%5D%22 %25 (cfg_file, section,))%0A            setattr(self, section, ConfigurationSection())%0A%0A            for (key_name, key_type, key_def_value) in template%5Bsection%5D:%0A                if not config.has_option(section, key_name):%0A                    # If key not found but a default value exists, set it%0A                    if key_def_value:%0A                        setattr(getattr(self, section), key_name, key_def_value)%0A                        continue%0A                    else:%0A                        raise IrmaConfigurationError(%22file %3C%25s%3E section %5B%25s%5D missing key %5B%25s%5D%22 %25 (cfg_file, section, key_name,))%0A                try:%0A                    if key_type == self.boolean:%0A                        value = config.getboolean(section, key_name)%0A                    elif key_type == self.integer:%0A                        value = config.getint(section, key_name)%0A                    else:%0A                        value = config.get(section, key_name)%0A                    setattr(getattr(self, section), key_name, value)%0A                except ValueError:%0A                    raise IrmaConfigurationError(%22file %3C%25s%3E missing section %5B%25s%5D Wrong type for key %5B%25s%5D%22 %25 (cfg_file, section, key_name,))%0A

add TemplatedConfiguration