woob.tools.backend

class BackendStorage(name, storage)[source]

Bases: object

This is an abstract layer to store data in storages (woob.tools.storage) easily.

It is instancied automatically in constructor of Module, in the Module.storage attribute.

Parameters:
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

delete(*args)[source]

Delete a value from the storage.

Parameters:

args – path to delete.

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:

Any

load(default)[source]

Load storage.

It is made automatically when your backend is created, and use the STORAGE class attribute as default.

Parameters:

default (dict) – this is the default tree if storage is empty

save()[source]

Save storage.

class BackendConfig(*values)[source]

Bases: ValuesDict

Configuration of a backend.

This class is firstly instanced as a woob.tools.value.ValuesDict, containing some woob.tools.value.Value (and derivated) objects.

Then, using the load() method will load configuration from file and create a copy of the BackendConfig object with the loaded values.

modname: str
instname: str
woob: WoobBase
load(woob, modname, instname, config, nofail=False)[source]

Load configuration from dict to create an instance.

Parameters:
  • woob (woob.core.woob.WoobBase) – woob object

  • modname (str) – name of the module

  • instname (str) – name of this backend

  • params (dict) – parameters to load

  • nofail (bool) – if true, this call can’t fail (default: False)

Return type:

BackendConfig

dump()[source]

Dump config in a dictionary.

Return type:

dict

save(edit=True, params=None)[source]

Save backend config.

Parameters:
  • edit (bool) – if true, it changes config of an existing backend (default: True)

  • params (dict) – if supplied, params to merge with the ones of the current object (default: None)

class Module(woob, name, config=None, storage=None, logger=None, nofail=False)[source]

Bases: object

Base class for modules.

You may derivate it, and also all capabilities you want to implement.

Parameters:
NAME: ClassVar[str]

Name of the maintainer of this module.

MAINTAINER: ClassVar[str] = '<unspecified>'

Name of the maintainer.

EMAIL: ClassVar[str] = '<unspecified>'

Email address of the maintainer.

DESCRIPTION: ClassVar[str] = '<unspecified>'

Description

LICENSE: ClassVar[str] = '<unspecified>'

License of the module

CONFIG: ClassVar[BackendConfig] = {}

Configuration required for backends.

Values must be woob.tools.value.Value objects.

STORAGE: ClassVar[Dict] = {}

Storage

BROWSER: Browser | None = None

Browser class

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.

DEPENDENCIES: ClassVar[Tuple[str]] = ()

Tuple of module names on which this module depends.

exception ConfigError(message, bad_fields=None)[source]

Bases: Exception

Raised when the config can’t be loaded.

property VERSION
dump_state()[source]

Dump module state into storage.

deinit()[source]

This abstract method is called when the backend is unloaded.

property weboob

Deprecated since version 3.4: Don’t use this attribute, but woob instead.

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’.

Return type:

Browser | None

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 instanciate

Return type:

Browser | None

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]

  • _proxy for HTTP requests

  • _proxy_ssl for HTTPS requests

classmethod iter_caps()[source]

Iter capabilities implemented by this backend.

Return type:

iter[woob.capabilities.base.Capability]

has_caps(*caps)[source]

Check if this backend implements at least one of these capabilities.

caps should be list of Capability objects (e.g. CapBank) or capability names (e.g. ‘bank’).

Return type:

bool

fillobj(obj, fields=None)[source]

Fill an object with the wanted fields.

Parameters:

fields (list) – what fields to fill; if None, all fields are filled (default: None)