mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-08 22:36:48 +02:00
fixes for python < 3.9
This commit is contained in:
@ -460,6 +460,7 @@ Examples:
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
from typing import Dict, Union
|
from typing import Dict, Union
|
||||||
|
import re
|
||||||
import binascii
|
import binascii
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import jc.utils
|
import jc.utils
|
||||||
@ -539,6 +540,11 @@ def parse(
|
|||||||
except Exception:
|
except Exception:
|
||||||
data = data.strip()
|
data = data.strip()
|
||||||
|
|
||||||
|
# python versions < 3.9 do not handle the ipv6 scope, so remove it if parsing fails
|
||||||
|
try:
|
||||||
|
interface = ipaddress.ip_interface(data)
|
||||||
|
except ValueError:
|
||||||
|
data = re.sub(r'%[a-zA-Z0-9]*[^/]', data)
|
||||||
interface = ipaddress.ip_interface(data)
|
interface = ipaddress.ip_interface(data)
|
||||||
|
|
||||||
network_string = str(interface.network).split('/')[0]
|
network_string = str(interface.network).split('/')[0]
|
||||||
@ -566,7 +572,12 @@ def parse(
|
|||||||
teredo_client = None
|
teredo_client = None
|
||||||
teredo_server = None
|
teredo_server = None
|
||||||
if interface.version == 6:
|
if interface.version == 6:
|
||||||
|
# scope_id not available in python version < 3.9
|
||||||
|
try:
|
||||||
scope_id = interface.scope_id
|
scope_id = interface.scope_id
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
ipv4_mapped = str(interface.ipv4_mapped) if interface.ipv4_mapped else None
|
ipv4_mapped = str(interface.ipv4_mapped) if interface.ipv4_mapped else None
|
||||||
sixtofour = str(interface.sixtofour) if interface.sixtofour else None
|
sixtofour = str(interface.sixtofour) if interface.sixtofour else None
|
||||||
teredo_client = str(interface.teredo[1]) if interface.teredo else None
|
teredo_client = str(interface.teredo[1]) if interface.teredo else None
|
||||||
|
Reference in New Issue
Block a user