Recursively extract files from the given dictionary based on specified paths. A path may look like this ['foo', 'files', ' ', 'data']. Note: this mutates the given dictionary.
(
# TODO: this needs to take Dict but variance issues.....
# create protocol type ?
query: Mapping[str, object],
*,
paths: Sequence[Sequence[str]],
)
| 36 | |
| 37 | |
| 38 | def extract_files( |
| 39 | # TODO: this needs to take Dict but variance issues..... |
| 40 | # create protocol type ? |
| 41 | query: Mapping[str, object], |
| 42 | *, |
| 43 | paths: Sequence[Sequence[str]], |
| 44 | ) -> list[tuple[str, FileTypes]]: |
| 45 | """Recursively extract files from the given dictionary based on specified paths. |
| 46 | |
| 47 | A path may look like this ['foo', 'files', '<array>', 'data']. |
| 48 | |
| 49 | Note: this mutates the given dictionary. |
| 50 | """ |
| 51 | files: list[tuple[str, FileTypes]] = [] |
| 52 | for path in paths: |
| 53 | files.extend(_extract_items(query, path, index=0, flattened_key=None)) |
| 54 | return files |
| 55 | |
| 56 | |
| 57 | def _extract_items( |