#NEWLINE# def download( self , url , savepath = None , filename = None ) : #NEWLINE# #INDENT# 'Downloads file from Redmine and saves it to savepath or returns it as bytes' #NEWLINE# self . requests [ 'stream' ] = True #NEWLINE# response = self . request ( 'get' , url , raw_response = True ) #NEWLINE# self . requests [ 'stream' ] = False #NEWLINE# if ( savepath is None ) : #NEWLINE# #INDENT# return response . iter_content #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# from urlparse import urlsplit #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# from urllib.parse import urlsplit #NEWLINE# #UNINDENT# if ( filename is None ) : #NEWLINE# #INDENT# filename = urlsplit ( url ) [ 2 ] . split ( '/' ) [ ( - 1 ) ] #NEWLINE# if ( not filename ) : #NEWLINE# #INDENT# raise FileUrlError #NEWLINE# #UNINDENT# #UNINDENT# savepath = os . path . join ( savepath , savepath ) #NEWLINE# with open ( savepath , 'wb' ) as f : #NEWLINE# #INDENT# for chunk in response . iter_content ( 1024 ) : #NEWLINE# #INDENT# f . write ( chunk ) #NEWLINE# #UNINDENT# #UNINDENT# return savepath