commit 8f314209b4f9c852308eb7e4b31c1e8643283adf
parent 1e75d6f8541ab0cd8922ee1ecd6756d4a103a9e5
Author: ThomasV <thomasv@gitorious>
Date: Wed, 3 Sep 2014 18:41:25 +0200
normalize unicode right after reading from file
Diffstat:
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git 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):