Clean up how we walk through ranges in ECAppIter

Besides being easier to reason about, this also lets us
run more unit tests under py37 which complains about a
a generator raising StopIteration

Change-Id: Ia6b945afef51bcc8ed20a7069fc60d5b8f9c9c0b
This commit is contained in:
Tim Burke 2019-02-19 13:53:07 -08:00
parent c9773bfd26
commit d6af42b6b6

View File

@ -25,6 +25,7 @@
# collected. We've seen objects hang around forever otherwise. # collected. We've seen objects hang around forever otherwise.
from six.moves.urllib.parse import unquote from six.moves.urllib.parse import unquote
from six.moves import zip
import collections import collections
import itertools import itertools
@ -1112,18 +1113,14 @@ class ECAppIter(object):
resp.content_type = self.learned_content_type resp.content_type = self.learned_content_type
resp.content_length = self.obj_length resp.content_length = self.obj_length
def _next_range(self): def _next_ranges(self):
# Each FA part should have approximately the same headers. We really # Each FA part should have approximately the same headers. We really
# only care about Content-Range and Content-Type, and that'll be the # only care about Content-Range and Content-Type, and that'll be the
# same for all the different FAs. # same for all the different FAs.
frag_iters = [] for part_infos in zip(*self.internal_parts_iters):
headers = None frag_iters = [pi['part_iter'] for pi in part_infos]
for parts_iter in self.internal_parts_iters: headers = HeaderKeyDict(part_infos[0]['headers'])
part_info = next(parts_iter) yield headers, frag_iters
frag_iters.append(part_info['part_iter'])
headers = part_info['headers']
headers = HeaderKeyDict(headers)
return headers, frag_iters
def _actual_range(self, req_start, req_end, entity_length): def _actual_range(self, req_start, req_end, entity_length):
# Takes 3 args: (requested-first-byte, requested-last-byte, # Takes 3 args: (requested-first-byte, requested-last-byte,
@ -1272,11 +1269,7 @@ class ECAppIter(object):
seen_first_headers = False seen_first_headers = False
ranges_for_resp = {} ranges_for_resp = {}
while True: for headers, frag_iters in self._next_ranges():
# this'll raise StopIteration and exit the loop
next_range = self._next_range()
headers, frag_iters = next_range
content_type = headers['Content-Type'] content_type = headers['Content-Type']
content_range = headers.get('Content-Range') content_range = headers.get('Content-Range')