MCPcopy Index your code
hub / github.com/python/cpython / address_exclude

Method address_exclude

Lib/ipaddress.py:788–861  ·  view source on GitHub ↗

Remove an address from a larger block. For example: addr1 = ip_network('192.0.2.0/28') addr2 = ip_network('192.0.2.1/32') list(addr1.address_exclude(addr2)) = [IPv4Network('192.0.2.0/32'), IPv4Network('192.0.2.2/31'), IPv

(self, other)

Source from the content-addressed store, hash-verified

786 return self._prefixlen
787
788 def address_exclude(self, other):
789 """Remove an address from a larger block.
790
791 For example:
792
793 addr1 = ip_network('192.0.2.0/28')
794 addr2 = ip_network('192.0.2.1/32')
795 list(addr1.address_exclude(addr2)) =
796 [IPv4Network('192.0.2.0/32'), IPv4Network('192.0.2.2/31'),
797 IPv4Network('192.0.2.4/30'), IPv4Network('192.0.2.8/29')]
798
799 or IPv6:
800
801 addr1 = ip_network('2001:db8::1/32')
802 addr2 = ip_network('2001:db8::1/128')
803 list(addr1.address_exclude(addr2)) =
804 [ip_network('2001:db8::1/128'),
805 ip_network('2001:db8::2/127'),
806 ip_network('2001:db8::4/126'),
807 ip_network('2001:db8::8/125'),
808 ...
809 ip_network('2001:db8:8000::/33')]
810
811 Args:
812 other: An IPv4Network or IPv6Network object of the same type.
813
814 Returns:
815 An iterator of the IPv(4|6)Network objects which is self
816 minus other.
817
818 Raises:
819 TypeError: If self and other are of differing address
820 versions, or if other is not a network object.
821 ValueError: If other is not completely contained by self.
822
823 """
824 if not self.version == other.version:
825 raise TypeError("%s and %s are not of the same version" % (
826 self, other))
827
828 if not isinstance(other, _BaseNetwork):
829 raise TypeError("%s is not a network object" % other)
830
831 if not other.subnet_of(self):
832 raise ValueError('%s not contained in %s' % (other, self))
833 if other == self:
834 return
835
836 # Make sure we're comparing the network of other.
837 other = other.__class__('%s/%s' % (other.network_address,
838 other.prefixlen))
839
840 s1, s2 = self.subnets()
841 while s1 != other and s2 != other:
842 if other.subnet_of(s1):
843 yield s2
844 s1, s2 = s1.subnets()
845 elif other.subnet_of(s2):

Callers 1

testAddrExcludeMethod · 0.80

Calls 3

subnetsMethod · 0.95
subnet_ofMethod · 0.80
__class__Method · 0.45

Tested by 1

testAddrExcludeMethod · 0.64