[Python-checkins] commit of r41728 - in python: branches/release24-maint/Lib/test/test_unicode.py branches/release24-maint/Misc/NEWS branches/release24-maint/Objects/unicodeobject.c trunk/Lib/test/test_unicode.py trunk/Misc/NEWS trunk/Objects/unicodeobject.c
hyeshik.chang
python-checkins at python.org
Sat Dec 17 05:38:34 CET 2005
Author: hyeshik.chang
Date: Sat Dec 17 05:38:31 2005
New Revision: 41728
Modified:
python/branches/release24-maint/Lib/test/test_unicode.py
python/branches/release24-maint/Misc/NEWS
python/branches/release24-maint/Objects/unicodeobject.c
python/trunk/Lib/test/test_unicode.py
python/trunk/Misc/NEWS
python/trunk/Objects/unicodeobject.c
Log:
Bug #1379994: Fix *unicode_escape codecs to encode r'\' as r'\\'
just like string codecs.
Modified: python/branches/release24-maint/Lib/test/test_unicode.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_unicode.py (original)
+++ python/branches/release24-maint/Lib/test/test_unicode.py Sat Dec 17 05:38:31 2005
@@ -611,20 +611,24 @@
self.assertEqual(u'hello'.encode('latin-1'), 'hello')
# Roundtrip safety for BMP (just the first 1024 chars)
- u = u''.join(map(unichr, xrange(1024)))
- for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le', 'utf-16-be',
- 'raw_unicode_escape', 'unicode_escape', 'unicode_internal'):
- self.assertEqual(unicode(u.encode(encoding),encoding), u)
+ for c in xrange(1024):
+ u = unichr(c)
+ for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le',
+ 'utf-16-be', 'raw_unicode_escape',
+ 'unicode_escape', 'unicode_internal'):
+ self.assertEqual(unicode(u.encode(encoding),encoding), u)
# Roundtrip safety for BMP (just the first 256 chars)
- u = u''.join(map(unichr, xrange(256)))
- for encoding in ('latin-1',):
- self.assertEqual(unicode(u.encode(encoding),encoding), u)
+ for c in xrange(256):
+ u = unichr(c)
+ for encoding in ('latin-1',):
+ self.assertEqual(unicode(u.encode(encoding),encoding), u)
# Roundtrip safety for BMP (just the first 128 chars)
- u = u''.join(map(unichr, xrange(128)))
- for encoding in ('ascii',):
- self.assertEqual(unicode(u.encode(encoding),encoding), u)
+ for c in xrange(128):
+ u = unichr(c)
+ for encoding in ('ascii',):
+ self.assertEqual(unicode(u.encode(encoding),encoding), u)
# Roundtrip safety for non-BMP (just a few chars)
u = u'\U00010001\U00020002\U00030003\U00040004\U00050005'
Modified: python/branches/release24-maint/Misc/NEWS
==============================================================================
--- python/branches/release24-maint/Misc/NEWS (original)
+++ python/branches/release24-maint/Misc/NEWS Sat Dec 17 05:38:31 2005
@@ -12,6 +12,9 @@
Core and builtins
-----------------
+- Bug #1379994: Builtin unicode_escape and raw_unicode_escape codec
+ now encodes backslash correctly.
+
- Bug #1281408: Py_BuildValue now works correct even with unsigned longs
and long longs.
Modified: python/branches/release24-maint/Objects/unicodeobject.c
==============================================================================
--- python/branches/release24-maint/Objects/unicodeobject.c (original)
+++ python/branches/release24-maint/Objects/unicodeobject.c Sat Dec 17 05:38:31 2005
@@ -1981,9 +1981,9 @@
while (size-- > 0) {
Py_UNICODE ch = *s++;
- /* Escape quotes */
- if (quotes &&
- (ch == (Py_UNICODE) PyString_AS_STRING(repr)[1] || ch == '\\')) {
+ /* Escape quotes and backslashes */
+ if ((quotes &&
+ ch == (Py_UNICODE) PyString_AS_STRING(repr)[1]) || ch == '\\') {
*p++ = '\\';
*p++ = (char) ch;
continue;
Modified: python/trunk/Lib/test/test_unicode.py
==============================================================================
--- python/trunk/Lib/test/test_unicode.py (original)
+++ python/trunk/Lib/test/test_unicode.py Sat Dec 17 05:38:31 2005
@@ -615,20 +615,24 @@
self.assertEqual(u'hello'.encode('latin-1'), 'hello')
# Roundtrip safety for BMP (just the first 1024 chars)
- u = u''.join(map(unichr, xrange(1024)))
- for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le', 'utf-16-be',
- 'raw_unicode_escape', 'unicode_escape', 'unicode_internal'):
- self.assertEqual(unicode(u.encode(encoding),encoding), u)
+ for c in xrange(1024):
+ u = unichr(c)
+ for encoding in ('utf-7', 'utf-8', 'utf-16', 'utf-16-le',
+ 'utf-16-be', 'raw_unicode_escape',
+ 'unicode_escape', 'unicode_internal'):
+ self.assertEqual(unicode(u.encode(encoding),encoding), u)
# Roundtrip safety for BMP (just the first 256 chars)
- u = u''.join(map(unichr, xrange(256)))
- for encoding in ('latin-1',):
- self.assertEqual(unicode(u.encode(encoding),encoding), u)
+ for c in xrange(256):
+ u = unichr(c)
+ for encoding in ('latin-1',):
+ self.assertEqual(unicode(u.encode(encoding),encoding), u)
# Roundtrip safety for BMP (just the first 128 chars)
- u = u''.join(map(unichr, xrange(128)))
- for encoding in ('ascii',):
- self.assertEqual(unicode(u.encode(encoding),encoding), u)
+ for c in xrange(128):
+ u = unichr(c)
+ for encoding in ('ascii',):
+ self.assertEqual(unicode(u.encode(encoding),encoding), u)
# Roundtrip safety for non-BMP (just a few chars)
u = u'\U00010001\U00020002\U00030003\U00040004\U00050005'
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Sat Dec 17 05:38:31 2005
@@ -12,6 +12,9 @@
Core and builtins
-----------------
+- Bug #1379994: Builtin unicode_escape and raw_unicode_escape codec
+ now encodes backslash correctly.
+
- Patch #1350409: Work around signal handling bug in Visual Studio 2005.
- Bug #1281408: Py_BuildValue now works correct even with unsigned longs
Modified: python/trunk/Objects/unicodeobject.c
==============================================================================
--- python/trunk/Objects/unicodeobject.c (original)
+++ python/trunk/Objects/unicodeobject.c Sat Dec 17 05:38:31 2005
@@ -1989,9 +1989,9 @@
while (size-- > 0) {
Py_UNICODE ch = *s++;
- /* Escape quotes */
- if (quotes &&
- (ch == (Py_UNICODE) PyString_AS_STRING(repr)[1] || ch == '\\')) {
+ /* Escape quotes and backslashes */
+ if ((quotes &&
+ ch == (Py_UNICODE) PyString_AS_STRING(repr)[1]) || ch == '\\') {
*p++ = '\\';
*p++ = (char) ch;
continue;
More information about the Python-checkins
mailing list