From bf25b1a9dd6f9183ca053dee6677401e7438f7f2 Mon Sep 17 00:00:00 2001 From: Julian Mehne Date: Wed, 10 Jan 2018 02:59:45 +0100 Subject: Fix writing/loading history, if a command contains a non-ascii character. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: - alot -l log -d debug - :search รถ - quit alot - in log file: stacktrace with UnicodeEncodeError, when writing the histfile. --- alot/ui.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'alot/ui.py') diff --git a/alot/ui.py b/alot/ui.py index c97f2fc1..568db134 100644 --- a/alot/ui.py +++ b/alot/ui.py @@ -6,6 +6,7 @@ from __future__ import absolute_import import logging import os import signal +import codecs from twisted.internet import reactor, defer, task import urwid @@ -729,7 +730,7 @@ class UI(object): if size == 0: return [] if os.path.exists(path): - with open(path) as histfile: + with codecs.open(path, 'r', encoding='utf-8') as histfile: lines = [line.rstrip('\n') for line in histfile] if size > 0: lines = lines[-size:] @@ -759,7 +760,7 @@ class UI(object): if not os.path.exists(directory): os.makedirs(directory) # Write linewise to avoid building a large string in menory. - with open(path, 'w') as histfile: + with codecs.open(path, 'w', encoding='utf-8') as histfile: for line in history: histfile.write(line) histfile.write('\n') -- cgit v1.2.3