<s> import six <EOL> from sahara import exceptions as ex <EOL> from sahara . i18n import _ <EOL> def check_tenant_for_delete ( context , object ) : <EOL> if object . tenant_id != context . tenant_id : <EOL> raise ex . DeletionFailed ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> object = type ( object ) . __name__ , id = object . id ) ) <EOL> def check_tenant_for_update ( context , object ) : <EOL> if object . tenant_id != context . tenant_id : <EOL> raise ex . UpdateFailedException ( <EOL> object . id , <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> object = type ( object ) . __name__ ) ) <EOL> def check_protected_from_delete ( object ) : <EOL> if object . is_protected : <EOL> raise ex . DeletionFailed ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> object = type ( object ) . __name__ , id = object . id ) ) <EOL> def check_protected_from_update ( object , data ) : <EOL> if object . is_protected and data . get ( '<STR_LIT>' , True ) : <EOL> if '<STR_LIT>' in data : <EOL> obj = object . to_dict ( ) <EOL> if all ( k == '<STR_LIT>' or ( <EOL> k in obj and obj [ k ] == v ) for k , v in six . iteritems ( data ) ) : <EOL> return <EOL> raise ex . UpdateFailedException ( <EOL> object . id , <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) . format ( <EOL> object = type ( object ) . __name__ ) ) </s>
