Commit f1e0b3f6 authored by Martin v. Löwis's avatar Martin v. Löwis

Bug #1704793: Return UTF-16 pair if unicodedata.lookup cannot

represent the result in a single character.
parent f25e35b9
...@@ -214,6 +214,9 @@ class UnicodeMiscTest(UnicodeDatabaseTest): ...@@ -214,6 +214,9 @@ class UnicodeMiscTest(UnicodeDatabaseTest):
count += 1 count += 1
self.assert_(count >= 10) # should have tested at least the ASCII digits self.assert_(count >= 10) # should have tested at least the ASCII digits
def test_bug_1704793(self):
self.assertEquals(self.db.lookup("GOTHIC LETTER FAIHU"), u'\U00010346')
def test_main(): def test_main():
test.test_support.run_unittest( test.test_support.run_unittest(
UnicodeMiscTest, UnicodeMiscTest,
......
...@@ -238,6 +238,9 @@ Core and builtins ...@@ -238,6 +238,9 @@ Core and builtins
Library Library
------- -------
- Bug #1704793: Return UTF-16 pair if unicodedata.lookup cannot
represent the result in a single character.
- Bug #978833: Close https sockets by releasing the _ssl object. - Bug #978833: Close https sockets by releasing the _ssl object.
- Change location of the package index to pypi.python.org/pypi - Change location of the package index to pypi.python.org/pypi
......
...@@ -1077,8 +1077,7 @@ static PyObject * ...@@ -1077,8 +1077,7 @@ static PyObject *
unicodedata_lookup(PyObject* self, PyObject* args) unicodedata_lookup(PyObject* self, PyObject* args)
{ {
Py_UCS4 code; Py_UCS4 code;
Py_UNICODE str[1]; Py_UNICODE str[2];
char errbuf[256];
char* name; char* name;
int namelen; int namelen;
...@@ -1086,22 +1085,18 @@ unicodedata_lookup(PyObject* self, PyObject* args) ...@@ -1086,22 +1085,18 @@ unicodedata_lookup(PyObject* self, PyObject* args)
return NULL; return NULL;
if (!_getcode(self, name, namelen, &code)) { if (!_getcode(self, name, namelen, &code)) {
/* XXX(nnorwitz): why are we allocating for the error msg? PyErr_Format(PyExc_KeyError, "undefined character name '%s'",
Why not always use snprintf? */ name);
char fmt[] = "undefined character name '%s'";
char *buf = PyMem_MALLOC(sizeof(fmt) + namelen);
if (buf)
sprintf(buf, fmt, name);
else {
buf = errbuf;
PyOS_snprintf(buf, sizeof(errbuf), fmt, name);
}
PyErr_SetString(PyExc_KeyError, buf);
if (buf != errbuf)
PyMem_FREE(buf);
return NULL; return NULL;
} }
#ifndef Py_UNICODE_WIDE
if (code >= 0x10000) {
str[0] = 0xd800 + ((code - 0x10000) >> 10);
str[1] = 0xdc00 + ((code - 0x10000) & 0x3ff);
return PyUnicode_FromUnicode(str, 2);
}
#endif
str[0] = (Py_UNICODE) code; str[0] = (Py_UNICODE) code;
return PyUnicode_FromUnicode(str, 1); return PyUnicode_FromUnicode(str, 1);
} }
......
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