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 {
#endif
#endif
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#if !defined(PYPY_VERSION) && defined(PYPY_VERSION_NUM)
......
......@@ -2554,7 +2554,9 @@ static PyObject *t_localematcher_acceptLanguage(PyTypeObject *type,
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;
}
......@@ -2618,7 +2620,9 @@ static PyObject *t_localematcher_acceptLanguageFromHTTP(PyTypeObject *type,
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;
}
......
......@@ -62,8 +62,7 @@ class TestLocaleMatcher(TestCase):
def testAcceptLanguage(self):
locale, status = LocaleMatcher.acceptLanguage(
('fr-CH', 'fr', 'en', 'de', '*'),
('de-AT', 'fr-CA'))
('fr-CH', 'fr', 'en', 'de', '*'), ('de-AT', 'fr-CA'))
self.assertEqual('fr_CA', locale)
self.assertEqual(UAcceptResult.FALLBACK, status)
......@@ -75,11 +74,15 @@ class TestLocaleMatcher(TestCase):
self.assertEqual('fr_CH', locale)
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):
locale, status = LocaleMatcher.acceptLanguageFromHTTP(
'fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5',
('de-AT', 'fr-CA'))
'fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5', ('de-AT', 'fr-CA'))
self.assertEqual('fr_CA', locale)
self.assertEqual(UAcceptResult.FALLBACK, status)
......@@ -91,6 +94,11 @@ class TestLocaleMatcher(TestCase):
self.assertEqual('fr_CH', locale)
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 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