[Python-checkins] r56600 - in python/branches/release25-maint: Lib/test/test_unicodedata.py Misc/NEWS Modules/unicodedata.c
martin.v.loewis
python-checkins at python.org
Sat Jul 28 09:01:43 CEST 2007
Author: martin.v.loewis
Date: Sat Jul 28 09:01:43 2007
New Revision: 56600
Modified:
python/branches/release25-maint/Lib/test/test_unicodedata.py
python/branches/release25-maint/Misc/NEWS
python/branches/release25-maint/Modules/unicodedata.c
Log:
Bug #1704793: Raise KeyError if unicodedata.lookup cannot
represent the result in a single character.
Modified: python/branches/release25-maint/Lib/test/test_unicodedata.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_unicodedata.py (original)
+++ python/branches/release25-maint/Lib/test/test_unicodedata.py Sat Jul 28 09:01:43 2007
@@ -6,7 +6,7 @@
"""#"
import unittest, test.test_support
-import hashlib
+import hashlib, sys
encoding = 'utf-8'
@@ -214,6 +214,10 @@
count += 1
self.assert_(count >= 10) # should have tested at least the ASCII digits
+ def test_bug_1704793(self):
+ if sys.maxunicode == 65535:
+ self.assertRaises(KeyError, self.db.lookup, "GOTHIC LETTER FAIHU")
+
def test_main():
test.test_support.run_unittest(
UnicodeMiscTest,
Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS (original)
+++ python/branches/release25-maint/Misc/NEWS Sat Jul 28 09:01:43 2007
@@ -26,6 +26,9 @@
Library
-------
+- Bug #1704793: Raise KeyError if unicodedata.lookup cannot
+ represent the result in a single character.
+
- Change location of the package index to pypi.python.org/pypi
- Bug #1701409: Fix a segfault in printing ctypes.c_char_p and
Modified: python/branches/release25-maint/Modules/unicodedata.c
==============================================================================
--- python/branches/release25-maint/Modules/unicodedata.c (original)
+++ python/branches/release25-maint/Modules/unicodedata.c Sat Jul 28 09:01:43 2007
@@ -1102,8 +1102,18 @@
return NULL;
}
+#ifndef Py_UNICODE_WIDE
+ if (code >= 0x10000) {
+ /* Raise KeyError for compatibility; the possibly more
+ correct ValueError was not documented as a possible
+ exception for 2.5.x and earlier. */
+ PyErr_Format(PyExc_KeyError, "result %d larger than sys.maxunicode",
+ code);
+ return NULL;
+ }
+#endif
str[0] = (Py_UNICODE) code;
- return PyUnicode_FromUnicode(str, 1);
+ return PyUnicode_FromUnicode(str, 1);
}
/* XXX Add doc strings. */
More information about the Python-checkins
mailing list