def _get_http(url, temp_file_name, initial_size, file_size, verbose_bool):
 req = urllib.request.Request(url)
 if (initial_size > 0):
  req.headers['Range'] = ('bytes=%s-' % (initial_size,))
 try:
  response = urllib.request.urlopen(req)
 except Exception:
  logger.info('Resuming download failed (server rejected the request). Attempting to restart downloading the entire file.')
  del req.headers['Range']
  response = urllib.request.urlopen(req)
 total_size = int(response.headers.get('Content-Length', '1').strip())
 if ((initial_size > 0) and (file_size == total_size)):
  logger.info('Resuming download failed (resume file size mismatch). Attempting to restart downloading the entire file.')
  initial_size = 0
 total_size += initial_size
 if (total_size != file_size):
  raise RuntimeError('URL could not be parsed properly')
 mode = ('ab' if (initial_size > 0) else 'wb')
 progress = ProgressBar(total_size, initial_value=initial_size, max_chars=40, spinner=True, mesg='file_sizes', verbose_bool=verbose_bool)
 chunk_size = 8192
 with open(temp_file_name, mode) as local_file:
  while True:
   t0 = time.time()
   chunk = response.read(chunk_size)
   dt = (time.time() - t0)
   if (dt < 0.005):
    chunk_size *= 2
   elif ((dt > 0.1) and (chunk_size > 8192)):
    chunk_size = (chunk_size // 2)
   if (not chunk):
    if verbose_bool:
     sys.stdout.write('\n')
     sys.stdout.flush()
    break
   local_file.write(chunk)
   progress.update_with_increment_value(len(chunk), mesg='file_sizes')

def _get_http ( url , temp_file_name , initial_size , file_size , verbose_bool ) : req = urllib . request . Request ( url ) if ( initial_size > 0 ) : req . headers [ 'Range' ] = ( 'bytes=%s-' % ( initial_size , ) ) try : response = urllib . request . urlopen ( req ) except Exception : logger . info ( 'Resuming download failed (server rejected the request). Attempting to restart downloading the entire file.' ) del req . headers [ 'Range' ] response = urllib . request . urlopen ( req ) total_size = int ( response . headers . get ( 'Content-Length' , '1' ) . strip ( ) ) if ( ( initial_size > 0 ) and ( file_size == total_size ) ) : logger . info ( 'Resuming download failed (resume file size mismatch). Attempting to restart downloading the entire file.' ) initial_size = 0 total_size += initial_size if ( total_size != file_size ) : raise RuntimeError ( 'URL could not be parsed properly' ) mode = ( 'ab' if ( initial_size > 0 ) else 'wb' ) progress = ProgressBar ( total_size , initial_value = initial_size , max_chars = 40 , spinner = True , mesg = 'file_sizes' , verbose_bool = verbose_bool ) chunk_size = 8192 with open ( temp_file_name , mode ) as local_file : while True : t0 = time . time ( ) chunk = response . read ( chunk_size ) dt = ( time . time ( ) - t0 ) if ( dt < 0.005 ) : chunk_size *= 2 elif ( ( dt > 0.1 ) and ( chunk_size > 8192 ) ) : chunk_size = ( chunk_size // 2 ) if ( not chunk ) : if verbose_bool : sys . stdout . write ( '\n' ) sys . stdout . flush ( ) break local_file . write ( chunk ) progress . update_with_increment_value ( len ( chunk ) , mesg = 'file_sizes' )
provides an authed http object .