Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] product_import_ubl: wrapping of XPathGetter functions #1114

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions product_import_ubl/wizard/product_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading