Fix obscure Windows line ending issue with decode

See https://bugs.python.org/issue40863
This commit is contained in:
Micah Jerome Ellison 2022-10-01 14:25:23 -07:00
parent fd6bdd79fb
commit ce4df8ee23
4 changed files with 6 additions and 10 deletions

View file

@ -157,7 +157,7 @@ class Journal:
return f.read()
def _store(self, filename, text):
with open(filename, "w", encoding="utf-8") as f:
with open(filename, "wb") as f:
f.write(text)
def _parse(self, journal_txt):

View file

@ -30,7 +30,7 @@ class BasePasswordEncryption(BaseEncryption):
def password(self, value: str) -> None:
self._password = value
def encrypt(self, text: str) -> str:
def encrypt(self, text: str) -> bytes:
if not self.password:
self.password = create_password(self._journal_name)
return self._encrypt(text)

View file

@ -40,12 +40,8 @@ class Jrnlv2Encryption(BasePasswordEncryption):
key = kdf.derive(password)
self._key = base64.urlsafe_b64encode(key)
def _encrypt(self, text: str) -> str:
return (
Fernet(self._key)
.encrypt(text.encode(self._encoding))
.decode(self._encoding)
)
def _encrypt(self, text: str) -> bytes:
return Fernet(self._key).encrypt(text.encode(self._encoding))
def _decrypt(self, text: bytes) -> str | None:
try:

View file

@ -7,8 +7,8 @@ class NoEncryption(BaseEncryption):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def _encrypt(self, text: str) -> str:
return text
def _encrypt(self, text: str) -> bytes:
return text.encode(self._encoding)
def _decrypt(self, text: bytes) -> str:
return text.decode(self._encoding)