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

excepthook(exc_type, exc_value, exc_traceback)[source]
flush()[source]
start_capturing(bar=None)[source]
stop_capturing(bar=None)[source]
unwrap(stdout=False, stderr=False)[source]
unwrap_excepthook()[source]
unwrap_stderr()[source]
unwrap_stdout()[source]
update_capturing()[source]
wrap(stdout=False, stderr=False)[source]
wrap_excepthook()[source]
wrap_stderr()[source]
wrap_stdout()[source]
class progressbar.utils.WrappingIO(target, capturing=False, listeners={})[source]

Bases: object

flush()[source]
write(value)[source]
progressbar.utils.deltas_to_seconds(*deltas, **kwargs)[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, default=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 environt variable is not defined, or has an unknown value, returns default

progressbar.utils.len_color(value)[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)[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'