Compare two IP objects. This is only concerned about the comparison of the integer representation of the network addresses. This means that the host bits aren't considered at all in this method. If you want to compare host bits, you can easily enough do a '
(self, other)
| 861 | (s1, s2, other)) |
| 862 | |
| 863 | def compare_networks(self, other): |
| 864 | """Compare two IP objects. |
| 865 | |
| 866 | This is only concerned about the comparison of the integer |
| 867 | representation of the network addresses. This means that the |
| 868 | host bits aren't considered at all in this method. If you want |
| 869 | to compare host bits, you can easily enough do a |
| 870 | 'HostA._ip < HostB._ip' |
| 871 | |
| 872 | Args: |
| 873 | other: An IP object. |
| 874 | |
| 875 | Returns: |
| 876 | If the IP versions of self and other are the same, returns: |
| 877 | |
| 878 | -1 if self < other: |
| 879 | eg: IPv4Network('192.0.2.0/25') < IPv4Network('192.0.2.128/25') |
| 880 | IPv6Network('2001:db8::1000/124') < |
| 881 | IPv6Network('2001:db8::2000/124') |
| 882 | 0 if self == other |
| 883 | eg: IPv4Network('192.0.2.0/24') == IPv4Network('192.0.2.0/24') |
| 884 | IPv6Network('2001:db8::1000/124') == |
| 885 | IPv6Network('2001:db8::1000/124') |
| 886 | 1 if self > other |
| 887 | eg: IPv4Network('192.0.2.128/25') > IPv4Network('192.0.2.0/25') |
| 888 | IPv6Network('2001:db8::2000/124') > |
| 889 | IPv6Network('2001:db8::1000/124') |
| 890 | |
| 891 | Raises: |
| 892 | TypeError if the IP versions are different. |
| 893 | |
| 894 | """ |
| 895 | # does this need to raise a ValueError? |
| 896 | if self.version != other.version: |
| 897 | raise TypeError('%s and %s are not of the same type' % ( |
| 898 | self, other)) |
| 899 | # self.version == other.version below here: |
| 900 | if self.network_address < other.network_address: |
| 901 | return -1 |
| 902 | if self.network_address > other.network_address: |
| 903 | return 1 |
| 904 | # self.network_address == other.network_address below here: |
| 905 | if self.netmask < other.netmask: |
| 906 | return -1 |
| 907 | if self.netmask > other.netmask: |
| 908 | return 1 |
| 909 | return 0 |
| 910 | |
| 911 | def _get_networks_key(self): |
| 912 | """Network-only key function. |
no outgoing calls