woob.tools.misc
¶
- 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'
- clean_text(text, *, remove_newlines=True, normalize='NFC', transliterate=False)[source]¶
Clean a given text.
This function is used by the
woob.browser.filters.standard.CleanText
browser filter.- Parameters:
text (
str
) – The text to clean.remove_newlines (
bool
) – Whether to transform newlines into spaces or not. (default:True
) If this parameter is set to false, newlines will be normalized as UNIX-style newlines (U+000A).normalize (
str
|bool
|None
) – The Unicode normalization to apply, if relevant. (default:'NFC'
)transliterate (
bool
) – Whether to transliterate Unicode characters into (default:False
) ASCII characters, when possible.
- Return type:
- Returns:
The cleaned text.
- 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.
- 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