[weboob] [PATCH 1/3] Add an url attribute to BaseObject

Simon Lipp laiquo at hwold.net
Sun Feb 7 17:22:42 CET 2016


Signed-off-by: Simon Lipp <laiquo at hwold.net>
---
 weboob/capabilities/account.py    |  8 ++++----
 weboob/capabilities/bank.py       |  4 ++--
 weboob/capabilities/base.py       |  4 +++-
 weboob/capabilities/bugtracker.py | 21 ++++++++++-----------
 weboob/capabilities/calendar.py   |  1 -
 weboob/capabilities/chat.py       |  4 ++--
 weboob/capabilities/cinema.py     |  8 ++++----
 weboob/capabilities/collection.py |  8 ++++----
 weboob/capabilities/contact.py    | 14 ++++++--------
 weboob/capabilities/file.py       |  1 -
 weboob/capabilities/gallery.py    |  8 ++------
 weboob/capabilities/gauge.py      |  3 ---
 weboob/capabilities/geolocip.py   |  4 ++--
 weboob/capabilities/housing.py    |  5 +----
 weboob/capabilities/job.py        |  1 -
 weboob/capabilities/lyrics.py     |  4 ++--
 weboob/capabilities/messages.py   |  5 +++--
 weboob/capabilities/paste.py      |  4 ++--
 weboob/capabilities/recipe.py     |  4 ++--
 weboob/capabilities/shop.py       |  1 -
 weboob/capabilities/subtitle.py   |  5 ++---
 weboob/capabilities/torrent.py    |  1 -
 weboob/capabilities/travel.py     | 12 ++++++------
 weboob/capabilities/weather.py    | 16 ++++++++--------
 24 files changed, 65 insertions(+), 81 deletions(-)

diff --git a/weboob/capabilities/account.py b/weboob/capabilities/account.py
index cfac8a5..729de02 100644
--- a/weboob/capabilities/account.py
+++ b/weboob/capabilities/account.py
@@ -38,8 +38,8 @@ class Account(BaseObject):
     password =      StringField('Password')
     properties =    Field('List of key/value properties', dict)
 
-    def __init__(self, id=None):
-        BaseObject.__init__(self, id)
+    def __init__(self, id=None, url=None):
+        BaseObject.__init__(self, id, url)
 
 
 class StatusField(BaseObject):
@@ -54,8 +54,8 @@ class StatusField(BaseObject):
     value =         StringField('Value')
     flags =         IntField('Flags')
 
-    def __init__(self, key, label, value, flags=0):
-        super(StatusField, self).__init__(key)
+    def __init__(self, key, label, value, flags=0, url=None):
+        super(StatusField, self).__init__(key, url)
         self.key = key
         self.label = label
         self.value = value
diff --git a/weboob/capabilities/bank.py b/weboob/capabilities/bank.py
index 917c020..941b9f3 100644
--- a/weboob/capabilities/bank.py
+++ b/weboob/capabilities/bank.py
@@ -55,8 +55,8 @@ class Recipient(BaseObject, Currency):
     label =     StringField('Name')
     currency =  StringField('Currency', default=None)
 
-    def __init__(self):
-        BaseObject.__init__(self, 0)
+    def __init__(self, id=0, url=None):
+        BaseObject.__init__(self, id, url)
 
     @property
     def currency_text(self):
diff --git a/weboob/capabilities/base.py b/weboob/capabilities/base.py
index be6943b..54fa00b 100644
--- a/weboob/capabilities/base.py
+++ b/weboob/capabilities/base.py
@@ -328,10 +328,12 @@ class BaseObject(object):
 
     id = None
     backend = None
+    url = None
     _fields = None
 
-    def __init__(self, id=u'', backend=None):
+    def __init__(self, id=u'', url=None, backend=None):
         self.id = to_unicode(id)
+        self.url = url
         self.backend = backend
         self._fields = deepcopy(self._fields)
 
diff --git a/weboob/capabilities/bugtracker.py b/weboob/capabilities/bugtracker.py
index df9639c..f235011 100644
--- a/weboob/capabilities/bugtracker.py
+++ b/weboob/capabilities/bugtracker.py
@@ -45,8 +45,8 @@ class Project(BaseObject):
     statuses =      Field('Available statuses for issues', list)
     priorities =    Field('Available priorities for issues', list)
 
