Remove condition from core
This commit is contained in:
parent
29567cffa4
commit
9a0f9d0fc9
4 changed files with 11 additions and 26 deletions
|
|
@ -28,7 +28,7 @@ from weboob.tools.misc import get_backtrace
|
|||
from weboob.tools.log import getLogger
|
||||
|
||||
|
||||
__all__ = ['BackendsCall', 'CallErrors', 'IResultsCondition', 'ResultsConditionError']
|
||||
__all__ = ['BackendsCall', 'CallErrors']
|
||||
|
||||
|
||||
class CallErrors(Exception):
|
||||
|
|
@ -44,22 +44,11 @@ class CallErrors(Exception):
|
|||
return self.errors.__iter__()
|
||||
|
||||
|
||||
class IResultsCondition(object):
|
||||
def is_valid(self, obj):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class ResultsConditionError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class BackendsCall(object):
|
||||
def __init__(self, backends, condition, function, *args, **kwargs):
|
||||
def __init__(self, backends, function, *args, **kwargs):
|
||||
"""
|
||||
:param backends: List of backends to call
|
||||
:type backends: list[:class:`BaseBackend`]
|
||||
:param condition: Condition applied on results (can be None)
|
||||
:type condition: :class:`IResultsCondition`
|
||||
:param function: backends' method name, or callable object.
|
||||
:type function: :class:`str` or :class:`callable`
|
||||
"""
|
||||
|
|
@ -68,8 +57,6 @@ class BackendsCall(object):
|
|||
self.backends = {}
|
||||
for backend in backends:
|
||||
self.backends[backend.name] = False
|
||||
# Condition
|
||||
self.condition = condition
|
||||
# Global mutex on object
|
||||
self.mutex = RLock()
|
||||
# Event set when every backends have give their data
|
||||
|
|
|
|||
|
|
@ -318,8 +318,6 @@ class Weboob(object):
|
|||
:type backends: list[:class:`str`]
|
||||
:param caps: iterate on backends which implement this caps
|
||||
:type caps: list[:class:`weboob.capabilities.base.IBaseCap`]
|
||||
:param condition: a condition to validate results
|
||||
:type condition: :class:`weboob.core.bcall.IResultsCondition`
|
||||
:rtype: A :class:`weboob.core.bcall.BackendsCall` object (iterable)
|
||||
"""
|
||||
backends = self.backend_instances.values()
|
||||
|
|
@ -349,13 +347,12 @@ class Weboob(object):
|
|||
if 'caps' in kwargs:
|
||||
caps = kwargs.pop('caps')
|
||||
backends = [backend for backend in backends if backend.has_caps(caps)]
|
||||
condition = kwargs.pop('condition', None)
|
||||
|
||||
# The return value MUST BE the BackendsCall instance. Please never iterate
|
||||
# here on this object, because caller might want to use other methods, like
|
||||
# wait() on callback_thread().
|
||||
# Thanks a lot.
|
||||
return BackendsCall(backends, condition, function, *args, **kwargs)
|
||||
return BackendsCall(backends, function, *args, **kwargs)
|
||||
|
||||
def schedule(self, interval, function, *args):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -305,7 +305,6 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
"""
|
||||
backends = kwargs.pop('backends', None)
|
||||
kwargs['backends'] = self.enabled_backends if backends is None else backends
|
||||
kwargs['condition'] = self.condition
|
||||
fields = kwargs.pop('fields', self.selected_fields) or self.selected_fields
|
||||
if '$direct' in fields:
|
||||
fields = []
|
||||
|
|
@ -449,10 +448,7 @@ class ReplApplication(Cmd, ConsoleApplication):
|
|||
|
||||
This method can be overrided to support more exceptions types.
|
||||
"""
|
||||
if isinstance(error, ResultsConditionError):
|
||||
print >>sys.stderr, u'Error(%s): condition error: %s' % (backend.name, error)
|
||||
else:
|
||||
return super(ReplApplication, self).bcall_error_handler(backend, error, backtrace)
|
||||
return super(ReplApplication, self).bcall_error_handler(backend, error, backtrace)
|
||||
|
||||
def bcall_errors_handler(self, errors, ignore=()):
|
||||
if self.interactive:
|
||||
|
|
|
|||
|
|
@ -18,11 +18,16 @@
|
|||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from weboob.core.bcall import IResultsCondition, ResultsConditionError
|
||||
|
||||
|
||||
__all__ = ['ResultsCondition', 'ResultsConditionError']
|
||||
|
||||
class IResultsCondition(object):
|
||||
def is_valid(self, obj):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class ResultsConditionError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class Condition(object):
|
||||
def __init__(self, left, op, right):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue