From 9a90900da59816b4d376c47b94b5513b849db070 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 18 Oct 2010 20:59:24 +0000 Subject: [PATCH] PyUnicode_FromFormatV(): Fix %A format It was not completly implemented. Add a test. --- Lib/test/test_unicode.py | 9 ++++++--- Objects/unicodeobject.c | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 5e96ba8b63b..94035ef597e 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -1380,20 +1380,23 @@ class UnicodeTest(string_tests.CommonTest, self.assertEqual("{}".format(s), '__str__ overridden') def test_from_format(self): - # Ensure that PyUnicode_FromFormat() raises an error for a non-ascii - # format string. from _testcapi import format_unicode # ascii format, non-ascii argument text = format_unicode(b'ascii\x7f=%U', 'unicode\xe9') self.assertEqual(text, 'ascii\x7f=unicode\xe9') - # non-ascii format, ascii argument + # non-ascii format, ascii argument: ensure that PyUnicode_FromFormat() + # raises an error for a non-ascii format string. self.assertRaisesRegexp(ValueError, '^PyUnicode_FromFormatV\(\) expects an ASCII-encoded format ' 'string, got a non-ASCII byte: 0xe9$', format_unicode, b'unicode\xe9=%s', 'ascii') + # other tests + text = format_unicode(b'%%A:%A', 'abc\xe9\uabcd\U0010ffff') + self.assertEqual(text, r"%A:'abc\xe9\uabcd\U0010ffff'") + # Test PyUnicode_AsWideChar() def test_aswidechar(self): from _testcapi import unicode_aswidechar diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 0e2f95018a5..7564b67a215 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1074,6 +1074,7 @@ PyUnicode_FromFormatV(const char *format, va_list vargs) } case 'S': case 'R': + case 'A': { Py_UNICODE *ucopy; Py_ssize_t usize;