-    def __init__(self, id, name):
-        BaseObject.__init__(self, id)
+    def __init__(self, id, name, url=None):
+        BaseObject.__init__(self, id, url)
         self.name = unicode(name)
 
     def __repr__(self):
@@ -112,8 +112,8 @@ class User(BaseObject):
     """
     name =      StringField('Name of user')
 
-    def __init__(self, id, name):
-        BaseObject.__init__(self, id)
+    def __init__(self, id, name, url=None):
+        BaseObject.__init__(self, id, url)
         self.name = unicode(name)
 
     def __repr__(self):
@@ -126,8 +126,8 @@ class Version(BaseObject):
     """
     name =      StringField('Name of version')
 
-    def __init__(self, id, name):
-        BaseObject.__init__(self, id)
+    def __init__(self, id, name, url=None):
+        BaseObject.__init__(self, id, url)
         self.name = unicode(name)
 
     def __repr__(self):
@@ -149,8 +149,8 @@ class Status(BaseObject):
     name =      StringField('Name of status')
     value =     IntField('Value of status (constants VALUE_*)')
 
-    def __init__(self, id, name, value):
-        BaseObject.__init__(self, id)
+    def __init__(self, id, name, value, url=None):
+        BaseObject.__init__(self, id, url)
         self.name = unicode(name)
         self.value = value
 
@@ -163,7 +163,6 @@ class Attachment(BaseObject):
     Attachment of an issue.
     """
     filename =      StringField('Filename')
-    url =           StringField('Direct URL to attachment')
 
     def __repr__(self):
         return '<Attachment %r>' % self.filename
@@ -228,8 +227,8 @@ class Query(BaseObject):
     category =      StringField('Filter on categories')
     status =        StringField('Filter on statuses')
 
-    def __init__(self):
-        BaseObject.__init__(self, '')
+    def __init__(self, id='', url=None):
+        BaseObject.__init__(self, id, url)
 
 
 class CapBugTracker(Capability):
diff --git a/weboob/capabilities/calendar.py b/weboob/capabilities/calendar.py
index 5e101bb..8c138b8 100644
--- a/weboob/capabilities/calendar.py
+++ b/weboob/capabilities/calendar.py
@@ -41,7 +41,6 @@ class BaseCalendarEvent(BaseObject):
     Represents a calendar event
     """
 
-    url = StringField('URL of the event')
     start_date = DateField('Start date of the event')
     end_date = DateField('End date of the event')
     timezone = StringField('Timezone of the event in order to convert to utc time', default='Etc/UCT')
diff --git a/weboob/capabilities/chat.py b/weboob/capabilities/chat.py
index 2527ae2..1b44ed3 100644
--- a/weboob/capabilities/chat.py
+++ b/weboob/capabilities/chat.py
@@ -42,8 +42,8 @@ class ChatMessage(BaseObject):
     message =       StringField('Content of message')
     date =          DateField('Date when the message has been sent')
 
-    def __init__(self, id_from, id_to, message, date=None):
-        BaseObject.__init__(self, '%s.%s' % (id_from, id_to))
+    def __init__(self, id_from, id_to, message, date=None, url=None):
+        BaseObject.__init__(self, '%s.%s' % (id_from, id_to), url)
         self.id_from = id_from
         self.id_to = id_to
         self.message = message
diff --git a/weboob/capabilities/cinema.py b/weboob/capabilities/cinema.py
index 2026077..2042f26 100644
--- a/weboob/capabilities/cinema.py
+++ b/weboob/capabilities/cinema.py
@@ -42,8 +42,8 @@ class Movie(BaseObject):
     roles            = Field('Lists of Persons related to the movie indexed by roles', dict)
     thumbnail_url    = StringField('Url of movie thumbnail')
 
-    def __init__(self, id, original_title):
-        BaseObject.__init__(self, id)
+    def __init__(self, id, original_title, url=None):
+        BaseObject.__init__(self, id, url)
         self.original_title = original_title
 
     def get_roles_by_person_name(self,name):
