Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eda95e9

Browse files
committed
Merged revisions 75537,75539 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ........ r75537 | antoine.pitrou | 2009-10-19 21:37:25 +0200 (lun., 19 oct. 2009) | 3 lines egreen is Derk Drukker + fix NEWS formatting ........ r75539 | antoine.pitrou | 2009-10-19 21:43:09 +0200 (lun., 19 oct. 2009) | 4 lines Issue #7080: locale.strxfrm() raises a MemoryError on 64-bit non-Windows platforms, and assorted locale fixes by Derk Drukker. ........
1 parent bc740a6 commit eda95e9

6 files changed

Lines changed: 54 additions & 14 deletions

File tree

Lib/locale.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,14 +575,13 @@ def getpreferredencoding(do_setlocale = True):
575575
# returning nothing will crash the
576576
# interpreter.
577577
result = 'UTF-8'
578-
579578
setlocale(LC_CTYPE, oldloc)
580-
return result
581579
else:
582580
result = nl_langinfo(CODESET)
583581
if not result and sys.platform == 'darwin':
584582
# See above for explanation
585583
result = 'UTF-8'
584+
return result
586585

587586

588587
### Database

Lib/test/test_locale.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88

99
def get_enUS_locale():
1010
global enUS_locale
11-
if sys.platform == 'darwin':
12-
raise unittest.SkipTest("Locale support on MacOSX is minimal")
1311
if sys.platform.startswith("win"):
1412
tlocs = ("En", "English")
1513
else:
16-
tlocs = ("en_US.UTF-8", "en_US.US-ASCII", "en_US")
14+
tlocs = ("en_US.UTF-8", "en_US.ISO8859-1", "en_US.US-ASCII", "en_US")
1715
oldlocale = locale.setlocale(locale.LC_NUMERIC)
1816
for tloc in tlocs:
1917
try:
@@ -309,6 +307,39 @@ def test_currency(self):
309307
grouping=True, international=True)
310308

311309

310+
class TestCollation(unittest.TestCase):
311+
# Test string collation functions
312+
313+
def test_strcoll(self):
314+
self.assertLess(locale.strcoll('a', 'b'), 0)
315+
self.assertEqual(locale.strcoll('a', 'a'), 0)
316+
self.assertGreater(locale.strcoll('b', 'a'), 0)
317+
318+
def test_strxfrm(self):
319+
self.assertLess(locale.strxfrm('a'), locale.strxfrm('b'))
320+
321+
322+
class TestEnUSCollation(BaseLocalizedTest, TestCollation):
323+
# Test string collation functions with a real English locale
324+
325+
locale_type = locale.LC_ALL
326+
327+
def setUp(self):
328+
BaseLocalizedTest.setUp(self)
329+
enc = codecs.lookup(locale.getpreferredencoding(False) or 'ascii').name
330+
if enc not in ('utf-8', 'iso8859-1', 'cp1252'):
331+
raise unittest.SkipTest('encoding not suitable')
332+
if enc != 'iso8859-1' and (sys.platform == 'darwin' or
333+
sys.platform.startswith('freebsd')):
334+
raise unittest.SkipTest('wcscoll/wcsxfrm have known bugs')
335+
336+
def test_strcoll_with_diacritic(self):
337+
self.assertLess(locale.strcoll('à', 'b'), 0)
338+
339+
def test_strxfrm_with_diacritic(self):
340+
self.assertLess(locale.strxfrm('à'), locale.strxfrm('b'))
341+
342+
312343
class TestMiscellaneous(unittest.TestCase):
313344
def test_getpreferredencoding(self):
314345
# Invoke getpreferredencoding to make sure it does not cause exceptions.
@@ -317,11 +348,10 @@ def test_getpreferredencoding(self):
317348
# If encoding non-empty, make sure it is valid
318349
codecs.lookup(enc)
319350

320-
if hasattr(locale, "strcoll"):
321-
def test_strcoll_3303(self):
322-
# test crasher from bug #3303
323-
self.assertRaises(TypeError, locale.strcoll, "a", None)
324-
self.assertRaises(TypeError, locale.strcoll, b"a", None)
351+
def test_strcoll_3303(self):
352+
# test crasher from bug #3303
353+
self.assertRaises(TypeError, locale.strcoll, "a", None)
354+
self.assertRaises(TypeError, locale.strcoll, b"a", None)
325355

326356

327357
def test_main():
@@ -331,6 +361,7 @@ def test_main():
331361
TestEnUSNumberFormatting,
332362
TestCNumberFormatting,
333363
TestFrFRNumberFormatting,
364+
TestCollation
334365
]
335366
# SkipTest can't be raised inside unittests, handle it manually instead
336367
try:
@@ -339,7 +370,7 @@ def test_main():
339370
if verbose:
340371
print("Some tests will be disabled: %s" % e)
341372
else:
342-
tests += [TestNumberFormatting]
373+
tests += [TestNumberFormatting, TestEnUSCollation]
343374
run_unittest(*tests)
344375

345376
if __name__ == '__main__':

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ Ismail Donmez
184184
Dima Dorfman
185185
Cesar Douady
186186
Dean Draayer
187+
Derk Drukker
187188
John DuBois
188189
Paul Dubois
189190
Graham Dumpleton

Misc/NEWS

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Core and Builtins
1313
-----------------
1414

1515
- Issue #7065: Fix a crash in bytes.maketrans and bytearray.maketrans when
16-
using byte values greater than 127. Patch by egreen.
16+
using byte values greater than 127. Patch by Derk Drukker.
1717

1818
- Issue #7019: Raise ValueError when unmarshalling bad long data, instead
1919
of producing internally inconsistent Python longs.
@@ -30,6 +30,9 @@ Core and Builtins
3030
Library
3131
-------
3232

33+
- Issue #7080: locale.strxfrm() raises a MemoryError on 64-bit non-Windows
34+
platforms, and assorted locale fixes by Derk Drukker.
35+
3336
- Issue #5833: Fix extra space character in readline completion with the
3437
GNU readline library version 6.0.
3538

@@ -45,7 +48,7 @@ Library
4548
is too large to fit in the current precision.
4649

4750
- Issue #6236, #6348: Fix various failures in the I/O library under AIX
48-
and other platforms, when using a non-gcc compiler. Patch by egreen.
51+
and other platforms, when using a non-gcc compiler. Patch by Derk Drukker.
4952

5053
- Issue #6954: Fixed crash when using DISTUTILS_DEBUG flag in Distutils.
5154

Modules/_localemodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This software comes with no warranty. Use at your own risk.
99
1010
******************************************************************/
1111

12+
#define PY_SSIZE_T_CLEAN
1213
#include "Python.h"
1314

1415
#include <stdio.h>
@@ -315,7 +316,7 @@ PyLocale_strxfrm(PyObject* self, PyObject* args)
315316
result = PyUnicode_FromWideChar(buf, n2);
316317
exit:
317318
if (buf) PyMem_Free(buf);
318-
#ifdef HAVE_USABLE_WCHAR_T
319+
#ifndef HAVE_USABLE_WCHAR_T
319320
PyMem_Free(s);
320321
#endif
321322
return result;

PC/pyconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,11 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
647647
#define HAVE_WCSCOLL 1
648648
#endif
649649

650+
/* Define to 1 if you have the `wcsxfrm' function. */
651+
#ifndef MS_WINCE
652+
#define HAVE_WCSXFRM 1
653+
#endif
654+
650655
/* Define if you have the <dlfcn.h> header file. */
651656
/* #undef HAVE_DLFCN_H */
652657

0 commit comments

Comments
 (0)