mpylab.tools.filenames moduleΒΆ

Helpers for generated file names.

mpylab.tools.filenames.filename_token(value: Any, max_length: int = 64, default: str = 'item') str

Return a filesystem-safe token for use inside generated filenames.

The returned token is derived from value, lower-cased, ASCII-normalized, stripped of path separators and other unsafe characters, and limited to max_length characters. If sanitizing or truncating changes the original text, a short stable hash is appended to reduce accidental collisions while keeping the human-readable prefix.

mpylab.tools.filenames.format_output_filename(pattern: str, *args: Any, max_token_length: int = 64) str

Format pattern with filename-safe versions of args.

Only the substitution arguments are sanitized. Directory components already present in pattern are preserved, so patterns such as "output/out_raw_%s.dat" keep their target directory unchanged.