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 = 0
excepthook(exc_type, exc_value, exc_traceback)[source]
flush() → None[source]
needs_clear() → bool[source]
start_capturing(bar: ProgressBarMixinBase | None = None) → None[source]
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() → progressbar.utils.WrappingIO[source]
wrap_stdout() → progressbar.utils.WrappingIO[source]
wrapped_excepthook = 0
wrapped_stderr = 0
wrapped_stdout = 0
class progressbar.utils.WrappingIO(target: base.IO, capturing: bool = False, listeners: types.Optional[types.Set[ProgressBar]] = None)[source]

Bases: object

close() → None[source]
fileno() → int[source]
flush() → None[source]
flush_target() → None[source]
isatty() → bool[source]
needs_clear = 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]
tell() → int[source]
truncate(size: Optional[int] = None) → int[source]
writable() → bool[source]
write(value: str) → int[source]
writelines(lines: Iterable[str]) → None[source]
progressbar.utils.deltas_to_seconds(*deltas, default: types.Optional[types.Type[ValueError]] = <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.env_flag(name: str, default: bool | None = None) → bool | None[source]

Accepts environt variables formatted as y/n, yes/no, 1/0, true/false, on/off, and returns it as a boolean

If the environment variable is not defined, or has an unknown value, returns default

progressbar.utils.is_ansi_terminal(fd: base.IO, is_terminal: bool | None = None) → bool[source]
progressbar.utils.is_terminal(fd: base.IO, is_terminal: bool | None = None) → bool[source]
progressbar.utils.len_color(value: Union[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'
True
>>> str(no_color(u'[1234]abc'))
'abc'
>>> str(no_color('[1234]abc'))
'abc'