From 8f314209b4f9c852308eb7e4b31c1e8643283adf Mon Sep 17 00:00:00 2001 From: ThomasV Date: Wed, 3 Sep 2014 18:41:25 +0200 Subject: [PATCH] normalize unicode right after reading from file --- lib/mnemonic.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/mnemonic.py b/lib/mnemonic.py index 9ca8d5d7f..bef500e97 100644 --- a/lib/mnemonic.py +++ b/lib/mnemonic.py @@ -20,6 +20,7 @@ import os import hmac import math import hashlib +import unicodedata import ecdsa import pbkdf2 @@ -43,14 +44,16 @@ class Mnemonic(object): filename = 'english.txt' path = os.path.join(os.path.dirname(__file__), 'wordlist', filename) - lines = open(path,'r').read().strip().split('\n') + s = open(path,'r').read().strip() + s = unicodedata.normalize('NFKD', s.decode('utf8')) + lines = s.split('\n') self.wordlist = [] for line in lines: line = line.split('#')[0] line = line.strip(' \r') assert ' ' not in line if line: - self.wordlist.append(line.decode('utf8')) + self.wordlist.append(line) print_error("wordlist has %d words"%len(self.wordlist)) @classmethod @@ -60,7 +63,6 @@ class Mnemonic(object): @classmethod def prepare_seed(self, seed): - import unicodedata return unicodedata.normalize('NFKD', unicode(seed.strip())) def mnemonic_encode(self, i):