cmsml.util

Helpful functions and utilities.

Functions:

is_lazy_iterable(obj)

Returns whether obj is iterable lazily, such as generators, range objects, maps, etc.

make_list(obj[, cast])

Converts an object obj to a list and returns it.

tmp_file([create, delete])

Prepares a temporary file and opens a context yielding its path.

tmp_dir([create, delete])

Prepares a temporary directory and opens a context yielding its path.

is_lazy_iterable(obj)[source]

Returns whether obj is iterable lazily, such as generators, range objects, maps, etc.

make_list(obj, cast=True)[source]

Converts an object obj to a list and returns it. Objects of types tuple and set are converted if cast is True. Otherwise, and for all other types, obj is put in a new list.

tmp_file(create=False, delete=True, **kwargs)[source]

Prepares a temporary file and opens a context yielding its path. When create is True, the file is created before the context is opened, and deleted upon closing if delete is True. All kwargs are forwarded to tempfile.mkstemp().

tmp_dir(create=True, delete=True, **kwargs)[source]

Prepares a temporary directory and opens a context yielding its path. When create is True, the directory is created before the context is opened, and deleted upon closing if delete is True. All kwargs are forwarded to tempfile.mkdtemp().