Ejemplo n.º 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)
Ejemplo n.º 2
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(f'{name}: {e}') from e

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

    return mappings.LazyValDict(config.keys, build_section)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
 def setup_method(self, method):
     super().setup_method(method)
     self.dict = mappings.LazyValDict(a_dozen, self.negate)
Ejemplo n.º 6
0
 def setup_method(self, method):
     super().setup_method(method)
     self.dict = mappings.LazyValDict(list(range(12)), self.negate)
Ejemplo n.º 7
0
 def setUp(self):
     RememberingNegateMixin.setUp(self)
     self.dict = mappings.LazyValDict(a_dozen, self.negate)
Ejemplo n.º 8
0
 def setUp(self):
     RememberingNegateMixin.setUp(self)
     self.dict = mappings.LazyValDict(range(12), self.negate)