diff --git a/pynfe/processamento/assinatura.py b/pynfe/processamento/assinatura.py index 50c5e263..43b6e690 100644 --- a/pynfe/processamento/assinatura.py +++ b/pynfe/processamento/assinatura.py @@ -48,7 +48,13 @@ def assinar(self, xml: etree._Element, retorna_string=False) -> Union[str, etree ref_uri = ("#%s" % reference) if reference else None signed_root = signer.sign(xml, key=self.key, cert=self.cert, reference_uri=ref_uri) + + # Reparse to ensure namespaces are correctly associated with elements + # This is required for lxml 6.x compatibility when using default namespace (None prefix) + signed_xml_str = etree.tostring(signed_root, encoding="unicode", pretty_print=False) + signed_root = etree.fromstring(signed_xml_str) + if retorna_string: - return etree.tostring(signed_root, encoding="unicode", pretty_print=False) + return signed_xml_str else: return signed_root diff --git a/pyproject.toml b/pyproject.toml index 2f56a155..63745d1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,9 +21,9 @@ line-length = 100 [tool.poetry.dependencies] requests = "^2.32.4" -signxml = "^4.1.0" -cryptography = "43.0.3" -lxml = "5.4.0" +signxml = ">=4.1.0" +cryptography = ">=43.0.3" +lxml = ">=5.4.0" pyopenssl = "^25.1.0" [tool.poetry.group.dev.dependencies] diff --git a/requirements.txt b/requirements.txt index a6557b46..f5f05db4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ # Dependencias basicas -requests -lxml -signxml -cryptography +requests>=2.32.4 +lxml>=5.4.0 +signxml>=4.1.0 +cryptography>=43.0.3 # Opcional para NFS-e #-r requirements-nfse.txt # Opcional para Desenvolvimento (Pytest, Ruff, MyPy, etc) diff --git a/tests/test_certificadoA1.py b/tests/test_certificadoA1.py index f53d3a2a..dd13e32e 100644 --- a/tests/test_certificadoA1.py +++ b/tests/test_certificadoA1.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # *-* encoding: utf8 *-* +import tempfile import unittest from pynfe.entidades.certificado import CertificadoA1 @@ -17,8 +18,9 @@ def test_assinatura_com_caminho(self): self.a1 = CertificadoA1(self.certificado_correto) cert = self.a1.separar_arquivo(senha=self.senha_correto, caminho=self.certificado_correto) - self.assertTrue(cert[0].startswith("/tmp/")) - self.assertTrue(cert[1].startswith("/tmp/")) + temp_dir = tempfile.gettempdir() + self.assertTrue(cert[0].startswith(temp_dir)) + self.assertTrue(cert[1].startswith(temp_dir)) self.a1.excluir()