From af7286cfa6b16b2aa02a530ca78a15c2d4cccb7b Mon Sep 17 00:00:00 2001 From: Vincent Ardisson Date: Thu, 27 Feb 2020 17:03:27 +0100 Subject: [PATCH] weboob.browser.filters.standard: in case of list Base returns first element The use case of this patch is being able to perform: Base(TableCell('foo'), CleanText('./span')) It was impossible without because CleanText was called with a list of matching elements, instead of a single lxml element. Not sure if it's the right way to fix the problem. Other ways include: - modifying TableCell to return the element instead of a list of elements - modifying CleanText to accept a list of elements - introducing another filter to take only the first element --- weboob/browser/filters/standard.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/weboob/browser/filters/standard.py b/weboob/browser/filters/standard.py index 8f1eeb5d04..4c052954e4 100644 --- a/weboob/browser/filters/standard.py +++ b/weboob/browser/filters/standard.py @@ -119,6 +119,9 @@ class Base(Filter): def __call__(self, item): base = self.select(self.base, item) + if isinstance(base, list): + assert len(base) == 1, 'If using a list, there must be one element only' + base = base[0] return self.select(self.selector, base) def __init__(self, base, selector=None, default=_NO_DEFAULT): -- GitLab