[Python-3000-checkins] r55231 - in python/branches/py3k-struni: Lib/test/test_array.py Modules/arraymodule.c

guido.van.rossum python-3000-checkins at python.org
Thu May 10 20:41:36 CEST 2007


Author: guido.van.rossum
Date: Thu May 10 20:41:30 2007
New Revision: 55231

Modified:
   python/branches/py3k-struni/Lib/test/test_array.py
   python/branches/py3k-struni/Modules/arraymodule.c
Log:
Fix the array tests.  Only a minor change to the C code was required.


Modified: python/branches/py3k-struni/Lib/test/test_array.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_array.py	(original)
+++ python/branches/py3k-struni/Lib/test/test_array.py	Thu May 10 20:41:30 2007
@@ -755,32 +755,28 @@
 if test_support.have_unicode:
     class UnicodeTest(StringTest):
         typecode = 'u'
-        example = str(r'\x01\u263a\x00\ufeff', 'unicode-escape')
-        smallerexample = str(r'\x01\u263a\x00\ufefe', 'unicode-escape')
-        biggerexample = str(r'\x01\u263a\x01\ufeff', 'unicode-escape')
+        example = '\x01\u263a\x00\ufeff'
+        smallerexample = '\x01\u263a\x00\ufefe'
+        biggerexample = '\x01\u263a\x01\ufeff'
         outside = str('\x33')
         minitemsize = 2
 
         def test_unicode(self):
-            self.assertRaises(TypeError, array.array, 'b', str('foo', 'ascii'))
+            self.assertRaises(TypeError, array.array, 'b', 'foo')
 
-            a = array.array('u', str(r'\xa0\xc2\u1234', 'unicode-escape'))
-            a.fromunicode(str(' ', 'ascii'))
-            a.fromunicode(str('', 'ascii'))
-            a.fromunicode(str('', 'ascii'))
-            a.fromunicode(str(r'\x11abc\xff\u1234', 'unicode-escape'))
+            a = array.array('u', '\xa0\xc2\u1234')
+            a.fromunicode(' ')
+            a.fromunicode('')
+            a.fromunicode('')
+            a.fromunicode('\x11abc\xff\u1234')
             s = a.tounicode()
-            self.assertEqual(
-                s,
-                str(r'\xa0\xc2\u1234 \x11abc\xff\u1234', 'unicode-escape')
-            )
+            self.assertEqual(s, '\xa0\xc2\u1234 \x11abc\xff\u1234')
 
-            s = str(r'\x00="\'a\\b\x80\xff\u0000\u0001\u1234', 'unicode-escape')
+            s = '\x00="\'a\\b\x80\xff\u0000\u0001\u1234'
             a = array.array('u', s)
             self.assertEqual(
                 repr(a),
-                r"""array('u', u'\x00="\'a\\b\x80\xff\x00\x01\u1234')"""
-            )
+                "array('u', '\\x00=\"\\'a\\\\b\\x80\\xff\\x00\\x01\\u1234')")
 
             self.assertRaises(TypeError, a.fromunicode)
 

Modified: python/branches/py3k-struni/Modules/arraymodule.c
==============================================================================
--- python/branches/py3k-struni/Modules/arraymodule.c	(original)
+++ python/branches/py3k-struni/Modules/arraymodule.c	Thu May 10 20:41:30 2007
@@ -104,7 +104,9 @@
 static PyObject *
 c_getitem(arrayobject *ap, Py_ssize_t i)
 {
-	return PyString_FromStringAndSize(&((char *)ap->ob_item)[i], 1);
+	Py_UNICODE buf[1];
+	buf[0] = ((unsigned char *)ap->ob_item)[i];
+	return PyUnicode_FromUnicode(buf, 1);
 }
 
 static int


More information about the Python-3000-checkins mailing list