'If client_chunk_size is set, makes sure we yield things starting on
chunk boundaries based on the Content-Range header in the response.
Sets our Range header\'s first byterange to the value learned from
the Content-Range header in the response; if we were given a
fully-specified range (e.g. "bytes=123-456"), this is a no-op.
If we were given a half-specified range (e.g. "bytes=123-" or
"bytes=-456"), then this changes the Range header to a
semantically-equivalent one *and* it lets us resume on a proper
boundary instead of just in the middle of a piece somewhere.'

def learn_size_from_content_range(self, start, end, length):

    if (length == 0):
        return
    if self.client_chunk_size:
        self.skip_bytes = bytes_to_skip(self.client_chunk_size, start)
    if ('Range' in self.backend_headers):
        try:
            req_range = Range(self.backend_headers['Range'])
            new_ranges = ([(start, end)] + req_range.ranges[1:])
        except ValueError:
            new_ranges = [(start, end)]
    else:
        new_ranges = [(start, end)]
    self.backend_headers['Range'] = ('bytes=' + ','.join((('%s-%s' % ((s if (s is not None) else ''), (e if (e is not None) else ''))) for (s, e) in new_ranges)))
