#NEWLINE# def _set_metadata( self , req , id , body ) : #NEWLINE# #INDENT# "Replaces the aggregate's existing metadata with new metadata." #NEWLINE# context = _get_context ( req ) #NEWLINE# authorize ( context ) #NEWLINE# if ( len ( body ) != 1 ) : #NEWLINE# #INDENT# raise exc . HTTPBadRequest ( ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# metadata = body [ 'metadata' ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# raise exc . HTTPBadRequest ( ) #NEWLINE# #UNINDENT# if ( not isinstance ( metadata , dict ) ) : #NEWLINE# #INDENT# msg = _ ( 'The value of metadata must be a dict' ) #NEWLINE# raise exc . HTTPBadRequest ( explanation = msg ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# for ( key , value ) in metadata . items ( ) : #NEWLINE# #INDENT# utils . check_string_length ( key , 'metadata.key' , 1 , 255 ) #NEWLINE# if ( value is not None ) : #NEWLINE# #INDENT# utils . check_string_length ( value , 'metadata.value' , 0 , 255 ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except exception . InvalidInput as e : #NEWLINE# #INDENT# raise exc . HTTPBadRequest ( explanation = e . format_message ( ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# aggregate = self . api . update_aggregate_metadata ( context , id , metadata ) #NEWLINE# #UNINDENT# except exception . AggregateNotFound : #NEWLINE# #INDENT# msg = ( _ ( 'Cannot set metadata %(metadata)s in aggregate %(id)s' ) % { #NEWLINE# #INDENT# 'metadata' : metadata , #NEWLINE# 'id' : id , #NEWLINE# #UNINDENT# } ) #NEWLINE# raise exc . HTTPNotFound ( explanation = msg ) #NEWLINE# #UNINDENT# except exception . InvalidAggregateAction as e : #NEWLINE# #INDENT# raise exc . HTTPBadRequest ( explanation = e . format_message ( ) ) #NEWLINE# #UNINDENT# return self . _marshall_aggregate ( aggregate )