woob.capabilities.base
¶
- exception FieldNotFound(obj, field)[source]¶
Bases:
Exception
A field isn’t found.
- Parameters
obj (
BaseObject
) – objectfield (
Field
) – field not found
- class Capability[source]¶
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 Field(doc, *args, **kwargs)[source]¶
Bases:
object
Field of a
BaseObject
class.- Parameters
doc (
str
) – docstring of the fieldargs – list of types accepted
default – default value of this field. If not specified,
NotLoaded
is used.
- empty(value)[source]¶
Checks if a value is empty (None, NotLoaded or NotAvailable).
- Return type
bool
- class BaseObject(id='', url=NotLoaded, backend=None)[source]¶
Bases:
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', str, date, datetime) origin = Field('Origin of transfer', int, str) recipient = Field('Recipient', int, str)
The docstring is mandatory.
- Variables
url – (
str
) url
- id = None¶
- backend = None¶
- property fullid¶
Full ID of the object, in form ‘ID@backend’.
- set_empty_fields(value, excepts=())[source]¶
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