def create_socket_pair(module, port=0):
 have_socketpair = hasattr(module, 'socketpair')
 if have_socketpair:
  (client_sock, srv_sock) = module.socketpair()
  return (client_sock, srv_sock)
 temp_srv_sock = module.socket()
 temp_srv_sock.setblocking(False)
 temp_srv_sock.bind(('', port))
 port = temp_srv_sock.getsockname()[1]
 temp_srv_sock.listen(1)
 client_sock = module.socket()
 client_sock.setblocking(False)
 try:
  client_sock.connect(('localhost', port))
 except module.error as err:
  if (err.errno != errno.EWOULDBLOCK):
   raise
 timeout = 1
 readable = select.select([temp_srv_sock], [], [], timeout)[0]
 if (temp_srv_sock not in readable):
  raise Exception(('Client socket not connected in %s second(s)' % timeout))
 (srv_sock, _) = temp_srv_sock.accept()
 return (client_sock, srv_sock)

def create_socket_pair ( module , port = 0 ) : have_socketpair = hasattr ( module , 'socketpair' ) if have_socketpair : ( client_sock , srv_sock ) = module . socketpair ( ) return ( client_sock , srv_sock ) temp_srv_sock = module . socket ( ) temp_srv_sock . setblocking ( False ) temp_srv_sock . bind ( ( '' , port ) ) port = temp_srv_sock . getsockname ( ) [ 1 ] temp_srv_sock . listen ( 1 ) client_sock = module . socket ( ) client_sock . setblocking ( False ) try : client_sock . connect ( ( 'localhost' , port ) ) except module . error as err : if ( err . errno != errno . EWOULDBLOCK ) : raise timeout = 1 readable = select . select ( [ temp_srv_sock ] , [ ] , [ ] , timeout ) [ 0 ] if ( temp_srv_sock not in readable ) : raise Exception ( ( 'Client socket not connected in %s second(s)' % timeout ) ) ( srv_sock , _ ) = temp_srv_sock . accept ( ) return ( client_sock , srv_sock )
create socket pair .