summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-08-15 07:32:56 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-08-15 07:32:56 (GMT)
commit47383403a0a11259acb640406a8efc38981d2255 (patch)
treead461e275dc3f2607bab86bb596366d71489b453 /Python/ast.c
parent32c4ac014387d3bffea5461339b8ad3044d0dafb (diff)
downloadcpython-47383403a0a11259acb640406a8efc38981d2255.zip
cpython-47383403a0a11259acb640406a8efc38981d2255.tar.gz
cpython-47383403a0a11259acb640406a8efc38981d2255.tar.bz2
Implement PEP 3131. Add isidentifier to str.
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 5426c02..c13d093 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -47,8 +47,27 @@ static PyObject *parsestrplus(struct compiling *, const node *n,
#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;