'Create an instance of an IP object.
Data can be a network specification or a single IP. IP
Addresses can be specified in all forms understood by
parseAddress.() the size of a network can be specified as
/prefixlen        a.b.c.0/24               2001:658:22a:cafe::/64
-lastIP           a.b.c.0-a.b.c.255        2001:658:22a:cafe::-2001:658:22a:cafe:ffff:ffff:ffff:ffff
/decimal netmask  a.b.c.d/255.255.255.0    not supported for IPv6
If no size specification is given a size of 1 address (/32 for
IPv4 and /128 for IPv6) is assumed.
>>> print IP(\'127.0.0.0/8\')
127.0.0.0/8
>>> print IP(\'127.0.0.0/255.0.0.0\')
127.0.0.0/8
>>> print IP(\'127.0.0.0-127.255.255.255\')
127.0.0.0/8
See module documentation for more examples.'

def __init__(self, data, ipversion=0):

    self.NoPrefixForSingleIp = 1
    self.WantPrefixLen = None
    netbits = 0
    prefixlen = (-1)
    if (isinstance(data, types.IntType) or isinstance(data, types.LongType)):
        self.ip = long(data)
        if (ipversion == 0):
            if (self.ip < 4294967296):
                ipversion = 4
            else:
                ipversion = 6
        if (ipversion == 4):
            prefixlen = 32
        elif (ipversion == 6):
            prefixlen = 128
        else:
            raise ValueError('only    IPv4    and    IPv6    supported')
        self._ipversion = ipversion
        self._prefixlen = prefixlen
    elif isinstance(data, IPint):
        self._ipversion = data._ipversion
        self._prefixlen = data._prefixlen
        self.ip = data.ip
    else:
        x = data.split('-')
        if (len(x) == 2):
            (ip, last) = x
            (self.ip, parsedVersion) = parseAddress(ip)
            if (parsedVersion != 4):
                raise ValueError('first-last    notation    only    allowed    for    IPv4')
            (last, lastversion) = parseAddress(last)
            if (lastversion != 4):
                raise ValueError('last    address    should    be    IPv4,    too')
            if (last < self.ip):
                raise ValueError('last    address    should    be    larger    than    first')
            size = (last - self.ip)
            netbits = _count1Bits(size)
        elif (len(x) == 1):
            x = data.split('/')
            if (len(x) == 1):
                ip = x[0]
                prefixlen = (-1)
            elif (len(x) > 2):
                raise ValueError("only    one    '/'    allowed    in    IP    Address")
            else:
                (ip, prefixlen) = x
                if (prefixlen.find('.') != (-1)):
                    (netmask, vers) = parseAddress(prefixlen)
                    if (vers != 4):
                        raise ValueError('netmask    must    be    IPv4')
                    prefixlen = _netmaskToPrefixlen(netmask)
        elif (len(x) > 2):
            raise ValueError("only    one    '-'    allowed    in    IP    Address")
        else:
            raise ValueError("can't    parse")
        (self.ip, parsedVersion) = parseAddress(ip)
        if (ipversion == 0):
            ipversion = parsedVersion
        if (prefixlen == (-1)):
            if (ipversion == 4):
                prefixlen = (32 - netbits)
            elif (ipversion == 6):
                prefixlen = (128 - netbits)
            else:
                raise ValueError('only    IPv4    and    IPv6    supported')
        self._ipversion = ipversion
        self._prefixlen = int(prefixlen)
        if (not _checkNetaddrWorksWithPrefixlen(self.ip, self._prefixlen, self._ipversion)):
            raise ValueError(('%s    goes    not    well    with    prefixlen    %d' % (hex(self.ip), self._prefixlen)))
