enhancement of load detection of fields
This commit is contained in:
parent
171722fce3
commit
b354f8d3a7
4 changed files with 35 additions and 13 deletions
|
|
@ -62,7 +62,30 @@ class CapBaseObject(object):
|
|||
self.id = id
|
||||
self.backend = backend
|
||||
|
||||
def __iscomplete__(self):
|
||||
"""
|
||||
Return True if the object is completed.
|
||||
|
||||
It is usefull when the object is a field of an other object which is
|
||||
going to be filled.
|
||||
|
||||
The default behavior is to iter on fields (with iter_fields) and if
|
||||
a field is NotLoaded, return False.
|
||||
"""
|
||||
for key, value in self.iter_fields():
|
||||
if value is NotLoaded:
|
||||
return False
|
||||
return True
|
||||
|
||||
def iter_fields(self):
|
||||
"""
|
||||
Iterate on the FIELDS keys and values.
|
||||
|
||||
Can be overloaded to iterate on other things.
|
||||
|
||||
@return [iter(key,value)] iterator on key, value
|
||||
"""
|
||||
|
||||
if self.FIELDS is None:
|
||||
for key, value in iter_fields(self):
|
||||
if key != 'backend':
|
||||
|
|
|
|||
|
|
@ -33,9 +33,10 @@ class ProfileNode(object):
|
|||
self.sufix = sufix
|
||||
self.flags = flags
|
||||
|
||||
class ContactPhoto(object):
|
||||
class ContactPhoto(CapBaseObject):
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
CapBaseObject.__init__(self, name)
|
||||
self.name = name #useless, but keep compatibility
|
||||
self.url = u''
|
||||
self.data = ''
|
||||
self.thumbnail_url = u''
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ from .base import IBaseCap, NotLoaded, CapBaseObject
|
|||
__all__ = ['BaseVideo', 'ICapVideo']
|
||||
|
||||
|
||||
class VideoThumbnail(object):
|
||||
class VideoThumbnail(CapBaseObject):
|
||||
def __init__(self, url):
|
||||
self.url = url.replace(' ', '%20')
|
||||
self.data = NotLoaded
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import os
|
|||
from threading import RLock
|
||||
from logging import debug
|
||||
|
||||
from weboob.capabilities.base import IBaseCap, NotLoaded
|
||||
from weboob.capabilities.base import IBaseCap, NotLoaded, CapBaseObject
|
||||
|
||||
|
||||
__all__ = ['BaseBackend', 'ObjectNotAvailable']
|
||||
|
|
@ -193,6 +193,9 @@ class BaseBackend(object):
|
|||
return False
|
||||
|
||||
def fillobj(self, obj, fields):
|
||||
def not_loaded(v):
|
||||
return (v is NotLoaded or isinstance(value, CapBaseObject) and not value.__iscomplete__())
|
||||
|
||||
missing_fields = []
|
||||
for field in fields:
|
||||
if not hasattr(obj, field):
|
||||
|
|
@ -200,17 +203,12 @@ class BaseBackend(object):
|
|||
value = getattr(obj, field)
|
||||
|
||||
missing = False
|
||||
if isinstance(value, dict):
|
||||
for v in value.itervalues():
|
||||
if hasattr(v, '__iscomplete__') and not v.__iscomplete__():
|
||||
if hasattr(value, '__iter__'):
|
||||
for v in (value.itervalues() if isinstance(value, dict) else value):
|
||||
if not_loaded(v):
|
||||
missing = True
|
||||
break
|
||||
elif isinstance(value, (list,tuple)):
|
||||
for v in value:
|
||||
if hasattr(v, '__iscomplete__') and not v.__iscomplete__():
|
||||
missing = True
|
||||
break
|
||||
elif value is NotLoaded or hasattr(value, '__iscomplete__') and not value.__iscomplete__():
|
||||
elif not_loaded(value):
|
||||
missing = True
|
||||
|
||||
if missing:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue