Skip to content

Commit

Permalink
Disable smart_strings in XPath results
Browse files Browse the repository at this point in the history
Instead of replacing them after the fact.
  • Loading branch information
apasel422 authored and acabal committed Jun 20, 2024
1 parent 98cdb7d commit 63faa54
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions se/easy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,12 @@ def xpath(self, selector: str, return_string: bool = False):
result: List[Union[str, EasyXmlElement, float]] = []

try:
query_result = self.etree.xpath(selector, namespaces=self.namespaces)
if isinstance(query_result, etree._ElementUnicodeResult): # pylint: disable=protected-access
result.append(str(query_result))
elif isinstance(query_result, float):
query_result = self.etree.xpath(selector, namespaces=self.namespaces, smart_strings=False)
if isinstance(query_result, str|float):
result.append(query_result)
else:
for element in query_result:
if isinstance(element, etree._ElementUnicodeResult): # pylint: disable=protected-access
result.append(str(element))
elif isinstance(element, str):
if isinstance(element, str):
result.append(element)
else:
result.append(EasyXmlElement(element, self.namespaces))
Expand Down Expand Up @@ -375,16 +371,12 @@ def xpath(self, selector: str, return_string: bool = False):

result: List[Union[str, EasyXmlElement, float]] = []

query_result = self.lxml_element.xpath(selector, namespaces=self.namespaces)
if isinstance(query_result, etree._ElementUnicodeResult): # pylint: disable=protected-access
result.append(str(query_result))
elif isinstance(query_result, float):
query_result = self.lxml_element.xpath(selector, namespaces=self.namespaces, smart_strings=False)
if isinstance(query_result, str|float):
result.append(query_result)
else:
for element in query_result:
if isinstance(element, etree._ElementUnicodeResult): # pylint: disable=protected-access
result.append(str(element))
elif isinstance(element, str):
if isinstance(element, str):
result.append(element)
else:
result.append(EasyXmlElement(element, self.namespaces))
Expand Down

0 comments on commit 63faa54

Please sign in to comment.