From fd2b1ba45a0c5c5459f37e3d0a6b118f2732c65c Mon Sep 17 00:00:00 2001 From: twalter-c2c Date: Mon, 27 Jan 2025 19:31:40 +0100 Subject: [PATCH] [IMP] product_import_ubl: wrapping of XPathGetter functions --- product_import_ubl/wizard/product_import.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/product_import_ubl/wizard/product_import.py b/product_import_ubl/wizard/product_import.py index 246536ff93..5f26bc4388 100644 --- a/product_import_ubl/wizard/product_import.py +++ b/product_import_ubl/wizard/product_import.py @@ -14,18 +14,22 @@ class XPathGetter(object): _missing = etree.Element("Missing") def __init__(self, element, namespaces): + self.element = element self._xpath = element.xpath self._ns = namespaces - def xpath(self, path): + def xpath(self, path, wrap=False): # Return a list of elements items = self._xpath(path, namespaces=self._ns) + if wrap: + return [self.__class__(x, self._ns) for x in items] return items - def xpath_get(self, path): + def xpath_get(self, path, wrap=False): # Return 1 element items = self._xpath(path, namespaces=self._ns) - return items[0] if items else self._missing + item = items[0] if items else self._missing + return self.__class__(item, self._ns) if wrap else item def xpath_text(self, path, default=False): # Return text or False