File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed
Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change 2424
2525from urllib import parse
2626
27- from typing import Any , Dict
27+ from typing import Any , Dict , Optional
2828
2929import logging
3030logger = logging .getLogger (__name__ )
@@ -206,16 +206,19 @@ def __repr__(self) -> str:
206206class SlowRetrievalError (DownloadError ):
207207 """"Indicate that downloading a file took an unreasonably long time."""
208208
209- def __init__ (self , average_download_speed : int ):
209+ def __init__ (self , average_download_speed : Optional [ int ] = None ):
210210 super (SlowRetrievalError , self ).__init__ ()
211211
212212 self .__average_download_speed = average_download_speed #bytes/second
213213
214214 def __str__ (self ) -> str :
215- return (
216- 'Download was too slow. Average speed: ' +
215+ msg = 'Download was too slow.'
216+ if self .__average_download_speed is not None :
217+ msg = ('Download was too slow. Average speed: ' +
217218 repr (self .__average_download_speed ) + ' bytes per second.' )
218219
220+ return msg
221+
219222 def __repr__ (self ) -> str :
220223 return self .__class__ .__name__ + ' : ' + str (self )
221224
Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ def _chunks(
141141 )
142142
143143 except urllib3 .exceptions .ReadTimeoutError as e :
144- raise exceptions .SlowRetrievalError ( str ( e ))
144+ raise exceptions .SlowRetrievalError from e
145145
146146 finally :
147147 response .close ()
You can’t perform that action at this time.
0 commit comments