From ec67f2f28d227d0dac99d56dbf5b810d5732fa9c Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 25 Aug 2023 01:26:14 +0530 Subject: [PATCH 1/2] add: added sanexml to req.txt Signed-off-by: 35C4n0r --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index baebd9a..f2560c6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ lxml>=4.0.0,<5.0.0 requests>=2.7.0,<3.0.0 six>=1.10,<2.0 +sanexml \ No newline at end of file From 6f85b0b90a5ba864d4ce3553d0f4af2ad0de7b2e Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 25 Aug 2023 01:28:39 +0530 Subject: [PATCH 2/2] feat: implemented logic to fallback to sanexml - If the lxml library is not present then we fallback to the lxml library. - POM_PARSER is now a function which returns a new XMLParser(). Signed-off-by: 35C4n0r --- pymaven/pom.py | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/pymaven/pom.py b/pymaven/pom.py index 679c678..45e1e96 100644 --- a/pymaven/pom.py +++ b/pymaven/pom.py @@ -23,7 +23,12 @@ import logging import re -from lxml import etree +try: + from lxml import etree +except ImportError: + from sanexml import etree + FALLBACK = True + import six from .artifact import Artifact @@ -42,14 +47,16 @@ """ -POM_PARSER = etree.XMLParser( - recover=True, - # we keep comments in case there is a license in the comments - remove_comments=False, - remove_pis=True, - remove_blank_text=True, - resolve_entities=False -) + +def POM_PARSER(): + return etree.XMLParser( + recover=True, + # we keep comments in case there is a license in the comments + remove_comments=False, + remove_pis=True, + remove_blank_text=True, + resolve_entities=False + ) PROPERTY_RE = re.compile(r'\$\{(.*?)\}') STRIP_NAMESPACE_RE = re.compile("", re.MULTILINE) @@ -79,10 +86,11 @@ def __init__(self, coordinate, client=None, pom_data=None, ns_aware=False): """ if pom_data is not None: # remove all namespaces + pom_data = pom_data.strip().strip("'").strip("\n'") pom_data = strip_namespace(pom_data) if isinstance(pom_data, six.text_type): pom_data = pom_data.encode("utf-8") - pom_data = etree.fromstring(pom_data, parser=POM_PARSER) + pom_data = etree.fromstring(pom_data, parser=POM_PARSER()) self._pom_data = pom_data self._client = client @@ -273,7 +281,7 @@ def _find_properties(self, elem=None): properties = OrderedDict() project_properties = _find(elem, "properties") if project_properties is not None: - for prop in project_properties.iterchildren(): + for prop in project_properties.iter(): if prop.tag == 'property': name = prop.get('name') value = prop.get('value') @@ -421,7 +429,7 @@ def pom_data(self): """ if self._client is None: _pom_data = EMPTY_POM.format(self) - return etree.fromstring(_pom_data.encode('utf-8'), parser=POM_PARSER) + return etree.fromstring(_pom_data.strip("'").strip("\n'").encode('utf-8'), parser=POM_PARSER()) contents = self._client.get_artifact(self.coordinate).contents with contents as fh: @@ -429,7 +437,7 @@ def pom_data(self): if not isinstance(contents_text, six.text_type): contents_text = contents_text.decode('utf-8') contents_text = strip_namespace(contents_text) - return etree.fromstring(contents_text, parser=POM_PARSER) + return etree.fromstring(contents_text, parser=POM_PARSER()) @property @memoize("_properties")