Commit cbc5614b authored by Andi Vajda's avatar Andi Vajda
Browse files

added #define PY_SSIZE_T_CLEAN to silence https://bugs.python.org/issue36381

parent 13c95c97
...@@ -40,6 +40,7 @@ namespace std { ...@@ -40,6 +40,7 @@ namespace std {
#endif #endif
#endif #endif
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#if !defined(PYPY_VERSION) && defined(PYPY_VERSION_NUM) #if !defined(PYPY_VERSION) && defined(PYPY_VERSION_NUM)
......
...@@ -2554,7 +2554,9 @@ static PyObject *t_localematcher_acceptLanguage(PyTypeObject *type, ...@@ -2554,7 +2554,9 @@ static PyObject *t_localematcher_acceptLanguage(PyTypeObject *type,
return NULL; return NULL;
} }
return Py_BuildValue("(s#i)", buffer, (int) size, (int) result); return Py_BuildValue(
"(s#i)", (result == ULOC_ACCEPT_FAILED ? NULL : buffer),
size, (int) result);
} }
break; break;
} }
...@@ -2618,7 +2620,9 @@ static PyObject *t_localematcher_acceptLanguageFromHTTP(PyTypeObject *type, ...@@ -2618,7 +2620,9 @@ static PyObject *t_localematcher_acceptLanguageFromHTTP(PyTypeObject *type,
return NULL; return NULL;
} }
return Py_BuildValue("(s#i)", buffer, (int) size, (int) result); return Py_BuildValue(
"(s#i)", (result == ULOC_ACCEPT_FAILED ? NULL : buffer),
size, (int) result);
} }
break; break;
} }
......
...@@ -62,8 +62,7 @@ class TestLocaleMatcher(TestCase): ...@@ -62,8 +62,7 @@ class TestLocaleMatcher(TestCase):
def testAcceptLanguage(self): def testAcceptLanguage(self):
locale, status = LocaleMatcher.acceptLanguage( locale, status = LocaleMatcher.acceptLanguage(
('fr-CH', 'fr', 'en', 'de', '*'), ('fr-CH', 'fr', 'en', 'de', '*'), ('de-AT', 'fr-CA'))
('de-AT', 'fr-CA'))
self.assertEqual('fr_CA', locale) self.assertEqual('fr_CA', locale)
self.assertEqual(UAcceptResult.FALLBACK, status) self.assertEqual(UAcceptResult.FALLBACK, status)
...@@ -75,11 +74,15 @@ class TestLocaleMatcher(TestCase): ...@@ -75,11 +74,15 @@ class TestLocaleMatcher(TestCase):
self.assertEqual('fr_CH', locale) self.assertEqual('fr_CH', locale)
self.assertEqual(UAcceptResult.VALID, status) self.assertEqual(UAcceptResult.VALID, status)
locale, status = LocaleMatcher.acceptLanguage(
('fr-CH', 'fr', 'de'), ('en-CA',))
self.assertEqual(None, locale)
self.assertEqual(UAcceptResult.FAILED, status)
def testAcceptLanguageFromHTTP(self): def testAcceptLanguageFromHTTP(self):
locale, status = LocaleMatcher.acceptLanguageFromHTTP( locale, status = LocaleMatcher.acceptLanguageFromHTTP(
'fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5', 'fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5', ('de-AT', 'fr-CA'))
('de-AT', 'fr-CA'))
self.assertEqual('fr_CA', locale) self.assertEqual('fr_CA', locale)
self.assertEqual(UAcceptResult.FALLBACK, status) self.assertEqual(UAcceptResult.FALLBACK, status)
...@@ -91,6 +94,11 @@ class TestLocaleMatcher(TestCase): ...@@ -91,6 +94,11 @@ class TestLocaleMatcher(TestCase):
self.assertEqual('fr_CH', locale) self.assertEqual('fr_CH', locale)
self.assertEqual(UAcceptResult.VALID, status) self.assertEqual(UAcceptResult.VALID, status)
locale, status = LocaleMatcher.acceptLanguageFromHTTP(
'fr-CH, fr;q=0.9, de;q=0.7', ('en-CA',))
self.assertEqual(None, locale)
self.assertEqual(UAcceptResult.FAILED, status)
if __name__ == "__main__": if __name__ == "__main__":
if ICU_VERSION >= '65.0': if ICU_VERSION >= '65.0':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment