def parse_content(self, content): doc = parse_doc(content) dict_all = {} for section in doc: section_dict = {} option_names = set(o.name for o in section) for name in option_names: options = [str(o.value) for o in section[name]] section_dict[name] = options[0] if len(options) == 1 else options dict_all[section.name] = section_dict self.data = dict_all
def parse_systemd_ini(content): """Function to parse config format file, the result format is dictionary""" doc = parse_doc(content) dict_all = {} for section in doc: section_dict = {} option_names = set(o.name for o in section) for name in option_names: options = [str(o.value) for o in section[name]] section_dict[name] = options[0] if len(options) == 1 else options dict_all[section.name] = section_dict return dict_all
def parse_systemd_ini(content): """ .. warning:: This function is deprecated, please use :py:class:`SystemdConf` instead. Function to parse config format file, the result format is dictionary. """ deprecated(parse_systemd_ini, "Use the `SystemdConf` class instead.") doc = parse_doc(content) dict_all = {} for section in doc: section_dict = {} option_names = set(o.name for o in section) for name in option_names: options = [str(o.value) for o in section[name]] section_dict[name] = options[0] if len(options) == 1 else options dict_all[section.name] = section_dict return dict_all
def parse_doc(self, content): return parse_doc(content)
def test_smb_conf(): conf = parse_doc(CONF1) assert conf["global"]["workgroup"][0].value == "SAMBA"