Author: walter.doerwald
Date: Mon Jun 11 16:55:19 2007
New Revision: 55892

Modified:
   python/branches/py3k-struni/Lib/test/test_descr.py
   python/branches/py3k-struni/Objects/typeobject.c
Log:
Check unicode identifier directly instead of converting
it to an 8bit string first.


Modified: python/branches/py3k-struni/Lib/test/test_descr.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_descr.py  (original)
+++ python/branches/py3k-struni/Lib/test/test_descr.py  Mon Jun 11 16:55:19 2007
@@ -1085,6 +1085,13 @@
         raise TestFailed, "['foo\\0bar'] slots not caught"
     try:
         class C(object):
+            __slots__ = ["foo\u1234bar"]
+    except TypeError:
+        pass
+    else:
+        raise TestFailed, "['foo\\u1234bar'] slots not caught"
+    try:
+        class C(object):
             __slots__ = ["1"]
     except TypeError:
         pass

Modified: python/branches/py3k-struni/Objects/typeobject.c
==============================================================================
--- python/branches/py3k-struni/Objects/typeobject.c    (original)
+++ python/branches/py3k-struni/Objects/typeobject.c    Mon Jun 11 16:55:19 2007
@@ -1561,7 +1561,7 @@
 static int
 valid_identifier(PyObject *s)
 {
-       unsigned char *p;
+       Py_UNICODE *p;
        Py_ssize_t i, n;
 
        if (!PyUnicode_Check(s)) {
@@ -1570,14 +1570,14 @@
                             s->ob_type->tp_name);
                return 0;
        }
-       p = (unsigned char *) PyUnicode_AsString(s);
-       n = strlen((char*)p)/*XXX PyString_GET_SIZE(s)*/;
+       p = PyUnicode_AS_UNICODE(s);
+       n = PyUnicode_GET_SIZE(s);
        /* We must reject an empty name.  As a hack, we bump the
           length to 1 so that the loop will balk on the trailing \0. */
        if (n == 0)
                n = 1;
        for (i = 0; i < n; i++, p++) {
-               if (!(i == 0 ? isalpha(*p) : isalnum(*p)) && *p != '_') {
+               if (i > 255 || (!(i == 0 ? isalpha(*p) : isalnum(*p)) && *p != 
'_')) {
                        PyErr_SetString(PyExc_TypeError,
                                        "__slots__ must be identifiers");
                        return 0;
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to