Python ipaddress.get_mixed_type_key() Examples
The following are 6
code examples of ipaddress.get_mixed_type_key().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ipaddress
, or try the search function
.
Example #1
Source File: test_ipaddress.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_mixed_type_key(self): # with get_mixed_type_key, you can sort addresses and network. v4_ordered = [self.v4addr, self.v4net, self.v4intf] v6_ordered = [self.v6addr, self.v6net, self.v6intf] self.assertEqual(v4_ordered, sorted(self.v4_objects, key=ipaddress.get_mixed_type_key)) self.assertEqual(v6_ordered, sorted(self.v6_objects, key=ipaddress.get_mixed_type_key)) self.assertEqual(v4_ordered + v6_ordered, sorted(self.objects, key=ipaddress.get_mixed_type_key)) self.assertEqual(NotImplemented, ipaddress.get_mixed_type_key(object))
Example #2
Source File: test_ipaddress.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_mixed_type_key(self): # with get_mixed_type_key, you can sort addresses and network. v4_ordered = [self.v4addr, self.v4net, self.v4intf] v6_ordered = [self.v6addr, self.v6net, self.v6intf] self.assertEqual(v4_ordered, sorted(self.v4_objects, key=ipaddress.get_mixed_type_key)) self.assertEqual(v6_ordered, sorted(self.v6_objects, key=ipaddress.get_mixed_type_key)) self.assertEqual(v4_ordered + v6_ordered, sorted(self.objects, key=ipaddress.get_mixed_type_key)) self.assertEqual(NotImplemented, ipaddress.get_mixed_type_key(object))
Example #3
Source File: test_ipaddress.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_mixed_type_key(self): # with get_mixed_type_key, you can sort addresses and network. v4_ordered = [self.v4addr, self.v4net, self.v4intf] v6_ordered = [self.v6addr, self.v6net, self.v6intf] self.assertEqual(v4_ordered, sorted(self.v4_objects, key=ipaddress.get_mixed_type_key)) self.assertEqual(v6_ordered, sorted(self.v6_objects, key=ipaddress.get_mixed_type_key)) self.assertEqual(v4_ordered + v6_ordered, sorted(self.objects, key=ipaddress.get_mixed_type_key)) self.assertEqual(NotImplemented, ipaddress.get_mixed_type_key(object))
Example #4
Source File: nacaddr.py From capirca with Apache License 2.0 | 5 votes |
def CollapseAddrList(addresses, complement_addresses=None): """Collapse an array of IP objects. Example: CollapseAddrList( [IPv4('1.1.0.0/24'), IPv4('1.1.1.0/24')]) -> [IPv4('1.1.0.0/23')] Note: this works just as well with IPv6 addresses too. On platforms that support exclude semantics with most specific match, this method should _always_ be called with complement addresses supplied. Not doing so can lead to *reversal* of intent. Consider this case: destination-address:: 10.0.0.0/8, 10.0.0.0/10 destination-exclude:: 10.0.0.0/9 Without optimization, 10.0.0.1 will _match_. With optimization, most specific prefix will _not_ match, reversing the intent. Supplying complement_addresses allows this method to consider those implications. Args: addresses: list of ipaddress.IPNetwork objects complement_addresses: list of ipaddress.IPNetwork objects that, if present, will be considered to avoid harmful optimizations. Returns: list of ipaddress.IPNetwork objects """ complements_dict = collections.defaultdict(list) address_set = set([a.network_address for a in addresses]) for ca in complement_addresses or []: if ca.network_address in address_set: complements_dict[ca.network_address].append(ca) return _CollapseAddrListInternal( sorted(addresses, key=ipaddress.get_mixed_type_key), complements_dict)
Example #5
Source File: nacaddr.py From capirca with Apache License 2.0 | 5 votes |
def SortAddrList(addresses): """Return a sorted list of nacaddr objects.""" return sorted(addresses, key=ipaddress.get_mixed_type_key)
Example #6
Source File: test_ipaddress.py From android_universal with MIT License | 5 votes |
def test_mixed_type_key(self): # with get_mixed_type_key, you can sort addresses and network. v4_ordered = [self.v4addr, self.v4net, self.v4intf] v6_ordered = [self.v6addr, self.v6net, self.v6intf] self.assertEqual(v4_ordered, sorted(self.v4_objects, key=ipaddress.get_mixed_type_key)) self.assertEqual(v6_ordered, sorted(self.v6_objects, key=ipaddress.get_mixed_type_key)) self.assertEqual(v4_ordered + v6_ordered, sorted(self.objects, key=ipaddress.get_mixed_type_key)) self.assertEqual(NotImplemented, ipaddress.get_mixed_type_key(object))