Module that provide util functions
Class | Peekable |
Undocumented |
Function | collate |
A helper function to iterate over multiple iterables yielding the same type of elements in a sorted way. |
A helper function to iterate over multiple iterables yielding the same type of elements in a sorted way.
This is very useful to iterate over search results from multiple search queries. For example, iterating over all contexts where the associated symbol name contains 'acpi'.
>>> acpi_iterables = [reven_server.trace.search.symbol(symbol) for symbol in reven_server.ossi.symbols('acpi')] >>> for ctx in collate(acpi_iterables): >>> print('#{}: {}'.format(ctx.transition_after().id, ctx.ossi.location().symbol)) #1471900994: HalAcpiGetTableDispatch #1471900999: HalpAcpiGetTable #1471901083: HalpAcpiGetTableWork #1471901099: HalpAcpiGetCachedTable #1471901168: HalpAcpiGetTableFromBios #1471903841: HalAcpiGetTableDispatch #1471903846: HalpAcpiGetTable #1471903930: HalpAcpiGetTableWork #1471903946: HalpAcpiGetCachedTable #1471903989: HalpAcpiIsCachedTableCompromised ...
Alternatively, using a kind of tag on iterable elements.
>>> from itertools import repeat >>> acpi_iterables = [zip(reven_server.trace.search.symbol(symbol), repeat(symbol.name)) for symbol in reven_server.ossi.symbols('acpi')] >>> for ctx, symbol in collate(acpi_iterables, key=lambda ctx_symbol: ctx_symbol[0]): >>> print('#{}: {}'.format(ctx.transition_after().id, symbol)) #1471900994: HalAcpiGetTableDispatch #1471900999: HalpAcpiGetTable #1471901083: HalpAcpiGetTableWork #1471901099: HalpAcpiGetCachedTable #1471901168: HalpAcpiGetTableFromBios #1471903841: HalAcpiGetTableDispatch #1471903846: HalpAcpiGetTable #1471903930: HalpAcpiGetTableWork #1471903946: HalpAcpiGetCachedTable #1471903989: HalpAcpiIsCachedTableCompromised ...
Parameters | iterables | A list of iterable yielding the same type of elements. |
key | A lambda function that defines the key used to sort iterable elements. | |
reverse | Whether increasing or decreasing order. | |
Returns | A generator of sorted iterable elements. |