@@ -78,8 +78,8 @@ class Person(BaseObject):
     roles            = Field('Lists of movies related to the person indexed by roles',dict)
     thumbnail_url    = StringField('Url of person thumbnail')
 
-    def __init__(self, id, name):
-        BaseObject.__init__(self, id)
+    def __init__(self, id, name, url=None):
+        BaseObject.__init__(self, id, url)
         self.name = name
 
     def get_roles_by_movie_title(self,title):
diff --git a/weboob/capabilities/collection.py b/weboob/capabilities/collection.py
index da28058..08f1778 100644
--- a/weboob/capabilities/collection.py
+++ b/weboob/capabilities/collection.py
@@ -40,8 +40,8 @@ class BaseCollection(BaseObject):
     However, this probably will not work properly for now.
     """
 
-    def __init__(self, split_path):
-        BaseObject.__init__(self, None)
+    def __init__(self, split_path, id=None, url=None):
+        BaseObject.__init__(self, id, url)
         self.split_path = split_path
 
     @property
@@ -83,9 +83,9 @@ class Collection(BaseCollection):
     title = StringField('Collection title')
     split_path = Field('Full collection path', list)
 
-    def __init__(self, split_path=None, title=None):
+    def __init__(self, split_path=None, title=None, id=None, url=None):
         self.title = title
-        BaseCollection.__init__(self, split_path)
+        BaseCollection.__init__(self, split_path, id, url)
 
     def __unicode__(self):
         if self.title and self.basename:
diff --git a/weboob/capabilities/contact.py b/weboob/capabilities/contact.py
index 9831fc5..f4a15c4 100644
--- a/weboob/capabilities/contact.py
+++ b/weboob/capabilities/contact.py
@@ -49,14 +49,13 @@ class ContactPhoto(BaseObject):
     Photo of a contact.
     """
     name =              StringField('Name of the photo')
-    url =               StringField('Direct URL to photo')
     data =              BytesField('Data of photo')
     thumbnail_url =     StringField('Direct URL to thumbnail')
     thumbnail_data =    BytesField('Data of thumbnail')
     hidden =            Field('True if the photo is hidden on website', bool)
 
-    def __init__(self, name):
-        BaseObject.__init__(self, name)
+    def __init__(self, name, url=None):
+        BaseObject.__init__(self, name, url)
         self.name = name
 
     def __iscomplete__(self):
@@ -82,14 +81,13 @@ class Contact(BaseObject):
 
     name =          StringField('Name of contact')
     status =        IntField('Status of contact (STATUS_* constants)')
-    url =           StringField('URL to the profile of contact')
     status_msg =    StringField('Message of status')
     summary =       StringField('Description of contact')
     photos =        Field('List of photos', dict, default=OrderedDict())
     profile =       Field('Contact profile', dict, default=OrderedDict())
 
-    def __init__(self, id, name, status):
-        BaseObject.__init__(self, id)
+    def __init__(self, id, name, status, url=None):
+        BaseObject.__init__(self, id, url)
         self.name = name
         self.status = status
 
@@ -160,8 +158,8 @@ class Query(BaseObject):
     """
     message =   StringField('Message received')
 
-    def __init__(self, id, message):
-        BaseObject.__init__(self, id)
+    def __init__(self, id, message, url=None):
+        BaseObject.__init__(self, id, url)
         self.message = message
 
 
diff --git a/weboob/capabilities/file.py b/weboob/capabilities/file.py
index a256cfa..8bc0a15 100644
--- a/weboob/capabilities/file.py
+++ b/weboob/capabilities/file.py
@@ -30,7 +30,6 @@ class BaseFile(BaseObject):
     Represent a file.
     """
     title =         StringField('File title')
-    url =           StringField('File URL')
     ext =           StringField('File extension')
     author =        StringField('File author')
     description =   StringField('File description')
