module documentation

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.
Variable _CollateType Undocumented
def collate(iterables, key=(lambda a: a), reverse=False):

A helper function to iterate over multiple iterables yielding the same type of elements in a sorted way.

Examples

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
...

Information

Parameters
iterables:_Iterable[_Iterable[_CollateType]]A list of iterable yielding the same type of elements.
key:_Callable[[_CollateType], _Any]A lambda function that defines the key used to sort iterable elements.
reverse:boolWhether increasing or decreasing order.
Returns
_Iterator[_CollateType]A generator of sorted iterable elements.
_CollateType =

Undocumented