Exemplo n.º 1
0
 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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
 def parse_doc(self, content):
     return parse_doc(content)
Exemplo n.º 5
0
def test_smb_conf():
    conf = parse_doc(CONF1)
    assert conf["global"]["workgroup"][0].value == "SAMBA"