mirror of
https://github.com/Cian-H/I-Form_Server_Node_Deployer.git
synced 2025-12-23 22:52:01 +00:00
ip interface passthrough fixed
This commit is contained in:
@@ -4,37 +4,73 @@ from ipaddress import IPv4Address, IPv6Address, ip_address
|
|||||||
class IPAddress:
|
class IPAddress:
|
||||||
def __init__(self, *args, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
self.obj: IPv4Address | IPv6Address = ip_address(*args, **kwargs)
|
self.obj: IPv4Address | IPv6Address = ip_address(*args, **kwargs)
|
||||||
to_passthrough = (
|
# to_passthrough = (
|
||||||
"compressed",
|
# "compressed",
|
||||||
"exploded",
|
# "exploded",
|
||||||
"is_global",
|
# "is_global",
|
||||||
"is_link_local",
|
# "is_link_local",
|
||||||
"is_loopback",
|
# "is_loopback",
|
||||||
"is_multicast",
|
# "is_multicast",
|
||||||
"is_private",
|
# "is_private",
|
||||||
"is_reserved",
|
# "is_reserved",
|
||||||
"is_unspecified",
|
# "is_unspecified",
|
||||||
"max_prefixlen",
|
# "max_prefixlen",
|
||||||
"packed",
|
# "packed",
|
||||||
"reverse_pointer",
|
# "reverse_pointer",
|
||||||
"version",
|
# "version",
|
||||||
)
|
# )
|
||||||
for attrname in to_passthrough:
|
|
||||||
self._passthrough(attrname)
|
|
||||||
|
|
||||||
def _passthrough(self, attrname: str) -> None:
|
@property
|
||||||
"""Passes through an attribute from the underlying IPv4Address or IPv6Address object
|
def compressed(self) -> str:
|
||||||
|
return self.obj.compressed
|
||||||
Args:
|
|
||||||
attrname (str): The name of the attribute to pass through
|
@property
|
||||||
|
def exploded(self) -> str:
|
||||||
Raises:
|
return self.obj.exploded
|
||||||
AttributeError: If the attribute is a method
|
|
||||||
"""
|
@property
|
||||||
attr = getattr(self.obj, attrname)
|
def is_global(self) -> bool:
|
||||||
if callable(attr):
|
return self.obj.is_global
|
||||||
raise AttributeError(f"Passthrough is unavailable for methods ({attrname})")
|
|
||||||
setattr(self, attrname, attr)
|
@property
|
||||||
|
def is_link_local(self) -> bool:
|
||||||
|
return self.obj.is_link_local
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_loopback(self) -> bool:
|
||||||
|
return self.obj.is_loopback
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_multicast(self) -> bool:
|
||||||
|
return self.obj.is_multicast
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_private(self) -> bool:
|
||||||
|
return self.obj.is_private
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_reserved(self) -> bool:
|
||||||
|
return self.obj.is_reserved
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_unspecified(self) -> bool:
|
||||||
|
return self.obj.is_unspecified
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_prefixlen(self) -> int:
|
||||||
|
return self.obj.max_prefixlen
|
||||||
|
|
||||||
|
@property
|
||||||
|
def packed(self) -> bytes:
|
||||||
|
return self.obj.packed
|
||||||
|
|
||||||
|
@property
|
||||||
|
def reverse_pointer(self) -> str:
|
||||||
|
return self.obj.reverse_pointer
|
||||||
|
|
||||||
|
@property
|
||||||
|
def version(self) -> int:
|
||||||
|
return self.obj.version
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return str(self.obj)
|
return str(self.obj)
|
||||||
|
|||||||
@@ -70,11 +70,9 @@ class TestIPInterface:
|
|||||||
|
|
||||||
@given(st.ip_addresses(v=4))
|
@given(st.ip_addresses(v=4))
|
||||||
def test_ipv4_attr_passthrough(self, ip: IPv4Address):
|
def test_ipv4_attr_passthrough(self, ip: IPv4Address):
|
||||||
# Should be able to access all attributes of ipaddress.IPv4Address directly,
|
|
||||||
# not just a copy of the attribute object at instantiation
|
|
||||||
ip_addr = ip_interface.IPAddress(str(ip))
|
ip_addr = ip_interface.IPAddress(str(ip))
|
||||||
for attr in self.TEST_ATTRS:
|
for attr in self.TEST_ATTRS:
|
||||||
assert getattr(ip_addr, attr) is getattr(ip_addr.obj, attr)
|
assert getattr(ip_addr, attr) == getattr(ip_addr.obj, attr)
|
||||||
|
|
||||||
@given(st.ip_addresses(v=4))
|
@given(st.ip_addresses(v=4))
|
||||||
def test_ipv4_bool(self, ip: IPv4Address):
|
def test_ipv4_bool(self, ip: IPv4Address):
|
||||||
@@ -89,11 +87,9 @@ class TestIPInterface:
|
|||||||
|
|
||||||
@given(st.ip_addresses(v=6))
|
@given(st.ip_addresses(v=6))
|
||||||
def test_ipv6_attr_passthrough(self, ip: IPv6Address):
|
def test_ipv6_attr_passthrough(self, ip: IPv6Address):
|
||||||
# Should be able to access all attributes of ipaddress.IPv4Address directly,
|
|
||||||
# not just a copy of the attribute object at instantiation
|
|
||||||
ip_addr = ip_interface.IPAddress(str(ip))
|
ip_addr = ip_interface.IPAddress(str(ip))
|
||||||
for attr in self.TEST_ATTRS:
|
for attr in self.TEST_ATTRS:
|
||||||
assert getattr(ip_addr, attr) is getattr(ip_addr.obj, attr)
|
assert getattr(ip_addr, attr) == getattr(ip_addr.obj, attr)
|
||||||
|
|
||||||
@given(st.ip_addresses(v=6))
|
@given(st.ip_addresses(v=6))
|
||||||
def test_ipv6_bool(self, ip: IPv6Address):
|
def test_ipv6_bool(self, ip: IPv6Address):
|
||||||
|
|||||||
Reference in New Issue
Block a user