mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-13 09:58:31 +02:00
Fix obscure Windows line ending issue with decode
See https://bugs.python.org/issue40863
This commit is contained in:
parent
fd6bdd79fb
commit
ce4df8ee23
4 changed files with 6 additions and 10 deletions
|
@ -157,7 +157,7 @@ class Journal:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
def _store(self, filename, text):
|
def _store(self, filename, text):
|
||||||
with open(filename, "w", encoding="utf-8") as f:
|
with open(filename, "wb") as f:
|
||||||
f.write(text)
|
f.write(text)
|
||||||
|
|
||||||
def _parse(self, journal_txt):
|
def _parse(self, journal_txt):
|
||||||
|
|
|
@ -30,7 +30,7 @@ class BasePasswordEncryption(BaseEncryption):
|
||||||
def password(self, value: str) -> None:
|
def password(self, value: str) -> None:
|
||||||
self._password = value
|
self._password = value
|
||||||
|
|
||||||
def encrypt(self, text: str) -> str:
|
def encrypt(self, text: str) -> bytes:
|
||||||
if not self.password:
|
if not self.password:
|
||||||
self.password = create_password(self._journal_name)
|
self.password = create_password(self._journal_name)
|
||||||
return self._encrypt(text)
|
return self._encrypt(text)
|
||||||
|
|
|
@ -40,12 +40,8 @@ class Jrnlv2Encryption(BasePasswordEncryption):
|
||||||
key = kdf.derive(password)
|
key = kdf.derive(password)
|
||||||
self._key = base64.urlsafe_b64encode(key)
|
self._key = base64.urlsafe_b64encode(key)
|
||||||
|
|
||||||
def _encrypt(self, text: str) -> str:
|
def _encrypt(self, text: str) -> bytes:
|
||||||
return (
|
return Fernet(self._key).encrypt(text.encode(self._encoding))
|
||||||
Fernet(self._key)
|
|
||||||
.encrypt(text.encode(self._encoding))
|
|
||||||
.decode(self._encoding)
|
|
||||||
)
|
|
||||||
|
|
||||||
def _decrypt(self, text: bytes) -> str | None:
|
def _decrypt(self, text: bytes) -> str | None:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -7,8 +7,8 @@ class NoEncryption(BaseEncryption):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def _encrypt(self, text: str) -> str:
|
def _encrypt(self, text: str) -> bytes:
|
||||||
return text
|
return text.encode(self._encoding)
|
||||||
|
|
||||||
def _decrypt(self, text: bytes) -> str:
|
def _decrypt(self, text: bytes) -> str:
|
||||||
return text.decode(self._encoding)
|
return text.decode(self._encoding)
|
||||||
|
|
Loading…
Add table
Reference in a new issue