Remove unnecessary manipulation with IPv6 scope outside of the IPv6Address object instance

This commit is contained in:
Bo Maryniuk 2018-09-19 00:32:22 +02:00
parent c314e1c675
commit 3ce265e7cc

View file

@ -1029,18 +1029,13 @@ def parse_resolv(src='/etc/resolv.conf'):
try:
(directive, arg) = (line[0].lower(), line[1:])
# Drop everything after # or ; (comments)
arg = list(itertools.takewhile(
lambda x: x[0] not in ('#', ';'), arg))
arg = list(itertools.takewhile(lambda x: x[0] not in ('#', ';'), arg))
if directive == 'nameserver':
# Split the scope (interface) if it is present
addr, scope = arg[0].split('%', 1) if '%' in arg[0] else (arg[0], '')
addr = arg[0]
try:
ip_addr = ipaddress.ip_address(addr)
version = ip_addr.version
# Rejoin scope after address validation
if scope:
ip_addr = '%'.join((str(ip_addr), scope))
ip_addr = str(ip_addr)
if ip_addr not in nameservers:
nameservers.append(ip_addr)
if version == 4 and ip_addr not in ip4_nameservers: