@@ -73,6 +73,7 @@ def setup_logging(level=None):
7373if ClientPayloadError is not None :
7474 S3_RETRYABLE_ERRORS += (ClientPayloadError ,)
7575
76+
7677def add_retryable_error (exc ):
7778 """
7879 Add an exception type to the list of retryable S3 errors.
@@ -86,18 +87,21 @@ def add_retryable_error(exc):
8687 ----------
8788 >>> class MyCustomError(Exception): # doctest: +SKIP
8889 ... pass # doctest: +SKIP
89- >>> add_retryable_error(MyCustomError) # doctest: +SKIP
90+ >>> add_retryable_error(MyCustomError) # doctest: +SKIP
9091 """
9192 global S3_RETRYABLE_ERRORS
9293 S3_RETRYABLE_ERRORS += (exc ,)
9394
95+
9496CUSTOM_ERROR_HANDLER = lambda _ : False
97+
98+
9599def set_custom_error_handler (func ):
96100 """Set a custom error handler function for S3 retryable errors.
97101
98102 The function should take an exception instance as its only argument,
99103 and return True if the operation should be retried, or False otherwise.
100- This can also be used for custom behavior on `ClientError` exceptions,
104+ This can also be used for custom behavior on `ClientError` exceptions,
101105 such as retrying other patterns.
102106
103107 Parameters
@@ -118,6 +122,7 @@ def set_custom_error_handler(func):
118122 global CUSTOM_ERROR_HANDLER
119123 CUSTOM_ERROR_HANDLER = func
120124
125+
121126_VALID_FILE_MODES = {"r" , "w" , "a" , "rb" , "wb" , "ab" }
122127
123128_PRESERVE_KWARGS = [
@@ -151,13 +156,14 @@ def set_custom_error_handler(func):
151156}
152157buck_acls = {"private" , "public-read" , "public-read-write" , "authenticated-read" }
153158
159+
154160async def _error_wrapper (func , * , args = (), kwargs = None , retries ):
155161 if kwargs is None :
156162 kwargs = {}
157163 err = None
158164 for i in range (retries ):
159165 wait_time = min (1.7 ** i * 0.1 , 15 )
160-
166+
161167 try :
162168 return await func (* args , ** kwargs )
163169 except S3_RETRYABLE_ERRORS as e :
@@ -177,7 +183,7 @@ async def _error_wrapper(func, *, args=(), kwargs=None, retries):
177183 if pattern in str (e ):
178184 matched = True
179185 break
180-
186+
181187 if matched :
182188 await asyncio .sleep (wait_time )
183189 else :
0 commit comments