@classmethod<EOL><INDENT>def _apply_sub_frames(cls, documents, subs):<DEDENT>
<EOL>for path, projection in subs.items():<EOL><INDENT>sub = None<EOL>expect_map = False<EOL>if '<STR_LIT>' in projection:<EOL><INDENT>sub = projection.pop('<STR_LIT>')<EOL><DEDENT>elif '<STR_LIT>' in projection:<EOL><INDENT>sub = projection.pop('<STR_LIT>')<EOL>expect_map = True<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT>raw_subs = []<EOL>for document in documents:<EOL><INDENT>value = cls._path_to_value(path, document)<EOL>if value is None:<EOL><INDENT>continue<EOL><DEDENT>if isinstance(value, dict):<EOL><INDENT>if expect_map:<EOL><INDENT>raw_subs += value.values()<EOL>for k, v in value.items():<EOL><INDENT>if isinstance(v ,list):<EOL><INDENT>value[k] = [<EOL>sub(u) for u in v if isinstance(u, dict)]<EOL><DEDENT>else:<EOL><INDENT>value[k] = sub(v)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raw_subs.append(value)<EOL>value = sub(value)<EOL><DEDENT><DEDENT>elif isinstance(value, list):<EOL><INDENT>raw_subs += value<EOL>value = [sub(v) for v in value if isinstance(v, dict)]<EOL><DEDENT>else:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>child_document = document<EOL>keys = cls._path_to_keys(path)<EOL>for key in keys[:-<NUM_LIT:1>]:<EOL><INDENT>child_document = child_document[key]<EOL><DEDENT>child_document[keys[-<NUM_LIT:1>]] = value<EOL><DEDENT>if projection:<EOL><INDENT>sub._apply_projection(raw_subs, projection)<EOL><DEDENT><DEDENT>
Convert embedded documents to sub-frames for one or more documents