Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update certificado.py #335

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions pynfe/entidades/certificado.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,22 @@
Se caminho for True grava na pasta temporaria e retorna o caminho dos arquivos,
senao retorna o objeto. Apos o uso devem ser excluidos com o metodo excluir.
"""

try:
with open(self.caminho_arquivo, "rb") as cert_arquivo:
cert_conteudo = cert_arquivo.read()
except (PermissionError, FileNotFoundError) as exc:
raise Exception(
"""Falha ao abrir arquivo do certificado digital A1.
Verifique local e permissoes do arquivo."""
) from exc
except Exception as exc:
raise Exception(
"Falha ao abrir arquivo do certificado digital A1. Causa desconhecida."
) from exc

if type(self.caminho_arquivo) is bytes:

Check failure on line 46 in pynfe/entidades/certificado.py

View workflow job for this annotation

GitHub Actions / build (3.8)

Ruff (E721)

pynfe/entidades/certificado.py:46:12: E721 Do not compare types, use `isinstance()`

Check failure on line 46 in pynfe/entidades/certificado.py

View workflow job for this annotation

GitHub Actions / build (3.9)

Ruff (E721)

pynfe/entidades/certificado.py:46:12: E721 Do not compare types, use `isinstance()`

Check failure on line 46 in pynfe/entidades/certificado.py

View workflow job for this annotation

GitHub Actions / build (3.10)

Ruff (E721)

pynfe/entidades/certificado.py:46:12: E721 Do not compare types, use `isinstance()`

Check failure on line 46 in pynfe/entidades/certificado.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (E721)

pynfe/entidades/certificado.py:46:12: E721 Do not compare types, use `isinstance()`

Check failure on line 46 in pynfe/entidades/certificado.py

View workflow job for this annotation

GitHub Actions / build (3.12)

Ruff (E721)

pynfe/entidades/certificado.py:46:12: E721 Do not compare types, use `isinstance()`
cert_conteudo = self.caminho_arquivo
else:
try:
with open(self.caminho_arquivo, "rb") as cert_arquivo:
cert_conteudo = cert_arquivo.read()
except (PermissionError, FileNotFoundError) as exc:
raise Exception(
"""Falha ao abrir arquivo do certificado digital A1.
Verifique local e permissoes do arquivo."""
) from exc
except Exception as exc:
raise Exception(
"Falha ao abrir arquivo do certificado digital A1. Causa desconhecida."
) from exc
Comment on lines +49 to +60
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creio que esse try precise ficar antes do if, todo o carregamento precisa ter o try-catch.


if not isinstance(senha, bytes):
senha = str.encode(senha)
Expand Down
Loading