def _extract_substructure(base, substructure):
if (type(substructure) is not dict and<EOL>type(base) is not dict):<EOL><INDENT>return base<EOL><DEDENT>if type(base) is not dict:<EOL><INDENT>raise MissingConfigError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(repr(base), repr(substructure)))<EOL><DEDENT>if type(substructure) is not dict:<EOL><INDENT>raise MissingConfigError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(repr(base), repr(substructure)))<EOL><DEDENT>try:<EOL><INDENT>subdict = []<EOL>for key, value in substructure.iteritems():<EOL><INDENT>if type(value) is _Optional:<EOL><INDENT>base_val = base.get(key, value.default)<EOL><DEDENT>elif _is_optional(value):<EOL><INDENT>base_val = base.get(key, {})<EOL><DEDENT>else:<EOL><INDENT>base_val = base[key]<EOL><DEDENT>subdict.append((key, _extract_substructure(base_val, value)))<EOL><DEDENT>return dict(subdict)<EOL><DEDENT>except KeyError as e:<EOL><INDENT>raise MissingConfigError(<EOL>"<STR_LIT>".format(e.args[<NUM_LIT:0>]))<EOL><DEDENT>
Assuming that substructure is a possibly nested dictionary, return a new
dictionary with the same keys (and subkeys) as substructure, but extract
the leaf values from base.

This is used to extract and verify a configuration from a yaml blob.