weboob.capabilities.base

exception weboob.capabilities.base.UserError

Bases: exceptions.Exception

Exception containing an error message for user.

exception weboob.capabilities.base.FieldNotFound(obj, field)

Bases: exceptions.Exception

A field isn’t found.

Parameters:
class weboob.capabilities.base.Capability

Bases: object

This is the base class for all capabilities.

A capability may define abstract methods (which raise NotImplementedError) with an explicit docstring to tell backends how to implement them.

Also, it may define some objects, using BaseObject.

class weboob.capabilities.base.Field(doc, *args, **kwargs)

Bases: object

Field of a BaseObject class.

Parameters:
  • doc (str) – docstring of the field
  • args – list of types accepted
  • default – default value of this field. If not specified, NotLoaded is used.
convert(value)

Convert value to the wanted one.

class weboob.capabilities.base.IntField(doc, **kwargs)

Bases: weboob.capabilities.base.Field

A field which accepts only int and long types.

convert(value)
class weboob.capabilities.base.DecimalField(doc, **kwargs)

Bases: weboob.capabilities.base.Field

A field which accepts only decimal type.

convert(value)
class weboob.capabilities.base.FloatField(doc, **kwargs)

Bases: weboob.capabilities.base.Field

A field which accepts only float type.

convert(value)
class weboob.capabilities.base.StringField(doc, **kwargs)

Bases: weboob.capabilities.base.Field

A field which accepts only unicode strings.

convert(value)
class weboob.capabilities.base.BytesField(doc, **kwargs)

Bases: weboob.capabilities.base.Field

A field which accepts only bytes strings.

convert(value)
class weboob.capabilities.base.BoolField(doc, **kwargs)

Bases: weboob.capabilities.base.Field

A field which accepts only bool type.

convert(value)
weboob.capabilities.base.empty(value)

Checks if a value is empty (None, NotLoaded or NotAvailable).

Return type:bool
class weboob.capabilities.base.BaseObject(id=u'', url=NotLoaded, backend=None)

Bases: weboob.tools.compat.StrConv, object

This is the base class for a capability object.

A capability interface may specify to return several kind of objects, to formalise retrieved information from websites.

As python is a flexible language where variables are not typed, we use a system to force backends to set wanted values on all fields. To do that, we use the Field class and all derived ones.

For example:

class Transfer(BaseObject):
    " Transfer from an account to a recipient.  "

    amount =    DecimalField('Amount to transfer')
    date =      Field('Date of transfer', basestring, date, datetime)
    origin =    Field('Origin of transfer', int, long, basestring)
    recipient = Field('Recipient', int, long, basestring)

The docstring is mandatory.

Variables:url – (unicode) url
backend = None
copy()
classmethod from_dict(values, backend=None)
fullid

Full ID of the object, in form ‘ID@backend‘.

id = None
iter_fields()

Iterate on the fields keys and values.

Can be overloaded to iterate on other things.

Return type:iter[(key, value)]
set_empty_fields(value, excepts=())

Set the same value on all empty fields.

Parameters:
  • value – value to set on all empty fields
  • excepts – if specified, do not change fields listed
to_dict()