woob.tools.backend¶
- class BackendStorage(name, storage)[source]¶
Bases:
objectThis is an abstract layer to store data in storages (
woob.tools.storage) easily.It is instancied automatically in constructor of
Module, in theModule.storageattribute.- Parameters:
name (str) – name of backend
storage (
woob.tools.storage.IStorage) – storage object
- set(*args)[source]¶
Set value in the storage.
Example:
>>> from woob.tools.storage import StandardStorage >>> backend = BackendStorage('blah', StandardStorage('/tmp/cfg')) >>> backend.storage.set('config', 'nb_of_threads', 10) >>>
- Parameters:
args – the path where to store value
- get(*args, **kwargs)[source]¶
Get a value or a dict of values in storage.
Example:
>>> from woob.tools.storage import StandardStorage >>> backend = BackendStorage('blah', StandardStorage('/tmp/cfg')) >>> backend.storage.get('config', 'nb_of_threads') 10 >>> backend.storage.get('config', 'unexistant', 'path', default='lol') 'lol' >>> backend.storage.get('config') {'nb_of_threads': 10, 'other_things': 'blah'}
- Parameters:
args – path to get
default – if specified, default value when path is not found
- Return type:
- class BackendConfig(*values)[source]¶
Bases:
ValuesDictConfiguration of a backend.
This class is firstly instanced as a
woob.tools.value.ValuesDict, containing somewoob.tools.value.Value(and derivated) objects.Then, using the
load()method will load configuration from file and create a copy of theBackendConfigobject with the loaded values.- load(woob, modname, instname, config, nofail=False)[source]¶
Load configuration from dict to create an instance.
- Parameters:
woob (
woob.core.woob.WoobBase) – woob objectmodname (
str) – name of the moduleinstname (
str) – name of this backendparams (
dict) – parameters to loadnofail (
bool) – if true, this call can’t fail (default:False)
- Return type:
- class Module(woob, name, config=None, storage=None, logger=None, nofail=False)[source]¶
Bases:
objectBase class for modules.
You may derivate it, and also all capabilities you want to implement.
- Parameters:
woob (
woob.core.woob.Woob) – woob instancename (
str) – name of backendconfig (
dict) – configuration of backend (optional) (default:None)storage (
woob.tools.storage.IStorage) – storage object (optional) (default:None)logger (
logging.Logger) – parent logger (optional) (default:None)
-
CONFIG:
ClassVar[BackendConfig] = {}¶ Configuration required for backends.
Values must be
woob.tools.value.Valueobjects.
-
ICON:
ClassVar[str|None] = None¶ URL to an optional icon.
If you want to create your own icon, create a ‘favicon.png’ icon in the module’s directory, and keep the ICON value to None.
-
OBJECTS:
ClassVar[dict] = {}¶ Supported objects to fill
The key is the class and the value the method to call to fill Method prototype: method(object, fields) When the method is called, fields are only the one which are NOT yet filled.
- exception ConfigError(message, bad_fields=None)[source]¶
Bases:
ExceptionRaised when the config can’t be loaded.
- property VERSION¶
- property weboob¶
Deprecated since version 3.4: Don’t use this attribute, but
woobinstead.
- property browser: Browser¶
Attribute ‘browser’. The browser is created at the first call of this attribute, to avoid useless pages access.
Note that the
create_default_browser()method is called to create it.
- create_default_browser()[source]¶
Method to overload to build the default browser in attribute ‘browser’.
- create_browser(*args, **kwargs)[source]¶
Build a browser from the BROWSER class attribute and the given arguments.
- Parameters:
klass (
woob.browser.browsers.Browser) – optional parameter to give another browser class to instanciateload_state (bool) – Whether to load the browser state if it supports the feature.
- Return type:
- get_proxy()[source]¶
Get proxy to use.
It will read in environment variables, then in backend config.
Proxy keys in backend config are: :rtype:
dict[str,str]_proxyfor HTTP requests_proxy_sslfor HTTPS requests