discodop.util

Misc code to avoid cyclic imports.

Functions

genericdecompressor(cmd, filename[, encoding]) Run command line decompressor on file and return file object.
merge(*iterables[, key]) Generator that performs an n-way merge of sorted iterables.
openread(filename[, encoding]) Open stdin/text file for reading; decompress gz/lz4/zst files on-the-fly.
readbytes(filename) Read binary file, return bytes; decompress gz/lz4/zst files on-the-fly.
run(*popenargs, **kwargs) Run command with arguments and return (returncode, stdout, stderr).
slice_bounds(seq, slice_obj[, allow_step]) Calculate the effective (start, stop) bounds of a slice.
tokenize(text) A basic tokenizer following English/French PTB/FTB conventions.
which(program[, exception]) Return first match for program in search path.
workerfunc(func) Wrap a multiprocessing worker function to produce a full traceback.

Classes

Entry(key, value, count) A PyAgenda entry.
OrderedSet([iterable]) A frozen, ordered set which maintains a regular list/tuple and set.
PyAgenda([iterable]) Priority Queue implemented with array-based heap.
discodop.util.which(program, exception=True)[source]

Return first match for program in search path.

Parameters:exception – By default, ValueError is raised when program not found. Pass False to return None in this case.
discodop.util.workerfunc(func)[source]

Wrap a multiprocessing worker function to produce a full traceback.

discodop.util.openread(filename, encoding='utf8')[source]

Open stdin/text file for reading; decompress gz/lz4/zst files on-the-fly.

discodop.util.slice_bounds(seq, slice_obj, allow_step=False)[source]

Calculate the effective (start, stop) bounds of a slice.

Takes into account None indices and negative indices.

Returns:tuple (start, stop, 1), s.t. 0 <= start <= stop <= len(seq)
Raises:ValueError – if slice_obj.step is not None.
Parameters:allow_step – If true, then the slice object may have a non-None step. If it does, then return a tuple (start, stop, step).
class discodop.util.OrderedSet(iterable=None)[source]

A frozen, ordered set which maintains a regular list/tuple and set.

The set is indexable. Equality is defined _without_ regard for order.