#NEWLINE# def upload_file( self , article_id , filepath_or_buffer ) : #NEWLINE# #INDENT# '\n        Upload a file.\n\n        `filepath_or_buffer` can be a string or an open file object.\n        ' #NEWLINE# if isinstance ( filepath_or_buffer , six . string_types ) : #NEWLINE# #INDENT# file = open ( filepath_or_buffer , 'rb' ) #NEWLINE# own_handle = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# file = filepath_or_buffer #NEWLINE# own_handle = False #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# files = { #NEWLINE# #INDENT# 'filedata' : ( os . path . basename ( file . name ) , file ) , #NEWLINE# #UNINDENT# } #NEWLINE# response = self . client . put ( ( '%s/articles/%s/files' % ( article_id . endpoint , article_id ) ) , files = files ) #NEWLINE# return response . json ( ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# if own_handle : #NEWLINE# #INDENT# file . close ( )