def parse_socket_string(socket_string, default_port):
 port = default_port
 if socket_string.startswith('['):
  match = IPV6_RE.match(socket_string)
  if (not match):
   raise ValueError(('Invalid IPv6 address: %s' % socket_string))
  host = match.group('address')
  port = (match.group('port') or port)
 elif (':' in socket_string):
  tokens = socket_string.split(':')
  if (len(tokens) > 2):
   raise ValueError("IPv6 addresses must be between '[]'")
  (host, port) = tokens
 else:
  host = socket_string
 return (host, port)

def parse_socket_string ( socket_string , default_port ) : port = default_port if socket_string . startswith ( '[' ) : match = IPV6_RE . match ( socket_string ) if ( not match ) : raise ValueError ( ( 'Invalid IPv6 address: %s' % socket_string ) ) host = match . group ( 'address' ) port = ( match . group ( 'port' ) or port ) elif ( ':' in socket_string ) : tokens = socket_string . split ( ':' ) if ( len ( tokens ) > 2 ) : raise ValueError ( "IPv6 addresses must be between '[]'" ) ( host , port ) = tokens else : host = socket_string return ( host , port )
given a string representing a socket .