#NEWLINE# @ gen . coroutine #NEWLINE# def save_attachment( self , doc , attachment ) : #NEWLINE# #INDENT# 'Save an attachment to the specified doc.\n        The attachment shall be a dict with keys: `mimetype`, `name`, `data`.\n        The doc shall be a dict, at least having the key `_id`, and if doc is\n        existing in the database, it shall also contain the key `_rev`' #NEWLINE# if any ( ( ( key not in attachment ) for key in [ 'mimetype' , 'name' , 'data' ] ) ) : #NEWLINE# #INDENT# raise KeyError ( 'Attachment dict is missing one or more required keys' ) #NEWLINE# #UNINDENT# url = '{0}/{1}/{2}{3}' . format ( self . db_name , url_escape ( doc [ '_id' ] ) , url_escape ( attachment [ 'name' ] ) , ( '?rev={0}' . format ( doc [ '_rev' ] ) if ( '_rev' in doc ) else '' ) ) #NEWLINE# headers = { #NEWLINE# #INDENT# 'Content-Type' : attachment [ 'mimetype' ] , #NEWLINE# #UNINDENT# } #NEWLINE# body = attachment [ 'data' ] #NEWLINE# r = ( yield self . _http_put ( url , body , headers = headers ) ) #NEWLINE# raise gen . Return ( r )