#NEWLINE# def post_download( project , filename , name = None , description = '' ) : #NEWLINE# #INDENT# 'Upload a file to the GitHub downloads area' #NEWLINE# if ( name is None ) : #NEWLINE# #INDENT# name = os . path . basename ( filename ) #NEWLINE# #UNINDENT# with open ( filename , 'rb' ) as f : #NEWLINE# #INDENT# filedata = f . read ( ) #NEWLINE# #UNINDENT# url = 'https://api.github.com/repos/{project}/downloads' . format ( project = project ) #NEWLINE# payload = json . dumps ( dict ( name = name , size = len ( filedata ) , description = description ) ) #NEWLINE# response = requests . post ( url , data = payload , headers = make_auth_header ( ) ) #NEWLINE# response . raise_for_status ( ) #NEWLINE# reply = json . loads ( response . content ) #NEWLINE# s3_url = reply [ 's3_url' ] #NEWLINE# fields = dict ( key = reply [ 'path' ] , acl = reply [ 'acl' ] , success_action_status = 201 , Filename = reply [ 'name' ] , AWSAccessKeyId = reply [ 'accesskeyid' ] , Policy = reply [ 'policy' ] , Signature = reply [ 'signature' ] , file = ( reply [ 'name' ] , filedata ) ) #NEWLINE# fields [ 'Content-Type' ] = reply [ 'mime_type' ] #NEWLINE# ( data , content_type ) = encode_multipart_formdata ( fields ) #NEWLINE# s3r = requests . post ( s3_url , data = data , headers = { #NEWLINE# #INDENT# 'Content-Type' : content_type , #NEWLINE# #UNINDENT# } ) #NEWLINE# return s3r