VirtualMailManager/network.py
branchv0.7.x
changeset 643 df1e3b67882a
parent 568 14abdd04ddf5
child 672 d3fd9bb0a5ea
equal deleted inserted replaced
642:4cd9d0a9f42f 643:df1e3b67882a
    79 
    79 
    80     When the `ip_address` could be validated successfully a tuple
    80     When the `ip_address` could be validated successfully a tuple
    81     `(address_family, address_as_long)` will be returned. The
    81     `(address_family, address_as_long)` will be returned. The
    82     `address_family`will be either `socket.AF_INET` or `socket.AF_INET6`.
    82     `address_family`will be either `socket.AF_INET` or `socket.AF_INET6`.
    83     """
    83     """
    84     if not isinstance(ip_address, basestring) or not ip_address:
    84     if not isinstance(ip_address, str) or not ip_address:
    85         raise TypeError('ip_address must be a non empty string.')
    85         raise TypeError('ip_address must be a non empty string.')
    86     if not ip_address.count(':'):
    86     if not ip_address.count(':'):
    87         family = socket.AF_INET
    87         family = socket.AF_INET
    88         try:
    88         try:
    89             address = socket.inet_aton(ip_address)
    89             address = socket.inet_aton(ip_address)
    95         family = socket.AF_INET6
    95         family = socket.AF_INET6
    96         try:
    96         try:
    97             address = socket.inet_pton(family, ip_address)
    97             address = socket.inet_pton(family, ip_address)
    98         except socket.error:
    98         except socket.error:
    99             raise ValueError('Not a valid IPv6 address: %r' % ip_address)
    99             raise ValueError('Not a valid IPv6 address: %r' % ip_address)
   100     return (family, long(address.encode('hex'), 16))
   100     return (family, int(address.encode('hex'), 16))