#NEWLINE# @ contextmanager #NEWLINE# def uploadStream( self , multipart = True , allowInlining = True ) : #NEWLINE# #INDENT# store = self . outer #NEWLINE# ( readable_fh , writable_fh ) = os . pipe ( ) #NEWLINE# with os . fdopen ( readable_fh , 'r' ) as readable : #NEWLINE# #INDENT# with os . fdopen ( writable_fh , 'w' ) as writable : #NEWLINE# #INDENT# def multipartReader( ) : #NEWLINE# #INDENT# buf = readable . read ( self . outer . partSize ) #NEWLINE# if ( allowInlining and ( len ( buf ) <= self . _maxInlinedSize ( ) ) ) : #NEWLINE# #INDENT# self . content = buf #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# headers = self . _s3EncryptionHeaders ( ) #NEWLINE# upload = store . filesBucket . initiate_multipart_upload ( key_name = self . fileID , headers = headers ) #NEWLINE# try : #NEWLINE# #INDENT# for part_num in itertools . count ( ) : #NEWLINE# #INDENT# if ( ( len ( buf ) == 0 ) and ( part_num > 0 ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# upload . upload_part_from_file ( fp = StringIO ( buf ) , part_num = ( part_num + 1 ) , headers = headers ) #NEWLINE# if ( len ( buf ) == 0 ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# buf = readable . read ( self . outer . partSize ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# upload . cancel_upload ( ) #NEWLINE# raise #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . version = upload . complete_upload ( ) . version_id #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# def reader( ) : #NEWLINE# #INDENT# buf = readable . read ( ) #NEWLINE# if ( allowInlining and ( len ( buf ) <= self . _maxInlinedSize ( ) ) ) : #NEWLINE# #INDENT# self . content = buf #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# key = store . filesBucket . new_key ( key_name = self . fileID ) #NEWLINE# buf = StringIO ( buf ) #NEWLINE# headers = self . _s3EncryptionHeaders ( ) #NEWLINE# assert ( buf . len == key . set_contents_from_file ( fp = buf , headers = headers ) ) #NEWLINE# self . version = key . version_id #NEWLINE# #UNINDENT# #UNINDENT# thread = ExceptionalThread ( target = ( writable if multipart else reader ) ) #NEWLINE# thread . start ( ) #NEWLINE# ( yield writable ) #NEWLINE# #UNINDENT# thread . join ( ) #NEWLINE# assert ( bool ( self . version ) == ( self . content is None ) )