---
caerbannog/passlist.py | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/caerbannog/passlist.py b/caerbannog/passlist.py
index 4967341..7a1dd62 100644
--- a/caerbannog/passlist.py
+++ b/caerbannog/passlist.py
@@ -4,8 +4,8 @@ import anytree
import fuzzyfinder
import gc
import gi
-import importlib
import os
+from typing import Optional, List
from .logger import Logger
gi.require_version('Gdk', '3.0')
gi.require_version('Gtk', '3.0')
@@ -176,10 +176,13 @@ class PassList(Gtk.ListBox):
def _copy_pass(self, pass_item):
pw = pass_item.get_pass()
- if not pw:
+ if pw is None:
self.emit('show-notification',
("Unable to copy password, decryption failed!"))
return
+ if pw == "":
+ self.emit('show-notification', "Empty password")
+ return
self._clipboard.set_text(pw, -1)
# schedule timer to clear clipboard
del pw
@@ -267,27 +270,24 @@ class PassItem(PassSection):
self._config = config
self._file = file
- # This will contain the (lazy) imported gpg module:
- self._gpg = None
- def get_pass(self):
+ def get_pass(self) -> Optional[str]:
contents = self._decrypt_file()
- if not contents:
+ if contents is None:
return None
- lines = contents.decode().split('\n')
+ lines: List[str] = contents.decode().split('\n')
if lines:
# per 'pass' specification
- return(lines[0])
+ return lines[0]
return None
- def _decrypt_file(self):
- text = None
- if not self._gpg:
- self._gpg = importlib.import_module('gpg')
+ def _decrypt_file(self) -> Optional[bytes]:
+ import gpg # type: ignore
with open(self._file, 'rb') as f:
try:
- text, result, result = self._gpg.Context().decrypt(f)
- except self._gpg.errors.GPGMEError as e:
- Logger.error(f"ERROR: unable to decrypt file: {self._file}")
+ text: bytes = gpg.Context().decrypt(f)[0]
+ return text
+ except gpg.errors.GPGMEError as e:
+ Logger.error(f"Unable to decrypt file: {self._file}")
Logger.error(e)
- return text
+ return None
--
2.30.1