'Given `data` as a structure of nested dictionaries, and `scheme` as a
structure of nested dictionaries , `yield` tuples `(attr, val)` where
`attr` and `val` are corresponding leaf nodes in `scheme` and `data`.
As its name indicates, `scheme` defines how the data is structured,
so this function tries to find leaf nodes in `data` that correspond
to the leafs nodes of `scheme`, and not the other way around.
Leaf nodes of `data` that do not exist in the `scheme` do not matter.
If a leaf node of `scheme` is not present in `data`,
no value is yielded for that attribute and a simple warning is issued.
Finally, to account for attributes of which the value is split between
several leaf nodes in `data`, leaf nodes of `scheme` can be tuples
`(attr, order)` where `attr` is the attribute to which the leaf node
belongs, and `order` is the place at which it should appear in the
value. The different `value`s belonging to the same `attr` are simply
joined with `\' \'`. This is hardcoded and not very flexible, but it gets
the job done.
For example:
>>> scheme = {
\'key1\': \'attribute\',
\'key group\': {
\'subkey1\': \'subattribute\',
\'subkey2\': (\'composite attribute\', 0)
\'key2\': (\'composite attribute\', 1)
>>> data = {
\'key1\': \'value\',
\'key group\': {
\'subkey1\': \'subvalue\',
\'subkey2\': \'part 1 of composite attr\'
\'key2\': \'part 2\'
>>> print(list(_map_data_to_scheme(data, scheme)))
[(\'subattribute\', \'subvalue\'),
(\'attribute\', \'value\'),
(\'composite attribute\', \'part 1 of composite attr part 2\')]'

def _map_data_to_scheme(self, data, scheme):

    composites = defaultdict(list)
    for (attr, val) in self._data_to_scheme_child(data, scheme, composites):
        (yield (attr, val))
    for (composite_attr, value_parts) in composites.items():
        (yield (composite_attr, '    '.join(value_parts)))
