@@ -132,32 +132,31 @@ def __init__(self, num_errors, success_json, success_data):
132
132
def request (self , * args , ** kwargs ):
133
133
if not self .num_errors :
134
134
return httplib2 .Response (self .success_json ), self .success_data
135
+ elif self .num_errors == 5 and PY3 :
136
+ ex = ConnectionResetError # noqa: F821
137
+ elif self .num_errors == 4 :
138
+ ex = httplib2 .ServerNotFoundError ()
139
+ elif self .num_errors == 3 :
140
+ ex = socket .error ()
141
+ ex .errno = socket .errno .EPIPE
142
+ elif self .num_errors == 2 :
143
+ ex = ssl .SSLError ()
135
144
else :
136
- self .num_errors -= 1
137
- if self .num_errors == 1 : # initial == 2
138
- raise ssl .SSLError ()
139
- if self .num_errors == 3 : # initial == 4
140
- raise httplib2 .ServerNotFoundError ()
141
- else : # initial != 2,4
142
- if self .num_errors == 2 :
143
- # first try a broken pipe error (#218)
144
- ex = socket .error ()
145
- ex .errno = socket .errno .EPIPE
145
+ # Initialize the timeout error code to the platform's error code.
146
+ try :
147
+ # For Windows:
148
+ ex = socket .error ()
149
+ ex .errno = socket .errno .WSAETIMEDOUT
150
+ except AttributeError :
151
+ # For Linux/Mac:
152
+ if PY3 :
153
+ ex = socket .timeout ()
146
154
else :
147
- # Initialize the timeout error code to the platform's error code.
148
- try :
149
- # For Windows:
150
- ex = socket .error ()
151
- ex .errno = socket .errno .WSAETIMEDOUT
152
- except AttributeError :
153
- # For Linux/Mac:
154
- if PY3 :
155
- ex = socket .timeout ()
156
- else :
157
- ex = socket .error ()
158
- ex .errno = socket .errno .ETIMEDOUT
159
- # Now raise the correct error.
160
- raise ex
155
+ ex = socket .error ()
156
+ ex .errno = socket .errno .ETIMEDOUT
157
+
158
+ self .num_errors -= 1
159
+ raise ex
161
160
162
161
163
162
class HttpMockWithNonRetriableErrors (object ):
@@ -562,14 +561,14 @@ def test_media_io_base_download_handle_4xx(self):
562
561
563
562
def test_media_io_base_download_retries_connection_errors (self ):
564
563
self .request .http = HttpMockWithErrors (
565
- 4 , {"status" : "200" , "content-range" : "0-2/3" }, b"123"
564
+ 5 , {"status" : "200" , "content-range" : "0-2/3" }, b"123"
566
565
)
567
566
568
567
download = MediaIoBaseDownload (fd = self .fd , request = self .request , chunksize = 3 )
569
568
download ._sleep = lambda _x : 0 # do nothing
570
569
download ._rand = lambda : 10
571
570
572
- status , done = download .next_chunk (num_retries = 4 )
571
+ status , done = download .next_chunk (num_retries = 5 )
573
572
574
573
self .assertEqual (self .fd .getvalue (), b"123" )
575
574
self .assertEqual (True , done )
@@ -899,13 +898,13 @@ def test_no_retry_connection_errors(self):
899
898
def test_retry_connection_errors_non_resumable (self ):
900
899
model = JsonModel ()
901
900
request = HttpRequest (
902
- HttpMockWithErrors (4 , {"status" : "200" }, '{"foo": "bar"}' ),
901
+ HttpMockWithErrors (5 , {"status" : "200" }, '{"foo": "bar"}' ),
903
902
model .response ,
904
903
u"https://www.example.com/json_api_endpoint" ,
905
904
)
906
905
request ._sleep = lambda _x : 0 # do nothing
907
906
request ._rand = lambda : 10
908
- response = request .execute (num_retries = 4 )
907
+ response = request .execute (num_retries = 5 )
909
908
self .assertEqual ({u"foo" : u"bar" }, response )
910
909
911
910
def test_retry_connection_errors_resumable (self ):
@@ -918,7 +917,7 @@ def test_retry_connection_errors_resumable(self):
918
917
919
918
request = HttpRequest (
920
919
HttpMockWithErrors (
921
- 4 , {"status" : "200" , "location" : "location" }, '{"foo": "bar"}'
920
+ 5 , {"status" : "200" , "location" : "location" }, '{"foo": "bar"}'
922
921
),
923
922
model .response ,
924
923
u"https://www.example.com/file_upload" ,
@@ -927,7 +926,7 @@ def test_retry_connection_errors_resumable(self):
927
926
)
928
927
request ._sleep = lambda _x : 0 # do nothing
929
928
request ._rand = lambda : 10
930
- response = request .execute (num_retries = 4 )
929
+ response = request .execute (num_retries = 5 )
931
930
self .assertEqual ({u"foo" : u"bar" }, response )
932
931
933
932
def test_retry (self ):
0 commit comments