Skip to content

Commit 7cf9314

Browse files
committed
[REF] pre-commit
1 parent 5d9e587 commit 7cf9314

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

src/erpbrasil/edoc/cte.py

+22-25
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1+
import base64
2+
import gzip
13
from contextlib import suppress
24

35
from lxml import etree
4-
import gzip
5-
import base64
66

77
from erpbrasil.edoc.edoc import DocumentoEletronico
88
from erpbrasil.transmissao import TransmissaoSOAP
99

10-
from .resposta import analisar_retorno_raw
11-
1210
with suppress(ImportError):
1311
from nfelib.cte.bindings.v4_0 import (
14-
Cte,
12+
ConsSitCte,
13+
ConsStatServCte,
1514
EvCancCte,
1615
RetConsSitCte,
1716
RetConsStatServCte,
1817
RetCte,
1918
RetEventoCte,
20-
ConsSitCte,
21-
Tcte,
22-
ConsStatServCte
2319
)
2420

2521
AMBIENTE_PRODUCAO = "producao"
@@ -106,7 +102,7 @@
106102
WS_CTE_RECEPCAO_SINC: "CTeWS/WS/CTeRecepcaoSincV4.asmx?wsdl",
107103
WS_CTE_STATUS_SERVICO: "CTeWS/WS/CTeStatusServicoV4.asmx?wsdl",
108104
QR_CODE_URL: "https://homologacao.nfe.fazenda.sp.gov.br/CTeConsulta/qrCode",
109-
}
105+
},
110106
}
111107

112108
SVRS = {
@@ -129,7 +125,7 @@
129125
WS_CTE_RECEPCAO_SINC: "ws/CTeRecepcaoSincV4/CTeRecepcaoSincV4.asmx?wsdl",
130126
WS_CTE_STATUS_SERVICO: "ws/CTeStatusServicoV4/CTeStatusServicoV4.asmx?wsdl",
131127
QR_CODE_URL: "https://dfe-portal.svrs.rs.gov.br/cte/qrCode",
132-
}
128+
},
133129
}
134130

135131
MT = {
@@ -152,7 +148,7 @@
152148
WS_CTE_RECEPCAO_SINC: "ctews2/services/CTeRecepcaoSincV4?wsdl",
153149
WS_CTE_STATUS_SERVICO: "ctews2/services/CTeStatusServicoV4?wsdl",
154150
QR_CODE_URL: "https://homologacao.sefaz.mt.gov.br/cte/qrcode",
155-
}
151+
},
156152
}
157153

158154
MS = {
@@ -175,7 +171,7 @@
175171
WS_CTE_RECEPCAO_SINC: "ws/CTeRecepcaoSincV4?wsdl",
176172
WS_CTE_STATUS_SERVICO: "ws/CTeStatusServicoV4?wsdl",
177173
QR_CODE_URL: "http://www.dfe.ms.gov.br/cte/qrcode",
178-
}
174+
},
179175
}
180176

181177
MG = {
@@ -198,7 +194,7 @@
198194
WS_CTE_RECEPCAO_SINC: "cte/services/CTeRecepcaoSincV4?wsdl",
199195
WS_CTE_STATUS_SERVICO: "cte/services/CTeStatusServicoV4?wsdl",
200196
QR_CODE_URL: "https://cte.fazenda.mg.gov.br/portalcte/sistema/qrcode.xhtml",
201-
}
197+
},
202198
}
203199

204200
PR = {
@@ -221,7 +217,7 @@
221217
WS_CTE_RECEPCAO_SINC: "cte4/CTeRecepcaoSincV4?wsdl",
222218
WS_CTE_STATUS_SERVICO: "cte4/CTeStatusServicoV4?wsdl",
223219
QR_CODE_URL: "http://www.fazenda.pr.gov.br/cte/qrcode",
224-
}
220+
},
225221
}
226222

227223

@@ -234,7 +230,9 @@ def get_service_url(sigla_estado, service, ambiente):
234230
state_config = sigla_estado
235231

236232
if not state_config:
237-
raise ValueError(f"Estado {sigla_estado} não suportado ou configuração ausente.")
233+
raise ValueError(
234+
f"Estado {sigla_estado} não suportado ou configuração ausente."
235+
)
238236

239237
environment = AMBIENTE_PRODUCAO if ambiente == 1 else AMBIENTE_HOMOLOGACAO
240238
if service == "QRCode":
@@ -279,9 +277,7 @@ def _verifica_resposta_envio_sucesso(self, proc_envio):
279277
)
280278

281279
def status_servico(self):
282-
raiz = ConsStatServCte(
283-
tpAmb=self.ambiente, cUF=self.uf, versao=self.versao
284-
)
280+
raiz = ConsStatServCte(tpAmb=self.ambiente, cUF=self.uf, versao=self.versao)
285281
return self._post(
286282
raiz=raiz,
287283
url=self._get_ws_endpoint(WS_CTE_STATUS_SERVICO),
@@ -302,10 +298,10 @@ def envia_documento(self, edoc):
302298
xml_assinado = self.assina_raiz(edoc, edoc.infCte.Id)
303299

304300
# Compactar o XML assinado com GZip
305-
gzipped_xml = gzip.compress(xml_assinado.encode('utf-8'))
301+
gzipped_xml = gzip.compress(xml_assinado.encode("utf-8"))
306302

307303
# Codificar o XML compactado em Base64
308-
base64_gzipped_xml = base64.b64encode(gzipped_xml).decode('utf-8')
304+
base64_gzipped_xml = base64.b64encode(gzipped_xml).decode("utf-8")
309305

310306
return self._post(
311307
raiz=base64_gzipped_xml,
@@ -332,17 +328,18 @@ def get_documento_id(self, edoc):
332328
return edoc.infCte.Id[:3], edoc.infCte.Id[3:]
333329

334330
def monta_qrcode(self, chave):
335-
return f"{self._get_ws_endpoint(QR_CODE_URL)}?chCTe={chave}&tpAmb={self.ambiente}"
331+
return (
332+
f"{self._get_ws_endpoint(QR_CODE_URL)}?chCTe={chave}&tpAmb={self.ambiente}"
333+
)
336334

337335

338336
class TransmissaoCTE(TransmissaoSOAP):
339-
340337
def interpretar_mensagem(self, mensagem, **kwargs):
341338
if isinstance(mensagem, str):
342339
try:
343-
return etree.fromstring(mensagem, parser=etree.XMLParser(
344-
remove_blank_text=True
345-
))
340+
return etree.fromstring(
341+
mensagem, parser=etree.XMLParser(remove_blank_text=True)
342+
)
346343
except (etree.XMLSyntaxError, ValueError):
347344
# Retorna a string original se houver um erro na conversão
348345
return mensagem

0 commit comments

Comments
 (0)