# -*- coding: utf-8 -*- # © 2016 Danimar Ribeiro, Trustcode # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from pytrustnfe.client import HttpClient from pytrustnfe.certificado import save_cert_key, extract_cert_and_key_from_pfx from ..xml import sanitize_response def _soap_xml(body, cabecalho): xml = '' xml += '' xml += '' xml += '' + cabecalho.estado + '' + cabecalho.versao + '' xml += '' xml += body xml += '' return xml.rstrip('\n') def executar_consulta(certificado, url, cabecalho, xmlEnviar, send_raw=False): cert, key = extract_cert_and_key_from_pfx( certificado.pfx, certificado.password) cert_path, key_path = save_cert_key(cert, key) client = HttpClient(url, cert_path, key_path) xml_enviar = _soap_xml(xmlEnviar, cabecalho) if send_raw: xml = '' + xmlEnviar.rstrip('\n') xml_enviar = xml xml_retorno = client.post_soap(xml_enviar, cabecalho, send_raw) return sanitize_response(xml_retorno.encode())