Uniquifies fetches from a list of fetch_mappers. This is a utility function used by _ListFetchMapper and _DictFetchMapper. It gathers all the unique fetches from a list of mappers and builds a list containing all of them but without duplicates (unique_fetches). It also returns a 2-D list
(fetch_mappers)
| 332 | |
| 333 | |
| 334 | def _uniquify_fetches(fetch_mappers): |
| 335 | """Uniquifies fetches from a list of fetch_mappers. |
| 336 | |
| 337 | This is a utility function used by _ListFetchMapper and _DictFetchMapper. It |
| 338 | gathers all the unique fetches from a list of mappers and builds a list |
| 339 | containing all of them but without duplicates (unique_fetches). |
| 340 | |
| 341 | It also returns a 2-D list of integers (values_indices) indicating at which |
| 342 | index in unique_fetches the fetches of the mappers are located. |
| 343 | |
| 344 | This list is as follows: |
| 345 | values_indices[mapper_index][mapper_fetch_index] = unique_fetches_index |
| 346 | |
| 347 | Args: |
| 348 | fetch_mappers: list of fetch mappers. |
| 349 | |
| 350 | Returns: |
| 351 | A list of fetches. |
| 352 | A 2-D list of integers. |
| 353 | """ |
| 354 | unique_fetches = [] |
| 355 | value_indices = [] |
| 356 | seen_fetches = object_identity.ObjectIdentityDictionary() |
| 357 | for m in fetch_mappers: |
| 358 | m_value_indices = [] |
| 359 | for f in m.unique_fetches(): |
| 360 | j = seen_fetches.get(f) |
| 361 | if j is None: |
| 362 | j = len(seen_fetches) |
| 363 | seen_fetches[f] = j |
| 364 | unique_fetches.append(f) |
| 365 | m_value_indices.append(j) |
| 366 | value_indices.append(m_value_indices) |
| 367 | return unique_fetches, value_indices |
| 368 | |
| 369 | |
| 370 | class _ListFetchMapper(_FetchMapper): |