Mercurial > cpython-lru_cache-weakref
diff Python/ast.c @ 42597:20477cbfd996
Implement PEP 3131. Add isidentifier to str.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Wed, 15 Aug 2007 07:32:56 +0000 |
| parents | 65f1d419f631 |
| children | 981ecc526703 |
line wrap: on
line diff
--- a/Python/ast.c Wed Aug 15 03:56:40 2007 +0000 +++ b/Python/ast.c Wed Aug 15 07:32:56 2007 +0000 @@ -47,8 +47,27 @@ #define COMP_SETCOMP 2 static identifier -new_identifier(const char* n, PyArena *arena) { +new_identifier(const char* n, PyArena *arena) +{ PyObject* id = PyUnicode_DecodeUTF8(n, strlen(n), NULL); + Py_UNICODE *u = PyUnicode_AS_UNICODE(id); + /* Check whether there are non-ASCII characters in the + identifier; if so, normalize to NFKC. */ + for (; *u; u++) { + if (*u >= 128) { + PyObject *m = PyImport_ImportModule("unicodedata"); + PyObject *id2; + if (!m) + return NULL; + id2 = PyObject_CallMethod(m, "normalize", "sO", "NFKC", id); + Py_DECREF(m); + if (!id2) + return NULL; + Py_DECREF(id); + id = id2; + break; + } + } PyUnicode_InternInPlace(&id); PyArena_AddPyObject(arena, id); return id;
