do not fail during fullobj() if the object is not supported by backend
This commit is contained in:
parent
bbcf8c7854
commit
6f46c41743
3 changed files with 28 additions and 12 deletions
|
|
@ -27,9 +27,10 @@ from weboob.tools.misc import to_unicode
|
|||
from weboob.tools.ordereddict import OrderedDict
|
||||
|
||||
|
||||
__all__ = ['UserError', 'FieldNotFound', 'NotAvailable', 'NotLoaded', 'IBaseCap',
|
||||
'Field', 'IntField', 'DecimalField', 'FloatField', 'StringField',
|
||||
'BytesField', 'DateField', 'DeltaField', 'empty', 'CapBaseObject']
|
||||
__all__ = ['UserError', 'FieldNotFound', 'ObjectNotSupported', 'NotAvailable',
|
||||
'NotLoaded', 'IBaseCap', 'Field', 'IntField', 'DecimalField',
|
||||
'FloatField', 'StringField', 'BytesField', 'DateField',
|
||||
'DeltaField', 'empty', 'CapBaseObject']
|
||||
|
||||
|
||||
def empty(value):
|
||||
|
|
@ -50,6 +51,12 @@ class UserError(Exception):
|
|||
"""
|
||||
|
||||
|
||||
class ObjectNotSupported(Exception):
|
||||
"""
|
||||
This object is not supported.
|
||||
"""
|
||||
|
||||
|
||||
class FieldNotFound(Exception):
|
||||
"""
|
||||
A field isn't found.
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ from optparse import OptionGroup, OptionParser, IndentedHelpFormatter
|
|||
import os
|
||||
import sys
|
||||
|
||||
from weboob.capabilities.base import FieldNotFound, CapBaseObject
|
||||
from weboob.capabilities.base import FieldNotFound, CapBaseObject, ObjectNotSupported
|
||||
from weboob.core import CallErrors
|
||||
from weboob.tools.application.formatters.iformatter import MandatoryFieldsNotFound
|
||||
from weboob.tools.misc import to_unicode
|
||||
|
|
@ -203,15 +203,21 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
except (IndexError, ValueError):
|
||||
pass
|
||||
else:
|
||||
if isinstance(obj, CapBaseObject):
|
||||
for backend, obj in self.do('fillobj', obj, fields, backends=[obj.backend]):
|
||||
if obj:
|
||||
return obj
|
||||
try:
|
||||
backend = self.weboob.get_backend(obj.backend)
|
||||
return backend.fillobj(obj, fields)
|
||||
except ObjectNotSupported:
|
||||
pass
|
||||
|
||||
_id, backend_name = self.parse_id(_id)
|
||||
backend_names = (backend_name,) if backend_name is not None else self.enabled_backends
|
||||
for backend, obj in self.do(method, _id, backends=backend_names):
|
||||
if obj:
|
||||
backend.fillobj(obj, fields)
|
||||
try:
|
||||
backend.fillobj(obj, fields)
|
||||
except ObjectNotSupported:
|
||||
pass
|
||||
|
||||
return obj
|
||||
|
||||
def get_object_list(self, method=None):
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ import os
|
|||
from threading import RLock
|
||||
from copy import copy
|
||||
|
||||
from weboob.capabilities.base import CapBaseObject, FieldNotFound, IBaseCap, NotLoaded
|
||||
from weboob.capabilities.base import CapBaseObject, FieldNotFound, ObjectNotSupported, \
|
||||
IBaseCap, NotLoaded
|
||||
from weboob.tools.misc import iter_fields
|
||||
from weboob.tools.log import getLogger
|
||||
from weboob.tools.value import ValuesDict
|
||||
|
|
@ -359,6 +360,10 @@ class BaseBackend(object):
|
|||
:param fields: what fields to fill; if None, all fields are filled
|
||||
:type fields: :class:`list`
|
||||
"""
|
||||
|
||||
if type(obj) not in self.OBJECTS:
|
||||
raise ObjectNotSupported('The object of type %s is not supported by the backend %s' % (type(obj).__name__, self))
|
||||
|
||||
def not_loaded(v):
|
||||
return (v is NotLoaded or isinstance(v, CapBaseObject) and not v.__iscomplete__())
|
||||
|
||||
|
|
@ -393,8 +398,6 @@ class BaseBackend(object):
|
|||
if not missing_fields:
|
||||
return obj
|
||||
|
||||
assert type(obj) in self.OBJECTS, 'The object of type %s is not supported by the backend %s' % (type(obj), self)
|
||||
|
||||
for key, value in self.OBJECTS.iteritems():
|
||||
if isinstance(obj, key):
|
||||
self.logger.debug(u'Fill %r with fields: %s' % (obj, missing_fields))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue