mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 04:58:32 +02:00
Drop use of codecs package
Use builtins.open() instead
This commit is contained in:
parent
65adb92ed4
commit
827a598dd8
6 changed files with 12 additions and 18 deletions
|
@ -5,7 +5,6 @@ from . import util
|
|||
from . import time
|
||||
import os
|
||||
import sys
|
||||
import codecs
|
||||
import re
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
@ -268,15 +267,15 @@ class Journal:
|
|||
class PlainJournal(Journal):
|
||||
@classmethod
|
||||
def _create(cls, filename):
|
||||
with codecs.open(filename, "a", "utf-8"):
|
||||
with open(filename, "a", encoding="utf-8"):
|
||||
pass
|
||||
|
||||
def _load(self, filename):
|
||||
with codecs.open(filename, "r", "utf-8") as f:
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
return f.read()
|
||||
|
||||
def _store(self, filename, text):
|
||||
with codecs.open(filename, 'w', "utf-8") as f:
|
||||
with open(filename, 'w', encoding="utf-8") as f:
|
||||
f.write(text)
|
||||
|
||||
|
||||
|
@ -285,7 +284,7 @@ class LegacyJournal(Journal):
|
|||
standard. Main difference here is that in 1.x, timestamps were not cuddled
|
||||
by square brackets. You'll not be able to save these journals anymore."""
|
||||
def _load(self, filename):
|
||||
with codecs.open(filename, "r", "utf-8") as f:
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
return f.read()
|
||||
|
||||
def _parse(self, journal_txt):
|
||||
|
|
|
@ -4,7 +4,6 @@ from .util import ERROR_COLOR, RESET_COLOR
|
|||
from .util import slugify
|
||||
from .plugins.template import Template
|
||||
import os
|
||||
import codecs
|
||||
|
||||
|
||||
class Exporter:
|
||||
|
@ -32,7 +31,7 @@ class Exporter:
|
|||
def write_file(self, journal, path):
|
||||
"""Exports a journal into a single file."""
|
||||
try:
|
||||
with codecs.open(path, "w", "utf-8") as f:
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(self.export_journal(journal))
|
||||
return f"[Journal exported to {path}]"
|
||||
except OSError as e:
|
||||
|
@ -46,7 +45,7 @@ class Exporter:
|
|||
for entry in journal.entries:
|
||||
try:
|
||||
full_path = os.path.join(path, self.make_filename(entry))
|
||||
with codecs.open(full_path, "w", "utf-8") as f:
|
||||
with open(full_path, "w", encoding="utf-8") as f:
|
||||
f.write(self.export_entry(entry))
|
||||
except OSError as e:
|
||||
return f"[{ERROR_COLOR}ERROR{RESET_COLOR}: {e.filename} {e.strerror}]"
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import codecs
|
||||
import sys
|
||||
from .. import util
|
||||
|
||||
|
@ -16,7 +15,7 @@ class JRNLImporter:
|
|||
old_cnt = len(journal.entries)
|
||||
old_entries = journal.entries
|
||||
if input:
|
||||
with codecs.open(input, "r", "utf-8") as f:
|
||||
with open(input, "r", encoding="utf-8") as f:
|
||||
other_journal_txt = f.read()
|
||||
else:
|
||||
try:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import codecs
|
||||
from ..util import slugify
|
||||
import os
|
||||
from ..util import ERROR_COLOR, RESET_COLOR
|
||||
|
@ -26,7 +25,7 @@ class TextExporter:
|
|||
def write_file(cls, journal, path):
|
||||
"""Exports a journal into a single file."""
|
||||
try:
|
||||
with codecs.open(path, "w", "utf-8") as f:
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(cls.export_journal(journal))
|
||||
return f"[Journal exported to {path}]"
|
||||
except IOError as e:
|
||||
|
@ -42,7 +41,7 @@ class TextExporter:
|
|||
for entry in journal.entries:
|
||||
try:
|
||||
full_path = os.path.join(path, cls.make_filename(entry))
|
||||
with codecs.open(full_path, "w", "utf-8") as f:
|
||||
with open(full_path, "w", encoding="utf-8") as f:
|
||||
f.write(cls.export_entry(entry))
|
||||
except IOError as e:
|
||||
return "[{2}ERROR{3}: {0} {1}]".format(e.filename, e.strerror, ERROR_COLOR, RESET_COLOR)
|
||||
|
|
|
@ -6,7 +6,6 @@ from . import util
|
|||
from .EncryptedJournal import EncryptedJournal
|
||||
from .util import UserAbort
|
||||
import os
|
||||
import codecs
|
||||
|
||||
|
||||
def backup(filename, binary=False):
|
||||
|
@ -19,7 +18,7 @@ def backup(filename, binary=False):
|
|||
|
||||
|
||||
def upgrade_jrnl_if_necessary(config_path):
|
||||
with codecs.open(config_path, "r", "utf-8") as f:
|
||||
with open(config_path, "r", encoding="utf-8") as f:
|
||||
config_file = f.read()
|
||||
if not config_file.strip().startswith("{"):
|
||||
return
|
||||
|
|
|
@ -10,7 +10,6 @@ if "win32" in sys.platform:
|
|||
import re
|
||||
import tempfile
|
||||
import subprocess
|
||||
import codecs
|
||||
import unicodedata
|
||||
import shlex
|
||||
import logging
|
||||
|
@ -106,14 +105,14 @@ def scope_config(config, journal_name):
|
|||
|
||||
def get_text_from_editor(config, template=""):
|
||||
filehandle, tmpfile = tempfile.mkstemp(prefix="jrnl", text=True, suffix=".txt")
|
||||
with codecs.open(tmpfile, 'w', "utf-8") as f:
|
||||
with open(tmpfile, 'w', encoding="utf-8") as f:
|
||||
if template:
|
||||
f.write(template)
|
||||
try:
|
||||
subprocess.call(shlex.split(config['editor'], posix="win" not in sys.platform) + [tmpfile])
|
||||
except AttributeError:
|
||||
subprocess.call(config['editor'] + [tmpfile])
|
||||
with codecs.open(tmpfile, "r", "utf-8") as f:
|
||||
with open(tmpfile, "r", encoding="utf-8") as f:
|
||||
raw = f.read()
|
||||
os.close(filehandle)
|
||||
os.remove(tmpfile)
|
||||
|
|
Loading…
Add table
Reference in a new issue