Spell module: fix check of UTF8 strings in pyaspell
This commit is contained in:
parent
8aaf3bd6dc
commit
9495e43cc0
|
@ -45,6 +45,8 @@ def cmd_spell(msg):
|
|||
def check_spell(word, lang='fr'):
|
||||
a = Aspell(("lang", lang))
|
||||
if a.check(word):
|
||||
return True
|
||||
ret = True
|
||||
else:
|
||||
return a.suggest(word)
|
||||
ret = a.suggest(word)
|
||||
a.close()
|
||||
return ret
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
# 2011-02-20
|
||||
# * python3 compatible
|
||||
# * fixed docs
|
||||
#
|
||||
#
|
||||
# 2008-09-xx:
|
||||
# * fixed typo in save_all, thanks to Thomas Waldecker (thomas!yospot.de)
|
||||
#
|
||||
|
@ -54,7 +54,7 @@ class AspellLinux(object):
|
|||
"""
|
||||
Aspell speller object. Allows to check spelling, get suggested
|
||||
spelling list, manage user dictionaries, and other.
|
||||
|
||||
|
||||
Must be closed with 'close' method, or one may experience
|
||||
problems, like segfaults.
|
||||
"""
|
||||
|
@ -113,7 +113,7 @@ class AspellLinux(object):
|
|||
return bool(
|
||||
self.__lib.aspell_speller_check(
|
||||
self.__speller,
|
||||
_to_bytes(word),
|
||||
word,
|
||||
len(word)
|
||||
))
|
||||
else:
|
||||
|
@ -132,7 +132,7 @@ class AspellLinux(object):
|
|||
return self._aspellwordlist(
|
||||
self.__lib.aspell_speller_suggest(
|
||||
self.__speller,
|
||||
_to_bytes(word),
|
||||
word,
|
||||
len(word)
|
||||
))
|
||||
else:
|
||||
|
@ -162,7 +162,7 @@ class AspellLinux(object):
|
|||
return self._aspellwordlist(
|
||||
self.__lib.aspell_speller_personal_word_list(self.__speller)
|
||||
)
|
||||
|
||||
|
||||
|
||||
def session_dict(self, word=None, clear=False):
|
||||
"""
|
||||
|
@ -193,7 +193,7 @@ class AspellLinux(object):
|
|||
return self._aspellwordlist(
|
||||
self.__lib.aspell_speller_session_word_list(self.__speller)
|
||||
)
|
||||
|
||||
|
||||
|
||||
def add_replacement_pair(self, misspelled, correct):
|
||||
"""
|
||||
|
@ -212,7 +212,7 @@ class AspellLinux(object):
|
|||
len(correct)
|
||||
)
|
||||
self._aspell_check_error()
|
||||
|
||||
|
||||
|
||||
def save_all(self):
|
||||
"""
|
||||
|
@ -221,13 +221,13 @@ class AspellLinux(object):
|
|||
"""
|
||||
self.__lib.aspell_speller_save_all_word_lists(self.__speller)
|
||||
self._aspell_check_error()
|
||||
|
||||
|
||||
|
||||
def configkeys(self):
|
||||
"""
|
||||
Returns list of all available config keys that can be passed
|
||||
to constructor.
|
||||
|
||||
|
||||
List contains a 3-tuples:
|
||||
1. key name
|
||||
2. default value of type:
|
||||
|
@ -239,7 +239,7 @@ class AspellLinux(object):
|
|||
if None, then this key is undocumented is should not
|
||||
be used, unless one know what really do
|
||||
"""
|
||||
|
||||
|
||||
config = self.__lib.aspell_speller_config(self.__speller)
|
||||
if config is None:
|
||||
raise AspellConfigError("Can't get speller's config")
|
||||
|
@ -315,7 +315,7 @@ class AspellLinux(object):
|
|||
Close aspell speller object.
|
||||
"""
|
||||
self.__lib.delete_aspell_speller(self.__speller)
|
||||
|
||||
|
||||
|
||||
# XXX: internal function, do not call directly
|
||||
def _aspellwordlist(self, wordlist_id):
|
||||
|
@ -336,7 +336,7 @@ class AspellLinux(object):
|
|||
|
||||
self.__lib.delete_aspell_string_enumeration(elements)
|
||||
return list
|
||||
|
||||
|
||||
|
||||
def _aspell_config_error(self, config):
|
||||
"""
|
||||
|
@ -345,13 +345,13 @@ class AspellLinux(object):
|
|||
Raise exception if operation of speller config
|
||||
caused an error. Additionally destroy config object.
|
||||
"""
|
||||
# make exception object & copy error msg
|
||||
# make exception object & copy error msg
|
||||
exc = AspellConfigError(
|
||||
_from_bytes(ctypes.c_char_p(
|
||||
self.__lib.aspell_config_error_message(config)
|
||||
).value)
|
||||
)
|
||||
|
||||
|
||||
# then destroy config objcet
|
||||
self.__lib.delete_aspell_config(config)
|
||||
|
||||
|
@ -393,7 +393,7 @@ if __name__ == '__main__':
|
|||
|
||||
for item in a.configkeys():
|
||||
print(item)
|
||||
|
||||
|
||||
a.close()
|
||||
|
||||
# vim: ts=4 sw=4
|
||||
|
|
Loading…
Reference in New Issue
Block a user