From d0e0a990ce59f7971aba2d2281c2a6720c5e9e95 Mon Sep 17 00:00:00 2001 From: William Ting Date: Thu, 22 Nov 2012 17:13:38 -0600 Subject: [PATCH] Set default encoding to UTF-8 when opening database file. Closes #162. --- bin/autojump | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/bin/autojump b/bin/autojump index 2301b8f..5f3491b 100755 --- a/bin/autojump +++ b/bin/autojump @@ -34,7 +34,7 @@ import re import shutil from tempfile import NamedTemporaryFile -VERSION = 'release-v21.1.0' +VERSION = 'release-v21.1.1' MAX_KEYWEIGHT = 1000 MAX_STORED_PATHS = 1000 COMPLETION_SEPARATOR = '__' @@ -114,11 +114,18 @@ class Database: """ if os.path.exists(self.filename): try: - with open(self.filename, 'r') as f: - for line in f.readlines(): - weight, path = line[:-1].split("\t", 1) - path = decode(path, 'utf-8') - self.data[path] = float(weight) + if sys.version > (2, 6): + with open(self.filename, 'r', encoding = 'utf-8') as f: + for line in f.readlines(): + weight, path = line[:-1].split("\t", 1) + path = decode(path, 'utf-8') + self.data[path] = float(weight) + else: + with open(self.filename, 'r') as f: + for line in f.readlines(): + weight, path = line[:-1].split("\t", 1) + path = decode(path, 'utf-8') + self.data[path] = float(weight) except (IOError, EOFError): self.load_backup(error_recovery) else: