def _register_custom_contracts(contract_name, contract_exceptions):
<EOL>global _CUSTOM_CONTRACTS<EOL>if not isinstance(contract_name, str):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if (<EOL>(not isinstance(contract_exceptions, list))<EOL>and (not isinstance(contract_exceptions, str))<EOL>and (not isinstance(contract_exceptions, dict))<EOL>):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if isinstance(contract_exceptions, dict):<EOL><INDENT>contract_exceptions = [contract_exceptions]<EOL><DEDENT>if isinstance(contract_exceptions, list) and any(<EOL>[<EOL>not isinstance(key, str)<EOL>for item in contract_exceptions<EOL>for key in item.keys()<EOL>]<EOL>):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if isinstance(contract_exceptions, list) and any(<EOL>[<EOL>not (<EOL>(set(item.keys()) == set(["<STR_LIT:name>", "<STR_LIT>"]))<EOL>or (set(item.keys()) == set(["<STR_LIT:name>", "<STR_LIT>", "<STR_LIT:type>"]))<EOL>)<EOL>for item in contract_exceptions<EOL>]<EOL>):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>extype = type(ValueError)<EOL>if isinstance(contract_exceptions, list) and any(<EOL>[<EOL>(not isinstance(item["<STR_LIT:name>"], str))<EOL>or (not isinstance(item["<STR_LIT>"], str))<EOL>or (not isinstance(item.get("<STR_LIT:type>", extype), extype))<EOL>for item in contract_exceptions<EOL>]<EOL>):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if isinstance(contract_exceptions, list):<EOL><INDENT>homogenized_exdict = dict(<EOL>(<EOL>exdict["<STR_LIT:name>"],<EOL>{<EOL>"<STR_LIT>": exnum,<EOL>"<STR_LIT>": exdict["<STR_LIT>"],<EOL>"<STR_LIT:type>": exdict.get("<STR_LIT:type>", RuntimeError),<EOL>"<STR_LIT>": _get_replacement_token(exdict["<STR_LIT>"]),<EOL>},<EOL>)<EOL>for exnum, exdict in enumerate(contract_exceptions)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>homogenized_exdict = {<EOL>"<STR_LIT:default>": {<EOL>"<STR_LIT>": <NUM_LIT:0>,<EOL>"<STR_LIT>": contract_exceptions,<EOL>"<STR_LIT:type>": RuntimeError,<EOL>"<STR_LIT>": _get_replacement_token(contract_exceptions),<EOL>}<EOL>}<EOL><DEDENT>if isinstance(contract_exceptions, list) and (<EOL>len(homogenized_exdict) != len(contract_exceptions)<EOL>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>msgs = [exvalue["<STR_LIT>"] for exvalue in homogenized_exdict.values()]<EOL>if len(set(msgs)) != len(msgs):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if (contract_name in _CUSTOM_CONTRACTS) and (<EOL>_CUSTOM_CONTRACTS[contract_name] != contract_exceptions<EOL>):<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>".format(contract_name)<EOL>)<EOL><DEDENT>fields = [<EOL>exdict["<STR_LIT>"]<EOL>for exdict in homogenized_exdict.values()<EOL>if exdict["<STR_LIT>"] is not None<EOL>]<EOL>if (len(fields) > <NUM_LIT:2>) or (<EOL>(len(fields) == <NUM_LIT:2>)<EOL>and (fields[<NUM_LIT:0>] != "<STR_LIT>")<EOL>and (fields[<NUM_LIT:1>] != "<STR_LIT>")<EOL>):<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>"<EOL>)<EOL><DEDENT>_CUSTOM_CONTRACTS[contract_name] = homogenized_exdict<EOL>return contract_exceptions<EOL>
Homogenize custom contract exception definition.