@@ -968,8 +968,17 @@ def dec(f):
968968 return wrapper
969969
970970
971- _network_error_classes = IOError , httplib .HTTPException
971+ _network_errno_vals = (
972+ 101 , # Network is unreachable
973+ 110 , # Connection timed out
974+ 104 , # Connection reset Error
975+ 54 , # Connection reset by peer
976+ )
972977
978+ _network_error_classes = (IOError , httplib .HTTPException )
979+
980+ if sys .version_info [:2 ] >= (3 ,3 ):
981+ _network_error_classes += (TimeoutError ,)
973982
974983def can_connect (url , error_classes = _network_error_classes ):
975984 """Try to connect to the given url. True if succeeds, False if IOError
@@ -998,7 +1007,9 @@ def can_connect(url, error_classes=_network_error_classes):
9981007@optional_args
9991008def network (t , url = "http://www.google.com" ,
10001009 raise_on_error = _RAISE_NETWORK_ERROR_DEFAULT ,
1001- check_before_test = False , error_classes = _network_error_classes ):
1010+ check_before_test = False ,
1011+ error_classes = _network_error_classes ,
1012+ skip_errnos = _network_errno_vals ):
10021013 """
10031014 Label a test as requiring network connection and, if an error is
10041015 encountered, only raise if it does not find a network connection.
@@ -1084,7 +1095,12 @@ def wrapper(*args, **kwargs):
10841095 raise SkipTest
10851096 try :
10861097 return t (* args , ** kwargs )
1087- except error_classes as e :
1098+ except Exception as e :
1099+ errno = getattr (e ,'errno' ,None )
1100+
1101+ if not isinstance (e , error_classes ) and not errno in skip_errnos :
1102+ raise
1103+
10881104 if raise_on_error or can_connect (url , error_classes ):
10891105 raise
10901106 else :
0 commit comments