MCPcopy Index your code
hub / github.com/RustPython/RustPython / address_exclude

Method address_exclude

Lib/ipaddress.py:791–864  ·  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

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

Callers 1

testAddrExcludeMethod · 0.80

Calls 4

subnetsMethod · 0.95
isinstanceFunction · 0.85
subnet_ofMethod · 0.80
__class__Method · 0.45

Tested by 1

testAddrExcludeMethod · 0.64