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