File tree 2 files changed +21
-0
lines changed
Filter options
2 files changed +21
-0
lines changed
Original file line number Diff line number Diff line change @@ -233,6 +233,16 @@ def addresses_by_version(self, version: IPVersion) -> List[bytes]:
233
233
* (addr .packed for addr in self ._ipv6_addresses ),
234
234
]
235
235
236
+ def ip_addresses_by_version (
237
+ self , version : IPVersion
238
+ ) -> Union [List [ipaddress .IPv4Address ], List [ipaddress .IPv6Address ], List [ipaddress ._BaseAddress ]]:
239
+ """List ip_address objects matching IP version."""
240
+ if version == IPVersion .V4Only :
241
+ return self ._ipv4_addresses
242
+ if version == IPVersion .V6Only :
243
+ return self ._ipv6_addresses
244
+ return [* self ._ipv4_addresses , * self ._ipv6_addresses ]
245
+
236
246
def parsed_addresses (self , version : IPVersion = IPVersion .All ) -> List [str ]:
237
247
"""List addresses in their parsed string form."""
238
248
result = self .addresses_by_version (version )
Original file line number Diff line number Diff line change 9
9
import socket
10
10
import threading
11
11
import unittest
12
+ from ipaddress import ip_address
12
13
from threading import Event
13
14
from typing import Iterable , List , Optional
14
15
from unittest .mock import patch
@@ -540,8 +541,18 @@ def test_multiple_addresses():
540
541
for info in infos :
541
542
assert info .addresses == [address ]
542
543
assert info .addresses_by_version (r .IPVersion .All ) == [address , address_v6 , address_v6_ll ]
544
+ assert info .ip_addresses_by_version (r .IPVersion .All ) == [
545
+ ip_address (address ),
546
+ ip_address (address_v6 ),
547
+ ip_address (address_v6_ll ),
548
+ ]
543
549
assert info .addresses_by_version (r .IPVersion .V4Only ) == [address ]
550
+ assert info .ip_addresses_by_version (r .IPVersion .V4Only ) == [ip_address (address )]
544
551
assert info .addresses_by_version (r .IPVersion .V6Only ) == [address_v6 , address_v6_ll ]
552
+ assert info .ip_addresses_by_version (r .IPVersion .V6Only ) == [
553
+ ip_address (address_v6 ),
554
+ ip_address (address_v6_ll ),
555
+ ]
545
556
assert info .parsed_addresses () == [address_parsed , address_v6_parsed , address_v6_ll_parsed ]
546
557
assert info .parsed_addresses (r .IPVersion .V4Only ) == [address_parsed ]
547
558
assert info .parsed_addresses (r .IPVersion .V6Only ) == [address_v6_parsed , address_v6_ll_parsed ]
You can’t perform that action at this time.
0 commit comments