def test_config_parser(self):
     writer = CustomConfigParser()
     writer.add_section('TEST')
     writer.set('TEST', "Windows:path", "not a valid linux:path!")
     writer.write(open("generated/config.test", "w"))
     # standard reader
     reader = ConfigParser()
     reader.readfp(open("generated/config.test"))
     self.assert_(reader.has_section('TEST'))
     self.assert_(reader.has_option('TEST', "Windows"))
     self.assertEquals(reader.get('TEST', "Windows"), "path = not a valid linux:path!")
     # custom reader
     reader = CustomConfigParser()
     reader.readfp(open("generated/config.test"))
     self.assert_(reader.has_section('TEST'))
     self.assert_(reader.has_option('TEST', "Windows:path"))
     self.assertEquals(reader.get('TEST', "Windows:path"), "not a valid linux:path!")
class FilterSaverMixin(DocSaverMixin):
    """Implements API for saving & loading in a File oriented context"""

    FILTERS = [PeerFilter, FileFilter]

    def __init__(self, encoding=ENCODING):
        DocSaverMixin.__init__(self, encoding)

    # menu
    def save(self, path):
        self.config = CustomConfigParser(self.encoding)
        for name, a_filter in self.filters.items():
            section_name = a_filter.PREFIX + (a_filter.filter_or and "OR_" or "AND_") + name
            if not self.config.has_section(section_name):
                self.config.add_section(section_name)
            for prop_name, value in a_filter.as_dict().items():
                self.config.set(section_name, prop_name, value)
        DocSaverMixin.save(self, path)

    def load(self, path):
        """fill document with information from .profile file"""
        # load config
        if not DocSaverMixin.load(self, path):
            return False
        # synchronize cache
        for section in self.config.sections():
            props = self.config.items(section)
            for filter_class in self.FILTERS:
                name, new_filter = filter_class.from_str(section, props)
                if new_filter is None:
                    continue
                else:
                    self.filters[name] = new_filter
                    break
        # add match all
        self._create_match_all()