diff --git a/weboob/capabilities/gallery.py b/weboob/capabilities/gallery.py
index 4f8663c..6e61548 100644
--- a/weboob/capabilities/gallery.py
+++ b/weboob/capabilities/gallery.py
@@ -34,7 +34,6 @@ class BaseGallery(BaseObject):
     This object has to be inherited to specify how to calculate the URL of the gallery from its ID.
     """
     title =         StringField('Title of gallery')
-    url =           StringField('Direct URL to gallery')
     description =   StringField('Description of gallery')
     cardinality =   IntField('Cardinality of gallery')
     date =          DateField('Date of gallery')
@@ -44,10 +43,9 @@ class BaseGallery(BaseObject):
 
     def __init__(self, _id, title=NotLoaded, url=NotLoaded, cardinality=NotLoaded, date=NotLoaded,
                  rating=NotLoaded, rating_max=NotLoaded, thumbnail=NotLoaded, thumbnail_url=None, nsfw=False):
-        BaseObject.__init__(self, unicode(_id))
+        BaseObject.__init__(self, unicode(_id), url)
 
         self.title = title
-        self.url = url
         self.date = date
         self.rating = rating
         self.rating_max = rating_max
@@ -78,7 +76,6 @@ class BaseImage(BaseObject):
     """
     index =     IntField('Usually page number')
     thumbnail = Field('Thumbnail of the image', Thumbnail)
-    url =       StringField('Direct URL to image')
     ext =       StringField('Extension of image')
     data =      BytesField('Data of image')
     gallery =   Field('Reference to the Gallery object', BaseGallery)
@@ -86,11 +83,10 @@ class BaseImage(BaseObject):
     def __init__(self, _id, index=None, thumbnail=NotLoaded, url=NotLoaded,
             ext=NotLoaded, gallery=None):
 
-        BaseObject.__init__(self, unicode(_id))
+        BaseObject.__init__(self, unicode(_id), url)
 
         self.index = index
         self.thumbnail = thumbnail
-        self.url = url
         self.ext = ext
         self.gallery = gallery
 
diff --git a/weboob/capabilities/gauge.py b/weboob/capabilities/gauge.py
index e0c2783..ff951c5 100644
--- a/weboob/capabilities/gauge.py
+++ b/weboob/capabilities/gauge.py
@@ -48,9 +48,6 @@ class GaugeMeasure(BaseObject):
     date =      DateField('Date of measure')
     alarm =     StringField('Alarm level')
 
-    def __init__(self):
-        BaseObject.__init__(self)
-
     def __repr__(self):
         if empty(self.level):
             return "<GaugeMeasure is %s>" % self.level
diff --git a/weboob/capabilities/geolocip.py b/weboob/capabilities/geolocip.py
index cb26383..7786f6d 100644
--- a/weboob/capabilities/geolocip.py
+++ b/weboob/capabilities/geolocip.py
@@ -39,8 +39,8 @@ class IpLocation(BaseObject):
     tld =       StringField('Top Level Domain')
     isp =       StringField('Internet Service Provider')
 
-    def __init__(self, ipaddr):
-        BaseObject.__init__(self, ipaddr)
+    def __init__(self, ipaddr, url=None):
+        BaseObject.__init__(self, ipaddr, url)
 
 
 class CapGeolocIp(Capability):
diff --git a/weboob/capabilities/housing.py b/weboob/capabilities/housing.py
index ed58661..4f0f913 100644
--- a/weboob/capabilities/housing.py
+++ b/weboob/capabilities/housing.py
@@ -39,12 +39,10 @@ class HousingPhoto(BaseObject):
     """
     Photo of a housing.
     """
-    url =       StringField('Direct URL to photo')
     data =      BytesField('Data of photo')
 
     def __init__(self, url):
-        BaseObject.__init__(self, url.split('/')[-1])
-        self.url = url
+        BaseObject.__init__(self, url.split('/')[-1], url)
 
     def __iscomplete__(self):
         return self.data
@@ -71,7 +69,6 @@ class Housing(BaseObject):
     phone =         StringField('Phone number to contact')
     photos =        Field('List of photos', list)
     details =       Field('Key/values of details', dict)
-    url =           StringField('Url of the the advert')
 
 
 class Query(BaseObject):
diff --git a/weboob/capabilities/job.py b/weboob/capabilities/job.py
index c5731d5..f15b3c3 100644
--- a/weboob/capabilities/job.py
+++ b/weboob/capabilities/job.py
@@ -27,7 +27,6 @@ class BaseJobAdvert(BaseObject):
     """
     Represents a job announce.
     """
