parameters: (ipstr)
docstring: Parse a string and return the corresponding IP address (as integer)
      and a guess of the IP version.
  
      Following address formats are recognized:
  
      >>> parseAddress('0x0123456789abcdef')           # IPv4 if <= 0xffffffff else IPv6
      (81985529216486895L, 6)
      >>> parseAddress('123.123.123.123')              # IPv4
      (2071690107L, 4)
      >>> parseAddress('123.123')                      # 0-padded IPv4
      (2071658496L, 4)
      >>> parseAddress('1080:0000:0000:0000:0008:0800:200C:417A')
      (21932261930451111902915077091070067066L, 6)
      >>> parseAddress('1080:0:0:0:8:800:200C:417A')
      (21932261930451111902915077091070067066L, 6)
      >>> parseAddress('1080:0::8:800:200C:417A')
      (21932261930451111902915077091070067066L, 6)
      >>> parseAddress('::1')
      (1L, 6)
      >>> parseAddress('::')
      (0L, 6)
      >>> parseAddress('0:0:0:0:0:FFFF:129.144.52.38')
      (281472855454758L, 6)
      >>> parseAddress('::13.1.68.3')
      (218186755L, 6)
      >>> parseAddress('::FFFF:129.144.52.38')
      (281472855454758L, 6)
docstring_summary: Parse a string and return the corresponding IP address (as integer)
      and a guess of the IP version.
docstring_tokens: Parse a string and return the corresponding IP address ( as integer ) and a guess of the IP version .
function: def parseAddress(ipstr):
      """
      Parse a string and return the corresponding IP address (as integer)
      and a guess of the IP version.
  
      Following address formats are recognized:
  
      >>> parseAddress('0x0123456789abcdef')           # IPv4 if <= 0xffffffff else IPv6
      (81985529216486895L, 6)
      >>> parseAddress('123.123.123.123')              # IPv4
      (2071690107L, 4)
      >>> parseAddress('123.123')                      # 0-padded IPv4
      (2071658496L, 4)
      >>> parseAddress('1080:0000:0000:0000:0008:0800:200C:417A')
      (21932261930451111902915077091070067066L, 6)
      >>> parseAddress('1080:0:0:0:8:800:200C:417A')
      (21932261930451111902915077091070067066L, 6)
      >>> parseAddress('1080:0::8:800:200C:417A')
      (21932261930451111902915077091070067066L, 6)
      >>> parseAddress('::1')
      (1L, 6)
      >>> parseAddress('::')
      (0L, 6)
      >>> parseAddress('0:0:0:0:0:FFFF:129.144.52.38')
      (281472855454758L, 6)
      >>> parseAddress('::13.1.68.3')
      (218186755L, 6)
      >>> parseAddress('::FFFF:129.144.52.38')
      (281472855454758L, 6)
      """
  
      if ipstr.startswith('0x'):
          ret = long(ipstr[2:], 16)
          if ret > 0xffffffffffffffffffffffffffffffffL:
              raise ValueError, "%r: IP Address can't be bigger than 2^128" % (ipstr)
          if ret < 0x100000000L:
              return (ret, 4)
          else:
              return (ret, 6)
  
      if ipstr.find(':') != -1:
          return (_parseAddressIPv6(ipstr), 6)
  
      elif len(ipstr) == 32:
          # assume IPv6 in pure hexadecimal notation
          return (long(ipstr, 16), 6)
  
      elif ipstr.find('.') != -1 or (len(ipstr) < 4 and int(ipstr) < 256):
          # assume IPv4  ('127' gets interpreted as '127.0.0.0')
          bytes = ipstr.split('.')
          if len(bytes) > 4:
              raise ValueError, "IPv4 Address with more than 4 bytes"
          bytes += ['0'] * (4 - len(bytes))
          bytes = [long(x) for x in bytes]
          for x in bytes:
              if x > 255 or x < 0:
                  raise ValueError, "%r: single byte must be 0 <= byte < 256" % (ipstr)
          return ((bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + bytes[3], 4)
  
      else:
          # we try to interprete it as a decimal digit -
          # this ony works for numbers > 255 ... others
          # will be interpreted as IPv4 first byte
          ret = long(ipstr, 10)
          if ret > 0xffffffffffffffffffffffffffffffffL:
              raise ValueError, "IP Address can't be bigger than 2^128"
          if ret <= 0xffffffffL:
              return (ret, 4)
          else:
              return (ret, 6)
function_tokens: def parseAddress ( ipstr ) : if ipstr . startswith ( '0x' ) : ret = long ( ipstr [ 2 : ] , 16 ) if ret > 0xffffffffffffffffffffffffffffffffL : raise ValueError , "%r: IP Address can't be bigger than 2^128" % ( ipstr ) if ret < 0x100000000L : return ( ret , 4 ) else : return ( ret , 6 ) if ipstr . find ( ':' ) != - 1 : return ( _parseAddressIPv6 ( ipstr ) , 6 ) elif len ( ipstr ) == 32 : # assume IPv6 in pure hexadecimal notation return ( long ( ipstr , 16 ) , 6 ) elif ipstr . find ( '.' ) != - 1 or ( len ( ipstr ) < 4 and int ( ipstr ) < 256 ) : # assume IPv4  ('127' gets interpreted as '127.0.0.0') bytes = ipstr . split ( '.' ) if len ( bytes ) > 4 : raise ValueError , "IPv4 Address with more than 4 bytes" bytes += [ '0' ] * ( 4 - len ( bytes ) ) bytes = [ long ( x ) for x in bytes ] for x in bytes : if x > 255 or x < 0 : raise ValueError , "%r: single byte must be 0 <= byte < 256" % ( ipstr ) return ( ( bytes [ 0 ] << 24 ) + ( bytes [ 1 ] << 16 ) + ( bytes [ 2 ] << 8 ) + bytes [ 3 ] , 4 ) else : # we try to interprete it as a decimal digit - # this ony works for numbers > 255 ... others # will be interpreted as IPv4 first byte ret = long ( ipstr , 10 ) if ret > 0xffffffffffffffffffffffffffffffffL : raise ValueError , "IP Address can't be bigger than 2^128" if ret <= 0xffffffffL : return ( ret , 4 ) else : return ( ret , 6 )