def make_iter_from_resp(resp): """ Makes a part iterator from a HTTP response iterator return tuples: (start, end, length, headers, body_file) """ if resp.status == 200: content_length = int(resp.getheader("Content-Length")) return iter([(0, content_length - 1, content_length, resp.getheaders(), resp)]) content_type, params = parse_content_type(resp.getheader("Content-Type")) if content_type != "multipart/byteranges": start, end, length = parse_content_range(resp.getheader("Content-Range")) return iter([(start, end, length, resp.getheaders(), resp)]) else: raise ValueError("Invalid response")
def make_iter_from_resp(resp): """ Makes a part iterator from a HTTP response iterator return tuples: (start, end, length, headers, body_file) """ if resp.status == 200: content_length = int(resp.getheader('Content-Length')) return iter([(0, content_length - 1, content_length, resp.getheaders(), resp)]) content_type, params = parse_content_type(resp.getheader('Content-Type')) if content_type != 'multipart/byteranges': start, end, length = parse_content_range( resp.getheader('Content-Range')) return iter([(start, end, length, resp.getheaders(), resp)]) else: raise ValueError("Invalid response")