parameters: (self, start, end)
return_statement: return out
docstring: Download a block of data
  
          The expectation is that the server returns only the requested bytes,
          with HTTP code 206. If this is not the case, we first check the headers,
          and then stream the output - if the data size is bigger than we
          requested, an exception is raised.
docstring_summary: Download a block of data
docstring_tokens: Download a block of data
function: def _fetch_range(self, start, end):
          """Download a block of data
  
          The expectation is that the server returns only the requested bytes,
          with HTTP code 206. If this is not the case, we first check the headers,
          and then stream the output - if the data size is bigger than we
          requested, an exception is raised.
          """
          kwargs = self.kwargs.copy()
          headers = kwargs.pop("headers", {})
          headers["Range"] = "bytes=%i-%i" % (start, end - 1)
          r = self.session.get(self.url, headers=headers, stream=True, **kwargs)
          if r.status_code == 416:
              # range request outside file
              return b""
          r.raise_for_status()
          if r.status_code == 206:
              # partial content, as expected
              out = r.content
          elif "Content-Length" in r.headers:
              cl = int(r.headers["Content-Length"])
              if cl <= end - start:
                  # data size OK
                  out = r.content
              else:
                  raise ValueError(
                      "Got more bytes (%i) than requested (%i)" % (cl, end - start)
                  )
          else:
              cl = 0
              out = []
              for chunk in r.iter_content(chunk_size=2 ** 20):
                  # data size unknown, let's see if it goes too big
                  if chunk:
                      out.append(chunk)
                      cl += len(chunk)
                      if cl > end - start:
                          raise ValueError(
                              "Got more bytes so far (>%i) than requested (%i)"
                              % (cl, end - start)
                          )
                  else:
                      break
              out = b"".join(out)
          return out
function_tokens: def _fetch_range ( self , start , end ) : kwargs = self . kwargs . copy ( ) headers = kwargs . pop ( "headers" , { } ) headers [ "Range" ] = "bytes=%i-%i" % ( start , end - 1 ) r = self . session . get ( self . url , headers = headers , stream = True , * * kwargs ) if r . status_code == 416 : # range request outside file return b"" r . raise_for_status ( ) if r . status_code == 206 : # partial content, as expected out = r . content elif "Content-Length" in r . headers : cl = int ( r . headers [ "Content-Length" ] ) if cl <= end - start : # data size OK out = r . content else : raise ValueError ( "Got more bytes (%i) than requested (%i)" % ( cl , end - start ) ) else : cl = 0 out = [ ] for chunk in r . iter_content ( chunk_size = 2 ** 20 ) : # data size unknown, let's see if it goes too big if chunk : out . append ( chunk ) cl += len ( chunk ) if cl > end - start : raise ValueError ( "Got more bytes so far (>%i) than requested (%i)" % ( cl , end - start ) ) else : break out = b"" . join ( out ) return out