#NEWLINE# def putObject( self , bucket , key , data , content_type = 'text/html' , public = True , headers = None , gzip = False ) : #NEWLINE# #INDENT# "\n        Add an object to a bucket.\n       \n        **Arguments:**\n         * *bucket* -- Bucket name\n         * *key* -- Key name\n         * *data* -- Data string\n       \n        **Keyword arguments:**\n         * *content_type* -- Content type header (Default 'text/html')\n         * *public* -- Boolean flag representing access (Default True)\n         * *headers* -- Custom header dictionary (Default empty dictionary)\n         * *gzip* -- Boolean flag to gzip data (Default False)\n        " #NEWLINE# bucket = convertToUTF8 ( bucket ) #NEWLINE# key = convertToUTF8 ( key ) #NEWLINE# if ( not isinstance ( data , str ) ) : #NEWLINE# #INDENT# data = convertToUTF8 ( data ) #NEWLINE# #UNINDENT# if ( headers is None ) : #NEWLINE# #INDENT# headers = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# headers = self . _encodeAmazonHeaders ( headers ) #NEWLINE# if gzip : #NEWLINE# #INDENT# headers [ 'content-encoding' ] = 'gzip' #NEWLINE# zbuf = cStringIO . StringIO ( ) #NEWLINE# zfile = gzip_package . GzipFile ( None , 'wb' , 9 , zbuf ) #NEWLINE# zfile . write ( data ) #NEWLINE# zfile . close ( ) #NEWLINE# data = zbuf . getvalue ( ) #NEWLINE# #UNINDENT# content_md5 = base64 . encodestring ( hashlib . md5 ( data ) . digest ( ) ) . strip ( ) #NEWLINE# if public : #NEWLINE# #INDENT# headers [ 'x-amz-acl' ] = 'public-read' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# headers [ 'x-amz-acl' ] = 'private' #NEWLINE# #UNINDENT# headers . update ( { #NEWLINE# #INDENT# 'Content-Length' : len ( data ) , #NEWLINE# 'Content-Type' : content_type , #NEWLINE# 'Content-MD5' : content_md5 , #NEWLINE# #UNINDENT# } ) #NEWLINE# path = ( ( ( '/' + bucket ) + '/' ) + key ) #NEWLINE# auth = self . _getAuthorization ( 'PUT' , content_md5 , content_type , headers , path ) #NEWLINE# headers . update ( auth ) #NEWLINE# url = ( 'http://%s/%s/%s' % ( self . host , bucket , key ) ) #NEWLINE# d = self . rq . getPage ( url , method = 'PUT' , headers = headers , postdata = data ) #NEWLINE# d . addErrback ( self . _genericErrback , url , method = 'PUT' , headers = headers , postdata = data ) #NEWLINE# return d