예제 #1
0
def config_from_file(file_obj):
    try:
        config = parser.parseFile(file_obj)
    except pyp.ParseException as e:
        name = getattr(file_obj, 'name', file_obj)
        raise errors.ConfigurationError('%s: %s' % (name, e))
    def build_section(name):
        return ConfigSection(config[name])
    return mappings.LazyValDict(config.keys, build_section)
예제 #2
0
파일: mke2fsformat.py 프로젝트: ulm/pkgcore
def config_from_file(file_obj):
    try:
        config = parser.parseFile(file_obj)
    except pyp.ParseException as e:
        name = getattr(file_obj, 'name', file_obj)
        raise errors.ConfigurationError(f'{name}: {e}') from e

    def build_section(name):
        return dhcpformat.ConfigSection(config[name])

    return mappings.LazyValDict(config.keys, build_section)
예제 #3
0
파일: cparser.py 프로젝트: ulm/pkgcore
def config_from_file(file_obj):
    """
    generate a config dict

    :param file_obj: file protocol instance
    :return: :obj:`snakeoil.mappings.LazyValDict` instance
    """
    cparser = CaseSensitiveConfigParser()
    try:
        cparser.read_file(file_obj)
    except configparser.ParsingError as e:
        raise errors.ParsingError(f'while parsing {file_obj}', e) from e

    def get_section(section):
        return basics.ConfigSectionFromStringDict(dict(cparser.items(section)))

    return mappings.LazyValDict(cparser.sections, get_section)
예제 #4
0
파일: cparser.py 프로젝트: chutz/pkgcore
def config_from_file(file_obj):
    """
    generate a config dict

    :param file_obj: file protocol instance
    :return: :obj:`snakeoil.mappings.LazyValDict` instance
    """
    cparser = CaseSensitiveConfigParser()
    try:
        if sys.hexversion < 0x03020000:
            cparser.readfp(file_obj)
        else:
            cparser.read_file(file_obj)
    except ConfigParser.ParsingError as pe:
        raise errors.ParsingError("while parsing %s" % (file_obj, ), pe)

    def get_section(section):
        return basics.ConfigSectionFromStringDict(dict(cparser.items(section)))

    return mappings.LazyValDict(cparser.sections, get_section)
예제 #5
0
 def setup_method(self, method):
     super().setup_method(method)
     self.dict = mappings.LazyValDict(a_dozen, self.negate)
예제 #6
0
 def setup_method(self, method):
     super().setup_method(method)
     self.dict = mappings.LazyValDict(list(range(12)), self.negate)
예제 #7
0
 def setUp(self):
     RememberingNegateMixin.setUp(self)
     self.dict = mappings.LazyValDict(a_dozen, self.negate)
예제 #8
0
 def setUp(self):
     RememberingNegateMixin.setUp(self)
     self.dict = mappings.LazyValDict(range(12), self.negate)