Better utf8 support

This commit is contained in:
Manuel Ebert 2013-04-19 17:32:32 +02:00
parent 8842b8589f
commit 884881546d
3 changed files with 13 additions and 6 deletions

View file

@ -4,8 +4,9 @@ Changelog
### 1.0.4
* [Improved] Python 2.6 compatibility
* [Improved] Better utf-8 support
* [New] Python 3 compatibility
* [New] Respects the `XDG_CONFIG_HOME` environment variable for storing your configuration file
* [New] Respects the `XDG_CONFIG_HOME` environment variable for storing your configuration file (Thanks [evaryont](https://github.com/evaryont))
### 1.0.3 (April 17, 2013)

View file

@ -104,9 +104,9 @@ class Journal(object):
Entries have the form (date, title, body)."""
filename = filename or self.config['journal']
journal = None
with codecs.open(filename, "r", "utf-8") as f:
journal = f.read()
if self.config['encrypt']:
with open(filename, "rb") as f:
journal = f.read()
decrypted = None
attempts = 0
while decrypted is None:
@ -121,6 +121,9 @@ class Journal(object):
print("Extremely wrong password.")
sys.exit(-1)
journal = decrypted
else:
with codecs.open(filename, "r", "utf-8") as f:
journal = f.read()
return journal
def parse(self, journal):
@ -181,8 +184,11 @@ class Journal(object):
journal = "\n".join([str(e) for e in self.entries])
if self.config['encrypt']:
journal = self._encrypt(journal)
with codecs.open(filename, 'w', "utf-8") as journal_file:
journal_file.write(journal)
with open(filename, 'wb') as journal_file:
journal_file.write(journal)
else:
with codecs.open(filename, 'w', "utf-8") as journal_file:
journal_file.write(journal)
def sort(self):
"""Sorts the Journal's entries by date"""

View file

@ -32,7 +32,7 @@ __author__ = 'Manuel Ebert, Stephan Gabler'
__license__ = 'MIT'
xdg_config = os.environ.get('XDG_CONFIG_HOME')
CONFIG_PATH = os.path.join(xdg_config, "jrnl") if xdg_config else os.path.expanduser('~/.jrnl_config'))
CONFIG_PATH = os.path.join(xdg_config, "jrnl") if xdg_config else os.path.expanduser('~/.jrnl_config')
PYCRYPTO = install.module_exists("Crypto")
def parse_args():