@@ -68,59 +68,29 @@ def __len__(self):
68
68
return self .content_length
69
69
70
70
async def __anext__ (self ):
71
- retry_active = True
72
- retry_total = 3
73
- while retry_active :
71
+ try :
74
72
try :
75
- try :
76
- chunk = await trio .to_thread .run_sync (
77
- _iterate_response_content ,
78
- self .iter_content_func ,
79
- )
80
- except AttributeError : # trio < 0.12.1
81
- chunk = await trio .run_sync_in_worker_thread ( # pylint: disable=no-member
82
- _iterate_response_content ,
83
- self .iter_content_func ,
84
- )
85
- if not chunk :
86
- raise _ResponseStopIteration ()
87
- self .downloaded += self .block_size
88
- return chunk
89
- except _ResponseStopIteration :
90
- self .response .internal_response .close ()
91
- raise StopAsyncIteration ()
92
- except (requests .exceptions .ChunkedEncodingError ,
93
- requests .exceptions .ConnectionError ):
94
- retry_total -= 1
95
- if retry_total <= 0 :
96
- retry_active = False
97
- else :
98
- await trio .sleep (1 )
99
- headers = {'range' : 'bytes=' + str (self .downloaded ) + '-' }
100
- resp = self .pipeline .run (self .request , stream = True , headers = headers )
101
- if resp .status_code == 416 :
102
- raise
103
- try :
104
- chunk = await trio .to_thread .run_sync (
105
- _iterate_response_content ,
106
- self .iter_content_func ,
107
- )
108
- except AttributeError : # trio < 0.12.1
109
- chunk = await trio .run_sync_in_worker_thread ( # pylint: disable=no-member
110
- _iterate_response_content ,
111
- self .iter_content_func ,
112
- )
113
- if not chunk :
114
- raise StopIteration ()
115
- self .downloaded += len (chunk )
116
- return chunk
117
- continue
118
- except requests .exceptions .StreamConsumedError :
119
- raise
120
- except Exception as err :
121
- _LOGGER .warning ("Unable to stream download: %s" , err )
122
- self .response .internal_response .close ()
123
- raise
73
+ chunk = await trio .to_thread .run_sync (
74
+ _iterate_response_content ,
75
+ self .iter_content_func ,
76
+ )
77
+ except AttributeError : # trio < 0.12.1
78
+ chunk = await trio .run_sync_in_worker_thread ( # pylint: disable=no-member
79
+ _iterate_response_content ,
80
+ self .iter_content_func ,
81
+ )
82
+ if not chunk :
83
+ raise _ResponseStopIteration ()
84
+ return chunk
85
+ except _ResponseStopIteration :
86
+ self .response .internal_response .close ()
87
+ raise StopAsyncIteration ()
88
+ except requests .exceptions .StreamConsumedError :
89
+ raise
90
+ except Exception as err :
91
+ _LOGGER .warning ("Unable to stream download: %s" , err )
92
+ self .response .internal_response .close ()
93
+ raise
124
94
125
95
class TrioRequestsTransportResponse (AsyncHttpResponse , RequestsTransportResponse ): # type: ignore
126
96
"""Asynchronous streaming of data from the response.
0 commit comments