capabilities objets inherit from CapBaseObject (refs #369)
This commit is contained in:
parent
33d1574878
commit
e980e040ba
20 changed files with 126 additions and 102 deletions
|
|
@ -21,7 +21,7 @@ if sys.version_info[:2] <= (2, 5):
|
|||
from weboob.tools.property import property
|
||||
|
||||
|
||||
from .base import IBaseCap
|
||||
from .base import IBaseCap, CapBaseObject
|
||||
|
||||
|
||||
__all__ = ['Account', 'AccountNotFound', 'ICapBank', 'Operation']
|
||||
|
|
@ -31,9 +31,10 @@ class AccountNotFound(Exception):
|
|||
pass
|
||||
|
||||
|
||||
class Account(object):
|
||||
class Account(CapBaseObject):
|
||||
FIELDS = ('label', 'balance', 'coming')
|
||||
def __init__(self):
|
||||
self.id = 0
|
||||
CapBaseObject.__init__(self, 0)
|
||||
self.label = ''
|
||||
self._balance = 0.0
|
||||
self._coming = 0.0
|
||||
|
|
@ -59,8 +60,10 @@ class Account(object):
|
|||
return u"<Account id='%s' label='%s'>" % (self.id, self.label)
|
||||
|
||||
|
||||
class Operation(object):
|
||||
class Operation(CapBaseObject):
|
||||
FIELDS = ('date', 'label', 'amount')
|
||||
def __init__(self):
|
||||
CapBaseObject(self, 0)
|
||||
self.date = None
|
||||
self._label = u''
|
||||
self._amount = 0.0
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010 Christophe Benz
|
||||
# Copyright(C) 2010 Christophe Benz, Romain Bignon
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -16,7 +16,9 @@
|
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
__all__ = ['IBaseCap', 'NotLoaded', 'LoadingError']
|
||||
from weboob.tools.misc import iter_fields
|
||||
|
||||
__all__ = ['IBaseCap', 'NotLoaded', 'LoadingError', 'CapBaseObject']
|
||||
|
||||
|
||||
class NotLoadedMeta(type):
|
||||
|
|
@ -45,3 +47,20 @@ class LoadingError(object):
|
|||
|
||||
class IBaseCap(object):
|
||||
pass
|
||||
|
||||
class CapBaseObject(object):
|
||||
FIELDS = None
|
||||
|
||||
def __init__(self, id, backend=None):
|
||||
self.id = id
|
||||
self.backend = backend
|
||||
|
||||
def iter_fields(self):
|
||||
if self.FIELDS is None:
|
||||
for key, value in iter_fields(self):
|
||||
if key != 'backend':
|
||||
yield key, value
|
||||
else:
|
||||
yield 'id', self.id
|
||||
for attrstr in self.FIELDS:
|
||||
yield attrstr, getattr(self, attrstr)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
import datetime
|
||||
|
||||
from .base import IBaseCap
|
||||
from .base import IBaseCap, CapBaseObject
|
||||
|
||||
|
||||
__all__ = ['ChatException', 'ICapChat']
|
||||
|
|
@ -28,8 +28,11 @@ class ChatException(Exception):
|
|||
pass
|
||||
|
||||
|
||||
class ChatMessage(object):
|
||||
def __init__(self, id_from, id_to, message, date=None):
|
||||
class ChatMessage(CapBaseObject):
|
||||
FIELDS = ('id_from', 'id_to', 'date', 'message')
|
||||
|
||||
def __init__(self, id_from, id_to, message, date=None):
|
||||
CapBaseObject.__init__(self, '%s.%s' % (id_from, id_to))
|
||||
self.id_from = id_from
|
||||
self.id_to = id_to
|
||||
self.message = message
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
from .base import IBaseCap
|
||||
from .base import IBaseCap, CapBaseObject
|
||||
from weboob.tools.ordereddict import OrderedDict
|
||||
|
||||
|
||||
|
|
@ -50,14 +50,16 @@ class ContactPhoto(object):
|
|||
def __repr__(self):
|
||||
return u'<ContactPhoto "%s" data=%do tndata=%do>' % (self.name, len(self.data), len(self.thumbnail_data))
|
||||
|
||||
class Contact(object):
|
||||
class Contact(CapBaseObject):
|
||||
FIELDS = ('name', 'status', 'status_msg', 'summary', 'avatar', 'photos', 'profile')
|
||||
|
||||
STATUS_ONLINE = 0x001
|
||||
STATUS_AWAY = 0x002
|
||||
STATUS_OFFLINE = 0x004
|
||||
STATUS_ALL = 0xfff
|
||||
|
||||
def __init__(self, id, name, status):
|
||||
self.id = id
|
||||
CapBaseObject.__init__(self, id)
|
||||
self.name = name
|
||||
self.status = status
|
||||
self.status_msg = u''
|
||||
|
|
@ -74,17 +76,6 @@ class Contact(object):
|
|||
for key, value in kwargs.iteritems():
|
||||
setattr(photo, key, value)
|
||||
|
||||
def iter_fields(self):
|
||||
return {'id': self.id,
|
||||
'name': self.name,
|
||||
'status': self.status,
|
||||
'status_msg': self.status_msg,
|
||||
'summary': self.summary,
|
||||
'avatar': self.avatar,
|
||||
'photos': self.photos,
|
||||
'profile': self.profile,
|
||||
}.iteritems()
|
||||
|
||||
class ICapContact(IBaseCap):
|
||||
def iter_contacts(self, status=Contact.STATUS_ALL, ids=None):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -16,13 +16,16 @@
|
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
from .cap import ICap
|
||||
from .base import IBaseCap, CapBaseObject
|
||||
|
||||
|
||||
__all__ = ('IpLocation', 'ICapGeolocIp')
|
||||
|
||||
class IpLocation(object):
|
||||
class IpLocation(CapBaseObject):
|
||||
FIELDS = ('city', 'region', 'zipcode', 'country', 'lt', 'lg', 'host', 'tls', 'isp')
|
||||
def __init__(self, ipaddr):
|
||||
CapBaseObject.__init__(self, ipaddr)
|
||||
|
||||
self.ipaddr = ipaddr
|
||||
self.city = None
|
||||
self.region = None
|
||||
|
|
@ -34,6 +37,6 @@ class IpLocation(object):
|
|||
self.tld = None
|
||||
self.isp = None
|
||||
|
||||
class ICapGeolocIp(ICap):
|
||||
class ICapGeolocIp(IBaseCap):
|
||||
def get_location(self, ipaddr):
|
||||
raise NotImplementedError()
|
||||
|
|
|
|||
|
|
@ -16,15 +16,19 @@
|
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
from .base import IBaseCap
|
||||
from .base import IBaseCap, CapBaseObject, NotLoaded
|
||||
|
||||
|
||||
__all__ = ['ICapTorrent', 'Torrent']
|
||||
|
||||
|
||||
class Torrent(object):
|
||||
def __init__(self, id, name, date=None, size=0.0, url=u'', seeders=0, leechers=0, files=[], description=u''):
|
||||
self.id = id
|
||||
class Torrent(CapBaseObject):
|
||||
FIELDS = ('name', 'size', 'date', 'url', 'seeders', 'leechers', 'files', 'description')
|
||||
|
||||
def __init__(self, id, name, date=NotLoaded, size=NotLoaded, url=NotLoaded,
|
||||
seeders=NotLoaded, leechers=NotLoaded, files=NotLoaded,
|
||||
description=NotLoaded):
|
||||
CapBaseObject.__init__(self, id)
|
||||
self.name = name
|
||||
self.date = date
|
||||
self.size = size
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
from datetime import time
|
||||
|
||||
from .base import IBaseCap
|
||||
from .base import IBaseCap, CapBaseObject
|
||||
|
||||
|
||||
__all__ = ['Departure', 'ICapTravel', 'Station']
|
||||
|
|
@ -45,18 +45,23 @@ class ICapTravel(IBaseCap):
|
|||
raise NotImplementedError()
|
||||
|
||||
|
||||
class Station(object):
|
||||
def __init__(self, _id, name):
|
||||
self.id = _id
|
||||
class Station(CapBaseObject):
|
||||
FIELDS = ('name',)
|
||||
|
||||
def __init__(self, id, name):
|
||||
CapBaseObject.__init__(self, id)
|
||||
self.name = name
|
||||
|
||||
def __repr__(self):
|
||||
return "<Station id='%s' name='%s'>" % (self.id, self.name)
|
||||
|
||||
|
||||
class Departure(object):
|
||||
def __init__(self, _id, _type, _time):
|
||||
self.id = _id
|
||||
class Departure(CapBaseObject):
|
||||
FIELDS = ('type', 'time', 'departure_station', 'arrival_station', 'late', 'information', 'plateform')
|
||||
|
||||
def __init__(self, id, _type, _time):
|
||||
CapBaseObject.__init__(self, id)
|
||||
|
||||
self.type = _type
|
||||
self.time = _time
|
||||
self.departure_station = u''
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
from .base import IBaseCap, LoadingError, NotLoaded
|
||||
from .base import IBaseCap, LoadingError, NotLoaded, CapBaseObject
|
||||
|
||||
|
||||
__all__ = ['BaseVideo', 'ICapVideo']
|
||||
|
|
@ -37,7 +37,9 @@ class VideoThumbnail(object):
|
|||
return self.data is not NotLoaded
|
||||
|
||||
|
||||
class BaseVideo(object):
|
||||
class BaseVideo(CapBaseObject):
|
||||
FIELDS = ('title', 'url', 'author', 'duration', 'date', 'rating', 'rating_max', 'thumbnail', 'nsfw')
|
||||
|
||||
def __init__(self, _id, title=NotLoaded, url=NotLoaded, author=NotLoaded, duration=NotLoaded, date=NotLoaded,
|
||||
rating=NotLoaded, rating_max=NotLoaded, thumbnail=NotLoaded, thumbnail_url=None, nsfw=False):
|
||||
self.id = unicode(_id)
|
||||
|
|
|
|||
|
|
@ -16,14 +16,15 @@
|
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
from .base import IBaseCap
|
||||
from .base import IBaseCap, CapBaseObject
|
||||
|
||||
|
||||
__all__ = ['City', 'CityNotFound', 'Current', 'Forecast', 'ICapWeather']
|
||||
|
||||
|
||||
class Forecast(object):
|
||||
class Forecast(CapBaseObject):
|
||||
def __init__(self, date, low, high, text, unit):
|
||||
CapBaseObject.__init__(self, date)
|
||||
self.date = date
|
||||
self.low = low
|
||||
self.high = high
|
||||
|
|
@ -31,17 +32,18 @@ class Forecast(object):
|
|||
self.unit = unit
|
||||
|
||||
|
||||
class Current(object):
|
||||
class Current(CapBaseObject):
|
||||
def __init__(self, date, temp, text, unit):
|
||||
CapBaseObject.__init__(self, date)
|
||||
self.date = date
|
||||
self.temp = temp
|
||||
self.text = text
|
||||
self.unit = unit
|
||||
|
||||
|
||||
class City(object):
|
||||
def __init__(self, city_id, name):
|
||||
self.city_id = city_id
|
||||
class City(CapBaseObject):
|
||||
def __init__(self, id, name):
|
||||
self.id = id
|
||||
self.name = name
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue