progressbar.utils module

class progressbar.utils.AttributeDict[source]

Bases: dict

A dict that can be accessed with .attribute.

>>> attrs = AttributeDict(spam=123)

# Reading

>>> attrs['spam']
123
>>> attrs.spam
123

# Read after update using attribute

>>> attrs.spam = 456
>>> attrs['spam']
456
>>> attrs.spam
456

# Read after update using dict access

>>> attrs['spam'] = 123
>>> attrs['spam']
123
>>> attrs.spam
123

# Read after update using dict access

>>> del attrs.spam
>>> attrs['spam']
Traceback (most recent call last):
...
KeyError: 'spam'
>>> attrs.spam
Traceback (most recent call last):
...
AttributeError: No such attribute: spam
>>> del attrs.spam
Traceback (most recent call last):
...
AttributeError: No such attribute: spam
class progressbar.utils.StreamWrapper[source]

Bases: object

Wrap stdout and stderr globally.

capturing: int = 0
excepthook(exc_type, exc_value, exc_traceback)[source]
flush() None[source]
listeners: set
needs_clear() bool[source]
original_excepthook: Callable[[Type[BaseException], BaseException, TracebackType | None], None]
start_capturing(bar: ProgressBarMixinBase | None = None) None[source]
stderr: TextIO | WrappingIO
stdout: TextIO | WrappingIO
stop_capturing(bar: ProgressBarMixinBase | None = None) None[source]
unwrap(stdout: bool = False, stderr: bool = False) None[source]
unwrap_excepthook() None[source]
unwrap_stderr() None[source]
unwrap_stdout() None[source]
update_capturing() None[source]
wrap(stdout: bool = False, stderr: bool = False) None[source]
wrap_excepthook() None[source]
wrap_stderr() WrappingIO[source]
wrap_stdout() WrappingIO[source]
wrapped_excepthook: int = 0
wrapped_stderr: int = 0
wrapped_stdout: int = 0
class progressbar.utils.WrappingIO(target: base.IO, capturing: bool = False, listeners: types.Optional[types.Set[ProgressBar]] = None)[source]

Bases: object

buffer: StringIO
capturing: bool
close() None[source]
fileno() int[source]
flush() None[source]
flush_target() None[source]
isatty() bool[source]
listeners: set
needs_clear: bool = False
read(n: int = -1) str[source]
readable() bool[source]
readline(limit: int = -1) str[source]
readlines(hint: int = -1) list[str][source]
seek(offset: int, whence: int = 0) int[source]
seekable() bool[source]
target: IO
tell() int[source]
truncate(size: int | None = None) int[source]
writable() bool[source]
write(value: str) int[source]
writelines(lines: Iterable[str]) None[source]
progressbar.utils.deltas_to_seconds(*deltas, default: ~typing.Type[ValueError] | None = <class 'ValueError'>) int | float | None[source]

Convert timedeltas and seconds as int to seconds as float while coalescing.

>>> deltas_to_seconds(datetime.timedelta(seconds=1, milliseconds=234))
1.234
>>> deltas_to_seconds(123)
123.0
>>> deltas_to_seconds(1.234)
1.234
>>> deltas_to_seconds(None, 1.234)
1.234
>>> deltas_to_seconds(0, 1.234)
0.0
>>> deltas_to_seconds()
Traceback (most recent call last):
...
ValueError: No valid deltas passed to `deltas_to_seconds`
>>> deltas_to_seconds(None)
Traceback (most recent call last):
...
ValueError: No valid deltas passed to `deltas_to_seconds`
>>> deltas_to_seconds(default=0.0)
0.0
progressbar.utils.len_color(value: str | bytes) int[source]

Return the length of value without ANSI escape codes.

>>> len_color(b'[1234]abc')
3
>>> len_color(u'[1234]abc')
3
>>> len_color('[1234]abc')
3
progressbar.utils.no_color(value: StringT) StringT[source]

Return the value without ANSI escape codes.

>>> no_color(b'[1234]abc')
b'abc'
>>> str(no_color(u'[1234]abc'))
'abc'
>>> str(no_color('[1234]abc'))
'abc'
>>> no_color(123)
Traceback (most recent call last):
...
TypeError: `value` must be a string or bytes, got 123