|
|
101174d |
From d83879975432cc1dda2e143a6d85bb4121c3d2ce Mon Sep 17 00:00:00 2001
|
|
|
101174d |
From: =?UTF-8?q?Beno=C3=AEt=20Latinier?= <benoit@latinier.fr>
|
|
|
101174d |
Date: Tue, 20 Feb 2018 22:50:48 +0100
|
|
|
101174d |
Subject: [PATCH 12/12] fix encoding problem (#32)
|
|
|
101174d |
|
|
|
101174d |
---
|
|
|
101174d |
.gitignore | 2 +-
|
|
|
101174d |
CHANGELOG.md | 1 +
|
|
|
101174d |
hunspell.cpp | 15 +++++++++++----
|
|
|
101174d |
setup.py | 2 +-
|
|
|
101174d |
tests/test_hunspell.py | 4 ++++
|
|
|
101174d |
5 files changed, 18 insertions(+), 6 deletions(-)
|
|
|
101174d |
|
|
|
101174d |
diff --git a/.gitignore b/.gitignore
|
|
|
101174d |
index b0ded7e..b961bfb 100644
|
|
|
101174d |
--- a/.gitignore
|
|
|
101174d |
+++ b/.gitignore
|
|
|
101174d |
@@ -1,5 +1,5 @@
|
|
|
101174d |
.pyc
|
|
|
101174d |
-venv
|
|
|
101174d |
+venv*
|
|
|
101174d |
__pycache__
|
|
|
101174d |
MANIFEST
|
|
|
101174d |
dist
|
|
|
101174d |
diff --git a/CHANGELOG.md b/CHANGELOG.md
|
|
|
101174d |
index 357f217..4a1ba5f 100644
|
|
|
101174d |
--- a/CHANGELOG.md
|
|
|
101174d |
+++ b/CHANGELOG.md
|
|
|
101174d |
@@ -3,6 +3,7 @@
|
|
|
101174d |
## 0.5.4 (???)
|
|
|
101174d |
### Bug fixes
|
|
|
101174d |
- Fix a memory leak at instanciation (issue #39 fixed by @Far3t)
|
|
|
101174d |
+- Fix an encoding problem (issue #32)
|
|
|
101174d |
|
|
|
101174d |
## 0.5.3 (2018-02-02)
|
|
|
101174d |
### Improvements
|
|
|
101174d |
diff --git a/hunspell.cpp b/hunspell.cpp
|
|
|
101174d |
index 6650641..7c5cb71 100644
|
|
|
101174d |
--- a/hunspell.cpp
|
|
|
101174d |
+++ b/hunspell.cpp
|
|
|
101174d |
@@ -152,8 +152,9 @@ static PyObject *
|
|
|
101174d |
HunSpell_suggest(HunSpell * self, PyObject *args)
|
|
|
101174d |
{
|
|
|
101174d |
char *word, **slist;
|
|
|
101174d |
- int i, num_slist, ret;
|
|
|
101174d |
+ int i, num_slist, ret, str_size;
|
|
|
101174d |
PyObject *slist_list, *pystr;
|
|
|
101174d |
+ PyObject *etype, *evalue, *etrace;
|
|
|
101174d |
|
|
|
101174d |
if (!PyArg_ParseTuple(args, "et", self->encoding, &word))
|
|
|
101174d |
return NULL;
|
|
|
101174d |
@@ -166,9 +167,15 @@ HunSpell_suggest(HunSpell * self, PyObject *args)
|
|
|
101174d |
PyMem_Free(word);
|
|
|
101174d |
|
|
|
101174d |
for (i = 0, ret = 0; !ret && i < num_slist; i++) {
|
|
|
101174d |
- pystr = PyUnicode_FromString(slist[i]);
|
|
|
101174d |
- if (!pystr)
|
|
|
101174d |
- break;
|
|
|
101174d |
+ str_size = strlen(slist[i]);
|
|
|
101174d |
+ pystr = PyUnicode_DecodeUTF8(slist[i], str_size, "strict");
|
|
|
101174d |
+ if (!pystr) {
|
|
|
101174d |
+ PyErr_Fetch(&etype, &evalue, &etrace);
|
|
|
101174d |
+ Py_DECREF(etype);
|
|
|
101174d |
+ pystr = PyUnicode_DecodeLatin1(slist[i], str_size, "strict");
|
|
|
101174d |
+ if (!pystr)
|
|
|
101174d |
+ break;
|
|
|
101174d |
+ }
|
|
|
101174d |
ret = PyList_Append(slist_list, pystr);
|
|
|
101174d |
Py_DECREF(pystr);
|
|
|
101174d |
}
|
|
|
101174d |
diff --git a/setup.py b/setup.py
|
|
|
101174d |
index 656c938..1b65ab5 100755
|
|
|
101174d |
--- a/setup.py
|
|
|
101174d |
+++ b/setup.py
|
|
|
101174d |
@@ -43,7 +43,7 @@ else:
|
|
|
101174d |
main = Extension('hunspell', **main_module_kwargs)
|
|
|
101174d |
|
|
|
101174d |
setup(name="hunspell",
|
|
|
101174d |
- version="0.5.3",
|
|
|
101174d |
+ version="0.5.4",
|
|
|
101174d |
description="Module for the Hunspell spellchecker engine",
|
|
|
101174d |
author="Benoît Latinier",
|
|
|
101174d |
author_email="benoit@latinier.fr",
|
|
|
101174d |
diff --git a/tests/test_hunspell.py b/tests/test_hunspell.py
|
|
|
101174d |
index 320f8ad..cdfd08d 100644
|
|
|
101174d |
--- a/tests/test_hunspell.py
|
|
|
101174d |
+++ b/tests/test_hunspell.py
|
|
|
101174d |
@@ -1,3 +1,4 @@
|
|
|
101174d |
+#-*- coding: utf-8 -*-
|
|
|
101174d |
import os
|
|
|
101174d |
import unittest
|
|
|
101174d |
from hunspell import HunSpell, HunSpellError
|
|
|
101174d |
@@ -28,6 +29,9 @@ class HunSpellTest(unittest.TestCase):
|
|
|
101174d |
self.assertEqual(self.hunspell.suggest('spookie'),
|
|
|
101174d |
['spookier', 'spookiness', 'spook', 'cookie',
|
|
|
101174d |
'bookie', 'Spokane', 'spoken'])
|
|
|
101174d |
+ self.assertEqual(self.hunspell.suggest('Eelysa'),
|
|
|
101174d |
+ ['Elyssa', 'Elysees', 'Elysha', 'Elysia',
|
|
|
101174d |
+ 'Elissa', 'Elysée'])
|
|
|
101174d |
|
|
|
101174d |
def test_hunspell_stem(self):
|
|
|
101174d |
self.assertEqual(self.hunspell.stem('dog'), [b'dog'])
|
|
|
101174d |
--
|
|
|
101174d |
2.14.3
|
|
|
101174d |
|