def create_compounded_metadata_statement(entity_id, entity_dict, statement,<EOL>context='<STR_LIT>', lifetime=<NUM_LIT>):
n = len(entity_id)<EOL>i = n-<NUM_LIT:1><EOL>fo = entity_dict[entity_id[i]].iss<EOL>sms = None<EOL>i -= <NUM_LIT:1><EOL>while i >= <NUM_LIT:0>:<EOL><INDENT>cms = statement[entity_id[i]]<EOL>ent = entity_dict[entity_id[i]]<EOL>ent.add_signing_keys(cms)<EOL>sup = entity_dict[entity_id[i+<NUM_LIT:1>]]<EOL>sup.add_sms_spec_to_request(cms, context=context)<EOL>sms = sup.self_signer.sign(cms, ent.iss, lifetime=lifetime)<EOL>try:<EOL><INDENT>ent.metadata_statements[context][fo] = sms<EOL><DEDENT>except KeyError:<EOL><INDENT>ent.metadata_statements[context] = {fo: sms}<EOL><DEDENT>i -= <NUM_LIT:1><EOL><DEDENT>return sms<EOL>
:param entity_id:
:param entity_dict:
:param statement:
:param context:
:param lifetime:
:return: