Spell module: fix encoding problem

This commit is contained in:
Némunaire 2014-02-26 18:51:12 +01:00
parent ad7c8e6fce
commit d88146780f
2 changed files with 15 additions and 21 deletions

View file

@ -80,10 +80,10 @@ def cmd_score(msg):
return res return res
def check_spell(word, lang='fr'): def check_spell(word, lang='fr'):
a = Aspell(("lang", lang)) a = Aspell([("lang", lang), ("lang", "fr")])
if a.check(word): if a.check(word.encode("iso-8859-15")):
ret = True ret = True
else: else:
ret = a.suggest(word) ret = a.suggest(word.encode("iso-8859-15"))
a.close() a.close()
return ret return ret

View file

@ -37,10 +37,10 @@ try:
bytes bytes
def _to_bytes(s): def _to_bytes(s):
return s.encode() return s.encode("ISO-8859-15")
def _from_bytes(s): def _from_bytes(s):
return s.decode() return s.decode("ISO-8859-15")
except NameError: except NameError:
def _to_bytes(s): def _to_bytes(s):
@ -109,15 +109,12 @@ class AspellLinux(object):
Check if word is present in main, personal or session Check if word is present in main, personal or session
dictionary. Boolean value is returned dictionary. Boolean value is returned
""" """
if type(word) is str: return bool(
return bool( self.__lib.aspell_speller_check(
self.__lib.aspell_speller_check( self.__speller,
self.__speller, word,
_to_bytes(word), len(word)
len(word)
)) ))
else:
raise TypeError("String expected")
__contains__ = check __contains__ = check
@ -128,15 +125,12 @@ class AspellLinux(object):
Return list of spelling suggestions of given word. Return list of spelling suggestions of given word.
Works even if word is correct. Works even if word is correct.
""" """
if type(word) is str: return self._aspellwordlist(
return self._aspellwordlist( self.__lib.aspell_speller_suggest(
self.__lib.aspell_speller_suggest( self.__speller,
self.__speller, word,
_to_bytes(word), len(word)
len(word)
)) ))
else:
raise TypeError("String expected")
def personal_dict(self, word=None): def personal_dict(self, word=None):