#NEWLINE# def urlretrieve( url , output = None , reporthook = None ) : #NEWLINE# #INDENT# r = requests . get ( url , stream = True ) #NEWLINE# try : #NEWLINE# #INDENT# maxsize = int ( r . headers [ 'content-length' ] ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# maxsize = ( - 1 ) #NEWLINE# #UNINDENT# if ( output is None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# filename = re . findall ( 'filename=(\\S+)' , r . headers [ 'content-disposition' ] ) [ 0 ] . strip ( '\'"' ) #NEWLINE# #UNINDENT# except ( IndexError , KeyError ) : #NEWLINE# #INDENT# filename = urlparse . unquote ( os . path . basename ( urlparse . urlparse ( url ) . path ) ) #NEWLINE# #UNINDENT# filename = unique_filename ( filename ) #NEWLINE# reporthook . filename = filename #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# filename = output #NEWLINE# #UNINDENT# with open ( filename , 'wb' ) as f : #NEWLINE# #INDENT# for ( i , chunk ) in enumerate ( r . iter_content ( chunk_size = ( 1024 * 8 ) ) ) : #NEWLINE# #INDENT# if chunk : #NEWLINE# #INDENT# f . write ( chunk ) #NEWLINE# if ( reporthook is not None ) : #NEWLINE# #INDENT# reporthook ( i , ( 1024 * 8 ) , maxsize )