do not fail during fullobj() if the object is not supported by backend

This commit is contained in:
Romain Bignon 2012-04-28 16:38:55 +02:00
commit 6f46c41743
3 changed files with 28 additions and 12 deletions

View file

@ -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.

View file

@ -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):

View file

@ -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))