From 63d2df03ba873de7f193bddd0564efaf819fc04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Felipe=20Mil=C3=A9o?= Date: Tue, 16 Jul 2024 20:58:07 -0300 Subject: [PATCH] [REF] Combined pattern analisar_retorno_raw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luis Felipe Miléo --- src/erpbrasil/edoc/resposta.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/erpbrasil/edoc/resposta.py b/src/erpbrasil/edoc/resposta.py index 8acca86..64144cb 100644 --- a/src/erpbrasil/edoc/resposta.py +++ b/src/erpbrasil/edoc/resposta.py @@ -6,6 +6,10 @@ from lxml import etree +combined_pattern = re.compile( + r"(.*?)|<[a-zA-Z0-9:]*Body[^>]*>(.*?)" +) + class RetornoSoap: def __init__(self, webservice, raiz, xml, retorno, resposta): @@ -18,10 +22,9 @@ def __init__(self, webservice, raiz, xml, retorno, resposta): def analisar_retorno_raw(operacao, raiz, xml, retorno, classe): retorno.raise_for_status() - pattern = r"<[a-zA-Z0-9:]Body.?>(.*?)" - match = re.search(pattern, retorno.text.replace("\n", "")) + match = re.search(combined_pattern, retorno.text.replace("\n", "")) if match: - xml_resposta = match.group(1) + xml_resposta = match.group(1) or match.group(2) xml_etree = etree.fromstring(xml_resposta) resultado = xml_etree[0]