-    url =              StringField('URL of the announce')
     publication_date = DateField('Date when the announce has been published')
     society_name =     StringField('Name of the society taht published the announce')
     place =            StringField('Place where the job take place')
diff --git a/weboob/capabilities/lyrics.py b/weboob/capabilities/lyrics.py
index bceb783..caf5840 100644
--- a/weboob/capabilities/lyrics.py
+++ b/weboob/capabilities/lyrics.py
@@ -32,8 +32,8 @@ class SongLyrics(BaseObject):
     artist =       StringField('Artist of the song')
     content =    StringField('Lyrics of the song')
 
-    def __init__(self, id, title):
-        BaseObject.__init__(self, id)
+    def __init__(self, id, title, url=None):
+        BaseObject.__init__(self, id, url)
         self.title = title
 
 
diff --git a/weboob/capabilities/messages.py b/weboob/capabilities/messages.py
index d4d89a2..1e7989d 100644
--- a/weboob/capabilities/messages.py
+++ b/weboob/capabilities/messages.py
@@ -62,8 +62,9 @@ class Message(BaseObject):
                        content=NotLoaded,
                        signature=NotLoaded,
                        children=NotLoaded,
-                       flags=0):
-        super(Message, self).__init__(id)
+                       flags=0,
+                       url=None):
+        super(Message, self).__init__(id, url)
         self.thread = thread
         self.title = title
         self.sender = sender
diff --git a/weboob/capabilities/paste.py b/weboob/capabilities/paste.py
index 358cb5e..73bea6e 100644
--- a/weboob/capabilities/paste.py
+++ b/weboob/capabilities/paste.py
@@ -43,8 +43,8 @@ class BasePaste(BaseObject):
     public =        Field('Is this paste public?', bool)
 
     def __init__(self, _id, title=NotLoaded, language=NotLoaded, contents=NotLoaded,
-            public=NotLoaded):
-        BaseObject.__init__(self, unicode(_id))
+            public=NotLoaded, url=None):
+        BaseObject.__init__(self, unicode(_id), url)
 
         self.title = title
         self.language = language
diff --git a/weboob/capabilities/recipe.py b/weboob/capabilities/recipe.py
index 803781a..a1983c9 100644
--- a/weboob/capabilities/recipe.py
+++ b/weboob/capabilities/recipe.py
@@ -63,8 +63,8 @@ class Recipe(BaseObject):
     instructions =      StringField('Instruction step list of the recipe')
     comments =          Field('User comments about the recipe', list)
 
-    def __init__(self, id='', title=u''):
-        BaseObject.__init__(self, id)
+    def __init__(self, id='', title=u'', url=None):
+        BaseObject.__init__(self, id, url)
         self.title = title
 
     def toKrecipesXml(self, author=None):
diff --git a/weboob/capabilities/shop.py b/weboob/capabilities/shop.py
index fda4e5f..1200525 100644
--- a/weboob/capabilities/shop.py
+++ b/weboob/capabilities/shop.py
@@ -67,7 +67,6 @@ class Item(BaseObject):
     Purchased item within an order.
     """
     label = StringField('Item label')
-    url   = StringField('URL with item description')
     price = DecimalField('Item price')
 
     def __repr__(self):
diff --git a/weboob/capabilities/subtitle.py b/weboob/capabilities/subtitle.py
index d4d80d8..83bc805 100644
--- a/weboob/capabilities/subtitle.py
+++ b/weboob/capabilities/subtitle.py
@@ -39,13 +39,12 @@ class Subtitle(BaseObject):
     """
     name =      StringField('Name of subtitle')
     ext =       StringField('Extension of file')
-    url =       StringField('Direct url to subtitle file')
     nb_cd =     IntField('Number of cd or files')
     language =  StringField('Language of the subtitle')
     description=StringField('Description of corresponding video')
 
-    def __init__(self, id, name):
-        BaseObject.__init__(self, id)
+    def __init__(self, id, name, url=None):
+        BaseObject.__init__(self, id, url)
         self.name = name
 
 
