woob.tools.misc

class NoDefaultType(*args, **kwargs)[source]

Bases: object

Type for the NO_DEFAULT constant.

get_backtrace(empty='Empty backtrace.')[source]

Try to get backtrace as string. Returns “Error while trying to get backtrace” on failure.

get_bytes_size(size, unit_name)[source]

Converts a unit and a number into a number of bytes.

>>> get_bytes_size(2, 'KB')
2048.0
iter_fields(obj)[source]
to_unicode(text)[source]
>>> to_unicode('ascii') == u'ascii'
True
>>> to_unicode(u'utf\xe9'.encode('UTF-8')) == u'utf\xe9'
True
>>> to_unicode(u'unicode') == u'unicode'
True
limit(iterator, lim)[source]

Iterate on the lim first elements of iterator.

find_exe(basename)[source]

Find the path to an executable by its base name (such as ‘gpg’).

The executable can be overriden using an environment variable in the form NAME_EXECUTABLE where NAME is the specified base name in upper case.

If the environment variable is not provided, the PATH will be searched both without and with a “.exe” suffix for Windows compatibility.

If the executable can not be found, None is returned.

polling_loop(*, count=None, timeout=None, delay=5)[source]

Delay iterator for polling loops.

The count or timeout must be specified; both can be simultaneously. The default delay is five seconds.

Parameters:
  • count (int) – Maximum number of iterations this loop can produce. (default: None) Can be None for unlimited retries.

  • timeout (float) – Maximum number of seconds to try the loop for. (default: None)

  • delay (float) – Delay in seconds between each iteration. (default: 5)

class classproperty(f)[source]

Bases: object

Use it as a decorator to define a class property.

>>> class C:
...     @classproperty
...     def VERSION(self):
...         return '3.3'
...
>>> C.VERSION
'3.3'
>>> C().VERSION
'3.3'