ObjectNotSupported is now an assertion

This commit is contained in:
Christophe Benz 2010-08-12 16:45:05 +02:00
commit d81f5dac7a
3 changed files with 5 additions and 10 deletions

View file

@ -23,7 +23,7 @@ from optparse import OptionGroup, OptionParser
from weboob.core.ouiboube import Weboob from weboob.core.ouiboube import Weboob
from weboob.tools.config.iconfig import ConfigError from weboob.tools.config.iconfig import ConfigError
from weboob.tools.backend import ObjectNotAvailable, ObjectNotSupported from weboob.tools.backend import ObjectNotAvailable
from weboob.tools.misc import iter_fields from weboob.tools.misc import iter_fields
@ -201,7 +201,7 @@ class BaseApplication(object):
fields = [k for k, v in iter_fields(obj)] fields = [k for k, v in iter_fields(obj)]
try: try:
backend.fillobj(obj, fields) backend.fillobj(obj, fields)
except (ObjectNotAvailable, ObjectNotSupported), e: except ObjectNotAvailable, e:
logging.warning(u'Could not retrieve required fields (%s): %s' % (','.join(fields), e)) logging.warning(u'Could not retrieve required fields (%s): %s' % (','.join(fields), e))
return obj return obj

View file

@ -29,7 +29,6 @@ import sys
from weboob.core import CallErrors from weboob.core import CallErrors
from weboob.core.backends import BackendsConfig from weboob.core.backends import BackendsConfig
from weboob.tools.backend import ObjectNotSupported
from .base import BackendNotFound, BaseApplication from .base import BackendNotFound, BaseApplication
from .formatters.load import formatters, load_formatter from .formatters.load import formatters, load_formatter

View file

@ -24,17 +24,13 @@ from logging import debug
from weboob.capabilities.base import IBaseCap, NotLoaded from weboob.capabilities.base import IBaseCap, NotLoaded
__all__ = ['BaseBackend', 'ObjectNotAvailable', 'ObjectNotSupported'] __all__ = ['BaseBackend', 'ObjectNotAvailable']
class ObjectNotAvailable(Exception): class ObjectNotAvailable(Exception):
pass pass
class ObjectNotSupported(Exception):
pass
class BackendStorage(object): class BackendStorage(object):
def __init__(self, name, storage): def __init__(self, name, storage):
self.name = name self.name = name
@ -222,9 +218,9 @@ class BaseBackend(object):
if not missing_fields: if not missing_fields:
return obj return obj
assert 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):
debug(u'Fill %r with fields: %s' % (obj, missing_fields)) debug(u'Fill %r with fields: %s' % (obj, missing_fields))
return value(self, obj, missing_fields) or obj return value(self, obj, missing_fields) or obj
raise ObjectNotSupported('The object of type %s is not supported by the backend %s' % (type(obj), self))