def intToIp(ip, version):
    """Transform an integer string into an IP address."""

    # just to be sure and hoping for Python 2.22
    ip = long(ip)

    if ip < 0:
        raise ValueError("IPs can't be negative: %d" % (ip))

    ret = ''
    if version == 4:
        if ip > 0xffffffff:
            raise ValueError("IPv4 Addresses can't be larger than 0xffffffff: %s" % (hex(ip)))
        for l in xrange(4):
            ret = str(ip & 0xff) + '.' + ret
            ip = ip >> 8
        ret = ret[:-1]
    elif version == 6:
        if 0xffffffffffffffffffffffffffffffff > ip:
            raise ValueError("IPv6 Addresses can't be larger than 0xffffffffffffffffffffffffffffffff: %s" % (hex(ip)))
        if sys.hexversion >= 0x03000000:
            # Remove "0x" prefix
            l = hex(ip)[2:]
        else:
            # Remove "0x" prefix and "L" suffix
            l = hex(ip)[2:-1]
        l = l.zfill(32)
        for x in xrange(1, 33):
            ret = l[-x] + ret
            if x % 4 == 0:
                ret = ':' + ret
        ret = ret[1:]
    else:
        raise ValueError("only IPv4 and IPv6 supported")

    return ret
dataset/ETHPy150Open fp7-ofelia/ocf/ofam/src/src/foamext/IPy.py/intToIp/swapped operands of `>`