diff --git a/weboob/capabilities/torrent.py b/weboob/capabilities/torrent.py
index a41f4a0..6bc1d64 100644
--- a/weboob/capabilities/torrent.py
+++ b/weboob/capabilities/torrent.py
@@ -42,7 +42,6 @@ class Torrent(BaseObject):
     name =      StringField('Name of torrent')
     size =      FloatField('Size of torrent')
     date =      DateField('Date when torrent has been published')
-    url =       StringField('Direct url to .torrent file')
     magnet =    StringField('URI of magnet')
     seeders =   IntField('Number of seeders')
     leechers =  IntField('Number of leechers')
diff --git a/weboob/capabilities/travel.py b/weboob/capabilities/travel.py
index fdecd5d..bdf4d00 100644
--- a/weboob/capabilities/travel.py
+++ b/weboob/capabilities/travel.py
@@ -32,8 +32,8 @@ class Station(BaseObject):
     """
     name =  StringField('Name of station')
 
-    def __init__(self, id=None, name=None):
-        BaseObject.__init__(self, id)
+    def __init__(self, id=None, name=None, url=None):
+        BaseObject.__init__(self, id, url)
         self.name = name
 
     def __repr__(self):
@@ -55,8 +55,8 @@ class Departure(BaseObject):
     price =             DecimalField('Price of ticket')
     currency =          StringField('Currency', default=None)
 
-    def __init__(self, id=None, _type=None, _time=None):
-        BaseObject.__init__(self, id)
+    def __init__(self, id=None, _type=None, _time=None, url=None):
+        BaseObject.__init__(self, id, url)
 
         self.type = _type
         self.time = _time
@@ -91,8 +91,8 @@ class RoadmapFilters(BaseObject):
     departure_time =    DateField('Wanted departure time')
     arrival_time =      DateField('Wanted arrival time')
 
-    def __init__(self):
-        BaseObject.__init__(self, '')
+    def __init__(self, id='', url=None):
+        BaseObject.__init__(self, id, url)
 
 
 class CapTravel(Capability):
diff --git a/weboob/capabilities/weather.py b/weboob/capabilities/weather.py
index b3d21b8..0e9a941 100644
--- a/weboob/capabilities/weather.py
+++ b/weboob/capabilities/weather.py
@@ -32,8 +32,8 @@ class Temperature(BaseObject):
     value =      FloatField('Temperature value')
     unit =       StringField('Input unit')
 
-    def __init__(self, value=NotLoaded, unit = u''):
-        BaseObject.__init__(self, unicode(value))
+    def __init__(self, value=NotLoaded, unit = u'', url=None):
+        BaseObject.__init__(self, unicode(value), url)
         self.value = value
         if unit not in [u'C', u'F']:
             unit = u''
@@ -69,8 +69,8 @@ class Forecast(BaseObject):
     high =      Field('High temperature', Temperature)
     text =      StringField('Comment on forecast')
 
-    def __init__(self, date=NotLoaded, low=None, high=None, text=None, unit=None):
-        BaseObject.__init__(self, unicode(date))
+    def __init__(self, date=NotLoaded, low=None, high=None, text=None, unit=None, url=None):
+        BaseObject.__init__(self, unicode(date), url)
         self.date = date
         self.low = Temperature(low, unit)
         self.high = Temperature(high, unit)
@@ -85,8 +85,8 @@ class Current(BaseObject):
     text =      StringField('Comment about current weather')
     temp =      Field('Current temperature', Temperature)
 
-    def __init__(self, date=NotLoaded, temp=None, text=None, unit=None):
-        BaseObject.__init__(self, unicode(date))
+    def __init__(self, date=NotLoaded, temp=None, text=None, unit=None, url=None):
+        BaseObject.__init__(self, unicode(date), url)
         self.date = date
         self.text = text
         self.temp = Temperature(temp, unit)
@@ -98,8 +98,8 @@ class City(BaseObject):
     """
     name =      StringField('Name of city')
 
-    def __init__(self, id='', name=None):
-        BaseObject.__init__(self, id)
+    def __init__(self, id='', name=None, url=None):
+        BaseObject.__init__(self, id, url)
         self.name = name
 
 
-- 
2.7.0




More information about the weboob mailing list