(self, other)
Called by comparison operations.

        Should return a negative integer if self < other, zero if self
        == other, a positive integer if self > other.

        Networks with different prefixlen are considered non-equal.
        Networks with the same prefixlen and differing addresses are
        considered non equal but are compared by thair base address
        integer value to aid sorting of IP objects.

        The Version of Objects is not put into consideration.

        >>> IP('10.0.0.0/24') > IP('10.0.0.0')
        1
        >>> IP('10.0.0.0/24') < IP('10.0.0.0')
        0
        >>> IP('10.0.0.0/24') < IP('12.0.0.0/24')
        1
        >>> IP('10.0.0.0/24') > IP('12.0.0.0/24')
        0
Called by comparison operations.
Called by comparison operations .
def __cmp__(self, other):
        """Called by comparison operations.

        Should return a negative integer if self < other, zero if self
        == other, a positive integer if self > other.

        Networks with different prefixlen are considered non-equal.
        Networks with the same prefixlen and differing addresses are
        considered non equal but are compared by thair base address
        integer value to aid sorting of IP objects.

        The Version of Objects is not put into consideration.

        >>> IP('10.0.0.0/24') > IP('10.0.0.0')
        1
        >>> IP('10.0.0.0/24') < IP('10.0.0.0')
        0
        >>> IP('10.0.0.0/24') < IP('12.0.0.0/24')
        1
        >>> IP('10.0.0.0/24') > IP('12.0.0.0/24')
        0

        """

        # Im not really sure if this is "the right thing to do"
        if self._prefixlen < other.prefixlen():
            return (other.prefixlen() - self._prefixlen)
        elif self._prefixlen > other.prefixlen():

            # Fixed bySamuel Krempp <krempp@crans.ens-cachan.fr>:

            # The bug is quite obvious really (as 99% bugs are once
            # spotted, isn't it ? ;-) Because of precedence of
            # multiplication by -1 over the substraction, prefixlen
            # differences were causing the __cmp__ function to always
            # return positive numbers, thus the function was failing
            # the basic assumptions for a __cmp__ function.

            # Namely we could have (a > b AND b > a), when the
            # prefixlen of a and b are different.  (eg let
            # a=IP("1.0.0.0/24"); b=IP("2.0.0.0/16");) thus, anything
            # could happen when launching a sort algorithm..
            # everything's in order with the trivial, attached patch.

            return (self._prefixlen - other.prefixlen()) * -1
        else:
            if self.ip < other.ip:
                return -1
            elif self.ip > other.ip:
                return 1
            else:
                return 0
def __cmp__ ( self , other ) : # Im not really sure if this is "the right thing to do" if self . _prefixlen < other . prefixlen ( ) : return ( other . prefixlen ( ) - self . _prefixlen ) elif self . _prefixlen > other . prefixlen ( ) : # Fixed bySamuel Krempp <krempp@crans.ens-cachan.fr>: # The bug is quite obvious really (as 99% bugs are once # spotted, isn't it ? ;-) Because of precedence of # multiplication by -1 over the substraction, prefixlen # differences were causing the __cmp__ function to always # return positive numbers, thus the function was failing # the basic assumptions for a __cmp__ function. # Namely we could have (a > b AND b > a), when the # prefixlen of a and b are different.  (eg let # a=IP("1.0.0.0/24"); b=IP("2.0.0.0/16");) thus, anything # could happen when launching a sort algorithm.. # everything's in order with the trivial, attached patch. return ( self . _prefixlen - other . prefixlen ( ) ) * - 1 else : if self . ip < other . ip : return - 1 elif self . ip > other . ip : return 1 else : return 0