tests/run-tests.py
changeset 30984 15f9084a9a0c
parent 30896 b9116befa784
child 30985 1f803482844a
equal deleted inserted replaced
30983:d4825798818b 30984:15f9084a9a0c
   109 
   109 
   110     _strpath = _bytespath
   110     _strpath = _bytespath
   111 
   111 
   112 # For Windows support
   112 # For Windows support
   113 wifexited = getattr(os, "WIFEXITED", lambda x: False)
   113 wifexited = getattr(os, "WIFEXITED", lambda x: False)
       
   114 
       
   115 # Whether to use IPv6
       
   116 def checkipv6available(port=20058):
       
   117     """return true if we can listen on localhost's IPv6 ports"""
       
   118     family = getattr(socket, 'AF_INET6', None)
       
   119     if family is None:
       
   120         return False
       
   121     try:
       
   122         s = socket.socket(family, socket.SOCK_STREAM)
       
   123         s.bind(('localhost', port))
       
   124         s.close()
       
   125         return True
       
   126     except socket.error as exc:
       
   127         if exc.errno == errno.EADDRINUSE:
       
   128             return True
       
   129         elif exc.errno in (errno.EADDRNOTAVAIL, errno.EPROTONOSUPPORT):
       
   130             return False
       
   131         else:
       
   132             raise
       
   133     else:
       
   134         return False
       
   135 
       
   136 useipv6 = checkipv6available()
   114 
   137 
   115 def checkportisavailable(port):
   138 def checkportisavailable(port):
   116     """return true if a port seems free to bind on localhost"""
   139     """return true if a port seems free to bind on localhost"""
   117     families = [getattr(socket, i, None)
   140     families = [getattr(socket, i, None)
   118                 for i in ('AF_INET', 'AF_INET6')
   141                 for i in ('AF_INET', 'AF_INET6')