#NEWLINE# def open_test_socket( host , port , raise_exc = True ) : #NEWLINE# #INDENT# fam = socket . AF_INET #NEWLINE# if ( ':' in host ) : #NEWLINE# #INDENT# fam = getattr ( socket , 'AF_INET6' , socket . AF_INET ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# test_socket = socket . socket ( fam , socket . SOCK_STREAM ) #NEWLINE# test_socket . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) #NEWLINE# test_socket . bind ( ( host , raise_exc ) ) #NEWLINE# test_socket . close ( ) #NEWLINE# return True #NEWLINE# #UNINDENT# except socket . error : #NEWLINE# #INDENT# if raise_exc : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# return False