Пример #1
0
    def read(self, filenames):
        # read the ini file the standard way
        BaseConfigParser.read(self, filenames)

        # convert _defaults to SortedDict int _mydefaults
        self._mydefaults = SortedDict(self._defaults)

        # set it empty to avoid interference with other sections
        self._defaults = SortedDict()

        # convert as well all sections to SortedDict
        for section in self._sections:
            self._sections[section] = SortedDict(self._sections[section])

        # and finally, convert the section list itself to SortedDict
        self._sections = SortedDict(self._sections)
Пример #2
0
class FileConfigParser(BaseConfigParser):
    """
    This class is a wrapper to python's ConfigParser to avoid the
    automatic merge between a section and the DEFAULT section.
    It also forces ConfigParser to use SortedDict instead of builtin
    dict.
    """
    import ConfigParser as CP
    CP.__builtins__['dict'] = SortedDict

    def read(self, filenames):
        # read the ini file the standard way
        BaseConfigParser.read(self, filenames)

        # convert _defaults to SortedDict int _mydefaults
        self._mydefaults = SortedDict(self._defaults)

        # set it empty to avoid interference with other sections
        self._defaults = SortedDict()

        # convert as well all sections to SortedDict
        for section in self._sections:
            self._sections[section] = SortedDict(self._sections[section])

        # and finally, convert the section list itself to SortedDict
        self._sections = SortedDict(self._sections)


    def defaults(self):
        # returns the real defaults
        return self._mydefaults

    def add_section(self, section):
        # add a section the standard way
        BaseConfigParser.add_section(self, section)
        # and convert it to a SortedDict
        self._sections[section] = SortedDict()

    def write(self, fp):
        # put _defaults back in place before writing
        self._mydefaults.update(self._defaults)
        self._defaults = self._mydefaults
        # write in alpha-sorted order
        BaseConfigParser.write(self, fp)
        # and set it back to an empty dict
        self._defaults = SortedDict()
Пример #3
0
 def write(self, fp):
     # put _defaults back in place before writing
     self._mydefaults.update(self._defaults)
     self._defaults = self._mydefaults
     # write in alpha-sorted order
     BaseConfigParser.write(self, fp)
     # and set it back to an empty dict
     self._defaults = SortedDict()
Пример #4
0
class FileConfigParser(BaseConfigParser):
    """
    This class is a wrapper to python's ConfigParser to avoid the
    automatic merge between a section and the DEFAULT section.
    It also forces ConfigParser to use SortedDict instead of builtin
    dict.
    """
    import ConfigParser as CP
    CP.__builtins__['dict'] = SortedDict

    def read(self, filenames):
        # read the ini file the standard way
        BaseConfigParser.read(self, filenames)

        # convert _defaults to SortedDict int _mydefaults
        self._mydefaults = SortedDict(self._defaults)

        # set it empty to avoid interference with other sections
        self._defaults = SortedDict()

        # convert as well all sections to SortedDict
        for section in self._sections:
            self._sections[section] = SortedDict(self._sections[section])

        # and finally, convert the section list itself to SortedDict
        self._sections = SortedDict(self._sections)

    def defaults(self):
        # returns the real defaults
        return self._mydefaults

    def add_section(self, section):
        # add a section the standard way
        BaseConfigParser.add_section(self, section)
        # and convert it to a SortedDict
        self._sections[section] = SortedDict()

    def write(self, fp):
        # put _defaults back in place before writing
        self._mydefaults.update(self._defaults)
        self._defaults = self._mydefaults
        # write in alpha-sorted order
        BaseConfigParser.write(self, fp)
        # and set it back to an empty dict
        self._defaults = SortedDict()
Пример #5
0
    def read(self, filenames):
        # read the ini file the standard way
        BaseConfigParser.read(self, filenames)

        # convert _defaults to SortedDict int _mydefaults
        self._mydefaults = SortedDict(self._defaults)

        # set it empty to avoid interference with other sections
        self._defaults = SortedDict()

        # convert as well all sections to SortedDict
        for section in self._sections:
            self._sections[section] = SortedDict(self._sections[section])

        # and finally, convert the section list itself to SortedDict
        self._sections = SortedDict(self._sections)
Пример #6
0
 def add_section(self, section):
     # add a section the standard way
     BaseConfigParser.add_section(self, section)
     # and convert it to a SortedDict
     self._sections[section] = SortedDict()