diff --git a/Lib/test/output/test_unicode b/Lib/test/output/test_unicode index 82ed2400751..2930d645176 100644 --- a/Lib/test/output/test_unicode +++ b/Lib/test/output/test_unicode @@ -6,3 +6,16 @@ Testing builtin unicode()... done. Testing builtin codecs... done. Testing standard mapping codecs... 0-127... 128-255... done. Testing Unicode string concatenation... done. +Testing Unicode printing... abc +abc def +abc def +abc def +abc + +abc +abc +def + +def + +done. diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index eff11cfa6a4..b859fbb77e5 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -644,3 +644,16 @@ verify((u"abc" "def") == u"abcdef") verify((u"abc" u"def" "ghi") == u"abcdefghi") verify(("abc" "def" u"ghi") == u"abcdefghi") print 'done.' + +print 'Testing Unicode printing...', +print u'abc' +print u'abc', u'def' +print u'abc', 'def' +print 'abc', u'def' +print u'abc\n' +print u'abc\n', +print u'abc\n', +print u'def\n' +print u'def\n' +print 'done.' + diff --git a/Python/ceval.c b/Python/ceval.c index b7077343496..21ee3dbb96c 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1349,14 +1349,24 @@ eval_frame(PyFrameObject *f) err = PyFile_WriteString(" ", w); if (err == 0) err = PyFile_WriteObject(v, w, Py_PRINT_RAW); - if (err == 0 && PyString_Check(v)) { + if (err == 0) { /* XXX move into writeobject() ? */ - char *s = PyString_AsString(v); - int len = PyString_Size(v); + if (PyString_Check(v)) { + char *s = PyString_AS_STRING(v); + int len = PyString_GET_SIZE(v); if (len > 0 && isspace(Py_CHARMASK(s[len-1])) && s[len-1] != ' ') PyFile_SoftSpace(w, 0); + } + else if (PyUnicode_Check(v)) { + Py_UNICODE *s = PyUnicode_AS_UNICODE(v); + int len = PyUnicode_GET_SIZE(v); + if (len > 0 && + Py_UNICODE_ISSPACE(s[len-1]) && + s[len-1] != ' ') + PyFile_SoftSpace(w, 0); + } } Py_DECREF(v); Py_XDECREF(stream);