Skip to content

In NetworkFile does not handle multiple addresses in [Network] section #1

Description

@ghuband

Using Python 3.5.
Fails to parse a network file with multiple "Address" entries in [Network]. Example:

File to parse:

[Match]
Name = br0

[Network]
DHCP = no
Address = 192.168.200.20/24
Address=192.168.1.188
Gateway=192.168.1.1

Code to parse:

# python3
Python 3.5.2 (default, Jul 17 2019, 17:56:15) 
[GCC 6.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sysdfiles import NetworkFile
>>> nf=NetworkFile("/etc/systemd/network/br0.network")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/site-packages/sysdfiles/network_file.py", line 10, in __init__
    IniFile.__init__(self, file_name)
  File "/usr/lib/python3.5/site-packages/sysdfiles/ini_file.py", line 56, in __init__
    line, options = self._process_line(line, full_line, options)
  File "/usr/lib/python3.5/site-packages/sysdfiles/ini_file.py", line 72, in _process_line
    i, existing = IniFile.find_option(options, line.name)
  File "/usr/lib/python3.5/site-packages/sysdfiles/ini_file.py", line 497, in find_option
    if line.name.lower() == name:
AttributeError: 'list' object has no attribute 'name'

Suggested fix:

    def find_option(options, name):
        name = name.lower()
        for i, line in enumerate(options):
            if isinstance(line, list):
                for j, lline in enumerate(line):
                    if lline.name.lower() == name:
                        return j, lline
            else:
                if line.name.lower() == name:
                    return i, line
        return -1, None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions